From 5e2aafeede13d337380f736567caf74f49713be7 Mon Sep 17 00:00:00 2001
From: linwe <872216996@qq.com>
Date: Fri, 09 Aug 2024 14:38:32 +0800
Subject: [PATCH] 代码优化
---
src/views/article/articleComment.vue | 385 ++++++++++++++++++++++++++++++-------------------------
1 files changed, 210 insertions(+), 175 deletions(-)
diff --git a/src/views/article/articleComment.vue b/src/views/article/articleComment.vue
index 786d536..d42b9f9 100644
--- a/src/views/article/articleComment.vue
+++ b/src/views/article/articleComment.vue
@@ -1,199 +1,234 @@
<template>
- <basicContainer>
- <avue-crud :data="dataList" ref="crud" :table-loading="loading" @current-change="currentChange"
- @search-change="searchChange" @search-reset="searchReset" @size-change="sizeChange" :option="option"
- v-model="data" :page="page" @selection-change="selectionChange" @row-del="rowDel" @refresh-change="refreshChange"
- @on-load="onLoad">
- <template slot="menuLeft">
- <!-- <el-button size="small" icon="el-icon-delete" plain v-if="permission.article_delete" @click="handleDelete">删 除
+ <basicContainer>
+ <avue-crud :data="dataList" ref="crud" :table-loading="loading" @current-change="currentChange"
+ @search-change="searchChange" @search-reset="searchReset" @size-change="sizeChange" :option="option"
+ v-model="data" :page="page" @selection-change="selectionChange" @row-del="rowDel"
+ @refresh-change="refreshChange" @on-load="onLoad">
+ <template slot="menuLeft">
+ <!-- <el-button size="small" icon="el-icon-delete" plain v-if="permission.article_delete" @click="handleDelete">删 除
</el-button> -->
- <el-button type="danger" size="small" plain icon="el-icon-delete" v-if="permission.user_delete"
- @click="handleDelete">批量删除
- </el-button>
- </template>
- </avue-crud>
- </basicContainer>
+ <el-button type="danger" size="small" plain icon="el-icon-delete" v-if="permission.user_delete"
+ @click="handleDelete">批量删除
+ </el-button>
+ </template>
+
+ <template slot-scope="{row, size}" slot="phone">
+ <el-button :size="size" type="text" @click="showStringDispose(row, 'phoneflag')"
+ v-text="textDispose(row, 'phoneflag', 'phone')">
+ </el-button>
+ </template>
+ </avue-crud>
+ </basicContainer>
</template>
<script>
- import {
+import {
getPageList,
remove,
update,
add,
getNotice,
upcomment
- } from "@/api/article/articleComment";
- import {
+} from "@/api/article/articleComment"
+import {
mapGetters
- } from "vuex";
+} from "vuex"
- import website from '@/config/website'
+import website from '@/config/website'
- export default {
- data() {
- return {
- page: {
- pageSize: 10,
- pageSizes: [10, 20, 30, 50, 100],
- currentPage: 1,
- total: 0
- },
- dataList: [],
- loading: true,
- selectionList: [],
- option: {
- selection: true,
- height: "auto",
- calcHeight: 54,
- align: 'center',
- menuAlign: 'center',
- addBtn: false,
- editBtn: false,
- searchMenuSpan: 3,
- searchBtn: true,
- column: [{
- label: '头像',
- prop: 'avatar',
- dataType: 'string',
- type: 'img',
+export default {
+ data () {
+ return {
+ page: {
+ pageSize: 10,
+ pageSizes: [10, 20, 30, 50, 100],
+ currentPage: 1,
+ total: 0
},
- {
- label: '电话',
- prop: 'phone',
- searchSpan: 4,
- search: true,
- },
- {
- label: '昵称',
- prop: 'name',
- searchSpan: 4,
- search: true,
- },
- {
- label: '标题',
- prop: 'title',
- searchSpan: 4,
- search: true,
- },
- {
- label: '评论',
- prop: 'content'
+ dataList: [],
+ loading: true,
+ selectionList: [],
+ option: {
+ labelWidth: 96,
+ searchLabelWidth: 66,
+ searchShow: true,
+ searchMenuSpan: 3,
+ menuWidth: 80,
+
+ selection: true,
+ height: "auto",
+ calcHeight: 54,
+ align: 'center',
+ menuAlign: 'center',
+ addBtn: false,
+ editBtn: false,
+ searchBtn: true,
+ column: [
+ {
+ width: 110,
+ label: '头像',
+ prop: 'avatar',
+ dataType: 'string',
+ type: 'img',
+ },
+ {
+ width: 120,
+ label: '电话',
+ prop: 'phone',
+ searchSpan: 4,
+ search: true,
+ searchLabelWidth: 46,
+ slot: true
+ },
+ {
+ width: 110,
+ label: '昵称',
+ prop: 'name',
+ searchSpan: 4,
+ search: true,
+ },
+ {
+ label: '标题',
+ prop: 'title',
+ searchSpan: 4,
+ search: true,
+ },
+ {
+ label: '评论',
+ prop: 'content'
+ }
+ ]
}
- ]
}
- }
},
computed: {
- ...mapGetters(["permission", "userInfo"]),
- permissionList() {
- return {
- addBtn: this.vaildData(this.permission.article_add, true),
- viewBtn: this.vaildData(this.permission.article_view, true),
- delBtn: this.vaildData(this.permission.article_delete, true),
- editBtn: this.vaildData(this.permission.article_edit, true),
- };
- },
- ids() {
- let ids = [];
- this.selectionList.forEach((ele) => {
- ids.push(ele.id);
- });
- return ids.join(",");
- },
+ ...mapGetters(["permission", "userInfo"]),
+ permissionList () {
+ return {
+ addBtn: this.vaildData(this.permission.article_add, true),
+ viewBtn: this.vaildData(this.permission.article_view, true),
+ delBtn: this.vaildData(this.permission.article_delete, true),
+ editBtn: this.vaildData(this.permission.article_edit, true),
+ }
+ },
+ ids () {
+ let ids = []
+ this.selectionList.forEach((ele) => {
+ ids.push(ele.id)
+ })
+ return ids.join(",")
+ },
+
+ textDispose () {
+ return (row, flag, type) => {
+ if (row[flag] || row[type] == null) {
+ return row[type]
+ } else {
+ if (type == 'principalIdCard') {
+ return row[type].replace(/^(.{6})(?:\d+)(.{4})$/, "$1******$2")
+ } else {
+ return row[type].replace(/^(.{3})(?:\d+)(.{4})$/, "$1****$2")
+ }
+ }
+ }
+ }
},
methods: {
- selectionChange(list) {
- this.selectionList = list;
- },
- rowDel(row) {
- this.$confirm("确定将选择数据删除?", {
- confirmButtonText: "确定",
- cancelButtonText: "取消",
- type: "warning",
- })
- .then(() => {
- return remove(row.id);
- })
- .then(() => {
- this.onLoad(this.page);
- this.$message({
- type: "success",
- message: "操作成功!",
- });
- });
- },
- refreshChange() {
- this.onLoad(this.page, this.query);
- },
- handleDelete() {
- if (this.selectionList.length === 0) {
- this.$message.warning("请选择至少一条数据");
- return;
- }
- this.$confirm("确定将选择数据删除?", {
- confirmButtonText: "确定",
- cancelButtonText: "取消",
- type: "warning",
- })
- .then(() => {
- return remove(this.ids);
- })
- .then(() => {
- this.onLoad(this.page);
- this.$message({
- type: "success",
- message: "操作成功!",
- });
- this.$refs.crud.toggleSelection();
- });
- },
- searchReset() {
- this.query = {};
- this.onLoad(this.page);
- },
- searchChange(params, done) {
- this.query = params;
- this.page.currentPage = 1;
- this.onLoad(this.page, params);
- done();
- },
- currentChange(currentPage) {
- console.log(currentPage)
- this.page.currentPage = currentPage;
- },
- sizeChange(pageSize) {
- console.log(pageSize)
- this.page.pageSize = pageSize;
- },
- onLoad(page, params = {}) {
- let values = {
- ...params,
- };
- this.loading = true;
- getPageList(page.currentPage, page.pageSize, values).then((res) => {
- const data = res.data.data;
- this.page.total = data.total;
- this.dataList = data.records;
- this.dataList.forEach(item => {
- if (item.avatar) {
- // var urls = []
- // var names = item.avatar.split(",")
- // names.forEach(name => {
- // urls.push(website.minioUrl + name)
- // })
- item.avatar = website.minioUrl + item.avatar
+ showStringDispose (row, type) {
+ row[type] = !row[type]
+ },
+
+ selectionChange (list) {
+ this.selectionList = list
+ },
+ rowDel (row) {
+ this.$confirm("确定将选择数据删除?", {
+ confirmButtonText: "确定",
+ cancelButtonText: "取消",
+ type: "warning",
+ })
+ .then(() => {
+ return remove(row.id)
+ })
+ .then(() => {
+ this.onLoad(this.page)
+ this.$message({
+ type: "success",
+ message: "操作成功!",
+ })
+ })
+ },
+ refreshChange () {
+ this.onLoad(this.page, this.query)
+ },
+ handleDelete () {
+ if (this.selectionList.length === 0) {
+ this.$message.warning("请选择至少一条数据")
+ return
}
- })
- this.loading = false;
- });
- },
- selectionClear() {
- this.selectionList = [];
- this.$refs.crud.toggleSelection();
- },
+ this.$confirm("确定将选择数据删除?", {
+ confirmButtonText: "确定",
+ cancelButtonText: "取消",
+ type: "warning",
+ })
+ .then(() => {
+ return remove(this.ids)
+ })
+ .then(() => {
+ this.onLoad(this.page)
+ this.$message({
+ type: "success",
+ message: "操作成功!",
+ })
+ this.$refs.crud.toggleSelection()
+ })
+ },
+ searchReset () {
+ this.query = {}
+ this.onLoad(this.page)
+ },
+ searchChange (params, done) {
+ this.query = params
+ this.page.currentPage = 1
+ this.onLoad(this.page, params)
+ done()
+ },
+ currentChange (currentPage) {
+ console.log(currentPage)
+ this.page.currentPage = currentPage
+ },
+ sizeChange (pageSize) {
+ console.log(pageSize)
+ this.page.pageSize = pageSize
+ },
+ onLoad (page, params = {}) {
+ let values = {
+ ...params,
+ }
+ this.loading = true
+ getPageList(page.currentPage, page.pageSize, values).then((res) => {
+ const data = res.data.data
+ this.page.total = data.total
+ this.dataList = data.records
+ this.dataList.forEach(item => {
+ this.$set(item, 'phoneflag', false)
+ if (item.avatar) {
+ // var urls = []
+ // var names = item.avatar.split(",")
+ // names.forEach(name => {
+ // urls.push(website.minioUrl + name)
+ // })
+ item.avatar = website.minioUrl + item.avatar
+ }
+ })
+ this.loading = false
+ })
+ },
+ selectionClear () {
+ this.selectionList = []
+ this.$refs.crud.toggleSelection()
+ },
}
- }
+}
</script>
-<style>
-</style>
\ No newline at end of file
+<style></style>
\ No newline at end of file
--
Gitblit v1.9.3