diff --git a/web/pages/admin/document/category.vue b/web/pages/admin/document/category.vue index ad10d7c..305ed79 100644 --- a/web/pages/admin/document/category.vue +++ b/web/pages/admin/document/category.vue @@ -78,10 +78,35 @@ export default { computed: { ...mapGetters('setting', ['settings']), }, + watch: { + '$route.query': { + immediate: true, + async handler() { + let search = { ...this.$route.query } + + // 不传页码和每页数量,一次查询全部 + // search.page = parseInt(this.$route.query.page) || 1 + // search.size = parseInt(this.$route.query.size) || 10 + + // 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] + } + + this.search = search + await this.initTableListFields() + this.listCategory() + }, + }, + }, async created() { this.initSearchForm() - this.initTableListFields() - await this.listCategory() + // this.initTableListFields() + // await this.listCategory() }, methods: { async listCategory() { @@ -104,15 +129,21 @@ export default { }, handleSizeChange(val) { this.search.size = val - this.listCategory() + this.$router.push({ + query: this.search, + }) }, handlePageChange(val) { this.search.page = val - this.listCategory() + this.$router.push({ + query: this.search, + }) }, onSearch(search) { - this.search = { ...this.search, page: 1, ...search } - this.listCategory() + this.search = { ...this.search, ...search, page: 1 } + this.$router.push({ + query: this.search, + }) }, onCreate() { this.category = { @@ -199,13 +230,16 @@ export default { placeholder: '请选择状态', multiple: true, options: [ - { label: '启用', value: true }, - { label: '禁用', value: false }, + { label: '启用', value: 1 }, + { label: '禁用', value: 0 }, ], }, ] }, initTableListFields() { + if (this.tableListFields.length > 0) { + return + } this.tableListFields = [ { prop: 'title', label: '名称', minWidth: 120, fixed: 'left' }, { diff --git a/web/pages/admin/document/list.vue b/web/pages/admin/document/list.vue index e377ebe..0bd875d 100644 --- a/web/pages/admin/document/list.vue +++ b/web/pages/admin/document/list.vue @@ -7,6 +7,7 @@ :show-create="true" :show-delete="true" :disabled-delete="selectedRow.length === 0" + :default-search="search" @onSearch="onSearch" @onCreate="onCreate" @onDelete="batchDelete" @@ -160,12 +161,53 @@ export default { computed: { ...mapGetters('setting', ['settings']), }, + watch: { + '$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] + } + + + // 需要先加载分类数据 + if (this.trees.length === 0) { + await this.listCategory() + } + await this.listDocument() + }, + }, + }, async created() { this.initSearchForm() this.initTableListFields() - // 需要先加载分类数据 - await this.listCategory() - await this.listDocument() + // // 需要先加载分类数据 + // await this.listCategory() + // await this.listDocument() }, methods: { async listCategory() { @@ -217,15 +259,21 @@ export default { }, handleSizeChange(val) { this.search.size = val - this.listDocument() + this.$router.push({ + query: this.search, + }) }, handlePageChange(val) { this.search.page = val - this.listDocument() + this.$router.push({ + query: this.search, + }) }, onSearch(search) { - this.search = { ...this.search, page: 1, ...search } - this.listDocument() + this.search = { ...this.search, ...search, page: 1 } + this.$router.push({ + query: this.search, + }) }, onCreate() { // 新增,跳转到前台文档上传页面 diff --git a/web/pages/admin/document/recycle.vue b/web/pages/admin/document/recycle.vue index ef0f51c..e3ad396 100644 --- a/web/pages/admin/document/recycle.vue +++ b/web/pages/admin/document/recycle.vue @@ -7,6 +7,7 @@ :show-create="false" :show-delete="false" :disabled-delete="selectedRow.length === 0" + :default-search="search" @onSearch="onSearch" >