fix: todo修复
This commit is contained in:
@@ -1,37 +1,24 @@
|
||||
import type { VbenFormSchema } from '#/adapter/form';
|
||||
import type { VxeGridPropTypes } from '#/adapter/vxe-table';
|
||||
import type { MpAccountApi } from '#/api/mp/account';
|
||||
|
||||
import { markRaw } from 'vue';
|
||||
|
||||
import { DICT_TYPE } from '@vben/constants';
|
||||
import { getDictObj, getDictOptions } from '@vben/hooks';
|
||||
import {
|
||||
AutoReplyMsgType,
|
||||
DICT_TYPE,
|
||||
RequestMessageTypes,
|
||||
} from '@vben/constants';
|
||||
import { getDictOptions } from '@vben/hooks';
|
||||
|
||||
import { getSimpleAccountList } from '#/api/mp/account';
|
||||
import { WxReplySelect } from '#/views/mp/components';
|
||||
|
||||
import { MsgType } from './modules/types';
|
||||
|
||||
/** 关联数据 */
|
||||
let accountList: MpAccountApi.AccountSimple[] = [];
|
||||
getSimpleAccountList().then((data) => (accountList = data));
|
||||
|
||||
// TODO @hw:要不要使用统一枚举?
|
||||
const RequestMessageTypes = new Set([
|
||||
'image',
|
||||
'link',
|
||||
'location',
|
||||
'shortvideo',
|
||||
'text',
|
||||
'video',
|
||||
'voice',
|
||||
]); // 允许选择的请求消息类型
|
||||
import { WxReply } from '#/views/mp/components';
|
||||
|
||||
/** 获取表格列配置 */
|
||||
export function useGridColumns(msgType: MsgType): VxeGridPropTypes.Columns {
|
||||
export function useGridColumns(
|
||||
msgType: AutoReplyMsgType,
|
||||
): VxeGridPropTypes.Columns {
|
||||
const columns: VxeGridPropTypes.Columns = [];
|
||||
// 请求消息类型列(仅消息回复显示)
|
||||
if (msgType === MsgType.Message) {
|
||||
if (msgType === AutoReplyMsgType.Message) {
|
||||
columns.push({
|
||||
field: 'requestMessageType',
|
||||
title: '请求消息类型',
|
||||
@@ -40,7 +27,7 @@ export function useGridColumns(msgType: MsgType): VxeGridPropTypes.Columns {
|
||||
}
|
||||
|
||||
// 关键词列(仅关键词回复显示)
|
||||
if (msgType === MsgType.Keyword) {
|
||||
if (msgType === AutoReplyMsgType.Keyword) {
|
||||
columns.push({
|
||||
field: 'requestKeyword',
|
||||
title: '关键词',
|
||||
@@ -49,7 +36,7 @@ export function useGridColumns(msgType: MsgType): VxeGridPropTypes.Columns {
|
||||
}
|
||||
|
||||
// 匹配类型列(仅关键词回复显示)
|
||||
if (msgType === MsgType.Keyword) {
|
||||
if (msgType === AutoReplyMsgType.Keyword) {
|
||||
columns.push({
|
||||
field: 'requestMatch',
|
||||
title: '匹配类型',
|
||||
@@ -67,9 +54,10 @@ export function useGridColumns(msgType: MsgType): VxeGridPropTypes.Columns {
|
||||
field: 'responseMessageType',
|
||||
title: '回复消息类型',
|
||||
minWidth: 120,
|
||||
// TODO @hw:这里和 antd 有差别。两侧尽量统一;
|
||||
formatter: ({ cellValue }) =>
|
||||
getDictObj(DICT_TYPE.MP_MESSAGE_TYPE, String(cellValue))?.label ?? '',
|
||||
cellRender: {
|
||||
name: 'CellDict',
|
||||
props: { type: DICT_TYPE.MP_MESSAGE_TYPE },
|
||||
},
|
||||
},
|
||||
{
|
||||
field: 'responseContent',
|
||||
@@ -94,12 +82,11 @@ export function useGridColumns(msgType: MsgType): VxeGridPropTypes.Columns {
|
||||
}
|
||||
|
||||
/** 新增/修改的表单 */
|
||||
export function useFormSchema(msgType: MsgType): VbenFormSchema[] {
|
||||
export function useFormSchema(msgType: AutoReplyMsgType): VbenFormSchema[] {
|
||||
const schema: VbenFormSchema[] = [];
|
||||
|
||||
// 消息类型(仅消息回复显示)
|
||||
// TODO @hw:这里和 antd 有差别。两侧尽量统一;
|
||||
if (Number(msgType) === MsgType.Message) {
|
||||
if (msgType === AutoReplyMsgType.Message) {
|
||||
schema.push({
|
||||
fieldName: 'requestMessageType',
|
||||
label: '消息类型',
|
||||
@@ -114,8 +101,7 @@ export function useFormSchema(msgType: MsgType): VbenFormSchema[] {
|
||||
}
|
||||
|
||||
// 匹配类型(仅关键词回复显示)
|
||||
// TODO @hw:这里和 antd 有差别。两侧尽量统一;
|
||||
if (Number(msgType) === MsgType.Keyword) {
|
||||
if (msgType === AutoReplyMsgType.Keyword) {
|
||||
schema.push({
|
||||
fieldName: 'requestMatch',
|
||||
label: '匹配类型',
|
||||
@@ -133,8 +119,7 @@ export function useFormSchema(msgType: MsgType): VbenFormSchema[] {
|
||||
}
|
||||
|
||||
// 关键词(仅关键词回复显示)
|
||||
// TODO @hw:这里和 antd 有差别。两侧尽量统一;
|
||||
if (Number(msgType) === MsgType.Keyword) {
|
||||
if (msgType === AutoReplyMsgType.Keyword) {
|
||||
schema.push({
|
||||
fieldName: 'requestKeyword',
|
||||
label: '关键词',
|
||||
@@ -147,31 +132,22 @@ export function useFormSchema(msgType: MsgType): VbenFormSchema[] {
|
||||
});
|
||||
}
|
||||
// 回复消息
|
||||
// TODO @hw:这里和 antd 有差别。两侧尽量统一;
|
||||
schema.push({
|
||||
fieldName: 'reply',
|
||||
label: '回复消息',
|
||||
component: markRaw(WxReplySelect),
|
||||
component: markRaw(WxReply),
|
||||
modelPropName: 'modelValue',
|
||||
});
|
||||
return schema;
|
||||
}
|
||||
|
||||
/** 列表的搜索表单 */
|
||||
// TODO @hw:是不是用 wxselect 组件哈?
|
||||
export function useGridFormSchema(): VbenFormSchema[] {
|
||||
return [
|
||||
{
|
||||
fieldName: 'accountId',
|
||||
label: '公众号',
|
||||
component: 'ApiSelect',
|
||||
componentProps: {
|
||||
options: accountList.map((item) => ({
|
||||
label: item.name,
|
||||
value: item.id,
|
||||
})),
|
||||
placeholder: '请选择公众号',
|
||||
},
|
||||
defaultValue: accountList[0]?.id,
|
||||
component: 'Input',
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
<script lang="ts" setup>
|
||||
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||
import type { MpAutoReplyApi } from '#/api/mp/autoReply';
|
||||
|
||||
import { computed, nextTick, ref } from 'vue';
|
||||
|
||||
import { DocAlert, Page, useVbenModal } from '@vben/common-ui';
|
||||
import { AutoReplyMsgType } from '@vben/constants';
|
||||
import { IconifyIcon } from '@vben/icons';
|
||||
|
||||
import {
|
||||
ElLoading,
|
||||
ElMessage,
|
||||
ElMessageBox,
|
||||
ElRow,
|
||||
@@ -27,14 +28,13 @@ import { WxAccountSelect } from '#/views/mp/components';
|
||||
import { useGridColumns, useGridFormSchema } from './data';
|
||||
import Content from './modules/content.vue';
|
||||
import Form from './modules/form.vue';
|
||||
import { MsgType } from './modules/types';
|
||||
|
||||
defineOptions({ name: 'MpAutoReply' });
|
||||
|
||||
const msgType = ref<string>(String(MsgType.Keyword)); // 消息类型
|
||||
const msgType = ref<string>(String(AutoReplyMsgType.Keyword)); // 消息类型
|
||||
|
||||
const showCreateButton = computed(() => {
|
||||
if (Number(msgType.value) !== MsgType.Follow) {
|
||||
if (Number(msgType.value) !== AutoReplyMsgType.Follow) {
|
||||
return true;
|
||||
}
|
||||
try {
|
||||
@@ -61,7 +61,7 @@ async function onTabChange(tabName: string) {
|
||||
msgType.value = tabName;
|
||||
await nextTick();
|
||||
// 更新 columns
|
||||
const columns = useGridColumns(Number(msgType.value) as MsgType);
|
||||
const columns = useGridColumns(Number(msgType.value) as AutoReplyMsgType);
|
||||
if (columns) {
|
||||
// 使用 setGridOptions 更新列配置
|
||||
gridApi.setGridOptions({ columns });
|
||||
@@ -77,8 +77,7 @@ async function handleCreate() {
|
||||
const formValues = await gridApi.formApi.getValues();
|
||||
formModalApi
|
||||
.setData({
|
||||
// TODO @hw:这里和 antd 不同,需要 number 下么?
|
||||
msgType: msgType.value,
|
||||
msgType: Number(msgType.value) as AutoReplyMsgType,
|
||||
accountId: formValues.accountId,
|
||||
})
|
||||
.open();
|
||||
@@ -87,14 +86,11 @@ async function handleCreate() {
|
||||
/** 修改自动回复 */
|
||||
async function handleEdit(row: any) {
|
||||
const data = (await getAutoReply(row.id)) as any;
|
||||
// TODO @hw:这里使用 formValues,还是使用 row?
|
||||
const formValues = await gridApi.formApi.getValues();
|
||||
formModalApi
|
||||
.setData({
|
||||
// TODO @hw:这里和 antd 不同,需要 number 下么?
|
||||
msgType: msgType.value,
|
||||
msgType: Number(msgType.value) as AutoReplyMsgType,
|
||||
accountId: row.accountId,
|
||||
row: data,
|
||||
accountId: formValues.accountId,
|
||||
})
|
||||
.open();
|
||||
}
|
||||
@@ -102,16 +98,10 @@ async function handleEdit(row: any) {
|
||||
/** 删除自动回复 */
|
||||
async function handleDelete(row: any) {
|
||||
await ElMessageBox.confirm('是否确认删除此数据?');
|
||||
const loadingInstance = ElLoading.service({
|
||||
text: $t('ui.actionMessage.deleting', ['自动回复']),
|
||||
});
|
||||
try {
|
||||
await deleteAutoReply(row.id);
|
||||
ElMessage.success('删除成功');
|
||||
handleRefresh();
|
||||
} finally {
|
||||
loadingInstance.close();
|
||||
}
|
||||
|
||||
await deleteAutoReply(row.id);
|
||||
ElMessage.success('删除成功');
|
||||
handleRefresh();
|
||||
}
|
||||
|
||||
const [FormModal, formModalApi] = useVbenModal({
|
||||
@@ -124,7 +114,7 @@ const [Grid, gridApi] = useVbenVxeGrid({
|
||||
schema: useGridFormSchema(),
|
||||
},
|
||||
gridOptions: {
|
||||
columns: useGridColumns(Number(msgType.value) as MsgType),
|
||||
columns: useGridColumns(Number(msgType.value) as AutoReplyMsgType),
|
||||
height: 'auto',
|
||||
keepSource: true,
|
||||
proxyConfig: {
|
||||
@@ -133,7 +123,7 @@ const [Grid, gridApi] = useVbenVxeGrid({
|
||||
return await getAutoReplyPage({
|
||||
pageNo: page.currentPage,
|
||||
pageSize: page.pageSize,
|
||||
type: Number(msgType.value) as MsgType,
|
||||
type: Number(msgType.value) as AutoReplyMsgType,
|
||||
...formValues,
|
||||
});
|
||||
},
|
||||
@@ -148,8 +138,7 @@ const [Grid, gridApi] = useVbenVxeGrid({
|
||||
refresh: true,
|
||||
search: true,
|
||||
},
|
||||
// TODO @hw:这里要调整下,linter 报错;
|
||||
} as VxeTableGridOptions<any>,
|
||||
} as VxeTableGridOptions<MpAutoReplyApi.AutoReply>,
|
||||
});
|
||||
</script>
|
||||
|
||||
@@ -170,14 +159,14 @@ const [Grid, gridApi] = useVbenVxeGrid({
|
||||
class="w-full"
|
||||
@tab-change="(activeName) => onTabChange(activeName as string)"
|
||||
>
|
||||
<ElTabPane :name="String(MsgType.Follow)">
|
||||
<ElTabPane :name="String(AutoReplyMsgType.Follow)">
|
||||
<template #label>
|
||||
<ElRow align="middle">
|
||||
<IconifyIcon icon="ep:star" class="mr-[2px]" /> 关注时回复
|
||||
</ElRow>
|
||||
</template>
|
||||
</ElTabPane>
|
||||
<ElTabPane :name="String(MsgType.Message)">
|
||||
<ElTabPane :name="String(AutoReplyMsgType.Message)">
|
||||
<template #label>
|
||||
<ElRow align="middle">
|
||||
<IconifyIcon icon="ep:chat-line-round" class="mr-[2px]" />
|
||||
@@ -185,7 +174,7 @@ const [Grid, gridApi] = useVbenVxeGrid({
|
||||
</ElRow>
|
||||
</template>
|
||||
</ElTabPane>
|
||||
<ElTabPane :name="String(MsgType.Keyword)">
|
||||
<ElTabPane :name="String(AutoReplyMsgType.Keyword)">
|
||||
<template #label>
|
||||
<ElRow align="middle">
|
||||
<IconifyIcon icon="fa:newspaper-o" class="mr-[2px]" />
|
||||
|
||||
@@ -4,22 +4,21 @@ import type { Reply } from '#/views/mp/components/wx-reply/types';
|
||||
import { computed, nextTick, ref } from 'vue';
|
||||
|
||||
import { useVbenModal } from '@vben/common-ui';
|
||||
import { AutoReplyMsgType, ReplyType } from '@vben/constants';
|
||||
|
||||
import { ElMessage } from 'element-plus';
|
||||
|
||||
import { useVbenForm } from '#/adapter/form';
|
||||
import { createAutoReply, updateAutoReply } from '#/api/mp/autoReply';
|
||||
import { $t } from '#/locales';
|
||||
import { ReplyType } from '#/views/mp/components/wx-reply/types';
|
||||
|
||||
import { useFormSchema } from '../data';
|
||||
import { MsgType } from './types';
|
||||
|
||||
const emit = defineEmits(['success']);
|
||||
|
||||
const formData = ref<{
|
||||
accountId?: number;
|
||||
msgType: MsgType;
|
||||
msgType: AutoReplyMsgType;
|
||||
row?: any;
|
||||
}>();
|
||||
const getTitle = computed(() => {
|
||||
@@ -37,8 +36,7 @@ const [Form, formApi] = useVbenForm({
|
||||
labelWidth: 100,
|
||||
},
|
||||
layout: 'horizontal',
|
||||
// TODO @hw:antd 和 ele 存在差异
|
||||
schema: useFormSchema(Number(formData.value?.msgType) as MsgType),
|
||||
schema: useFormSchema(AutoReplyMsgType.Keyword),
|
||||
showDefaultActions: false,
|
||||
});
|
||||
|
||||
@@ -59,8 +57,7 @@ const [Modal, modalApi] = useVbenModal({
|
||||
if (formData.value?.row?.id && !submitForm.id) {
|
||||
submitForm.id = formData.value.row.id;
|
||||
}
|
||||
// TODO @hw:antd 和 ele 存在差异
|
||||
const reply = submitForm.reply as Reply | undefined;
|
||||
const reply = submitForm.reply as Reply;
|
||||
if (reply) {
|
||||
submitForm.responseMessageType = reply.type;
|
||||
submitForm.responseContent = reply.content;
|
||||
@@ -99,8 +96,7 @@ const [Modal, modalApi] = useVbenModal({
|
||||
// 加载数据
|
||||
const data = modalApi.getData<{
|
||||
accountId?: number;
|
||||
// TODO @hw:antd 和 ele 存在差异
|
||||
msgType: MsgType;
|
||||
msgType: AutoReplyMsgType;
|
||||
row?: any;
|
||||
}>();
|
||||
if (!data) {
|
||||
@@ -138,8 +134,7 @@ const [Modal, modalApi] = useVbenModal({
|
||||
accountId: data.accountId || -1,
|
||||
type: data.msgType,
|
||||
requestKeyword: undefined,
|
||||
// TODO @hw:antd 和 ele 存在差异
|
||||
requestMatch: data.msgType === MsgType.Keyword ? 1 : undefined,
|
||||
requestMatch: data.msgType === AutoReplyMsgType.Keyword ? 1 : undefined,
|
||||
requestMessageType: undefined,
|
||||
reply: {
|
||||
type: ReplyType.Text,
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
// 消息类型(Follow: 关注时回复;Message: 消息回复;Keyword: 关键词回复)
|
||||
// 作为 tab.name,enum 的数字不能随意修改,与 api 参数相关
|
||||
// TODO @hw:ele 相比 antd 多了,看看要不要统一下;
|
||||
export enum MsgType {
|
||||
Follow = 1,
|
||||
Keyword = 3,
|
||||
Message = 2,
|
||||
}
|
||||
Reference in New Issue
Block a user