refactor(@vben/web-antd): 优化 Word模块的属性定义和类型安全

- 修改 typing.ts 中的 Props接口
- 优化 extractDocxInfo 函数的返回类型,增加对 filename 的 undefined 支持
This commit is contained in:
Kven 2025-06-25 23:16:19 +08:00
parent 2dd824324f
commit 655eca8e4d
2 changed files with 28 additions and 26 deletions

View File

@ -7,7 +7,7 @@ import type {
import type { DrawerPlacement } from '@vben/common-ui'; import type { DrawerPlacement } from '@vben/common-ui';
import type { Props, ResultItem, WordTempItem } from '../typing'; import type { Props, ResultItem } from '../typing';
import { computed, h, ref, watch } from 'vue'; import { computed, h, ref, watch } from 'vue';
@ -42,26 +42,32 @@ import WordPreview from './word-preview.vue';
defineOptions({ name: 'WordWorkView' }); defineOptions({ name: 'WordWorkView' });
const props = withDefaults(defineProps<Props>(), { const props = withDefaults(defineProps<Props>(), {
item: { item: () => {
id: '', return {
name: '', id: '',
} as WordTempItem, name: '',
};
},
itemMessage: Array, itemMessage: Array,
paramsData: Array, paramsData: Array,
runChatFlow: () => async () => ({ runChatFlow: () => {
event: '', return {
conversationId: '', event: '',
messageFiles: [], conversationId: '',
messageId: '', messageFiles: [],
taskId: '', messageId: '',
id: '', taskId: '',
answer: '', id: '',
}), answer: '',
projectInfo: { };
projectName: '', },
projectContext: '', projectInfo: () => {
projectKeyAvoidTechOrKeyword: '', return {
userInitialInnovationPoint: '', projectContext: '',
projectKeyAvoidTechOrKeyword: '',
projectName: '',
userInitialInnovationPoint: '',
};
}, },
}); });
@ -182,7 +188,7 @@ function openPreviewDrawer(
// ==================== Event ==================== // ==================== Event ====================
function extractDocxInfo( function extractDocxInfo(
markdownLink: string, markdownLink: string,
): null | { filename: string; url: string } { ): null | { filename: string | undefined; url: string } {
const fileRegex = /\[(.*?)\]/; const fileRegex = /\[(.*?)\]/;
const urlRegex = /\((.*?)\)/; const urlRegex = /\((.*?)\)/;
const fileMatch = markdownLink.match(fileRegex); const fileMatch = markdownLink.match(fileRegex);
@ -254,7 +260,6 @@ const startFetching = async () => {
h( h(
Button, Button,
{ {
size: 'normal',
type: 'primary', type: 'primary',
onClick: () => { onClick: () => {
openPreviewDrawer('right', url); openPreviewDrawer('right', url);
@ -265,13 +270,12 @@ const startFetching = async () => {
h( h(
Button, Button,
{ {
size: 'normal',
type: 'primary', type: 'primary',
style: { marginLeft: '10px' }, style: { marginLeft: '10px' },
onClick: () => { onClick: () => {
const link = document.createElement('a'); const link = document.createElement('a');
link.href = url; link.href = url;
link.download = filename; link.download = filename as string;
document.body.append(link); document.body.append(link);
link.click(); link.click();
link.remove(); link.remove();
@ -321,7 +325,6 @@ watch(
h( h(
Button, Button,
{ {
size: 'normal',
type: 'primary', type: 'primary',
onClick: () => { onClick: () => {
openPreviewDrawer('right', url); openPreviewDrawer('right', url);
@ -332,7 +335,6 @@ watch(
h( h(
Button, Button,
{ {
size: 'normal',
type: 'primary', type: 'primary',
style: { marginLeft: '10px' }, style: { marginLeft: '10px' },
onClick: () => { onClick: () => {

View File

@ -48,7 +48,7 @@ interface WorkflowResult {
} }
interface Props { interface Props {
itemMessage?: ResultItem[]; itemMessage?: ResultItem[];
item?: null | WordTempItem; item?: WordTempItem;
paramsData?: string[]; paramsData?: string[];
runChatFlow?: ( runChatFlow?: (
appId: null | string, appId: null | string,