feat: 接口对接

feat-im-0607-xwk
向文可 2 years ago
parent 2d80b2f2ac
commit e2f84193cd

@ -7,7 +7,7 @@ const state = () => ({
total: 0, total: 0,
opts: { opts: {
init: false, init: false,
system: [], store: [],
}, },
}); });
const getters = {}; const getters = {};
@ -34,12 +34,12 @@ const actions = {
load: async ({ commit }) => { load: async ({ commit }) => {
commit('setOpts', { commit('setOpts', {
init: true, init: true,
system: (await api.searchSystem({ pageIndex: 1, length: 9999 }))?.records || [], store: (await api.searchStore({ pageIndex: 1, length: 9999 }))?.records || [],
}); });
}, },
save: async ({ dispatch }, data) => { save: async ({ state, dispatch }, data) => {
if (data.id) { if (data.id) {
data.systemId = data.sysId; data.systemId = state.condition.systemid;
} }
let save = data.id ? api.updateWaiter : api.createWaiter; let save = data.id ? api.updateWaiter : api.createWaiter;
let res = await save(data); let res = await save(data);
@ -51,13 +51,13 @@ const actions = {
} }
return res; return res;
}, },
remove: async ({ dispatch }, ids) => { remove: async ({ dispatch }, data) => {
if (!ids.length) { if (!data.waiterIds.length) {
ElMessage.warning('请选择要删除的数据'); ElMessage.warning('请选择要删除的数据');
} else { } else {
try { try {
await ElMessageBox.confirm('数据删除后无法恢复,确定要删除吗?', '危险操作'); await ElMessageBox.confirm('数据删除后无法恢复,确定要删除吗?', '危险操作');
let res = await api.removeWaiter({ ids }); let res = await api.removeWaiter(data);
if (res) { if (res) {
ElMessage.success('删除成功'); ElMessage.success('删除成功');
dispatch('search'); dispatch('search');

@ -61,6 +61,14 @@ instance.interceptors.request.use(
if (token) { if (token) {
config.headers['Authorization'] = token; config.headers['Authorization'] = token;
} }
config.params = Object.fromEntries(
Object.entries(config.params || {}).filter(
(entry) =>
entry[1] !== null &&
typeof entry[1] !== 'undefined' &&
(typeof entry[1] !== 'string' || entry[1].trim() !== '')
)
);
if (config.data && config.headers['Content-Type'] === 'application/x-www-form-urlencoded;charset=UTF-8') { if (config.data && config.headers['Content-Type'] === 'application/x-www-form-urlencoded;charset=UTF-8') {
config.data = qs.stringify(config.data); config.data = qs.stringify(config.data);
} }

@ -26,7 +26,13 @@
</template> </template>
</table-list> </table-list>
<el-dialog v-model="formState.formVisible" :title="formState.form.id ? '编辑' : '添加' + '店铺'"> <el-dialog v-model="formState.formVisible" :title="formState.form.id ? '编辑' : '添加' + '店铺'">
<el-form ref="refsForm" label-width="100px" :model="formState.form" :rules="formState.rules"> <el-form
ref="refsForm"
v-loading="formState.submitting"
label-width="100px"
:model="formState.form"
:rules="formState.rules"
>
<el-form-item label="所属系统" prop="sysId"> <el-form-item label="所属系统" prop="sysId">
<el-select <el-select
v-model="formState.form.sysId" v-model="formState.form.sysId"
@ -55,6 +61,7 @@
import ElImage from '@/components/extra/ElImage.vue'; import ElImage from '@/components/extra/ElImage.vue';
const store = useStore(); const store = useStore();
const route = useRoute(); const route = useRoute();
const router = useRouter();
const { proxy } = getCurrentInstance(); const { proxy } = getCurrentInstance();
const loading = ref(false); const loading = ref(false);
const code = computed(() => store.state.chatStore.code); const code = computed(() => store.state.chatStore.code);
@ -145,6 +152,14 @@
rows.map((item) => item.id) rows.map((item) => item.id)
); );
}; };
const handleWaiter = (row) => {
router.push({
name: 'ChatWaiter',
query: {
storeId: row.id,
},
});
};
const config = reactive({ const config = reactive({
// //
columns: [ columns: [
@ -169,19 +184,22 @@
{ {
label: '操作', label: '操作',
fixed: 'right', fixed: 'right',
width: 160,
slots: { slots: {
default: ({ row }) => ( default: ({ row }) => (
<div> <div>
<ElButton type="text" onClick={() => handleCreate(row)}> <ElButton type="text" onClick={() => handleCreate(row)}>
编辑 编辑
</ElButton> </ElButton>
<ElButton type="text" onClick={() => handleWaiter(row)}>
客服
</ElButton>
<ElButton type="text" onClick={() => handleRemove([row])}> <ElButton type="text" onClick={() => handleRemove([row])}>
删除 删除
</ElButton> </ElButton>
</div> </div>
), ),
}, },
width: 120,
}, },
], ],
}); });

@ -16,6 +16,7 @@
<el-dialog v-model="formState.formVisible" :title="formState.form.id ? '查看' : '添加' + '系统'"> <el-dialog v-model="formState.formVisible" :title="formState.form.id ? '查看' : '添加' + '系统'">
<el-form <el-form
ref="refsForm" ref="refsForm"
v-loading="formState.submitting"
:disabled="!!formState.form.id" :disabled="!!formState.form.id"
label-width="100px" label-width="100px"
:model="formState.form" :model="formState.form"

@ -15,11 +15,11 @@
> >
<template #search> <template #search>
<el-form inline> <el-form inline>
<el-form-item label="所属系统" prop="systemId"> <el-form-item label="所属店铺" prop="storeId">
<el-select <el-select
v-model="state.condition.systemId" v-model="state.condition.storeId"
:config="{ label: 'name', value: 'id' }" :config="{ label: 'name', value: 'id' }"
:opts="opts.system" :opts="opts.store"
/> />
</el-form-item> </el-form-item>
<el-form-item label="客服ID" prop="waiterId"> <el-form-item label="客服ID" prop="waiterId">
@ -32,23 +32,29 @@
</template> </template>
</table-list> </table-list>
<el-dialog v-model="formState.formVisible" :title="formState.form.id ? '编辑' : '添加' + '店铺'"> <el-dialog v-model="formState.formVisible" :title="formState.form.id ? '编辑' : '添加' + '店铺'">
<el-form ref="refsForm" label-width="100px" :model="formState.form" :rules="formState.rules"> <el-form
<el-form-item label="所属系统" prop="systemId"> ref="refsForm"
v-loading="formState.submitting"
label-width="100px"
:model="formState.form"
:rules="formState.rules"
>
<el-form-item label="所属店铺" prop="storeId">
<el-select <el-select
v-model="formState.form.sysId" v-model="formState.form.storeId"
:config="{ label: 'name', value: 'id' }" :config="{ label: 'name', value: 'id' }"
:disabled="formState.form.id" :disabled="formState.form.id"
:opts="opts.system" :opts="opts.store"
/> />
</el-form-item> </el-form-item>
<el-form-item label="客服类型" prop="type"> <el-form-item label="客服类型" prop="type">
<el-radio-group v-model="formState.form.type" :opts="opts.type" /> <el-input v-model="formState.form.type" />
</el-form-item> </el-form-item>
<el-form-item label="客服头像" prop="waiterAvatar"> <el-form-item label="客服头像" prop="waiterAvatar">
<el-upload-image v-model="formState.form.waiterAvatar" config-id="im/" /> <el-upload-image v-model="formState.form.waiterAvatar" config-id="im/" />
</el-form-item> </el-form-item>
<el-form-item label="客服ID" prop="waiterId"> <el-form-item label="客服ID" prop="waiterId">
<el-input v-model="formState.form.waiterId" /> <el-input v-model="formState.form.waiterId" :disabled="!!formState.form.id" />
</el-form-item> </el-form-item>
<el-form-item label="客服昵称" prop="waiterNickname"> <el-form-item label="客服昵称" prop="waiterNickname">
<el-input v-model="formState.form.waiterNickname" /> <el-input v-model="formState.form.waiterNickname" />
@ -78,35 +84,50 @@
} }
const state = reactive({ const state = reactive({
condition: { condition: {
systemId: null, storeId: null,
waiterId: null, waiterId: null,
waiterNickname: null, waiterNickname: null,
}, },
}); });
const handleReset = () => { const handleReset = () => {
state.condition = { state.condition = {
systemId: null, storeId: null,
waiterId: null, waiterId: null,
waiterNickname: null, waiterNickname: null,
}; };
}; };
const handleSearch = async () => { const handleSearch = async () => {
loading.value = true; if (state.condition.storeId) {
await store.dispatch('chatWaiter/search'); loading.value = true;
loading.value = false; await store.dispatch('chatWaiter/search');
loading.value = false;
}
}; };
watch(
() => unref(opts).store,
(value) => {
if (!state.condition.storeId) {
state.condition.storeId = value[0]?.id;
}
}
);
watch( watch(
() => state.condition, () => state.condition,
(value) => { (value) => {
store.commit('chatWaiter/setCondition', _.cloneDeep(value)); store.commit('chatWaiter/setCondition', _.cloneDeep(value));
handleSearch();
}, },
{ immediate: true, deep: true } { immediate: true, deep: true }
); );
watch(
() => state.condition.storeId,
() => {
handleSearch();
}
);
onActivated(() => { onActivated(() => {
let sysId = route.query.sysId; let storeId = route.query.storeId;
if (sysId) { if (storeId) {
state.condition.sysId = +sysId; state.condition.storeId = +storeId;
} else { } else {
handleSearch(); handleSearch();
} }
@ -119,14 +140,14 @@
submitting: false, submitting: false,
form: { form: {
id: null, id: null,
systemId: null, storeId: null,
type: 0, type: null,
waiterAvatar: null, waiterAvatar: null,
waiterId: null, waiterId: null,
waiterNickname: null, waiterNickname: null,
}, },
rules: { rules: {
systemId: [{ required: true, message: '所属系统不能为空' }], storeId: [{ required: true, message: '所属店铺不能为空' }],
type: [{ required: true, message: '客服类型不能为空' }], type: [{ required: true, message: '客服类型不能为空' }],
waiterAvatar: [{ required: true, message: '客服头像不能为空' }], waiterAvatar: [{ required: true, message: '客服头像不能为空' }],
waiterId: [{ required: true, message: '客服ID不能为空' }], waiterId: [{ required: true, message: '客服ID不能为空' }],
@ -139,13 +160,16 @@
formState.form, formState.form,
row || { row || {
id: null, id: null,
systemId: null, storeId: null,
type: 0, type: null,
waiterAvatar: null, waiterAvatar: null,
waiterId: null, waiterId: null,
waiterNickname: null, waiterNickname: null,
} }
); );
if (!formState.form.storeId) {
formState.form.storeId = state.condition.storeId;
}
formState.formVisible = true; formState.formVisible = true;
}; };
// //
@ -162,19 +186,19 @@
formState.submitting = false; formState.submitting = false;
}; };
const handleRemove = async (rows) => { const handleRemove = async (rows) => {
store.dispatch( store.dispatch('chatWaiter/remove', {
'chatWaiter/remove', storeId: state.condition.storeId,
rows.map((item) => item.id) waiterIds: rows.map((item) => item.waiterId),
); });
}; };
const config = reactive({ const config = reactive({
// //
columns: [ columns: [
{ {
label: '所属系统', label: '所属店铺',
width: 160, width: 160,
slots: { slots: {
default: ({ row }) => proxy.$dict(unref(opts).system, row.sysId, { label: 'name', value: 'id' }), default: ({ row }) => proxy.$dict(unref(opts).store, row.storeId, { label: 'name', value: 'id' }),
}, },
}, },
{ {

Loading…
Cancel
Save