diff --git a/src/utils/event-bus.ts b/src/utils/event-bus.ts index df4d259..d488e5e 100644 --- a/src/utils/event-bus.ts +++ b/src/utils/event-bus.ts @@ -1,3 +1,39 @@ - import Vue from 'vue' + export const EventBus = new Vue() +/** + * 自定义题目更新 + * @type {string} + */ +export const EVENT_SHOP_PUZZLES_UPDATE = 'event_shop_puzzles_update' +/** + * 活动数据更新 + * @type {string} + */ +export const EVENT_ACTIVITY_UPDATE = 'event_activity_update' + +/** + * 挑战数据更新 + * @type {string} + */ +export const EVENT_EXAM_UPDATE = 'event_exam_update' +/** + * 游戏数据更新 + * @type {string} + */ +export const EVENT_GAME_UPDATE = 'event_game_update' +/** + * 优惠券信息更新 + * @type {string} + */ +export const EVENT_COUPON_UPDATE = 'event_coupon_update' +/** + * 题目信息更新 + * @type {string} + */ +export const EVENT_PUZZLE_UPDATE = 'event_puzzle_update' +/** + * 店铺信息更新 + * @type {string} + */ +export const EVENT_SHOP_UPDATE = 'event_shop_update' diff --git a/src/views/activity/edit.vue b/src/views/activity/edit.vue index e1fe762..8dfec28 100644 --- a/src/views/activity/edit.vue +++ b/src/views/activity/edit.vue @@ -394,13 +394,7 @@ import Sticky from '@/components/Sticky/index.vue' import UploadImage from '@/components/UploadImage/index.vue' import RegionPicker from '@/components/RegionPicker/index.vue' import { getMyShop, getShops } from '@/api/shop' -import { - defaultActivityData, - defaultRewardData, - getActivity, - IRewardData, - saveActivity -} from '@/api/activity' +import { defaultActivityData, defaultRewardData, getActivity, IRewardData, saveActivity } from '@/api/activity' import { sec2TimeStr, timeStr2Sec } from '@/utils' import { getAllCategory } from '@/api/question' import { cloneDeep } from 'lodash' @@ -409,6 +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, EventBus } from '@/utils/event-bus' @Component({ name: 'ActivityEditor', @@ -594,6 +589,7 @@ export default class extends Vue { type: 'success', duration: 2000 }) + EventBus.$emit(EVENT_ACTIVITY_UPDATE, {}) } catch (err) { console.error('Submit Error!') return false diff --git a/src/views/activity/list.vue b/src/views/activity/list.vue index 022383c..d69fa33 100644 --- a/src/views/activity/list.vue +++ b/src/views/activity/list.vue @@ -139,6 +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' @Component({ name: 'ActivityList', @@ -201,6 +202,13 @@ export default class extends Vue { } await this.getRemoteCategory() await this.getList() + EventBus.$on(EVENT_ACTIVITY_UPDATE, () => { + this.getList() + }) + } + + beforeDestory() { + EventBus.$off(EVENT_ACTIVITY_UPDATE) } private async getList() { diff --git a/src/views/exam/edit.vue b/src/views/exam/edit.vue index 2abd327..9d97b78 100644 --- a/src/views/exam/edit.vue +++ b/src/views/exam/edit.vue @@ -323,6 +323,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_EXAM_UPDATE, EVENT_SHOP_PUZZLES_UPDATE, EventBus } from '@/utils/event-bus' @Component({ name: 'ExamEditor', components: { @@ -472,6 +473,7 @@ export default class extends Vue { type: 'success', duration: 2000 }) + EventBus.$emit(EVENT_EXAM_UPDATE, {}) } catch (err) { console.error('Submit Error!') return false diff --git a/src/views/exam/list.vue b/src/views/exam/list.vue index a38c8c7..e3b93f8 100644 --- a/src/views/exam/list.vue +++ b/src/views/exam/list.vue @@ -137,6 +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' @Component({ name: 'ExamList', @@ -198,6 +199,13 @@ export default class extends Vue { } await this.getRemoteCategory() await this.getList() + EventBus.$on(EVENT_EXAM_UPDATE, () => { + this.getList() + }) + } + + beforeDestory() { + EventBus.$off(EVENT_EXAM_UPDATE) } private async getList() { diff --git a/src/views/game/game_edit.vue b/src/views/game/game_edit.vue index 7de4f46..677748e 100644 --- a/src/views/game/game_edit.vue +++ b/src/views/game/game_edit.vue @@ -150,6 +150,7 @@ import { import { ITagView, TagsViewModule } from '@/store/modules/tags-view' import UploadImage from '@/components/UploadImage/index.vue' import { AppModule } from '@/store/modules/app' +import { EVENT_GAME_UPDATE, EVENT_SHOP_PUZZLES_UPDATE, EventBus } from '@/utils/event-bus' @Component({ name: 'GameEdit', @@ -249,6 +250,7 @@ export default class extends Vue { type: 'success', duration: 2000 }) + EventBus.$emit(EVENT_GAME_UPDATE, {}) } catch (err) { console.error('Submit Error!') return false diff --git a/src/views/game/game_list.vue b/src/views/game/game_list.vue index 97afcda..83f21d7 100644 --- a/src/views/game/game_list.vue +++ b/src/views/game/game_list.vue @@ -100,6 +100,7 @@ import { Component, Vue } from 'vue-property-decorator' import Pagination from '@/components/Pagination/index.vue' import { parseTime } from '@/utils' import { deleteGame, getGames, IGameData } from '@/api/game' +import { EVENT_GAME_UPDATE, EventBus } from '@/utils/event-bus' @Component({ name: 'GameList', @@ -145,10 +146,13 @@ export default class extends Vue { created() { this.getList() + EventBus.$on(EVENT_GAME_UPDATE, () => { + this.getList() + }) } - activated() { - this.getList() + beforeDestory() { + EventBus.$off(EVENT_GAME_UPDATE) } private async getList() { diff --git a/src/views/marketing/coupon.vue b/src/views/marketing/coupon.vue index 07ab1bd..971f92d 100644 --- a/src/views/marketing/coupon.vue +++ b/src/views/marketing/coupon.vue @@ -133,6 +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' @Component({ name: 'CouponList', @@ -191,6 +192,9 @@ export default class extends Vue { this.listQuery.shop = UserModule.department } await this.getList() + EventBus.$on(EVENT_COUPON_UPDATE, () => { + this.getList() + }) } private async getList() { @@ -202,6 +206,10 @@ export default class extends Vue { this.total = data.total } + beforeDestory() { + EventBus.$off(EVENT_COUPON_UPDATE) + } + private async handleDelete(scope: any) { const { $index, row } = scope await this.$confirm('确认删除该优惠券?', 'Warning', { diff --git a/src/views/marketing/coupon_edit.vue b/src/views/marketing/coupon_edit.vue index 6c5b2d8..81bb34c 100644 --- a/src/views/marketing/coupon_edit.vue +++ b/src/views/marketing/coupon_edit.vue @@ -134,6 +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' @Component({ name: 'CouponEditor', @@ -263,6 +264,7 @@ export default class extends Vue { type: 'success', duration: 2000 }) + EventBus.$emit(EVENT_COUPON_UPDATE, {}) } catch (err) { console.error('Submit Error!') return false diff --git a/src/views/question/editor.vue b/src/views/question/editor.vue index fa54f99..1eb3632 100644 --- a/src/views/question/editor.vue +++ b/src/views/question/editor.vue @@ -193,6 +193,7 @@ import { saveQuestion, saveTag } from '@/api/question' +import { EVENT_PUZZLE_UPDATE, EVENT_SHOP_PUZZLES_UPDATE, EventBus } from '@/utils/event-bus' @Component({ name: 'QuestionPrepare', @@ -346,6 +347,7 @@ export default class extends Vue { type: 'success', duration: 2000 }) + EventBus.$emit(EVENT_PUZZLE_UPDATE, {}) } catch (err) { console.error('Submit Error!') this.loading = false diff --git a/src/views/question/list.vue b/src/views/question/list.vue index 609ba58..b686015 100644 --- a/src/views/question/list.vue +++ b/src/views/question/list.vue @@ -143,6 +143,7 @@ import { getQuestions, IQuestionData } from '@/api/question' +import { EVENT_PUZZLE_UPDATE, EVENT_SHOP_PUZZLES_UPDATE, EventBus } from '@/utils/event-bus' @Component({ name: 'QuestionList', @@ -198,6 +199,13 @@ export default class extends Vue { this.getList() this.getRemoteTags() this.getRemoteCategory() + EventBus.$on(EVENT_PUZZLE_UPDATE, () => { + this.getList() + }) + } + + beforeDestory() { + EventBus.$off(EVENT_PUZZLE_UPDATE) } private async getList() { diff --git a/src/views/question/shop_puzzle_editor.vue b/src/views/question/shop_puzzle_editor.vue index b9b8eb8..a1eb4cd 100644 --- a/src/views/question/shop_puzzle_editor.vue +++ b/src/views/question/shop_puzzle_editor.vue @@ -160,7 +160,7 @@ import Tinymce from '@/components/Tinymce/index.vue' import UploadImage from '@/components/UploadImage/index.vue' import { defaultQuestionData } from '@/api/question' import { deleteShopQuestion, getShopQuestion, saveShopQuestion } from '@/api/shoppuzzle' -import { EventBus } from '@/utils/event-bus' +import { EVENT_SHOP_PUZZLES_UPDATE, EventBus } from '@/utils/event-bus' @Component({ name: 'ShopPuzzleEdit', @@ -286,7 +286,7 @@ export default class extends Vue { type: 'success', duration: 2000 }) - EventBus.$emit('shop_puzzles_update', {}) + EventBus.$emit(EVENT_SHOP_PUZZLES_UPDATE, {}) } catch (err) { console.error('Submit Error!') this.loading = false @@ -304,7 +304,7 @@ export default class extends Vue { }) await deleteShopQuestion(this.postForm.shop!, this.postForm._id!) this.loading = false - EventBus.$emit('shop_puzzles_update', {}) + EventBus.$emit(EVENT_SHOP_PUZZLES_UPDATE, {}) this.$store.dispatch('delView', this.$route) this.$router.go(-1) } catch (e) { diff --git a/src/views/question/shop_puzzles.vue b/src/views/question/shop_puzzles.vue index 03b2f89..fdbfbe8 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 { EventBus } from '@/utils/event-bus' +import { EVENT_SHOP_PUZZLES_UPDATE, EventBus } from '@/utils/event-bus' @Component({ name: 'ShopPuzzles', @@ -223,13 +223,13 @@ export default class extends Vue { await this.getList() } // this.getList() - EventBus.$on('shop_puzzles_update', () => { + EventBus.$on(EVENT_SHOP_PUZZLES_UPDATE, () => { this.getList() }) } beforeDestory() { - EventBus.$off('shop_puzzles_update') + EventBus.$off(EVENT_SHOP_PUZZLES_UPDATE) } private async getList() { diff --git a/src/views/shop/edit.vue b/src/views/shop/edit.vue index 4aba62b..b770d9a 100644 --- a/src/views/shop/edit.vue +++ b/src/views/shop/edit.vue @@ -122,6 +122,7 @@ import RegionPicker from '@/components/RegionPicker/index.vue' import { defaultShopData, getShop, saveShop } from '@/api/shop' import { addressToLoc, IAreaData, queryArea } from '@/api/map' import i18n from '@/lang' +import { EVENT_SHOP_PUZZLES_UPDATE, EVENT_SHOP_UPDATE, EventBus } from '@/utils/event-bus' @Component({ name: 'ShopEditor', @@ -219,6 +220,7 @@ export default class extends Vue { type: 'success', duration: 2000 }) + EventBus.$emit(EVENT_SHOP_UPDATE, {}) } catch (err) { console.error('Submit Error!') return false diff --git a/src/views/shop/list.vue b/src/views/shop/list.vue index 469b4f5..cbcdf8f 100644 --- a/src/views/shop/list.vue +++ b/src/views/shop/list.vue @@ -151,6 +151,7 @@ import Pagination from '@/components/Pagination/index.vue' import { deleteShop, getShops, updateShopPublish } from '@/api/shop' import { parseTime } from '@/utils' import i18n from '@/lang' +import { EVENT_SHOP_PUZZLES_UPDATE, EVENT_SHOP_UPDATE, EventBus } from '@/utils/event-bus' @Component({ name: 'ShopList', @@ -186,10 +187,13 @@ export default class extends Vue { created() { this.getList() + EventBus.$on(EVENT_SHOP_UPDATE, () => { + this.getList() + }) } - activated() { - this.getList() + beforeDestory() { + EventBus.$off(EVENT_SHOP_UPDATE) } private async getList() {