From 4789117bf127e77094d842febf2e6a3a28001f9d 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:39:33 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20IM=E5=AE=A2=E6=9C=8D=E9=87=8D?= =?UTF-8?q?=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/chat/waiter.js | 36 +++++++++++ src/store/modules/chat/chatWaiter.js | 28 ++++---- src/views/chat/waiter.vue | 97 ++++++---------------------- src/views/im/store/index.vue | 2 +- src/views/im/system/index.vue | 2 +- src/views/im/waiter/index.vue | 4 -- 6 files changed, 72 insertions(+), 97 deletions(-) create mode 100644 src/api/chat/waiter.js diff --git a/src/api/chat/waiter.js b/src/api/chat/waiter.js new file mode 100644 index 0000000..03004fc --- /dev/null +++ b/src/api/chat/waiter.js @@ -0,0 +1,36 @@ +import request from '@/utils/request.js'; +export const search = (params) => { + return request({ + url: '/mall/im/admin/waiterUser', + method: 'get', + params, + }); +}; +export const detail = (userId) => { + return request({ + url: '/mall/im/admin/waiterUser/getWaiterByUserId', + method: 'get', + params: { userId }, + }); +}; +export const create = (data) => { + return request({ + url: '/mall/im/admin/waiterUser', + method: 'post', + data, + }); +}; +export const update = (data) => { + return request({ + url: '/mall/im/admin/waiterUser', + method: 'put', + data, + }); +}; +export const remove = (ids) => { + return request({ + url: '/mall/im/admin/waiterUser', + method: 'delete', + data: { ids }, + }); +}; diff --git a/src/store/modules/chat/chatWaiter.js b/src/store/modules/chat/chatWaiter.js index 3d4c0d7..7451300 100644 --- a/src/store/modules/chat/chatWaiter.js +++ b/src/store/modules/chat/chatWaiter.js @@ -1,4 +1,5 @@ -import * as api from '@/api/im/index.js'; +import * as api from '@/api/chat/waiter.js'; +import * as EmployeeAPI from '@/api/permission/employee.js'; import { ElMessage, ElMessageBox } from '@/plugins/element-plus'; const state = () => ({ code: 'ChatWaiter', @@ -7,7 +8,7 @@ const state = () => ({ total: 0, opts: { init: false, - store: [], + employee: [], }, }); const getters = {}; @@ -21,27 +22,26 @@ const mutations = { const actions = { search: async ({ state, commit, rootGetters }) => { let data = { ...state.condition }; - let res = await api.searchWaiter({ ...rootGetters['local/page'](state.code), ...data }); - if (res) { - commit('setList', res.records); - commit('setTotal', res.total); - } else { + let res = await api.search({ ...rootGetters['local/page'](state.code), ...data }); + commit('setList', res?.records || []); + commit('setTotal', res?.total || 0); + if (!res) { ElMessage.error('查询失败'); - commit('setList', []); } return res; }, - load: async ({ commit }) => { + load: async ({ state, commit }) => { commit('setOpts', { + ...state.opts, init: true, - store: (await api.searchStore({ pageIndex: 1, length: 9999 }))?.records || [], + employee: (await EmployeeAPI.search({ pageIndex: 1, length: 9999 }))?.records || [], }); }, save: async ({ state, dispatch }, data) => { if (data.id) { data.systemId = state.condition.systemid; } - let save = data.id ? api.updateWaiter : api.createWaiter; + let save = data.id ? api.update : api.create; let res = await save(data); if (res) { ElMessage.success('保存成功'); @@ -51,13 +51,13 @@ const actions = { } return res; }, - remove: async ({ dispatch }, data) => { - if (!data.waiterIds.length) { + remove: async ({ dispatch }, ids) => { + if (!ids.length) { ElMessage.warning('请选择要删除的数据'); } else { try { await ElMessageBox.confirm('数据删除后无法恢复,确定要删除吗?', '危险操作'); - let res = await api.removeWaiter(data); + let res = await api.remove(ids); if (res) { ElMessage.success('删除成功'); dispatch('search'); diff --git a/src/views/chat/waiter.vue b/src/views/chat/waiter.vue index 08614ff..4d15ea3 100644 --- a/src/views/chat/waiter.vue +++ b/src/views/chat/waiter.vue @@ -15,16 +15,6 @@ >