review:【antd】【mp】代码评审

This commit is contained in:
YunaiV
2025-11-17 13:57:41 +08:00
parent 6f0273ab4e
commit f11b7aea69
21 changed files with 101 additions and 140 deletions

View File

@@ -27,7 +27,6 @@ export function useGridColumns(): VxeTableGridOptions['columns'] {
}
/** 列表的搜索表单 */
// DONE @hw这里的公众号选择要改参考 /apps/web-antd/src/views/mp/tag/data.ts相关联的代码还简单点~
export function useGridFormSchema(): VbenFormSchema[] {
return [
{

View File

@@ -10,7 +10,6 @@ import { message } from 'ant-design-vue';
import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
import { deleteDraft, getDraftPage } from '#/api/mp/draft';
// DONE @hwMpFreePublishApi 去掉,直接 import参考别的模块哈
import { submitFreePublish } from '#/api/mp/freePublish';
import { createEmptyNewsItem } from '#/views/mp/draft/modules/types';
@@ -18,8 +17,6 @@ import { useGridColumns, useGridFormSchema } from './data';
import DraftTableCell from './modules/draft-table.vue';
import Form from './modules/form.vue';
// DONE @hw参考 tag/index.vue 放到 formValues.accountId;
// DONE @hw看看这个 watch、provide 能不能简化掉;
defineOptions({ name: 'MpDraft' });
/** 刷新表格 */
@@ -27,12 +24,7 @@ function handleRefresh() {
gridApi.query();
}
const [FormModal, formModalApi] = useVbenModal({
connectedComponent: Form,
destroyOnClose: true,
});
/** 新增按钮操作 */
/** 新增草稿 */
async function handleCreate() {
const formValues = await gridApi.formApi.getValues();
const accountId = formValues.accountId;
@@ -49,7 +41,7 @@ async function handleCreate() {
.open();
}
/** 修改按钮操作 */
/** 修改草稿 */
async function handleEdit(row: Article) {
const formValues = await gridApi.formApi.getValues();
const accountId = formValues.accountId;
@@ -67,11 +59,32 @@ async function handleEdit(row: Article) {
.open();
}
/** 发布按钮操作 */
/** 删除草稿 */
async function handleDelete(row: Article) {
const formValues = await gridApi.formApi.getValues();
const accountId = formValues.accountId;
if (!accountId) {
message.warning('请先选择公众号');
return;
}
await confirm('此操作将永久删除该草稿, 是否继续?');
const hideLoading = message.loading({
content: '删除中...',
duration: 0,
});
try {
await deleteDraft(accountId, row.mediaId);
message.success('删除成功');
handleRefresh();
} finally {
hideLoading();
}
}
/** 发布草稿 */
async function handlePublish(row: Article) {
const formValues = await gridApi.formApi.getValues();
const accountId = formValues.accountId;
// DONE @hw看看能不能去掉 -1 的判断哈?
if (!accountId) {
message.warning('请先选择公众号');
return;
@@ -94,27 +107,10 @@ async function handlePublish(row: Article) {
}
}
/** 删除按钮操作 */
async function handleDelete(row: Article) {
const formValues = await gridApi.formApi.getValues();
const accountId = formValues.accountId;
if (!accountId) {
message.warning('请先选择公众号');
return;
}
await confirm('此操作将永久删除该草稿, 是否继续?');
const hideLoading = message.loading({
content: '删除中...',
duration: 0,
});
try {
await deleteDraft(accountId, row.mediaId);
message.success('删除成功');
handleRefresh();
} finally {
hideLoading();
}
}
const [FormModal, formModalApi] = useVbenModal({
connectedComponent: Form,
destroyOnClose: true,
});
const [Grid, gridApi] = useVbenVxeGrid({
formOptions: {
@@ -157,10 +153,9 @@ const [Grid, gridApi] = useVbenVxeGrid({
refresh: true,
search: true,
},
// TODO @hw这里有点纠结一般是 MpDraftApi.Article但是一改貌似就 linter 告警了。
} as VxeTableGridOptions<Article>,
});
// DONE @hw看看能不能参考 tag/index.vue 简化下
</script>
<template>

View File

@@ -56,12 +56,11 @@ function onMaterialSelected(item: any) {
newsItem.value.thumbMediaId = item.mediaId;
newsItem.value.thumbUrl = item.url;
}
// DONE @hw注释都补充下哈
/** 上传前校验 */
const onBeforeUpload = (file: UploadFile) =>
useBeforeUpload(UploadType.Image, 2)(file as any);
// DONE @hw注释都补充下哈
/** 上传错误处理 */
function onUploadChange(info: any) {
if (info.file.status === 'error') {
@@ -69,7 +68,6 @@ function onUploadChange(info: any) {
}
}
// DONE @hw注释都补充下哈
/** 上传成功处理 */
function onUploadSuccess(res: any) {
if (res.code !== 0) {
@@ -84,7 +82,6 @@ function onUploadSuccess(res: any) {
newsItem.value.thumbUrl = res.data.url;
}
// DONE @hw注释都补充下哈
/** 上传失败处理 */
function onUploadError(err: Error) {
message.error(`上传失败: ${err.message}`);
@@ -94,8 +91,6 @@ function onUploadError(err: Error) {
<template>
<div>
<p>封面:</p>
<!-- DONE @hw我貌似上传不成功不确定是不是我这边的问题可以微信沟通下哈 -->
<!-- DONE @hw尽量使用 tindwind 替代ps如果多个组件复用那就不用调整 -->
<div class="flex w-full flex-col items-center justify-center text-center">
<Image
v-if="newsItem.thumbUrl"
@@ -138,7 +133,6 @@ function onUploadError(err: Error) {
支持 bmp/png/jpeg/jpg/gif 格式大小不超过 2M
</div>
</div>
<!-- DONE @hw是不是使用 vben 自带的 Modal 这样 ele 通用性更好点其它模块涉及到 Modal 也按照这个调整噢 -->
<Modal
v-model:open="dialogVisible"
title="图片选择"

View File

@@ -13,25 +13,22 @@ import NewsForm from './news-form.vue';
const emit = defineEmits(['success']);
// DONE @hw是不是通过 id 字段判断是否为新增?类似 /Users/yunai/Java/yudao-ui-admin-vben-v5/apps/web-antd/src/views/system/user/modules/form.vue
const formData = ref<{
accountId: number;
mediaId?: string;
newsList?: NewsItem[];
}>();
const newsList = ref<NewsItem[]>([]);
// DONE @hw不需要 isSave通过 modal 去 lock 就好啦。
const isSubmitting = ref(false);
const getTitle = computed(() => {
return formData.value?.mediaId ? '修改图文' : '新建图文';
});
// 提供 accountId 给子组件
provide(
'accountId',
computed(() => formData.value?.accountId),
);
); // 提供 accountId 给子组件
const [Modal, modalApi] = useVbenModal({
async onConfirm() {
@@ -39,6 +36,7 @@ const [Modal, modalApi] = useVbenModal({
return;
}
// TODO @hw是不是 isSubmitting 非必须哈?因为 modal 已经去 lock 啦。
isSubmitting.value = true;
modalApi.lock();
try {

View File

@@ -44,7 +44,6 @@ const activeNewsItem = computed(() => {
return item;
});
// DONE @hw注释使用 /** */
/** 将图文向下移动 */
function moveDownNews(index: number) {
const current = newsList.value[index];
@@ -86,7 +85,6 @@ function plusNews() {
<template>
<Layout>
<Layout.Sider width="40%" theme="light">
<!-- DONE @hw尽量使用 tindwind 替代ps如果多个组件复用那就不用调整 -->
<div class="mx-auto mb-[10px] w-[60%] border border-[#eaeaea] p-[10px]">
<div v-for="(news, index) in newsList" :key="index">
<div

View File

@@ -1,4 +1,4 @@
// DONE @hw要不把 components 里的部分,拿到 modules 里
// TODO @hw这个要融合到 draftApi 里么?类似其他模块的
interface NewsItem {
title: string;
thumbMediaId: string;