MyMessage.vue 8.5 KB
Newer Older
1
<template>
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
  <div>
    <el-container>
      <el-main>
        <el-form :inline="true" :model="formInline" class="demo-form-inline">
          <el-form-item>
            <el-input size="small" clearable v-model="formInline.userName" placeholder="请输入用户名"
                      @keydown.enter.native="messagePage"></el-input>
          </el-form-item>
          <el-form-item>
            <el-input size="small" clearable v-model="formInline.nickName" placeholder="请输入用户昵称"
                      @keydown.enter.native="messagePage"></el-input>
          </el-form-item>
          <el-form-item>
            <el-select size="small" v-model="formInline.hasRepliedInfo" placeholder="请选择收藏状态" @change="messagePage">
              <el-option v-for="item in hasRepliedInfo" :key="item.type" :label="item.name"
                         :value="item.type"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-button size="small" type="primary" @click="messagePage">查询</el-button>
          </el-form-item>
23

24 25 26 27 28
          <el-form-item>
            <el-button size="small" type="primary" @click="prepareRefreshMessage">刷新私信列表</el-button>
            <el-dialog title="提示" :visible.sync="refreshMessageDialogVisible" width="30%" :before-close="handleClose">
              <span>确认刷新私信列表吗?</span>
              <span slot="footer" class="dialog-footer">
29
								<el-button @click="refreshMessageDialogVisible = false">取 消</el-button>
30
								<el-button type="primary" @click.prevent="acquireMessage()">确 定</el-button>
31
							</span>
32 33
            </el-dialog>
          </el-form-item>
34

35 36 37 38 39 40 41 42 43 44 45 46 47
          <el-form-item>
            <el-button size="small" type="primary" @click="messageDeal">私信点赞收藏</el-button>
          </el-form-item>
        </el-form>
        <el-table  border ref="multipleTable" v-loading="loading" :data="csdnMessageList" tooltip-effect="dark"
                  style="width: 100%">
          <el-table-column prop="id" label="序号" width="100" sortable></el-table-column>
          <el-table-column prop="userName" label="用户名称" show-overflow-tooltip></el-table-column>
          <el-table-column prop="nickName" label="用户昵称" show-overflow-tooltip>
            <template slot-scope="scope">
              <a :href="scope.row.messageUrl" target="_blank">{{ scope.row.nickName }}</a>
            </template>
          </el-table-column>
48

49 50 51 52 53
          <el-table-column prop="hasRepliedName" label="是否回复" show-overflow-tooltip>
            <template slot-scope="scope">
              <el-tag :type="getTagType(scope.row.hasRepliedName)">{{ scope.row.hasRepliedName }}</el-tag>
            </template>
          </el-table-column>
54

55
          <el-table-column prop="content" label="回复内容" show-overflow-tooltip></el-table-column>
56

57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
          <el-table-column label="更新时间">
            <template slot-scope="props">
              {{ props.row.updateTime | dateFormat }}
            </template>
          </el-table-column>
          <el-table-column prop="操作" label="操作" width="380px">
            <template slot-scope="props">
              <el-button type="primary" @click="dealMessageOne(props.row.userName)" size="small">私信</el-button>
            </template>
          </el-table-column>
        </el-table>
        <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="currentPage"
                       :page-sizes="[8, 50, 100, 200, 400]" :page-size="pageSize"
                       layout="total, sizes, prev, pager, next, jumper" :total="total"></el-pagination>
      </el-main>
      <el-backtop class="backtop"></el-backtop>
    </el-container>
  </div>
75 76 77 78
</template>

<script>
import axios from 'axios'
79
import ApiService from '../../api/ApiService'
80
export default {
81
  name: 'MyMessage',
82

83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
  data() {
    return {
      formInline: {
        userName: '',
        nickName: '',
        hasRepliedInfo: null,
      },
      hasRepliedInfo: [
        {
          type: -1,
          name: '全部',
        },
        {
          type: 0,
          name: '未回复',
        },
        {type: 1, name: '已回复'},
      ],
      refreshMessageDialogVisible: false,
      // 用户列表数据
      csdnMessageList: [],
      loading: false,
      elementui_page_component_key: 0,
      currentPage: Number(localStorage.getItem('csdnUserPage')) || 1,
      pageSize: 8,
      total: 0,
      currentRowId: null,
      currentUserName: null,
    }
  },
  watch: {
    'formInline.userName'(newVal, oldVal) {
      if (newVal !== oldVal) {
        this.currentPage = 1
        localStorage.setItem('csdnUserPage', this.currentPage)
        this.messagePage()
      }
    },
    'formInline.nickName'(newVal, oldVal) {
      if (newVal !== oldVal) {
        this.currentPage = 1
        localStorage.setItem('csdnUserPage', this.currentPage)
        this.messagePage()
      }
    },
    // 监听currentPage的变化,将新值保存到localStorage中
    currentPage(newPage) {
      localStorage.setItem('csdnUserPage', newPage.toString())
    },
  },
  created() {
    //获取问题类型的枚举
    this.messagePage()
  },
  mounted() {
    this.currentPage = 1
  },
  methods: {
    prepareRefreshMessage() {
      this.refreshMessageDialogVisible = true
    },
144

145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173
    handleClose(done) {
      this.$confirm('确认关闭?')
          .then((_) => {
            done()
          })
          .catch((_) => {
          })
    },
    handleConfirm(addType) {
      this.dialogFormVisible = false // 关闭对话框
      this.dialogMutiFormVisible = false
      this.addUser(addType) // 发送请求
    },
    async messagePage() {
      this.loading = true
      const {data: res} = await ApiService.messagePage(this.currentPage, this.pageSize, this.formInline)
      if (res.code === 200) {
        this.total = res.result.totalElements
        const userWeightMap = {}
        this.hasRepliedInfo.forEach((option) => {
          userWeightMap[option.type] = option.name
        })
        res.result.content.forEach((item) => {
          item.hasRepliedName = userWeightMap[item.hasReplied]
        })
        this.csdnMessageList = res.result.content
      }
      this.loading = false
    },
174

175 176 177 178 179 180 181 182 183 184 185
    async dealMessageOne(userName) {
      this.loading = true
      const {data: res} = await ApiService.dealMessageOne(userName)
      if (res.code === 200) {
        this.currentUserName = null
        await this.messagePage()
      } else {
        console.error('Received non-200 status code', res)
      }
      this.loading = false
    },
186

187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234
    async messageDeal() {
      this.loading = true
      const {data: res1} = await ApiService.dealMessage()
      if (res1.code === 200) {
        await this.messagePage()
      } else {
        console.error('Received non-200 status code', res1)
      }
      const {data: res2} = await ApiService.dealLikeCollect()
      if (res2.code === 200) {
        await this.messagePage()
      } else {
        console.error('Received non-200 status code', res2)
      }
      this.loading = false
    },
    async acquireMessage() {
      this.loading = true
      this.refreshMessageDialogVisible = false
      const {data: res} = await ApiService.acquireMessage()
      if (res.code === 200) {
        await this.messagePage()
      } else {
        console.error('Received non-200 status code', res)
      }
      this.loading = false
    },
    refreshPage() {
      //获取问题类型的枚举
      this.messagePage()
      location.reload()
    },
    handleCurrentChange(currentPage) {
      this.currentPage = currentPage
      this.messagePage()
    },
    handleSizeChange(currentSize) {
      this.pageSize = currentSize
      this.messagePage()
    },
    getTagType(hasRepliedName) {
      if (hasRepliedName == '未回复') {
        return 'warning'
      } else {
        return 'success'
      }
    },
  },
235 236 237 238 239
}
</script>

<style lang="less" scoped>
.el-header {
240 241 242
  background-color: #b3c0d1;
  color: #333;
  line-height: 60px;
243 244 245
}

.el-aside {
246
  color: #333;
247 248 249
}

.pagination {
250 251
  margin-top: 16px;
  text-align: right;
252
}
253

254
.header-button-item {
255 256
  margin-right: 15px;
  font-size: 20px;
257 258 259
}

.red-title {
260 261 262
  line-height: 24px;
  font-size: 18px;
  color: red;
263 264 265
}

.backtop {
266 267 268 269 270 271 272 273 274 275 276 277
  position: fixed;
  bottom: 50px;
  right: 50px;
  height: 40px;
  width: 40px;
  line-height: 40px;
  text-align: center;
  border-radius: 20px;
  background-color: #007aff;
  color: #fff;
  cursor: pointer;
  z-index: 999;
278
}
279

280
.custom-textarea {
281 282
  width: 100%;
  text-align: left;
283
}
284

285
.backtop:hover {
286
  background-color: #0050a0;
287 288
}
</style>