正在显示
5 个修改的文件
包含
288 行增加
和
185 行删除
| @@ -6,7 +6,7 @@ | @@ -6,7 +6,7 @@ | ||
| 6 | <template #tableTitle> | 6 | <template #tableTitle> |
| 7 | <a-button type="primary" v-auth="'embeddings:embeddings:add'" @click="handleAdd" preIcon="ant-design:plus-outlined"> 新增</a-button> | 7 | <a-button type="primary" v-auth="'embeddings:embeddings:add'" @click="handleAdd" preIcon="ant-design:plus-outlined"> 新增</a-button> |
| 8 | <a-button type="primary" v-auth="'embeddings:embeddings:exportXls'" preIcon="ant-design:export-outlined" @click="onExportXls"> 导出</a-button> | 8 | <a-button type="primary" v-auth="'embeddings:embeddings:exportXls'" preIcon="ant-design:export-outlined" @click="onExportXls"> 导出</a-button> |
| 9 | - <j-upload-button type="primary" v-auth="'embeddings:embeddings:importExcel'" preIcon="ant-design:import-outlined" @click="onImportXls" | 9 | + <j-upload-button type="primary" v-auth="'embeddings:embeddings:importWord'" preIcon="ant-design:import-outlined" @click="onImportXls" |
| 10 | >导入</j-upload-button | 10 | >导入</j-upload-button |
| 11 | > | 11 | > |
| 12 | <a-dropdown v-if="selectedRowKeys.length > 0"> | 12 | <a-dropdown v-if="selectedRowKeys.length > 0"> |
| @@ -39,14 +39,15 @@ | @@ -39,14 +39,15 @@ | ||
| 39 | </template> | 39 | </template> |
| 40 | 40 | ||
| 41 | <script lang="ts" name="test-test" setup> | 41 | <script lang="ts" name="test-test" setup> |
| 42 | - import { ref, reactive, computed, unref } from 'vue'; | ||
| 43 | - import { BasicTable, useTable, TableAction } from '/@/components/Table'; | 42 | + import { ref, reactive } from 'vue'; |
| 43 | + import { BasicTable, TableAction } from '/@/components/Table'; | ||
| 44 | import { useModal } from '/@/components/Modal'; | 44 | import { useModal } from '/@/components/Modal'; |
| 45 | import { useListPage } from '/@/hooks/system/useListPage'; | 45 | import { useListPage } from '/@/hooks/system/useListPage'; |
| 46 | import TestModal from './components/TestModal.vue'; | 46 | import TestModal from './components/TestModal.vue'; |
| 47 | import { columns, searchFormSchema, superQuerySchema } from './Test.data'; | 47 | import { columns, searchFormSchema, superQuerySchema } from './Test.data'; |
| 48 | import { list, deleteOne, batchDelete, getImportUrl, getExportUrl } from './Test.api'; | 48 | import { list, deleteOne, batchDelete, getImportUrl, getExportUrl } from './Test.api'; |
| 49 | import { useUserStore } from '/@/store/modules/user'; | 49 | import { useUserStore } from '/@/store/modules/user'; |
| 50 | + import JUploadButton from "@/components/Button/src/JUploadButton.vue"; | ||
| 50 | const queryParam = reactive<any>({}); | 51 | const queryParam = reactive<any>({}); |
| 51 | const checkedKeys = ref<Array<string | number>>([]); | 52 | const checkedKeys = ref<Array<string | number>>([]); |
| 52 | const userStore = useUserStore(); | 53 | const userStore = useUserStore(); |
| @@ -85,12 +86,10 @@ | @@ -85,12 +86,10 @@ | ||
| 85 | success: handleSuccess, | 86 | success: handleSuccess, |
| 86 | }, | 87 | }, |
| 87 | }); | 88 | }); |
| 88 | - | ||
| 89 | const [registerTable, { reload }, { rowSelection, selectedRowKeys }] = tableContext; | 89 | const [registerTable, { reload }, { rowSelection, selectedRowKeys }] = tableContext; |
| 90 | 90 | ||
| 91 | // 高级查询配置 | 91 | // 高级查询配置 |
| 92 | const superQueryConfig = reactive(superQuerySchema); | 92 | const superQueryConfig = reactive(superQuerySchema); |
| 93 | - | ||
| 94 | /** | 93 | /** |
| 95 | * 高级查询事件 | 94 | * 高级查询事件 |
| 96 | */ | 95 | */ |
| @@ -107,6 +106,11 @@ | @@ -107,6 +106,11 @@ | ||
| 107 | openModal(true, { | 106 | openModal(true, { |
| 108 | isUpdate: false, | 107 | isUpdate: false, |
| 109 | showFooter: true, | 108 | showFooter: true, |
| 109 | + record: { | ||
| 110 | + // 关键:添加初始值 | ||
| 111 | + docName: '', | ||
| 112 | + text: '', | ||
| 113 | + }, | ||
| 110 | }); | 114 | }); |
| 111 | } | 115 | } |
| 112 | /** | 116 | /** |
| @@ -167,6 +171,7 @@ | @@ -167,6 +171,7 @@ | ||
| 167 | { | 171 | { |
| 168 | label: '详情', | 172 | label: '详情', |
| 169 | onClick: handleDetail.bind(null, record), | 173 | onClick: handleDetail.bind(null, record), |
| 174 | + auth: 'embeddings:embeddings:edit', | ||
| 170 | }, | 175 | }, |
| 171 | { | 176 | { |
| 172 | label: '删除', | 177 | label: '删除', |
| @@ -11,54 +11,24 @@ enum Api { | @@ -11,54 +11,24 @@ enum Api { | ||
| 11 | deleteBatch = '/embeddings/embeddings/deleteBatch', | 11 | deleteBatch = '/embeddings/embeddings/deleteBatch', |
| 12 | importExcel = '/embeddings/embeddings/importExcel', | 12 | importExcel = '/embeddings/embeddings/importExcel', |
| 13 | exportXls = '/embeddings/embeddings/exportXls', | 13 | exportXls = '/embeddings/embeddings/exportXls', |
| 14 | + importWord = '/embeddings/embeddings/importWord', | ||
| 15 | + queryid = '/queryById', | ||
| 14 | } | 16 | } |
| 15 | - | ||
| 16 | /** | 17 | /** |
| 17 | * 导出api | 18 | * 导出api |
| 18 | * @param params | 19 | * @param params |
| 19 | */ | 20 | */ |
| 20 | export const getExportUrl = Api.exportXls; | 21 | export const getExportUrl = Api.exportXls; |
| 21 | - | ||
| 22 | /** | 22 | /** |
| 23 | * 导入api | 23 | * 导入api |
| 24 | */ | 24 | */ |
| 25 | -export const getImportUrl = Api.importExcel; | 25 | +export const getImportUrl = Api.importWord; |
| 26 | 26 | ||
| 27 | /** | 27 | /** |
| 28 | * 列表接口 | 28 | * 列表接口 |
| 29 | * @param params | 29 | * @param params |
| 30 | */ | 30 | */ |
| 31 | -export const list = async (params) => { | ||
| 32 | - try { | ||
| 33 | - // 设置足够大的size获取所有数据 | ||
| 34 | - const res = await defHttp.get({ | ||
| 35 | - url: Api.list, | ||
| 36 | - params: { ...params, size: 1000 } | ||
| 37 | - }); | ||
| 38 | - | ||
| 39 | - if (res?.records && Array.isArray(res.records)) { | ||
| 40 | - // 将metadata中的字段提取到顶层 | ||
| 41 | - res.records = res.records.map(item => ({ | ||
| 42 | - ...item, | ||
| 43 | - ...item.metadata, // 将metadata中的字段展开 | ||
| 44 | - docName: item.metadata?.docName || '', | ||
| 45 | - knowledgeId: item.metadata?.knowledgeId || '', | ||
| 46 | - docId: item.metadata?.docId || '', | ||
| 47 | - index: item.metadata?.index || '', | ||
| 48 | - })); | ||
| 49 | - } | ||
| 50 | - return res; | ||
| 51 | - } catch (error) { | ||
| 52 | - console.error("Error fetching data:", error); | ||
| 53 | - return { | ||
| 54 | - records: [], | ||
| 55 | - total: 0, | ||
| 56 | - size: 10, | ||
| 57 | - current: 1, | ||
| 58 | - pages: 0 | ||
| 59 | - }; | ||
| 60 | - } | ||
| 61 | -} | 31 | +export const list = (params) => defHttp.get({ url: Api.list, params }); |
| 62 | 32 | ||
| 63 | /** | 33 | /** |
| 64 | * 删除单个 | 34 | * 删除单个 |
| @@ -68,7 +38,6 @@ export const deleteOne = (params, handleSuccess) => { | @@ -68,7 +38,6 @@ export const deleteOne = (params, handleSuccess) => { | ||
| 68 | handleSuccess(); | 38 | handleSuccess(); |
| 69 | }); | 39 | }); |
| 70 | }; | 40 | }; |
| 71 | - | ||
| 72 | /** | 41 | /** |
| 73 | * 批量删除 | 42 | * 批量删除 |
| 74 | * @param params | 43 | * @param params |
| @@ -87,7 +56,6 @@ export const batchDelete = (params, handleSuccess) => { | @@ -87,7 +56,6 @@ export const batchDelete = (params, handleSuccess) => { | ||
| 87 | }, | 56 | }, |
| 88 | }); | 57 | }); |
| 89 | }; | 58 | }; |
| 90 | - | ||
| 91 | /** | 59 | /** |
| 92 | * 保存或者更新 | 60 | * 保存或者更新 |
| 93 | * @param params | 61 | * @param params |
| 1 | import { BasicColumn } from '/@/components/Table'; | 1 | import { BasicColumn } from '/@/components/Table'; |
| 2 | import { FormSchema } from '/@/components/Table'; | 2 | import { FormSchema } from '/@/components/Table'; |
| 3 | +import { h } from 'vue'; | ||
| 4 | +//import { Tooltip } from 'ant-design-vue'; | ||
| 3 | 5 | ||
| 4 | -// 列表数据 | 6 | +//列表数据 |
| 5 | export const columns: BasicColumn[] = [ | 7 | export const columns: BasicColumn[] = [ |
| 6 | - { | 8 | + /*{ |
| 7 | title: 'ID', | 9 | title: 'ID', |
| 8 | align: 'center', | 10 | align: 'center', |
| 9 | dataIndex: 'id', | 11 | dataIndex: 'id', |
| 10 | - width: 200, | ||
| 11 | - }, | ||
| 12 | - { | ||
| 13 | - title: '文本内容', | 12 | + customRender: ({ text, record }) => { |
| 13 | + // 调试:检查ID值和原始记录 | ||
| 14 | + console.log(`ID渲染 - 值: ${text}, 记录:`, record); | ||
| 15 | + | ||
| 16 | + // 如果ID为空,显示详细的调试信息 | ||
| 17 | + if (!text || text === 'ID-未找到') { | ||
| 18 | + return h('div', { style: 'color: #f50; cursor: help;', title: '点击查看详情' }, [ | ||
| 19 | + h('span', { style: 'font-weight: bold;' }, 'ID缺失'), | ||
| 20 | + h('div', { style: 'font-size: 10px; margin-top: 4px;' }, `字段: ${Object.keys(record._raw || {}).join(', ')}`), | ||
| 21 | + ]); | ||
| 22 | + } | ||
| 23 | + | ||
| 24 | + return h('span', { style: 'font-family: monospace' }, text); | ||
| 25 | + }, | ||
| 26 | + },*/ | ||
| 27 | + /*{ | ||
| 28 | + title: '文件名称', | ||
| 14 | align: 'center', | 29 | align: 'center', |
| 15 | dataIndex: 'text', | 30 | dataIndex: 'text', |
| 16 | - width: 300 | ||
| 17 | - }, | 31 | + },*/ |
| 18 | { | 32 | { |
| 19 | - title: '文件名称', | 33 | + title: '文档名称', |
| 20 | align: 'center', | 34 | align: 'center', |
| 21 | dataIndex: 'docName', | 35 | dataIndex: 'docName', |
| 22 | - width: 150 | 36 | + width: 180, |
| 37 | + customRender: ({ record }) => { | ||
| 38 | + return renderMetadataField(record, 'docName'); | ||
| 39 | + }, | ||
| 23 | }, | 40 | }, |
| 24 | { | 41 | { |
| 25 | - title: '知识ID', | 42 | + title: '文件内容', |
| 43 | + align: 'center', | ||
| 44 | + dataIndex: 'text', | ||
| 45 | + }, | ||
| 46 | + /* { | ||
| 47 | + title: '知识库ID', | ||
| 26 | align: 'center', | 48 | align: 'center', |
| 27 | dataIndex: 'knowledgeId', | 49 | dataIndex: 'knowledgeId', |
| 28 | - width: 150 | 50 | + width: 150, |
| 51 | + customRender: ({ record }) => { | ||
| 52 | + return renderMetadataField(record, 'knowledgeId'); | ||
| 53 | + }, | ||
| 54 | + }, | ||
| 55 | + { | ||
| 56 | + title: '文档名称', | ||
| 57 | + align: 'center', | ||
| 58 | + dataIndex: 'docName', | ||
| 59 | + width: 180, | ||
| 60 | + customRender: ({ record }) => { | ||
| 61 | + return renderMetadataField(record, 'docName'); | ||
| 62 | + }, | ||
| 29 | }, | 63 | }, |
| 30 | { | 64 | { |
| 31 | title: '文档ID', | 65 | title: '文档ID', |
| 32 | align: 'center', | 66 | align: 'center', |
| 33 | dataIndex: 'docId', | 67 | dataIndex: 'docId', |
| 34 | - width: 150 | 68 | + width: 150, |
| 69 | + customRender: ({ record }) => { | ||
| 70 | + return renderMetadataField(record, 'docId'); | ||
| 71 | + }, | ||
| 35 | }, | 72 | }, |
| 36 | { | 73 | { |
| 37 | - title: '索引', | 74 | + title: '索引位置', |
| 38 | align: 'center', | 75 | align: 'center', |
| 39 | dataIndex: 'index', | 76 | dataIndex: 'index', |
| 40 | - width: 80 | 77 | + width: 100, |
| 78 | + customRender: ({ record }) => { | ||
| 79 | + return renderMetadataField(record, 'index'); | ||
| 80 | + }, | ||
| 41 | }, | 81 | }, |
| 42 | { | 82 | { |
| 43 | - title: '相似度', | 83 | + title: 'metadata', |
| 44 | align: 'center', | 84 | align: 'center', |
| 45 | - dataIndex: 'similarity', | ||
| 46 | - width: 100 | ||
| 47 | - }, | 85 | + dataIndex: 'metadata', |
| 86 | + customRender: ({ text }) => { | ||
| 87 | + if (!text) return '-'; | ||
| 88 | + | ||
| 89 | + try { | ||
| 90 | + // 尝试解析JSON | ||
| 91 | + const metadata = typeof text === 'string' ? JSON.parse(text) : text; | ||
| 92 | + | ||
| 93 | + // 创建元数据标签 | ||
| 94 | + const tags = Object.entries(metadata).map(([key, value]) => h(tags, { color: 'blue' }, `${key}: ${value}`)); | ||
| 95 | + | ||
| 96 | + return h( | ||
| 97 | + Tooltip, | ||
| 98 | + { | ||
| 99 | + title: h('pre', JSON.stringify(metadata, null, 2)), | ||
| 100 | + overlayStyle: { maxWidth: '600px' }, | ||
| 101 | + }, | ||
| 102 | + () => h('div', { style: 'display: flex; flex-wrap: wrap; gap: 4px;' }, tags) | ||
| 103 | + ); | ||
| 104 | + } catch (e) { | ||
| 105 | + // 无法解析时显示原始文本 | ||
| 106 | + const displayText = typeof text === 'string' ? text : JSON.stringify(text); | ||
| 107 | + const shortText = displayText.length > 20 ? displayText.substring(0, 20) + '...' : displayText; | ||
| 108 | + | ||
| 109 | + return h(Tooltip, { title: displayText }, () => h('span', shortText)); | ||
| 110 | + } | ||
| 111 | + }, | ||
| 112 | + },*/ | ||
| 48 | ]; | 113 | ]; |
| 49 | 114 | ||
| 50 | -// 查询数据 | ||
| 51 | -export const searchFormSchema: FormSchema[] = []; | 115 | +function renderMetadataField(record: any, fieldName: string) { |
| 116 | + if (!record.metadata) return '-'; | ||
| 52 | 117 | ||
| 53 | -// 表单数据 | ||
| 54 | -export const formSchema: FormSchema[] = [ | 118 | + try { |
| 119 | + // 尝试解析metadata | ||
| 120 | + const metadata = typeof record.metadata === 'string' ? JSON.parse(record.metadata) : record.metadata; | ||
| 121 | + | ||
| 122 | + // 获取字段值 | ||
| 123 | + const value = metadata[fieldName]; | ||
| 124 | + | ||
| 125 | + if (value === undefined || value === null) { | ||
| 126 | + return h('span', { style: 'color: #999' }, '无'); | ||
| 127 | + } | ||
| 128 | + | ||
| 129 | + // 根据字段类型渲染 | ||
| 130 | + switch (fieldName) { | ||
| 131 | + case 'knowledgeId': | ||
| 132 | + case 'docId': | ||
| 133 | + return h('span', { style: 'font-family: monospace' }, value); | ||
| 134 | + | ||
| 135 | + case 'index': | ||
| 136 | + return h('span', { style: 'font-weight: bold' }, value); | ||
| 137 | + | ||
| 138 | + default: | ||
| 139 | + return h('span', value); | ||
| 140 | + } | ||
| 141 | + } catch (e) { | ||
| 142 | + return h('span', { style: 'color: #f50' }, '解析错误'); | ||
| 143 | + } | ||
| 144 | +} | ||
| 145 | + | ||
| 146 | +//查询数据 | ||
| 147 | +export const searchFormSchema: FormSchema[] = [ | ||
| 55 | { | 148 | { |
| 56 | - label: 'text', | 149 | + label: '文本内容', |
| 57 | field: 'text', | 150 | field: 'text', |
| 58 | component: 'Input', | 151 | component: 'Input', |
| 59 | }, | 152 | }, |
| 153 | +]; | ||
| 154 | +//表单数据 | ||
| 155 | +export const formSchema: FormSchema[] = [ | ||
| 156 | + { | ||
| 157 | + label: '文件名称', | ||
| 158 | + field: 'docName', // 使用新的字段名 | ||
| 159 | + component: 'Input', | ||
| 160 | + required: true, | ||
| 161 | + componentProps: { | ||
| 162 | + placeholder: '请输入文档名称', | ||
| 163 | + }, | ||
| 164 | + }, | ||
| 165 | + { | ||
| 166 | + label: '文本内容', | ||
| 167 | + field: 'text', | ||
| 168 | + required: true, | ||
| 169 | + component: 'InputTextArea', | ||
| 170 | + }, | ||
| 171 | + // TODO 主键隐藏字段,目前写死为ID | ||
| 60 | { | 172 | { |
| 61 | label: '', | 173 | label: '', |
| 62 | field: 'id', | 174 | field: 'id', |
| @@ -67,13 +179,14 @@ export const formSchema: FormSchema[] = [ | @@ -67,13 +179,14 @@ export const formSchema: FormSchema[] = [ | ||
| 67 | 179 | ||
| 68 | // 高级查询数据 | 180 | // 高级查询数据 |
| 69 | export const superQuerySchema = { | 181 | export const superQuerySchema = { |
| 70 | - name: { title: 'text', order: 0, view: 'text', type: 'string' }, | 182 | + name: { title: 'name', order: 0, view: 'text', type: 'string' }, |
| 71 | }; | 183 | }; |
| 72 | 184 | ||
| 73 | /** | 185 | /** |
| 74 | - * 流程表单调用这个方法获取formSchema | 186 | + * 流程表单调用这个方法获取formSchemaqrtz_fired_triggers |
| 75 | * @param param | 187 | * @param param |
| 76 | */ | 188 | */ |
| 77 | export function getBpmFormSchema(_formData): FormSchema[] { | 189 | export function getBpmFormSchema(_formData): FormSchema[] { |
| 190 | + // 默认和原始表单保持一致 如果流程中配置了权限数据,这里需要单独处理formSchema | ||
| 78 | return formSchema; | 191 | return formSchema; |
| 79 | } | 192 | } |
| 1 | <template> | 1 | <template> |
| 2 | - <div style="min-height: 400px"> | ||
| 3 | - <BasicForm @register="registerForm"></BasicForm> | ||
| 4 | - <div style="width: 100%;text-align: center" v-if="!formDisabled"> | ||
| 5 | - <a-button @click="submitForm" pre-icon="ant-design:check" type="primary">提 交</a-button> | ||
| 6 | - </div> | 2 | + <div style="min-height: 400px"> |
| 3 | + <BasicForm @register="registerForm" /> | ||
| 4 | + <div style="width: 100%; text-align: center" v-if="!formDisabled"> | ||
| 5 | + <a-button @click="submitForm" pre-icon="ant-design:check" type="primary">提 交</a-button> | ||
| 7 | </div> | 6 | </div> |
| 7 | + </div> | ||
| 8 | </template> | 8 | </template> |
| 9 | 9 | ||
| 10 | <script lang="ts"> | 10 | <script lang="ts"> |
| 11 | - import {BasicForm, useForm} from '/@/components/Form/index'; | ||
| 12 | - import {computed, defineComponent} from 'vue'; | ||
| 13 | - import {defHttp} from '/@/utils/http/axios'; | ||
| 14 | - import { propTypes } from '/@/utils/propTypes'; | ||
| 15 | - import {getBpmFormSchema} from '../Test.data'; | ||
| 16 | - import {saveOrUpdate} from '../Test.api'; | ||
| 17 | - | ||
| 18 | - export default defineComponent({ | ||
| 19 | - name: "TestForm", | ||
| 20 | - components:{ | ||
| 21 | - BasicForm | ||
| 22 | - }, | ||
| 23 | - props:{ | ||
| 24 | - formData: propTypes.object.def({}), | ||
| 25 | - formBpm: propTypes.bool.def(true), | ||
| 26 | - }, | ||
| 27 | - setup(props){ | ||
| 28 | - const [registerForm, { setFieldsValue, setProps, getFieldsValue }] = useForm({ | ||
| 29 | - labelWidth: 150, | ||
| 30 | - schemas: getBpmFormSchema(props.formData), | ||
| 31 | - showActionButtonGroup: false, | ||
| 32 | - baseColProps: {span: 24} | ||
| 33 | - }); | 11 | + import { BasicForm, useForm } from '/@/components/Form/index'; |
| 12 | + import { computed, defineComponent } from 'vue'; | ||
| 13 | + import { defHttp } from '/@/utils/http/axios'; | ||
| 14 | + import { propTypes } from '/@/utils/propTypes'; | ||
| 15 | + import { getBpmFormSchema } from '../Test.data'; | ||
| 16 | + import { saveOrUpdate } from '../Test.api'; | ||
| 34 | 17 | ||
| 35 | - const formDisabled = computed(()=>{ | ||
| 36 | - if(props.formData.disabled === false){ | ||
| 37 | - return false; | ||
| 38 | - } | ||
| 39 | - return true; | ||
| 40 | - }); | 18 | + export default defineComponent({ |
| 19 | + name: 'TestForm', | ||
| 20 | + components: { | ||
| 21 | + BasicForm, | ||
| 22 | + }, | ||
| 23 | + props: { | ||
| 24 | + formData: propTypes.object.def({}), | ||
| 25 | + formBpm: propTypes.bool.def(true), | ||
| 26 | + }, | ||
| 27 | + setup(props) { | ||
| 28 | + const [registerForm, { setFieldsValue, setProps, getFieldsValue }] = useForm({ | ||
| 29 | + labelWidth: 150, | ||
| 30 | + schemas: getBpmFormSchema(props.formData), | ||
| 31 | + showActionButtonGroup: false, | ||
| 32 | + baseColProps: { span: 24 }, | ||
| 33 | + }); | ||
| 41 | 34 | ||
| 42 | - let formData = {}; | ||
| 43 | - const queryByIdUrl = '/test/test/queryById'; | ||
| 44 | - async function initFormData(){ | ||
| 45 | - let params = {id: props.formData.dataId}; | ||
| 46 | - const data = await defHttp.get({url: queryByIdUrl, params}); | ||
| 47 | - formData = {...data} | ||
| 48 | - //设置表单的值 | ||
| 49 | - await setFieldsValue(formData); | ||
| 50 | - //默认是禁用 | ||
| 51 | - await setProps({disabled: formDisabled.value}) | ||
| 52 | - } | 35 | + const formDisabled = computed(() => { |
| 36 | + if (props.formData.disabled === false) { | ||
| 37 | + return false; | ||
| 38 | + } | ||
| 39 | + return true; | ||
| 40 | + }); | ||
| 53 | 41 | ||
| 54 | - async function submitForm() { | ||
| 55 | - let data = getFieldsValue(); | ||
| 56 | - let params = Object.assign({}, formData, data); | ||
| 57 | - console.log('表单数据', params) | ||
| 58 | - await saveOrUpdate(params, true) | ||
| 59 | - } | 42 | + let formData = {}; |
| 43 | + const queryByIdUrl = '/test/test/queryById'; | ||
| 44 | + async function initFormData() { | ||
| 45 | + let params = { id: props.formData.dataId }; | ||
| 46 | + const data = await defHttp.get({ url: queryByIdUrl, params }); | ||
| 47 | + formData = { ...data }; | ||
| 48 | + //设置表单的值 | ||
| 49 | + await setFieldsValue(formData); | ||
| 50 | + //默认是禁用 | ||
| 51 | + await setProps({ disabled: formDisabled.value }); | ||
| 52 | + } | ||
| 60 | 53 | ||
| 61 | - initFormData(); | ||
| 62 | - | ||
| 63 | - return { | ||
| 64 | - registerForm, | ||
| 65 | - formDisabled, | ||
| 66 | - submitForm, | ||
| 67 | - } | ||
| 68 | - } | ||
| 69 | - }); | ||
| 70 | -</script> | ||
| 54 | + async function submitForm() { | ||
| 55 | + let data = getFieldsValue(); | ||
| 56 | + let params = Object.assign({}, formData, data); | ||
| 57 | + console.log('表单数据', params); | ||
| 58 | + await saveOrUpdate(params, true); | ||
| 59 | + } | ||
| 60 | + | ||
| 61 | + initFormData(); | ||
| 62 | + | ||
| 63 | + return { | ||
| 64 | + registerForm, | ||
| 65 | + formDisabled, | ||
| 66 | + submitForm, | ||
| 67 | + }; | ||
| 68 | + }, | ||
| 69 | + }); | ||
| 70 | +</script> |
| 1 | <template> | 1 | <template> |
| 2 | <BasicModal v-bind="$attrs" @register="registerModal" destroyOnClose :title="title" :width="800" @ok="handleSubmit"> | 2 | <BasicModal v-bind="$attrs" @register="registerModal" destroyOnClose :title="title" :width="800" @ok="handleSubmit"> |
| 3 | - <BasicForm @register="registerForm" name="TestForm" /> | 3 | + <BasicForm @register="registerForm" name="TestForm" /> |
| 4 | </BasicModal> | 4 | </BasicModal> |
| 5 | </template> | 5 | </template> |
| 6 | 6 | ||
| 7 | <script lang="ts" setup> | 7 | <script lang="ts" setup> |
| 8 | - import {ref, computed, unref} from 'vue'; | ||
| 9 | - import {BasicModal, useModalInner} from '/@/components/Modal'; | ||
| 10 | - import {BasicForm, useForm} from '/@/components/Form/index'; | ||
| 11 | - import {formSchema} from '../Test.data'; | ||
| 12 | - import {saveOrUpdate} from '../Test.api'; | ||
| 13 | - // Emits声明 | ||
| 14 | - const emit = defineEmits(['register','success']); | ||
| 15 | - const isUpdate = ref(true); | ||
| 16 | - const isDetail = ref(false); | ||
| 17 | - //表单配置 | ||
| 18 | - const [registerForm, { setProps,resetFields, setFieldsValue, validate, scrollToField }] = useForm({ | ||
| 19 | - labelWidth: 150, | ||
| 20 | - schemas: formSchema, | ||
| 21 | - showActionButtonGroup: false, | ||
| 22 | - baseColProps: {span: 24} | ||
| 23 | - }); | ||
| 24 | - //表单赋值 | ||
| 25 | - const [registerModal, {setModalProps, closeModal}] = useModalInner(async (data) => { | ||
| 26 | - //重置表单 | ||
| 27 | - await resetFields(); | ||
| 28 | - setModalProps({confirmLoading: false,showCancelBtn:!!data?.showFooter,showOkBtn:!!data?.showFooter}); | ||
| 29 | - isUpdate.value = !!data?.isUpdate; | ||
| 30 | - isDetail.value = !!data?.showFooter; | ||
| 31 | - if (unref(isUpdate)) { | ||
| 32 | - //表单赋值 | ||
| 33 | - await setFieldsValue({ | ||
| 34 | - ...data.record, | ||
| 35 | - }); | ||
| 36 | - } | ||
| 37 | - // 隐藏底部时禁用整个表单 | ||
| 38 | - setProps({ disabled: !data?.showFooter }) | ||
| 39 | - }); | ||
| 40 | - //设置标题 | ||
| 41 | - const title = computed(() => (!unref(isUpdate) ? '新增' : !unref(isDetail) ? '详情' : '编辑')); | ||
| 42 | - //表单提交事件 | ||
| 43 | - async function handleSubmit(v) { | 8 | + import { ref, computed, unref } from 'vue'; |
| 9 | + import { BasicModal, useModalInner } from '/@/components/Modal'; | ||
| 10 | + import { BasicForm, useForm } from '/@/components/Form/index'; | ||
| 11 | + import { formSchema } from '../Test.data'; | ||
| 12 | + import { saveOrUpdate } from '../Test.api'; | ||
| 13 | + // Emits声明 | ||
| 14 | + const emit = defineEmits(['register', 'success']); | ||
| 15 | + const isUpdate = ref(true); | ||
| 16 | + const isDetail = ref(false); | ||
| 17 | + //表单配置 | ||
| 18 | + const [registerForm, { setProps, resetFields, setFieldsValue, validate, scrollToField }] = useForm({ | ||
| 19 | + labelWidth: 150, | ||
| 20 | + schemas: formSchema, | ||
| 21 | + showActionButtonGroup: false, | ||
| 22 | + baseColProps: { span: 24 }, | ||
| 23 | + }); | ||
| 24 | + //表单赋值 | ||
| 25 | + const [registerModal, { setModalProps, closeModal }] = useModalInner(async (data) => { | ||
| 26 | + //重置表单 | ||
| 27 | + await resetFields(); | ||
| 28 | + setModalProps({ confirmLoading: false, showCancelBtn: !!data?.showFooter, showOkBtn: !!data?.showFooter }); | ||
| 29 | + isUpdate.value = !!data?.isUpdate; | ||
| 30 | + isDetail.value = !!data?.showFooter; | ||
| 31 | + if (unref(isUpdate)) { | ||
| 32 | + const formData = { ...data.record }; | ||
| 33 | + | ||
| 34 | + // 如果是详情模式,提取 metadata 中的 docName | ||
| 35 | + if (formData.metadata) { | ||
| 44 | try { | 36 | try { |
| 45 | - let values = await validate(); | ||
| 46 | - setModalProps({confirmLoading: true}); | ||
| 47 | - //提交表单 | ||
| 48 | - await saveOrUpdate(values, isUpdate.value); | ||
| 49 | - //关闭弹窗 | ||
| 50 | - closeModal(); | ||
| 51 | - //刷新列表 | ||
| 52 | - emit('success'); | ||
| 53 | - } catch ({ errorFields }) { | ||
| 54 | - if (errorFields) { | ||
| 55 | - const firstField = errorFields[0]; | ||
| 56 | - if (firstField) { | ||
| 57 | - scrollToField(firstField.name, { behavior: 'smooth', block: 'center' }); | ||
| 58 | - } | ||
| 59 | - } | ||
| 60 | - return Promise.reject(errorFields); | ||
| 61 | - } finally { | ||
| 62 | - setModalProps({confirmLoading: false}); | 37 | + const metadata = typeof formData.metadata === 'string' ? JSON.parse(formData.metadata) : formData.metadata; |
| 38 | + formData.docName = metadata.docName || '未命名'; | ||
| 39 | + } catch (e) { | ||
| 40 | + console.error('元数据解析失败', e); | ||
| 41 | + formData.docName = '元数据格式错误'; | ||
| 63 | } | 42 | } |
| 43 | + } | ||
| 44 | + | ||
| 45 | + await setFieldsValue(formData); | ||
| 64 | } | 46 | } |
| 47 | + // 隐藏底部时禁用整个表单 | ||
| 48 | + setProps({ disabled: !data?.showFooter }); | ||
| 49 | + }); | ||
| 50 | + //设置标题 | ||
| 51 | + const title = computed(() => (!unref(isUpdate) ? '新增' : !unref(isDetail) ? '详情' : '编辑')); | ||
| 52 | + //表单提交事件 | ||
| 53 | + async function handleSubmit() { | ||
| 54 | + try { | ||
| 55 | + let values = await validate(); | ||
| 56 | + | ||
| 57 | + // 仅保留需要的字段,其他由后端自动生成 | ||
| 58 | + const payload = { | ||
| 59 | + id: values.id, | ||
| 60 | + docName: values.docName, // 文件名称 | ||
| 61 | + text: values.text, // 文件内容 | ||
| 62 | + }; | ||
| 63 | + setModalProps({ confirmLoading: true }); | ||
| 64 | + //提交表单 | ||
| 65 | + await saveOrUpdate(payload, isUpdate.value); | ||
| 66 | + //关闭弹窗 | ||
| 67 | + closeModal(); | ||
| 68 | + //刷新列表 | ||
| 69 | + emit('success'); | ||
| 70 | + } catch ({ errorFields }) { | ||
| 71 | + if (errorFields) { | ||
| 72 | + const firstField = errorFields[0]; | ||
| 73 | + if (firstField) { | ||
| 74 | + scrollToField(firstField.name, { behavior: 'smooth', block: any }); | ||
| 75 | + } | ||
| 76 | + } | ||
| 77 | + return Promise.reject(errorFields); | ||
| 78 | + } finally { | ||
| 79 | + setModalProps({ confirmLoading: false }); | ||
| 80 | + } | ||
| 81 | + } | ||
| 65 | </script> | 82 | </script> |
| 66 | 83 | ||
| 67 | <style lang="less" scoped> | 84 | <style lang="less" scoped> |
| 68 | - /** 时间和数字输入框样式 */ | 85 | + /** 时间和数字输入框样式 */ |
| 69 | :deep(.ant-input-number) { | 86 | :deep(.ant-input-number) { |
| 70 | width: 100%; | 87 | width: 100%; |
| 71 | } | 88 | } |
| @@ -73,4 +90,4 @@ | @@ -73,4 +90,4 @@ | ||
| 73 | :deep(.ant-calendar-picker) { | 90 | :deep(.ant-calendar-picker) { |
| 74 | width: 100%; | 91 | width: 100%; |
| 75 | } | 92 | } |
| 76 | -</style> | ||
| 93 | +</style> |
-
请 注册 或 登录 后发表评论