review:【antd】【mp】自动回复优化

pull/259/MERGE
YunaiV 2025-11-09 16:55:03 +08:00
parent f8abee2b63
commit d6cbad72e5
5 changed files with 33 additions and 32 deletions

View File

@ -68,6 +68,7 @@ defineExpose({
</script> </script>
<template> <template>
<!-- TODO @hw可以使用 <Form class="mx-4" /> 这种组件形式么 融合到 /Users/yunai/Java/yudao-ui-admin-vben-v5/apps/web-antd/src/views/mp/autoReply/modules/form.vue -->
<div> <div>
<Form <Form
ref="formRef" ref="formRef"
@ -135,5 +136,3 @@ defineExpose({
</Form> </Form>
</div> </div>
</template> </template>
<style scoped></style>

View File

@ -3,7 +3,7 @@ import { WxMusic } from '#/views/mp/modules/wx-music';
import { WxNews } from '#/views/mp/modules/wx-news'; import { WxNews } from '#/views/mp/modules/wx-news';
import { WxVideoPlayer } from '#/views/mp/modules/wx-video-play'; import { WxVideoPlayer } from '#/views/mp/modules/wx-video-play';
import { WxVoicePlayer } from '#/views/mp/modules/wx-voice-play'; import { WxVoicePlayer } from '#/views/mp/modules/wx-voice-play';
// TODO @hw /Users/yunai/Java/yudao-ui-admin-vben-v5/apps/web-antd/src/views/mp/autoReply/modules = = content.vue ~
defineOptions({ name: 'ReplyContentCell' }); defineOptions({ name: 'ReplyContentCell' });
const props = defineProps<{ const props = defineProps<{

View File

@ -26,10 +26,12 @@ import Form from './modules/form.vue';
defineOptions({ name: 'MpAutoReply' }); defineOptions({ name: 'MpAutoReply' });
const msgType = ref<string>(String(MsgType.Keyword)); // const msgType = ref<string>(String(MsgType.Keyword)); //
async function onTabChange(_tabName: string) {
msgType.value = _tabName; /** 切换回复类型 */
// msgType async function onTabChange(tabName: string) {
msgType.value = tabName;
await nextTick(); await nextTick();
// columns
const columns = useGridColumns(Number(msgType.value) as MsgType); const columns = useGridColumns(Number(msgType.value) as MsgType);
if (columns) { if (columns) {
// 使 setGridOptions // 使 setGridOptions
@ -37,15 +39,14 @@ async function onTabChange(_tabName: string) {
// //
await nextTick(); await nextTick();
} }
//
await gridApi.query(); await gridApi.query();
//
updateTableDataLength(); updateTableDataLength();
} }
/** 新增按钮操作 */ /** 新增按钮操作 */
async function handleCreate() { async function handleCreate() {
const formValues = await gridApi.formApi.getValues(); const formValues = await gridApi.formApi.getValues();
formModalApi formModalApi
.setData({ .setData({
isCreating: true, isCreating: true,
@ -93,13 +94,11 @@ const [FormModal, formModalApi] = useVbenModal({
const [Grid, gridApi] = useVbenVxeGrid({ const [Grid, gridApi] = useVbenVxeGrid({
formOptions: { formOptions: {
schema: useGridFormSchema(), schema: useGridFormSchema(),
// accountId submitOnChange: true, // accountId
submitOnChange: true,
}, },
gridOptions: { gridOptions: {
columns: useGridColumns(Number(msgType.value) as MsgType), columns: useGridColumns(Number(msgType.value) as MsgType),
height: 'calc(100vh - 300px)', height: 'calc(100vh - 300px)',
// height: '600px',
keepSource: true, keepSource: true,
proxyConfig: { proxyConfig: {
ajax: { ajax: {
@ -112,8 +111,7 @@ const [Grid, gridApi] = useVbenVxeGrid({
}); });
}, },
}, },
// autoLoad: false, //
autoLoad: false,
}, },
rowConfig: { rowConfig: {
keyField: 'id', keyField: 'id',
@ -126,10 +124,10 @@ const [Grid, gridApi] = useVbenVxeGrid({
} as VxeTableGridOptions<any>, } as VxeTableGridOptions<any>,
}); });
// // TODO @hw
const tableDataLength = ref(0); const tableDataLength = ref(0); //
// getTableData /** 更新表格数据长度(避免在模板中直接调用 getTableData 导致响应式循环) */
function updateTableDataLength() { function updateTableDataLength() {
try { try {
if (!gridApi.grid) { if (!gridApi.grid) {
@ -142,6 +140,7 @@ function updateTableDataLength() {
} }
} }
// TODO @hw tableaction
// //
const showCreateButton = computed(() => { const showCreateButton = computed(() => {
if (Number(msgType.value) !== MsgType.Follow) { if (Number(msgType.value) !== MsgType.Follow) {
@ -150,20 +149,21 @@ const showCreateButton = computed(() => {
return tableDataLength.value <= 0; return tableDataLength.value <= 0;
}); });
// /** 页面挂载后,等待表单初始化完成再加载数据 */
onMounted(async () => { onMounted(async () => {
// WxAccountSelect // WxAccountSelect
await nextTick(); await nextTick();
if (gridApi.formApi) { if (!gridApi.formApi) {
const formValues = await gridApi.formApi.getValues(); return;
// accountId }
if (formValues.accountId) { const formValues = await gridApi.formApi.getValues();
// // accountId
gridApi.formApi.setLatestSubmissionValues(formValues); if (formValues.accountId) {
// //
await gridApi.query(); gridApi.formApi.setLatestSubmissionValues(formValues);
updateTableDataLength(); //
} await gridApi.query();
updateTableDataLength();
} }
}); });
</script> </script>
@ -173,6 +173,7 @@ onMounted(async () => {
<DocAlert title="自动回复" url="https://doc.iocoder.cn/mp/auto-reply/" /> <DocAlert title="自动回复" url="https://doc.iocoder.cn/mp/auto-reply/" />
<!-- tab 切换 --> <!-- tab 切换 -->
<!-- TODO @hw貌似 tabs 里面套 table 的样式在 vben 里有点丑要不我们按照 /Users/yunai/Java/yudao-ui-admin-vben-v5/apps/web-antd/src/views/mall/trade/afterSale/index.vue1第一层是公众号的选择2第二层是 tab3第三层是 table -->
<ContentWrap> <ContentWrap>
<Tabs <Tabs
v-model:active-key="msgType" v-model:active-key="msgType"

View File

@ -13,6 +13,7 @@ import { ReplyType } from '#/views/mp/modules/wx-reply/types';
import ReplyForm from '../components/ReplyForm.vue'; import ReplyForm from '../components/ReplyForm.vue';
import { MsgType } from '../components/types'; import { MsgType } from '../components/types';
import Form from '#/views/system/user/modules/form.vue';
const emit = defineEmits(['success']); const emit = defineEmits(['success']);
@ -24,7 +25,6 @@ const reply = ref<Reply>({
type: ReplyType.Text, type: ReplyType.Text,
accountId: -1, accountId: -1,
}); });
const getTitle = computed(() => { const getTitle = computed(() => {
return formData.value?.isCreating return formData.value?.isCreating
? $t('ui.actionTitle.create', ['自动回复']) ? $t('ui.actionTitle.create', ['自动回复'])
@ -130,6 +130,7 @@ const [Modal, modalApi] = useVbenModal({
</script> </script>
<template> <template>
<!-- TODO @hw可以使用 <Form class="mx-4" /> 这种组件形式么 -->
<Modal :title="getTitle" class="w-4/5"> <Modal :title="getTitle" class="w-4/5">
<ReplyForm <ReplyForm
v-if="formData" v-if="formData"

View File

@ -39,11 +39,11 @@ const [Modal, modalApi] = useVbenModal({
return; return;
} }
modalApi.lock(); modalApi.lock();
/** 提交表单 */ //
const values = (await formApi.getValues()) as MpUserApi.User; const values = (await formApi.getValues()) as MpUserApi.User;
try { try {
await updateUser({ ...formData.value, ...values }); await updateUser({ ...formData.value, ...values });
/** 关闭并提示 */ //
await modalApi.close(); await modalApi.close();
emit('success'); emit('success');
message.success($t('ui.actionMessage.operationSuccess')); message.success($t('ui.actionMessage.operationSuccess'));
@ -56,7 +56,7 @@ const [Modal, modalApi] = useVbenModal({
formData.value = undefined; formData.value = undefined;
return; return;
} }
/** 加载数据 */ //
const data = modalApi.getData<{ id: number }>(); const data = modalApi.getData<{ id: number }>();
if (!data || !data.id) { if (!data || !data.id) {
return; return;
@ -64,7 +64,7 @@ const [Modal, modalApi] = useVbenModal({
modalApi.lock(); modalApi.lock();
try { try {
formData.value = await getUser(data.id); formData.value = await getUser(data.id);
/** 设置到 values */ // values
await formApi.setValues(formData.value); await formApi.setValues(formData.value);
} finally { } finally {
modalApi.unlock(); modalApi.unlock();