From 66018c607a1abec63955211cc866092f99e59bbe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=91=E6=96=87=E5=8F=AF?= <1041367524@qq.com> Date: Mon, 13 Jun 2022 10:01:23 +0800 Subject: [PATCH] refactor: im --- src/store/modules/{im => chat}/chatWaiter.js | 0 src/store/modules/chat/customerService.js | 91 ------- .../modules/im/{chatHome.js => imHome.js} | 0 .../modules/im/{chatStore.js => imStore.js} | 2 +- .../modules/im/{chatSystem.js => imSystem.js} | 2 +- src/store/modules/im/{im.js => imWaiter.js} | 29 +- src/views/chat/waiter.vue | 247 ++++++++++++++++++ src/views/im/home/index.vue | 20 +- src/views/im/store/index.vue | 18 +- src/views/im/system/index.vue | 18 +- src/views/im/waiter/index.vue | 44 +--- 11 files changed, 302 insertions(+), 169 deletions(-) rename src/store/modules/{im => chat}/chatWaiter.js (100%) delete mode 100644 src/store/modules/chat/customerService.js rename src/store/modules/im/{chatHome.js => imHome.js} (100%) rename src/store/modules/im/{chatStore.js => imStore.js} (99%) rename src/store/modules/im/{chatSystem.js => imSystem.js} (98%) rename src/store/modules/im/{im.js => imWaiter.js} (71%) create mode 100644 src/views/chat/waiter.vue diff --git a/src/store/modules/im/chatWaiter.js b/src/store/modules/chat/chatWaiter.js similarity index 100% rename from src/store/modules/im/chatWaiter.js rename to src/store/modules/chat/chatWaiter.js diff --git a/src/store/modules/chat/customerService.js b/src/store/modules/chat/customerService.js deleted file mode 100644 index 50de3ee..0000000 --- a/src/store/modules/chat/customerService.js +++ /dev/null @@ -1,91 +0,0 @@ -import * as api from '@/api/chat/index.js'; -import { ElMessage, ElMessageBox } from '@/plugins/element-plus'; -const state = () => ({ - code: 'CustomerServiceManagement', - condition: {}, - list: [], - total: 0, - opts: { - init: false, - customerServiceType: [ - { - label: '售前', - value: 1, - }, - { - label: '售后', - value: 2, - }, - { - label: '发货', - value: 3, - }, - ], - }, -}); -const getters = {}; -const mutations = { - setCode: (state, data) => (state.code = data), - setCondition: (state, data) => (state.condition = data), - setList: (state, data) => (state.list = data), - setTotal: (state, data) => (state.total = data), - setOpts: (state, data) => (state.opts = data), -}; -const actions = { - search: async ({ commit }) => { - let res = await api.searchService(1); - commit('setList', res || []); - if (!res) { - ElMessage.error('查询失败'); - } - return res; - }, - load: async ({ state, commit }) => { - commit('setOpts', { - ...state.opts, - init: true, - }); - }, - detail: async (context, id) => { - let res = await api.detail(id); - if (!res) { - ElMessage.error('加载详情失败'); - } - return res; - }, - save: async ({ dispatch }, data) => { - let save = data.id ? api.update : api.create; - let res = await save(data); - if (res) { - ElMessage.success('保存成功'); - dispatch('search'); - } else { - ElMessage.error('保存失败'); - } - return res; - }, - remove: async ({ dispatch }, idList) => { - if (!idList.length) { - ElMessage.warning('请选择要删除的数据'); - } else { - try { - await ElMessageBox.confirm('数据删除后无法恢复,确定要删除吗?', '危险操作'); - let res = await api.remove(idList.join(',')); - if (res) { - ElMessage.success('删除成功'); - dispatch('search'); - } else { - ElMessage.error('删除失败'); - } - } catch (e) { - console.info('取消删除', e); - } - } - }, -}; -export default { - state, - getters, - mutations, - actions, -}; diff --git a/src/store/modules/im/chatHome.js b/src/store/modules/im/imHome.js similarity index 100% rename from src/store/modules/im/chatHome.js rename to src/store/modules/im/imHome.js diff --git a/src/store/modules/im/chatStore.js b/src/store/modules/im/imStore.js similarity index 99% rename from src/store/modules/im/chatStore.js rename to src/store/modules/im/imStore.js index 48528f4..41523a8 100644 --- a/src/store/modules/im/chatStore.js +++ b/src/store/modules/im/imStore.js @@ -1,7 +1,7 @@ import * as api from '@/api/im/index.js'; import { ElMessage, ElMessageBox } from '@/plugins/element-plus'; const state = () => ({ - code: 'ChatStore', + code: 'ImStore', condition: {}, list: [], total: 0, diff --git a/src/store/modules/im/chatSystem.js b/src/store/modules/im/imSystem.js similarity index 98% rename from src/store/modules/im/chatSystem.js rename to src/store/modules/im/imSystem.js index 7bc9559..c2ddf62 100644 --- a/src/store/modules/im/chatSystem.js +++ b/src/store/modules/im/imSystem.js @@ -1,7 +1,7 @@ import * as api from '@/api/im/index.js'; import { ElMessage, ElMessageBox } from '@/plugins/element-plus'; const state = () => ({ - code: 'ChatSystem', + code: 'ImSystem', condition: {}, list: [], total: 0, diff --git a/src/store/modules/im/im.js b/src/store/modules/im/imWaiter.js similarity index 71% rename from src/store/modules/im/im.js rename to src/store/modules/im/imWaiter.js index 535c033..824f28c 100644 --- a/src/store/modules/im/im.js +++ b/src/store/modules/im/imWaiter.js @@ -1,12 +1,13 @@ -import * as api from '@/api/system/notify.js'; +import * as api from '@/api/im/index.js'; import { ElMessage, ElMessageBox } from '@/plugins/element-plus'; const state = () => ({ - code: 'NotifyManagement', + code: 'ImWaiter', condition: {}, list: [], total: 0, opts: { init: false, + store: [], }, }); const getters = {}; @@ -20,10 +21,7 @@ const mutations = { const actions = { search: async ({ state, commit, rootGetters }) => { let data = { ...state.condition }; - data.startReleaseTime = data.dateRange?.[0]; - data.endReleaseTime = data.dateRange?.[1]; - delete data.dateRange; - let res = await api.search({ ...rootGetters['local/page'](state.code), ...state.condition }); + let res = await api.searchWaiter({ ...rootGetters['local/page'](state.code), ...data }); if (res) { commit('setList', res.records); commit('setTotal', res.total); @@ -36,17 +34,14 @@ const actions = { load: async ({ commit }) => { commit('setOpts', { init: true, + store: (await api.searchStore({ pageIndex: 1, length: 9999 }))?.records || [], }); }, - detail: async (context, id) => { - let res = await api.detail(id); - if (!res) { - ElMessage.error('加载详情失败'); + save: async ({ state, dispatch }, data) => { + if (data.id) { + data.systemId = state.condition.systemid; } - return res; - }, - save: async ({ dispatch }, data) => { - let save = data.id ? api.update : api.create; + let save = data.id ? api.updateWaiter : api.createWaiter; let res = await save(data); if (res) { ElMessage.success('保存成功'); @@ -56,13 +51,13 @@ const actions = { } return res; }, - remove: async ({ dispatch }, idList) => { - if (!idList.length) { + remove: async ({ dispatch }, data) => { + if (!data.waiterIds.length) { ElMessage.warning('请选择要删除的数据'); } else { try { await ElMessageBox.confirm('数据删除后无法恢复,确定要删除吗?', '危险操作'); - let res = await api.remove(idList.join(',')); + let res = await api.removeWaiter(data); if (res) { ElMessage.success('删除成功'); dispatch('search'); diff --git a/src/views/chat/waiter.vue b/src/views/chat/waiter.vue new file mode 100644 index 0000000..08614ff --- /dev/null +++ b/src/views/chat/waiter.vue @@ -0,0 +1,247 @@ + + + + + diff --git a/src/views/im/home/index.vue b/src/views/im/home/index.vue index 43f1998..1d8d72e 100644 --- a/src/views/im/home/index.vue +++ b/src/views/im/home/index.vue @@ -43,9 +43,9 @@ import DateRange from './dateRange.vue'; const store = useStore(); const loading = ref(false); - const opts = computed(() => store.state.chatStore.opts); + const opts = computed(() => store.state.imStore.opts); if (!unref(opts).init) { - store.dispatch('chatStore/load'); + store.dispatch('imStore/load'); } const systemId = ref(null); @@ -58,11 +58,11 @@ }, { immediate: true } ); - const online = computed(() => store.state.chatHome.online); + const online = computed(() => store.state.imHome.online); const handleLoadOnline = async () => { loading.value = true; if (unref(systemId)) { - await store.dispatch('chatHome/loadOnline', { systemId: unref(systemId) }); + await store.dispatch('imHome/loadOnline', { systemId: unref(systemId) }); } loading.value = false; }; @@ -140,10 +140,10 @@ const date1 = ref(dayjs(new Date()).format('YYYY-MM-DD')); const handleLoadSingle = async () => { loading.value = true; - store.commit('chatHome/setSingle', []); + store.commit('imHome/setSingle', []); if (unref(systemId)) { if (unref(date1)) { - await store.dispatch('chatHome/loadSingle', { + await store.dispatch('imHome/loadSingle', { systemId: unref(systemId), days: unref(date1), }); @@ -154,7 +154,7 @@ watch(date1, handleLoadSingle, { immediate: true }); watch(systemId, handleLoadSingle); watch( - () => store.state.chatHome.single, + () => store.state.imHome.single, (value) => { handleChart( '.chart-1', @@ -174,10 +174,10 @@ const date2 = ref([]); const handleLoadRange = async () => { loading.value = true; - store.commit('chatHome/setRange', []); + store.commit('imHome/setRange', []); if (unref(systemId)) { if (unref(date2)?.length) { - await store.dispatch('chatHome/loadRange', { + await store.dispatch('imHome/loadRange', { systemId: unref(systemId), start: unref(date2)[0], end: unref(date2)[1], @@ -189,7 +189,7 @@ watch(date2, handleLoadRange); watch(systemId, handleLoadRange); watch( - () => store.state.chatHome.range, + () => store.state.imHome.range, (value) => { handleChart( '.chart-2', diff --git a/src/views/im/store/index.vue b/src/views/im/store/index.vue index 508f7ce..29bc429 100644 --- a/src/views/im/store/index.vue +++ b/src/views/im/store/index.vue @@ -64,12 +64,12 @@ const router = useRouter(); const { proxy } = getCurrentInstance(); const loading = ref(false); - const code = computed(() => store.state.chatStore.code); - const list = computed(() => store.state.chatStore.list); - const total = computed(() => store.state.chatStore.total); - const opts = computed(() => store.state.chatStore.opts); + const code = computed(() => store.state.imStore.code); + const list = computed(() => store.state.imStore.list); + const total = computed(() => store.state.imStore.total); + const opts = computed(() => store.state.imStore.opts); if (!unref(opts).init) { - store.dispatch('chatStore/load'); + store.dispatch('imStore/load'); } const state = reactive({ condition: { @@ -83,13 +83,13 @@ }; const handleSearch = async () => { loading.value = true; - await store.dispatch('chatStore/search'); + await store.dispatch('imStore/search'); loading.value = false; }; watch( () => state.condition, (value) => { - store.commit('chatStore/setCondition', _.cloneDeep(value)); + store.commit('imStore/setCondition', _.cloneDeep(value)); handleSearch(); }, { immediate: true, deep: true } @@ -139,7 +139,7 @@ try { await proxy.$validate(refsForm); let data = _.cloneDeep(formState.form); - await store.dispatch('chatStore/save', data); + await store.dispatch('imStore/save', data); formState.formVisible = false; } catch (e) { console.info('取消保存', e); @@ -148,7 +148,7 @@ }; const handleRemove = async (rows) => { store.dispatch( - 'chatStore/remove', + 'imStore/remove', rows.map((item) => item.id) ); }; diff --git a/src/views/im/system/index.vue b/src/views/im/system/index.vue index 3f1f30e..c605698 100644 --- a/src/views/im/system/index.vue +++ b/src/views/im/system/index.vue @@ -53,12 +53,12 @@ const router = useRouter(); const { proxy } = getCurrentInstance(); const loading = ref(false); - const code = computed(() => store.state.chatSystem.code); - const list = computed(() => store.state.chatSystem.list); - const total = computed(() => store.state.chatSystem.total); - const opts = computed(() => store.state.chatSystem.opts); + const code = computed(() => store.state.imSystem.code); + const list = computed(() => store.state.imSystem.list); + const total = computed(() => store.state.imSystem.total); + const opts = computed(() => store.state.imSystem.opts); if (!unref(opts).init) { - store.dispatch('chatSystem/load'); + store.dispatch('imSystem/load'); } const state = reactive({ condition: { @@ -68,7 +68,7 @@ watch( () => state.condition, (value) => { - store.commit('chatSystem/setCondition', _.cloneDeep(value)); + store.commit('imSystem/setCondition', _.cloneDeep(value)); }, { immediate: true, deep: true } ); @@ -79,7 +79,7 @@ }; const handleSearch = async () => { loading.value = true; - await store.dispatch('chatSystem/search'); + await store.dispatch('imSystem/search'); loading.value = false; }; onActivated(handleSearch); @@ -117,7 +117,7 @@ try { await proxy.$validate(refsForm); let data = _.cloneDeep(formState.form); - await store.dispatch('chatSystem/save', data); + await store.dispatch('imSystem/save', data); formState.formVisible = false; } catch (e) { console.info('取消保存', e); @@ -126,7 +126,7 @@ }; const handleRemove = async (rows) => { store.dispatch( - 'chatSystem/remove', + 'imSystem/remove', rows.map((item) => item.id) ); }; diff --git a/src/views/im/waiter/index.vue b/src/views/im/waiter/index.vue index 08614ff..2cbc990 100644 --- a/src/views/im/waiter/index.vue +++ b/src/views/im/waiter/index.vue @@ -5,7 +5,7 @@ :code="code" :config="config" :data="list" - :operation="['create', 'search', 'remove']" + :operation="['search']" :reset="handleReset" title="客服" :total="total" @@ -31,7 +31,7 @@ - +