From fab2137eb4297b8e099012fa321400ce2d6ccf7d Mon Sep 17 00:00:00 2001 From: zhl Date: Mon, 31 May 2021 15:35:24 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=BA=97=E9=93=BA=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=E5=90=8E,=20=E6=9B=B4=E6=96=B0=E5=85=B6=E4=BB=96?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2=E4=B8=8A=E7=9A=84=E5=BA=97=E9=93=BA=E4=BF=A1?= =?UTF-8?q?=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/activity/edit.vue | 8 +++++++- src/views/activity/list.vue | 8 +++++++- src/views/exam/components/PuzzleList.vue | 10 ++++++++++ src/views/exam/edit.vue | 8 +++++++- src/views/exam/list.vue | 8 +++++++- src/views/game/game_setting.vue | 12 +++++++++++- src/views/marketing/coupon.vue | 8 +++++++- src/views/marketing/coupon_edit.vue | 11 ++++++++++- src/views/question/list.vue | 6 ------ src/views/question/setting.vue | 14 ++++++++++++-- src/views/question/shop_puzzles.vue | 8 +++++++- src/views/shop/list.vue | 1 + src/views/shop/shop_admin.vue | 12 ++++++++++-- src/views/system/admin.vue | 17 ++++++++++++----- 14 files changed, 108 insertions(+), 23 deletions(-) diff --git a/src/views/activity/edit.vue b/src/views/activity/edit.vue index 405c353..b75e697 100644 --- a/src/views/activity/edit.vue +++ b/src/views/activity/edit.vue @@ -403,7 +403,7 @@ import { IShopData } from '@/api/types' import { ElTree } from 'element-ui/types/tree' import { UserModule } from '@/store/modules/user' import UploadCorpImage from '@/components/UploadCorpImage/index.vue' -import { EVENT_ACTIVITY_UPDATE, EVENT_COUPON_UPDATE, EventBus } from '@/utils/event-bus' +import { EVENT_ACTIVITY_UPDATE, EVENT_COUPON_UPDATE, EVENT_SHOP_UPDATE, EventBus } from '@/utils/event-bus' @Component({ name: 'ActivityEditor', @@ -509,6 +509,9 @@ export default class extends Vue { } if (UserModule.level === 1) { await this.getRemoteDeptList() + EventBus.$on(EVENT_SHOP_UPDATE, () => { + this.getRemoteDeptList() + }) } else { this.postForm.shop = UserModule.department await this.fetchMyShop() @@ -524,6 +527,9 @@ export default class extends Vue { beforeDestory() { EventBus.$off(EVENT_COUPON_UPDATE) + if (UserModule.level === 1) { + EventBus.$off(EVENT_SHOP_UPDATE) + } } private async fetchData(id: string) { diff --git a/src/views/activity/list.vue b/src/views/activity/list.vue index d69fa33..731d5d3 100644 --- a/src/views/activity/list.vue +++ b/src/views/activity/list.vue @@ -139,7 +139,7 @@ import { parseTime } from '@/utils' import { getAllCategory, getAllTags } from '@/api/question' import { deleteActivity, getActivitys, publishActivity, IActivityData } from '@/api/activity' import { UserModule } from '@/store/modules/user' -import { EVENT_ACTIVITY_UPDATE, EVENT_SHOP_PUZZLES_UPDATE, EventBus } from '@/utils/event-bus' +import { EVENT_ACTIVITY_UPDATE, EVENT_SHOP_PUZZLES_UPDATE, EVENT_SHOP_UPDATE, EventBus } from '@/utils/event-bus' @Component({ name: 'ActivityList', @@ -196,6 +196,9 @@ export default class extends Vue { async created() { if (UserModule.level === 1) { await this.getRemoteDeptList() + EventBus.$on(EVENT_SHOP_UPDATE, () => { + this.getRemoteDeptList() + }) } else { this.filterForm.shop = UserModule.department this.listQuery.shop = UserModule.department @@ -209,6 +212,9 @@ export default class extends Vue { beforeDestory() { EventBus.$off(EVENT_ACTIVITY_UPDATE) + if (UserModule.level === 1) { + EventBus.$off(EVENT_SHOP_UPDATE) + } } private async getList() { diff --git a/src/views/exam/components/PuzzleList.vue b/src/views/exam/components/PuzzleList.vue index 4e76a4e..837099c 100644 --- a/src/views/exam/components/PuzzleList.vue +++ b/src/views/exam/components/PuzzleList.vue @@ -305,6 +305,7 @@ import { cloneDeep } from 'lodash' import { UserModule } from '@/store/modules/user' import { IShopData } from '@/api/types' import { getShops } from '@/api/shop' +import { EVENT_SHOP_UPDATE, EventBus } from '@/utils/event-bus' declare module 'vue/types/vue' { interface Vue { @@ -361,11 +362,20 @@ export default class extends Vue { async created() { if (UserModule.level === 1) { await this.getRemoteDeptList() + EventBus.$on(EVENT_SHOP_UPDATE, () => { + this.getRemoteDeptList() + }) } else if (UserModule.department) { this.shop = UserModule.department } } + beforeDestory() { + if (UserModule.level === 1) { + EventBus.$off(EVENT_SHOP_UPDATE) + } + } + private modalRules = { question: [{ required: true, message: '请输入题目', trigger: 'blur' }, { min: 2, max: 35, message: '长度在 2 到 35 个字符', trigger: 'blur' }], diff --git a/src/views/exam/edit.vue b/src/views/exam/edit.vue index 480b592..b6727b4 100644 --- a/src/views/exam/edit.vue +++ b/src/views/exam/edit.vue @@ -319,7 +319,7 @@ import { UserModule } from '@/store/modules/user' import { defaultRewardData, IRewardData } from '@/api/activity' import PuzzleList from './components/PuzzleList.vue' import UploadCorpImage from '@/components/UploadCorpImage/index.vue' -import { EVENT_COUPON_UPDATE, EVENT_EXAM_UPDATE, EventBus } from '@/utils/event-bus' +import { EVENT_COUPON_UPDATE, EVENT_EXAM_UPDATE, EVENT_SHOP_UPDATE, EventBus } from '@/utils/event-bus' @Component({ name: 'ExamEditor', @@ -407,6 +407,9 @@ export default class extends Vue { } if (UserModule.level === 1) { await this.getRemoteDeptList() + EventBus.$on(EVENT_SHOP_UPDATE, () => { + this.getRemoteDeptList() + }) } else { this.postForm.shop = UserModule.department await this.fetchMyShop() @@ -422,6 +425,9 @@ export default class extends Vue { beforeDestory() { EventBus.$off(EVENT_COUPON_UPDATE) + if (UserModule.level === 1) { + EventBus.$off(EVENT_SHOP_UPDATE) + } } private async fetchData(id: string) { diff --git a/src/views/exam/list.vue b/src/views/exam/list.vue index e3b93f8..48225dd 100644 --- a/src/views/exam/list.vue +++ b/src/views/exam/list.vue @@ -137,7 +137,7 @@ import { parseTime } from '@/utils' import { getAllCategory, getAllTags, IQuestionData } from '@/api/question' import { deleteExam, getExams } from '@/api/exam' import { UserModule } from '@/store/modules/user' -import { EVENT_EXAM_UPDATE, EVENT_SHOP_PUZZLES_UPDATE, EventBus } from '@/utils/event-bus' +import { EVENT_EXAM_UPDATE, EVENT_SHOP_PUZZLES_UPDATE, EVENT_SHOP_UPDATE, EventBus } from '@/utils/event-bus' @Component({ name: 'ExamList', @@ -193,6 +193,9 @@ export default class extends Vue { async created() { if (UserModule.level === 1) { await this.getRemoteDeptList() + EventBus.$on(EVENT_SHOP_UPDATE, () => { + this.getRemoteDeptList() + }) } else { this.filterForm.shop = UserModule.department this.listQuery.shop = UserModule.department @@ -206,6 +209,9 @@ export default class extends Vue { beforeDestory() { EventBus.$off(EVENT_EXAM_UPDATE) + if (UserModule.level === 1) { + EventBus.$off(EVENT_SHOP_UPDATE) + } } private async getList() { diff --git a/src/views/game/game_setting.vue b/src/views/game/game_setting.vue index 69359da..15f7299 100644 --- a/src/views/game/game_setting.vue +++ b/src/views/game/game_setting.vue @@ -114,6 +114,7 @@ import { saveShopGameInfo } from '@/api/shop' import { UserModule } from '@/store/modules/user' +import { EVENT_SHOP_UPDATE, EventBus } from '@/utils/event-bus' @Component({ name: 'GameSetting', @@ -156,11 +157,20 @@ export default class extends Vue { await this.getList() if (UserModule.level === 1) { await this.getRemoteDeptList('') + EventBus.$on(EVENT_SHOP_UPDATE, () => { + this.getRemoteDeptList() + }) } else { this.shop = UserModule.department } } + beforeDestory() { + if (UserModule.level === 1) { + EventBus.$off(EVENT_SHOP_UPDATE) + } + } + @Watch('shop') private onShopChange() { if (this.shop) { @@ -224,7 +234,7 @@ export default class extends Vue { } } - private async getRemoteDeptList(name: string) { + private async getRemoteDeptList(name?: string) { if (UserModule.level > 1) { return } diff --git a/src/views/marketing/coupon.vue b/src/views/marketing/coupon.vue index 971f92d..47a36c4 100644 --- a/src/views/marketing/coupon.vue +++ b/src/views/marketing/coupon.vue @@ -133,7 +133,7 @@ import { getShops } from '@/api/shop' import { parseTime } from '@/utils' import { deleteCoupon, getCoupons } from '@/api/coupon' import { UserModule } from '@/store/modules/user' -import { EVENT_COUPON_UPDATE, EventBus } from '@/utils/event-bus' +import { EVENT_COUPON_UPDATE, EVENT_SHOP_UPDATE, EventBus } from '@/utils/event-bus' @Component({ name: 'CouponList', @@ -187,6 +187,9 @@ export default class extends Vue { async created() { if (UserModule.level === 1) { await this.getRemoteDeptList() + EventBus.$on(EVENT_SHOP_UPDATE, () => { + this.getRemoteDeptList() + }) } else { this.filterForm.department = UserModule.department this.listQuery.shop = UserModule.department @@ -208,6 +211,9 @@ export default class extends Vue { beforeDestory() { EventBus.$off(EVENT_COUPON_UPDATE) + if (UserModule.level === 1) { + EventBus.$off(EVENT_SHOP_UPDATE) + } } private async handleDelete(scope: any) { diff --git a/src/views/marketing/coupon_edit.vue b/src/views/marketing/coupon_edit.vue index 81bb34c..ffce24a 100644 --- a/src/views/marketing/coupon_edit.vue +++ b/src/views/marketing/coupon_edit.vue @@ -134,7 +134,7 @@ import Tinymce from '@/components/Tinymce/index.vue' import { getShops } from '@/api/shop' import { defaultCouponData, getCoupon, saveCoupon } from '@/api/coupon' import { UserModule } from '@/store/modules/user' -import { EVENT_COUPON_UPDATE, EVENT_SHOP_PUZZLES_UPDATE, EventBus } from '@/utils/event-bus' +import { EVENT_COUPON_UPDATE, EVENT_SHOP_PUZZLES_UPDATE, EVENT_SHOP_UPDATE, EventBus } from '@/utils/event-bus' @Component({ name: 'CouponEditor', @@ -194,6 +194,9 @@ export default class extends Vue { const id = this.$route.params?.id if (UserModule.level === 1) { this.getRemoteDeptList('') + EventBus.$on(EVENT_SHOP_UPDATE, () => { + this.getRemoteDeptList() + }) } else { this.postForm.shop = UserModule.department } @@ -203,6 +206,12 @@ export default class extends Vue { this.tempTagView = Object.assign({}, this.$route) } + beforeDestory() { + if (UserModule.level === 1) { + EventBus.$off(EVENT_SHOP_UPDATE) + } + } + @Watch('dataRange') private onDataRangeChange(val: Date[]) { console.log(`onDataRangeChange ${val}`) diff --git a/src/views/question/list.vue b/src/views/question/list.vue index b686015..9a6aaa8 100644 --- a/src/views/question/list.vue +++ b/src/views/question/list.vue @@ -251,12 +251,6 @@ export default class extends Vue { this.$refs.filterForm.resetFields() } - private async getRemoteDeptList(name: string) { - const { data } = await getShops({ key: name }) - if (!data.records) return - this.allDepts = data.records - } - private async getRemoteTags() { const { data } = await getAllTags() console.log(data) diff --git a/src/views/question/setting.vue b/src/views/question/setting.vue index 9c2a6aa..315de4a 100644 --- a/src/views/question/setting.vue +++ b/src/views/question/setting.vue @@ -57,6 +57,7 @@ import { getAllCategory } from '@/api/question' import { ElTree } from 'element-ui/types/tree' import { IShopData } from '@/api/types' import { UserModule } from '@/store/modules/user' +import { EVENT_COUPON_UPDATE, EVENT_SHOP_UPDATE, EventBus } from '@/utils/event-bus' @Component({ name: 'QuestionSetting', @@ -92,7 +93,10 @@ export default class extends Vue { async created() { await this.getRemoteCategory() if (UserModule.level === 1) { - await this.getRemoteDeptList('') + await this.getRemoteDeptList() + EventBus.$on(EVENT_SHOP_UPDATE, () => { + this.getRemoteDeptList() + }) } else { this.shop = UserModule.department await this.fetchMyShop() @@ -100,6 +104,12 @@ export default class extends Vue { this.loading = false } + beforeDestory() { + if (UserModule.level === 1) { + EventBus.$off(EVENT_SHOP_UPDATE) + } + } + @Watch('shop') private onShopChange() { if (this.shop && UserModule.level === 1) { @@ -120,7 +130,7 @@ export default class extends Vue { } } - private async getRemoteDeptList(name: string) { + private async getRemoteDeptList(name?: string) { const { data } = await getShops({ key: name }) if (!data.records) return this.allDepts = data.records diff --git a/src/views/question/shop_puzzles.vue b/src/views/question/shop_puzzles.vue index fdbfbe8..111a4b7 100644 --- a/src/views/question/shop_puzzles.vue +++ b/src/views/question/shop_puzzles.vue @@ -157,7 +157,7 @@ import { IQuestionData } from '@/api/question' import { UserModule } from '@/store/modules/user' import { deleteShopQuestion, getShopCategory, getShopQuestions } from '@/api/shoppuzzle' import { IShopData } from '@/api/types' -import { EVENT_SHOP_PUZZLES_UPDATE, EventBus } from '@/utils/event-bus' +import { EVENT_SHOP_PUZZLES_UPDATE, EVENT_SHOP_UPDATE, EventBus } from '@/utils/event-bus' @Component({ name: 'ShopPuzzles', @@ -217,6 +217,9 @@ export default class extends Vue { async created() { if (UserModule.level === 1) { await this.getRemoteDeptList() + EventBus.$on(EVENT_SHOP_UPDATE, () => { + this.getRemoteDeptList() + }) } else { this.filterForm.shop = UserModule.department this.listQuery.shop = UserModule.department @@ -230,6 +233,9 @@ export default class extends Vue { beforeDestory() { EventBus.$off(EVENT_SHOP_PUZZLES_UPDATE) + if (UserModule.level === 1) { + EventBus.$off(EVENT_SHOP_UPDATE) + } } private async getList() { diff --git a/src/views/shop/list.vue b/src/views/shop/list.vue index cbcdf8f..c091c74 100644 --- a/src/views/shop/list.vue +++ b/src/views/shop/list.vue @@ -237,6 +237,7 @@ export default class extends Vue { }) await updateShopPublish({ id: row._id, publish: !row.publish }) row.publish = !row.publish + EventBus.$emit(EVENT_SHOP_UPDATE, {}) } catch (err) { console.log(err) } diff --git a/src/views/shop/shop_admin.vue b/src/views/shop/shop_admin.vue index bd80e6a..c62d61b 100644 --- a/src/views/shop/shop_admin.vue +++ b/src/views/shop/shop_admin.vue @@ -295,6 +295,7 @@ import { IRole } from '@/views/system/role.vue' import { IShopData } from '@/api/types' import { UserModule } from '@/store/modules/user' import { getShops } from '@/api/shop' +import { EVENT_SHOP_UPDATE, EventBus } from '@/utils/event-bus' @Component({ name: 'ShopAdmin', @@ -353,9 +354,16 @@ export default class extends Vue { } async created() { - this.allDepts = await this.getRemoteDeptList('') + await this.getRemoteDeptList() await this.getRecords() await this.getAllRole() + EventBus.$on(EVENT_SHOP_UPDATE, () => { + this.getRemoteDeptList() + }) + } + + beforeDestory() { + EventBus.$off(EVENT_SHOP_UPDATE) } private search() { @@ -571,7 +579,7 @@ export default class extends Vue { const { data } = await getShops({ key: name }) if (!data.records) return this.deptListOptions = data.records - return data.records + this.allDepts = data.records } private formatDept(row: any) { diff --git a/src/views/system/admin.vue b/src/views/system/admin.vue index 6e56303..4896062 100644 --- a/src/views/system/admin.vue +++ b/src/views/system/admin.vue @@ -229,10 +229,8 @@ > { + this.getRemoteDeptList() + }) + } + + beforeDestory() { + EventBus.$off(EVENT_SHOP_UPDATE) } private search() { @@ -556,11 +563,11 @@ export default class extends Vue { }) } - private async getRemoteDeptList(name: string) { + private async getRemoteDeptList(name?: string) { const { data } = await getShops({ key: name }) if (!data.records) return this.deptListOptions = data.records - return data.records + this.allDepts = data.records } private formatDept(row: any) {