From a6a41b4077eb791106fd369929c6f5610d06d1e5 Mon Sep 17 00:00:00 2001 From: truthhun <1272881215@qq.com> Date: Mon, 13 Mar 2023 00:05:13 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E7=AE=A1=E7=90=86=E5=90=8E?= =?UTF-8?q?=E5=8F=B0=E9=A1=B5=E9=9D=A2=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/components/FormCommentCheck.vue | 4 +++ web/pages/admin/article.vue | 12 ++++--- web/pages/admin/attachment.vue | 32 +++++------------ web/pages/admin/banner.vue | 36 +++++--------------- web/pages/admin/comment.vue | 24 +++++-------- web/pages/admin/config.vue | 4 --- web/pages/admin/dashboard.vue | 6 ++-- web/pages/admin/document/category.vue | 25 ++++---------- web/pages/admin/document/list.vue | 49 +++++++++------------------ web/pages/admin/document/recycle.vue | 33 ++++++------------ web/pages/admin/friendlink.vue | 29 +++++++--------- web/pages/admin/report.vue | 26 +++++--------- web/pages/admin/user/group.vue | 14 ++++---- web/pages/admin/user/list.vue | 34 ++++++------------- web/pages/admin/user/permission.vue | 14 ++++---- web/utils/utils.js | 25 ++++++++++++++ 16 files changed, 144 insertions(+), 223 deletions(-) diff --git a/web/components/FormCommentCheck.vue b/web/components/FormCommentCheck.vue index 0e84102..b4e6048 100644 --- a/web/components/FormCommentCheck.vue +++ b/web/components/FormCommentCheck.vue @@ -43,6 +43,10 @@ export default { type: Object, default: () => {}, }, + placeholder: { + type: String, + default: '请输入评论内容', + }, }, data() { return { diff --git a/web/pages/admin/article.vue b/web/pages/admin/article.vue index 80f6cbc..e391213 100644 --- a/web/pages/admin/article.vue +++ b/web/pages/admin/article.vue @@ -119,10 +119,12 @@ export default { '$route.query': { immediate: true, handler() { - this.search.page = parseInt(this.$route.query.page) || 1 - this.search.size = parseInt(this.$route.query.size) || 10 - this.search.wd = this.$route.query.wd || '' - + this.search = { + ...this.search, + ...this.$route.query, + page: parseInt(this.$route.query.page) || 1, + size: parseInt(this.$route.query.size) || 10, + } this.listArticle() }, }, @@ -159,7 +161,7 @@ export default { // this.listArticle() }, onSearch(search) { - this.search = { ...this.search, page: 1, ...search } + this.search = { ...this.search, ...search, page: 1 } this.$router.push({ query: this.search, }) diff --git a/web/pages/admin/attachment.vue b/web/pages/admin/attachment.vue index 31fb42f..2e0e182 100644 --- a/web/pages/admin/attachment.vue +++ b/web/pages/admin/attachment.vue @@ -43,7 +43,7 @@ - + @@ -59,6 +59,7 @@ import TableList from '~/components/TableList.vue' import FormSearch from '~/components/FormSearch.vue' import FormAttachment from '~/components/FormAttachment.vue' import { attachmentTypeOptions } from '~/utils/enum' +import { parseQueryIntArray } from '~/utils/utils' import { mapGetters } from 'vuex' export default { components: { TableList, FormSearch, FormAttachment }, @@ -93,28 +94,13 @@ export default { '$route.query': { immediate: true, handler() { - this.search.page = parseInt(this.$route.query.page) || 1 - this.search.size = parseInt(this.$route.query.size) || 10 - this.search.wd = this.$route.query.wd || '' - - // enable - if (typeof this.$route.query.enable === 'object') { - this.search.enable = (this.$route.query.enable || []).map((item) => - parseInt(item) - ) - } else if (this.$route.query.enable) { - this.search.enable = [parseInt(this.$route.query.enable) || 0] - } - - // type - if (typeof this.$route.query.type === 'object') { - this.search.type = (this.$route.query.type || []).map((item) => - parseInt(item) - ) - } else if (this.$route.query.type) { - this.search.type = [parseInt(this.$route.query.type) || 0] + this.search = { + ...this.search, + ...this.$route.query, + page: parseInt(this.$route.query.page) || 1, + size: parseInt(this.$route.query.size) || 10, + ...parseQueryIntArray(this.$route.query, ['enable', 'type']), } - this.listAttachment() }, }, @@ -151,7 +137,7 @@ export default { // this.listAttachment() }, onSearch(search) { - this.search = { ...this.search, page: 1, ...search } + this.search = { ...this.search, ...search, page: 1 } this.$router.push({ query: this.search, }) diff --git a/web/pages/admin/banner.vue b/web/pages/admin/banner.vue index d058162..b62d94a 100644 --- a/web/pages/admin/banner.vue +++ b/web/pages/admin/banner.vue @@ -46,7 +46,7 @@ @@ -65,6 +65,7 @@ import TableList from '~/components/TableList.vue' import FormSearch from '~/components/FormSearch.vue' import FormBanner from '~/components/FormBanner.vue' import { bannerTypeOptions } from '~/utils/enum' +import { parseQueryIntArray } from '~/utils/utils' import { mapGetters } from 'vuex' export default { components: { TableList, FormSearch, FormBanner }, @@ -99,28 +100,13 @@ export default { '$route.query': { immediate: true, handler() { - this.search.page = parseInt(this.$route.query.page) || 1 - this.search.size = parseInt(this.$route.query.size) || 10 - this.search.wd = this.$route.query.wd || '' - - // enable - if (typeof this.$route.query.enable === 'object') { - this.search.enable = (this.$route.query.enable || []).map((item) => - parseInt(item) - ) - } else if (this.$route.query.enable) { - this.search.enable = [parseInt(this.$route.query.enable) || 0] - } - - // type - if (typeof this.$route.query.type === 'object') { - this.search.type = (this.$route.query.type || []).map((item) => - parseInt(item) - ) - } else if (this.$route.query.type) { - this.search.type = [parseInt(this.$route.query.type) || 0] + this.search = { + ...this.search, + ...this.$route.query, + page: parseInt(this.$route.query.page) || 1, + size: parseInt(this.$route.query.size) || 10, + ...parseQueryIntArray(this.$route.query, ['enable', 'type']), } - this.listBanner() }, }, @@ -128,7 +114,6 @@ export default { async created() { this.initSearchForm() this.initTableListFields() - // await this.listBanner() }, methods: { async listBanner() { @@ -147,21 +132,18 @@ export default { this.$router.push({ query: this.search, }) - // this.listBanner() }, handlePageChange(val) { this.search.page = val this.$router.push({ query: this.search, }) - // this.listBanner() }, onSearch(search) { - this.search = { ...this.search, page: 1, ...search } + this.search = { ...this.search, ...search, page: 1 } this.$router.push({ query: this.search, }) - // this.listBanner() }, onCreate() { this.banner = {} diff --git a/web/pages/admin/comment.vue b/web/pages/admin/comment.vue index cf22603..6c57ca0 100644 --- a/web/pages/admin/comment.vue +++ b/web/pages/admin/comment.vue @@ -64,7 +64,7 @@ v-if="comment.id > 0" title="评论编审" :visible.sync="formCommentVisible" - width="640px" + width="520px" > - parseInt(item) - ) - } else if (this.$route.query.status) { - this.search.status = [parseInt(this.$route.query.status) || 0] + this.search = { + ...this.search, + ...this.$route.query, + page: parseInt(this.$route.query.page) || 1, + size: parseInt(this.$route.query.size) || 10, + ...parseQueryIntArray(this.$route.query, ['status']), } this.listComment() }, @@ -137,7 +135,6 @@ export default { async created() { this.initSearchForm() this.initTableListFields() - // await this.listComment() }, methods: { async listComment() { @@ -159,21 +156,18 @@ export default { this.$router.push({ query: this.search, }) - // this.listComment() }, handlePageChange(val) { this.search.page = val this.$router.push({ query: this.search, }) - // this.listComment() }, onSearch(search) { - this.search = { ...this.search, page: 1, ...search } + this.search = { ...this.search, ...search, page: 1 } this.$router.push({ query: this.search, }) - // this.listComment() }, onCreate() { this.comment = { id: 0 } diff --git a/web/pages/admin/config.vue b/web/pages/admin/config.vue index 09158af..ad05927 100644 --- a/web/pages/admin/config.vue +++ b/web/pages/admin/config.vue @@ -85,9 +85,6 @@ export default { immediate: true, }, }, - // created() { - // this.loadConfig() - // }, methods: { handleClick(tab) { this.activeName = tab.name @@ -96,7 +93,6 @@ export default { tab: tab.name, }, }) - // this.loadConfig() }, async loadConfig() { const res = await listConfig({ category: [this.activeName] }) diff --git a/web/pages/admin/dashboard.vue b/web/pages/admin/dashboard.vue index 0686db0..e4e8cd1 100644 --- a/web/pages/admin/dashboard.vue +++ b/web/pages/admin/dashboard.vue @@ -126,12 +126,12 @@ empty-text="您暂无权限查看环境依赖情况" > + > diff --git a/web/pages/admin/document/category.vue b/web/pages/admin/document/category.vue index 305ed79..391cee9 100644 --- a/web/pages/admin/document/category.vue +++ b/web/pages/admin/document/category.vue @@ -31,7 +31,7 @@ - parseInt(item) - ) - } else if (this.$route.query.enable) { - this.search.enable = [parseInt(this.$route.query.enable) || 0] + this.search = { + ...this.search, + ...this.$route.query, + ...parseQueryIntArray(this.$route.query, ['enable']), } - - this.search = search await this.initTableListFields() this.listCategory() }, @@ -105,8 +94,6 @@ export default { }, async created() { this.initSearchForm() - // this.initTableListFields() - // await this.listCategory() }, methods: { async listCategory() { diff --git a/web/pages/admin/document/list.vue b/web/pages/admin/document/list.vue index 0bd875d..594e77d 100644 --- a/web/pages/admin/document/list.vue +++ b/web/pages/admin/document/list.vue @@ -97,7 +97,7 @@ - + @@ -125,7 +125,11 @@ import { } from '~/api/document' import TableList from '~/components/TableList.vue' import FormSearch from '~/components/FormSearch.vue' -import { categoryToTrees } from '~/utils/utils' +import { + categoryToTrees, + parseQueryIntArray, + parseQueryBoolArray, +} from '~/utils/utils' import { documentStatusOptions, boolOptions } from '~/utils/enum' import FormUpdateDocument from '~/components/FormUpdateDocument.vue' import { mapGetters } from 'vuex' @@ -165,39 +169,21 @@ export default { '$route.query': { immediate: true, async handler() { - this.search.page = parseInt(this.$route.query.page) || 1 - this.search.size = parseInt(this.$route.query.size) || 10 - this.search.wd = this.$route.query.wd || '' - - if (typeof this.$route.query.category_id === 'object') { - this.search.category_id = (this.$route.query.category_id || []).map((item) => - parseInt(item) - ) - } else if (this.$route.query.category_id) { - this.search.category_id = [parseInt(this.$route.query.category_id) || 0] - } - - if (typeof this.$route.query.status === 'object') { - this.search.status = (this.$route.query.status || []).map((item) => - parseInt(item) - ) - } else if (this.$route.query.status) { - this.search.status = [parseInt(this.$route.query.status) || 0] - } - - if (typeof this.$route.query.is_recommend === 'object') { - this.search.is_recommend = (this.$route.query.is_recommend || []).map((item) => - item=="true" - ) - } else if (this.$route.query.is_recommend) { - this.search.is_recommend = [this.$route.query.is_recommend==="true" || false] + let search = { ...this.search, ...this.$route.query } + search.page = parseInt(this.$route.query.page) || 1 + search.size = parseInt(this.$route.query.size) || 10 + search.wd = this.$route.query.wd || '' + this.search = { + ...search, + ...parseQueryIntArray(this.$route.query, ['category_id', 'status']), + ...parseQueryBoolArray(this.$route.query, ['is_recommend']), } - // 需要先加载分类数据 if (this.trees.length === 0) { await this.listCategory() } + await this.listDocument() }, }, @@ -205,9 +191,6 @@ export default { async created() { this.initSearchForm() this.initTableListFields() - // // 需要先加载分类数据 - // await this.listCategory() - // await this.listDocument() }, methods: { async listCategory() { diff --git a/web/pages/admin/document/recycle.vue b/web/pages/admin/document/recycle.vue index e3ad396..58c5f4b 100644 --- a/web/pages/admin/document/recycle.vue +++ b/web/pages/admin/document/recycle.vue @@ -91,7 +91,7 @@ import { } from '~/api/document' import TableList from '~/components/TableList.vue' import FormSearch from '~/components/FormSearch.vue' -import { categoryToTrees } from '~/utils/utils' +import { categoryToTrees, parseQueryIntArray } from '~/utils/utils' import { documentStatusOptions } from '~/utils/enum' import { mapGetters } from 'vuex' export default { @@ -128,27 +128,14 @@ export default { '$route.query': { immediate: true, async handler() { - this.search.page = parseInt(this.$route.query.page) || 1 - this.search.size = parseInt(this.$route.query.size) || 10 - this.search.wd = this.$route.query.wd || '' - - if (typeof this.$route.query.category_id === 'object') { - this.search.category_id = (this.$route.query.category_id || []).map((item) => - parseInt(item) - ) - } else if (this.$route.query.category_id) { - this.search.category_id = [parseInt(this.$route.query.category_id) || 0] + this.search = { + ...this.search, + ...this.$route.query, + page: parseInt(this.$route.query.page) || 1, + size: parseInt(this.$route.query.size) || 10, + ...parseQueryIntArray(this.$route.query, ['category_id', 'status']), } - if (typeof this.$route.query.status === 'object') { - this.search.status = (this.$route.query.status || []).map((item) => - parseInt(item) - ) - } else if (this.$route.query.status) { - this.search.status = [parseInt(this.$route.query.status) || 0] - } - - // 需要先加载分类数据 if (this.trees.length === 0) { await this.listCategory() @@ -210,19 +197,19 @@ export default { handleSizeChange(val) { this.search.size = val this.$router.push({ - query: this.search + query: this.search, }) }, handlePageChange(val) { this.search.page = val this.$router.push({ - query: this.search + query: this.search, }) }, onSearch(search) { this.search = { ...this.search, ...search, page: 1 } this.$router.push({ - query: this.search + query: this.search, }) }, recoverRow(row) { diff --git a/web/pages/admin/friendlink.vue b/web/pages/admin/friendlink.vue index bb2e74d..aaae1c6 100644 --- a/web/pages/admin/friendlink.vue +++ b/web/pages/admin/friendlink.vue @@ -47,7 +47,7 @@ - parseInt(item) - ) - } else if (this.$route.query.enable) { - this.search.enable = [parseInt(this.$route.query.enable) || 0] + this.search = { + ...this.search, + ...this.$route.query, + page: parseInt(this.$route.query.page) || 1, + size: parseInt(this.$route.query.size) || 10, + ...parseQueryIntArray(this.$route.query, ['enable']), } this.listFriendlink() }, @@ -135,23 +133,20 @@ export default { handleSizeChange(val) { this.search.size = val this.$router.push({ - query: this.search + query: this.search, }) - // this.listFriendlink() }, handlePageChange(val) { this.search.page = val this.$router.push({ - query: this.search + query: this.search, }) - // this.listFriendlink() }, onSearch(search) { - this.search = { ...this.search, page: 1, ...search } + this.search = { ...this.search, ...search, page: 1 } this.$router.push({ - query: this.search + query: this.search, }) - // this.listFriendlink() }, onCreate() { this.friendlink = { id: 0 } diff --git a/web/pages/admin/report.vue b/web/pages/admin/report.vue index 87fb072..ef9a895 100644 --- a/web/pages/admin/report.vue +++ b/web/pages/admin/report.vue @@ -47,7 +47,7 @@ import { listReport, deleteReport } from '~/api/report' import { reportOptions } from '~/utils/enum' +import { parseQueryIntArray } from '~/utils/utils' import TableList from '~/components/TableList.vue' import FormSearch from '~/components/FormSearch.vue' import FormReport from '~/components/FormReport.vue' @@ -99,22 +100,16 @@ export default { async created() { this.initSearchForm() this.initTableListFields() - // await this.listReport() }, watch: { '$route.query': { handler() { - this.search.page = parseInt(this.$route.query.page) || 1 - this.search.size = parseInt(this.$route.query.size) || 10 - this.search.wd = this.$route.query.wd || '' - - // 判断 this.$route.query.status 是否是数组,如果不是数组,转为数组 - if (typeof this.$route.query.status === 'object') { - this.search.status = (this.$route.query.status || []).map((item) => - parseInt(item) - ) - } else if (this.$route.query.status) { - this.search.status = [parseInt(this.$route.query.status) || 0] + this.search = { + ...this.search, + ...this.$route.query, + page: parseInt(this.$route.query.page) || 1, + size: parseInt(this.$route.query.size) || 10, + ...parseQueryIntArray(this.$route.query, ['status']), } this.listReport() }, @@ -138,18 +133,15 @@ export default { this.$router.push({ query: this.search, }) - // this.listReport() }, handlePageChange(val) { this.search.page = val this.$router.push({ query: this.search, }) - // this.listReport() }, onSearch(search) { - this.search = { ...this.search, page: 1, ...search } - // this.listReport() + this.search = { ...this.search, ...search, page: 1 } this.$router.push({ query: this.search, }) diff --git a/web/pages/admin/user/group.vue b/web/pages/admin/user/group.vue index 56d3588..0340055 100644 --- a/web/pages/admin/user/group.vue +++ b/web/pages/admin/user/group.vue @@ -58,7 +58,7 @@ @@ -95,8 +95,6 @@ export default { search: { wd: '', page: 1, - // status: [], - // group_id: [], size: 10, }, groups: [], @@ -119,10 +117,12 @@ export default { '$route.query': { immediate: true, handler() { - let search = { ...this.$route.query } - search.page = parseInt(this.$route.query.page) || 1 - search.size = parseInt(this.$route.query.size) || 10 - this.search = search + this.search = { + ...this.search, + ...this.$route.query, + page: parseInt(this.$route.query.page) || 1, + size: parseInt(this.$route.query.size) || 10, + } this.listGroup() }, }, diff --git a/web/pages/admin/user/list.vue b/web/pages/admin/user/list.vue index 7514e61..9dfd6ac 100644 --- a/web/pages/admin/user/list.vue +++ b/web/pages/admin/user/list.vue @@ -59,7 +59,7 @@ - parseInt(item) - ) - } else if (this.$route.query.group_id) { - search.group_id = [parseInt(this.$route.query.group_id) || 0] - } - - // status - if (typeof this.$route.query.status === 'object') { - search.status = (this.$route.query.status || []).map((item) => - parseInt(item) - ) - } else if (this.$route.query.status) { - search.status = [parseInt(this.$route.query.status) || 0] + this.search = { + ...this.search, + ...this.$route.query, + page: parseInt(this.$route.query.page) || 1, + size: parseInt(this.$route.query.size) || 10, + ...parseQueryIntArray(this.$route.query, ['group_id', 'status']), } - this.search = search // 这里要执行下初始化,避免数据请求回来了,但是表格字段还没初始化,导致列表布局错乱 await this.initTableListFields() this.listUser() @@ -195,7 +181,7 @@ export default { }) }, onSearch(search) { - this.search = { ...this.search, page: 1, ...search } + this.search = { ...this.search, ...search, page: 1 } this.$router.push({ query: this.search, }) diff --git a/web/pages/admin/user/permission.vue b/web/pages/admin/user/permission.vue index 23ad5d2..0059311 100644 --- a/web/pages/admin/user/permission.vue +++ b/web/pages/admin/user/permission.vue @@ -41,7 +41,7 @@ - + @@ -87,10 +87,12 @@ export default { '$route.query': { immediate: true, handler() { - let search = { ...this.$route.query } - search.page = parseInt(this.$route.query.page) || 1 - search.size = parseInt(this.$route.query.size) || 10 - this.search = search + this.search = { + ...this.search, + ...this.$route.query, + page: parseInt(this.$route.query.page) || 1, + size: parseInt(this.$route.query.size) || 10, + } this.listPermission() }, }, @@ -124,7 +126,7 @@ export default { }) }, onSearch(search) { - this.search = { ...this.search, page: 1, ...search } + this.search = { ...this.search, ...search, page: 1 } this.$router.push({ query: this.search, }) diff --git a/web/utils/utils.js b/web/utils/utils.js index 5755ed2..3fdc43e 100644 --- a/web/utils/utils.js +++ b/web/utils/utils.js @@ -177,3 +177,28 @@ const extMapIcon = { export function getIcon(ext) { return extMapIcon[ext] || 'other' } + +// 解析 $route.query 中的数组 +export function parseQueryIntArray(query, keys) { + const result = {} + keys.forEach((key) => { + if (typeof query[key] === 'object') { + result[key] = (query[key] || []).map((item) => parseInt(item)) + } else if (query[key]) { + result[key] = [parseInt(query[key]) || 0] + } + }) + return result +} + +export function parseQueryBoolArray(query, keys) { + const result = {} + keys.forEach((key) => { + if (typeof query[key] === 'object') { + result[key] = (query[key] || []).map((item) => item === 'true') + } else if (query[key]) { + result[key] = [query[key] === 'true'] + } + }) + return result +}