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

View File

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