利用elementPlus写一个查看用户评价的页面vue
时间: 2023-12-03 18:43:45 浏览: 85
好的,以下是一个简单的利用Element Plus实现的查看用户评价的页面:
```html
<template>
<div class="user-comment-view">
<el-card>
<el-row>
<el-col :span="6">
<el-form :inline="true" class="search-form">
<el-form-item label="用户名">
<el-input v-model="username" placeholder="请输入用户名"></el-input>
</el-form-item>
<el-form-item label="评价状态">
<el-select v-model="status" placeholder="请选择">
<el-option label="全部" value=""></el-option>
<el-option label="待审核" value="pending"></el-option>
<el-option label="已通过" value="approved"></el-option>
<el-option label="未通过" value="rejected"></el-option>
</el-select>
</el-form-item>
<el-form-item>
<el-button type="primary" @click="search">搜索</el-button>
</el-form-item>
</el-form>
</el-col>
<el-col :span="18" style="text-align: right;">
<el-button type="primary" icon="el-icon-plus" @click="addComment">添加评价</el-button>
</el-col>
</el-row>
<el-table :data="comments" style="width: 100%">
<el-table-column prop="id" label="ID" width="80"></el-table-column>
<el-table-column prop="username" label="用户名"></el-table-column>
<el-table-column prop="content" label="评价内容"></el-table-column>
<el-table-column prop="status" label="状态">
<template v-slot="{ row }">
<el-tag :type="getStatusTagType(row.status)">{{ getStatusLabel(row.status) }}</el-tag>
</template>
</el-table-column>
<el-table-column label="操作" width="160">
<template v-slot="{ row }">
<el-button type="text" size="small" @click="editComment(row)">编辑</el-button>
<el-button type="text" size="small" @click="deleteComment(row.id)">删除</el-button>
</template>
</el-table-column>
</el-table>
<el-pagination
:current-page="currentPage"
:page-size="pageSize"
:total="total"
layout="total, sizes, prev, pager, next, jumper"
@size-change="handleSizeChange"
@current-change="handleCurrentPageChange"
></el-pagination>
</el-card>
</div>
</template>
<script>
import { mapActions } from "vuex";
export default {
name: "UserCommentView",
data() {
return {
username: "",
status: "",
currentPage: 1,
pageSize: 10,
total: 0,
comments: [],
};
},
methods: {
...mapActions(["fetchComments", "deleteComment"]),
getStatusLabel(status) {
switch (status) {
case "pending":
return "待审核";
case "approved":
return "已通过";
case "rejected":
return "未通过";
default:
return "";
}
},
getStatusTagType(status) {
switch (status) {
case "pending":
return "warning";
case "approved":
return "success";
case "rejected":
return "danger";
default:
return "";
}
},
search() {
this.fetchComments({
username: this.username,
status: this.status,
page: this.currentPage,
pageSize: this.pageSize,
}).then(({ total, comments }) => {
this.total = total;
this.comments = comments;
});
},
handleSizeChange(pageSize) {
this.pageSize = pageSize;
this.search();
},
handleCurrentPageChange(currentPage) {
this.currentPage = currentPage;
this.search();
},
addComment() {
this.$router.push({ name: "AddUserComment" });
},
editComment(comment) {
this.$router.push({ name: "EditUserComment", params: { id: comment.id } });
},
deleteComment(id) {
this.$confirm("确认删除该评价吗?", "提示", { type: "warning" })
.then(() => {
this.deleteComment(id).then(() => {
this.search();
});
})
.catch(() => {});
},
},
mounted() {
this.search();
},
};
</script>
<style scoped>
.user-comment-view {
padding: 20px;
}
.search-form {
margin-bottom: 20px;
}
.el-table-column--selection {
width: 50px;
}
.el-pagination {
margin-top: 20px;
text-align: right;
}
</style>
```
此页面通过Element Plus提供的表格、分页、表单等组件来实现了查看用户评价的功能,并且可以进行搜索、分页、添加、删除、编辑评价等操作。
阅读全文