MyMessage.vue 9.9 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 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 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 174 175 176 177 178 179 180 181 182 183 184 185 186 187
<template>
	<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>

					<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">
								<el-button @click="refreshMessageDialogVisible = false">取 消</el-button>
								<el-button type="primary" @click.prevent="refreshMessage()">确 定</el-button>
							</span>
						</el-dialog>
					</el-form-item>

					<el-form-item>
						<el-button size="small" type="primary" @click="prepareMeaasge">私信点赞收藏</el-button>
						<el-dialog title="提示" :visible.sync="messageDialogVisible" width="30%" :before-close="handleClose">
							<span>确认处理私信点赞收藏吗?</span>
							<span slot="footer" class="dialog-footer">
								<el-button @click="messageDialogVisible = false">取 消</el-button>
								<el-button type="primary" @click.prevent="messageDeal()">确 定</el-button>
							</span>
						</el-dialog>
					</el-form-item>
				</el-form>
				<el-table 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>

					<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>

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

					<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="prepareDealMessageOne(props.row.userName)" size="small">私信</el-button>
							<el-dialog title="提示" :visible.sync="dealMessageOneVisible" width="30%" :before-close="handleClose">
								<span>确认私信吗?</span>
								<span slot="footer" class="dialog-footer">
									<el-button @click="dealMessageOneVisible = false">取 消</el-button>
									<el-button type="primary" @click.prevent="dealMessageOne(currentUserName)">确 定</el-button>
								</span>
							</el-dialog>
							<el-button type="danger" @click="prepareDelete(props.row.id)" size="small">删除</el-button>
							<el-dialog title="提示" :visible.sync="deleteDialogVisible" width="30%" :before-close="handleClose">
								<span>确认删除?</span>
								<span slot="footer" class="dialog-footer">
									<el-button @click="deleteDialogVisible = false">取 消</el-button>
									<el-button type="primary" @click.prevent="onDelete(currentRowId)">确 定</el-button>
								</span>
							</el-dialog>
						</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>
</template>

<script>
import axios from 'axios'
export default {
	name: 'MyMessage',

	data() {
		return {
			formInline: {
				userName: '',
				nickName: '',
				hasRepliedInfo: null,
			},
			hasRepliedInfo: [
				{
					type: -1,
					name: '全部',
				},
				{
					type: 0,
					name: '未回复',
				},
				{ type: 1, name: '已回复' },
			],
			deleteDialogVisible: false,
			dealMessageOneVisible: false,
			messageDialogVisible: false,
			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: {
		prepareMeaasge() {
			this.messageDialogVisible = true
		},
		prepareRefreshMessage() {
			this.refreshMessageDialogVisible = true
		},
		prepareDelete(id) {
			this.currentRowId = id
			this.deleteDialogVisible = true
		},
		prepareDealMessageOne(userName) {
			this.currentUserName = userName
			this.dealMessageOneVisible = true
		},

		handleClose(done) {
			this.$confirm('确认关闭?')
				.then((_) => {
					done()
				})
				.catch((_) => {})
		},
		handleConfirm(addType) {
			this.dialogFormVisible = false // 关闭对话框
			this.dialogMutiFormVisible = false
			this.addUser(addType) // 发送请求
		},
		async messagePage() {
			this.loading = true
188
			const { data: res } = await axios.post('http://localhost:80/csdn/message/page', {
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211
				page: this.currentPage,
				pageSize: this.pageSize,
				userName: this.formInline.userName,
				nickName: this.formInline.nickName,
				hasReplied: this.formInline.hasRepliedInfo == -1 ? null : this.formInline.hasRepliedInfo,
			})
			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
		},

		async dealMessageOne(userName) {
			this.loading = true
			this.dealMessageOneVisible = false
212
			const { data: res } = await axios.get('http://localhost:80/csdn/message/dealMessageOne?userName=' + userName)
213 214 215 216 217 218 219 220 221 222 223 224
			if (res.code === 200) {
				this.currentUserName = null
				this.messagePage()
			} else {
				console.error('Received non-200 status code', res)
			}
			this.loading = false
		},

		async messageDeal() {
			this.loading = true
			this.messageDialogVisible = false
225
			const { data: res1 } = await axios.get('http://localhost:80/csdn/message/dealMessage')
226 227 228 229 230
			if (res1.code === 200) {
				this.messagePage()
			} else {
				console.error('Received non-200 status code', res1)
			}
231
			const { data: res2 } = await axios.get('http://localhost:80/csdn/likeCollect/dealLikeCollect')
232 233 234 235 236 237 238 239 240 241
			if (res2.code === 200) {
				this.messagePage()
			} else {
				console.error('Received non-200 status code', res2)
			}
			this.loading = false
		},
		async refreshMessage() {
			this.loading = true
			this.refreshMessageDialogVisible = false
242
			const { data: res } = await axios.get('http://localhost:80/csdn/message/acquireMessage')
243 244 245 246 247 248 249 250 251
			if (res.code === 200) {
				this.messagePage()
			} else {
				console.error('Received non-200 status code', res)
			}
			this.loading = false
		},
		async onDelete(id) {
			this.loading = true
252
			const { data: res } = await axios.get('http://localhost:80/csdn/user/delete', {
253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332
				params: {
					id: id,
				},
			})
			this.deleteDialogVisible = false
			this.messagePage()
			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'
			}
		},
	},
}
</script>

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

.el-aside {
	color: #333;
}

.pagination {
	margin-top: 16px;
	text-align: right;
}
.header-button-item {
	margin-right: 15px;
	font-size: 20px;
}

.red-title {
	line-height: 24px;
	font-size: 18px;
	color: red;
}

.backtop {
	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;
}
.custom-textarea {
	width: 100%;
	text-align: left;
}
.backtop:hover {
	background-color: #0050a0;
}
</style>