From f19b6c63e6a87a9ae06123af972c0690ac34f7d9 Mon Sep 17 00:00:00 2001 From: AaronWu <2463371514@qq.com> Date: Tue, 24 Jun 2025 10:08:04 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=AE=A2=E6=88=B7=E7=AB=AF=E6=96=B0?= =?UTF-8?q?=E5=A2=9E=E5=B7=A5=E5=8D=95=E6=B7=BB=E5=8A=A0=E7=BC=93=E5=AD=98?= =?UTF-8?q?=E6=9C=80=E8=BF=91=E4=B8=80=E6=AC=A1=E6=8F=90=E4=BA=A4=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env.development | 4 +- src/utils/issueCache.ts | 71 ++++++++++++++++++++++++ src/views/client/issue/index.vue | 57 ++++++++++++++++++- src/views/question/issue/detail.vue | 4 ++ src/views/question/issue/formSchemas.tsx | 16 +++++- src/views/question/issue/index.vue | 8 +-- src/views/question/knowledge/index.vue | 2 +- 7 files changed, 151 insertions(+), 11 deletions(-) create mode 100644 src/utils/issueCache.ts diff --git a/.env.development b/.env.development index 7f13400..62ffa56 100644 --- a/.env.development +++ b/.env.development @@ -9,8 +9,8 @@ # 只在开发模式中被载入 # 网站前缀 -VITE_BASE_API_URL = http://192.168.2.110:8089/server/ -# VITE_BASE_API_URL = http://43.137.2.78:8085/server/ +# VITE_BASE_API_URL = http://192.168.2.110:8089/server/ +VITE_BASE_API_URL = http://43.137.2.78:8085/server/ # base api VITE_BASE_API = '/server/' diff --git a/src/utils/issueCache.ts b/src/utils/issueCache.ts new file mode 100644 index 0000000..4697f0d --- /dev/null +++ b/src/utils/issueCache.ts @@ -0,0 +1,71 @@ +// 问题工单字段缓存工具 +const CACHE_KEY = 'issue_form_cache'; + +export interface IssueFormCache { + contacts?: string; + contactsMobile?: string; + contactsEmail?: string; + customer?: string; + productId?: number; + versionId?: number; + appVersion?: string; + agent?: string; +} + +/** + * 保存问题工单表单字段到localStorage + */ +export const saveIssueFormCache = (formData: Partial) => { + try { + const cacheData: IssueFormCache = {}; + + // 只缓存指定的字段 + const fieldsToCache = [ + 'contacts', + 'contactsMobile', + 'contactsEmail', + 'customer', + 'productId', + 'versionId', + 'appVersion', + 'agent' + ] as const; + + fieldsToCache.forEach(field => { + const value = formData[field]; + if (value !== undefined) { + (cacheData as any)[field] = value; + } + }); + + localStorage.setItem(CACHE_KEY, JSON.stringify(cacheData)); + } catch (error) { + console.error('保存表单缓存失败:', error); + } +}; + +/** + * 从localStorage获取问题工单表单字段缓存 + */ +export const getIssueFormCache = (): IssueFormCache => { + try { + const cacheStr = localStorage.getItem(CACHE_KEY); + if (cacheStr) { + return JSON.parse(cacheStr); + } + } catch (error) { + console.error('获取表单缓存失败:', error); + } + return {}; +}; + +/** + * 清除问题工单表单字段缓存 + */ +export const clearIssueFormCache = () => { + try { + localStorage.removeItem(CACHE_KEY); + } catch (error) { + console.error('清除表单缓存失败:', error); + } +}; \ No newline at end of file diff --git a/src/views/client/issue/index.vue b/src/views/client/issue/index.vue index d8ecf21..736604f 100644 --- a/src/views/client/issue/index.vue +++ b/src/views/client/issue/index.vue @@ -156,6 +156,7 @@ import { type TableListItem } from '@/views/question/issue/columns'; import { useRouter } from 'vue-router'; import { stateTypeList } from '@/views/question/issue/data'; + import { saveIssueFormCache, getIssueFormCache } from '@/utils/issueCache'; const router = useRouter(); // 目录树数据 const treeData = ref([]); @@ -283,6 +284,21 @@ await (values.id ? updateIssue : createIssue)(values); message.success(`${values.id ? '编辑' : '新增'}成功`); + + // 如果是新增操作,保存字段到localStorage缓存 + if (!values.id) { + saveIssueFormCache({ + contacts: values.contacts, + contactsMobile: values.contactsMobile, + contactsEmail: values.contactsEmail, + customer: values.customer, + productId: values.productId, + versionId: values.versionId, + appVersion: values.appVersion, + agent: values.agent, + }); + } + visible.value = false; resetFormFields(); // 重新获取树数据 @@ -307,11 +323,50 @@ formRef.clearValidate(); }; - const handleAdd = () => { + const handleAdd = async () => { curRow.value = {}; // formRef?.setFieldsValue(curRecord.value); quillEditor.value?.setContents(''); resetFormFields(); + + // 从localStorage获取缓存的字段值 + const cachedData = getIssueFormCache(); + if (Object.keys(cachedData).length > 0) { + // 如果有缓存数据,填充到表单 + const formData: any = { ...cachedData }; + + // 如果缓存中有产品ID,需要先加载版本列表 + if (cachedData.productId) { + try { + const { data } = await fetchVersionPageList({ + productId: cachedData.productId, + current: 1, + size: 999, + }); + if (data && Array.isArray(data) && data.length) { + formRef?.updateSchema({ + field: 'versionId', + componentProps: { + options: data.map((e) => { + return { + label: e.name, + value: e.id, + }; + }), + }, + }); + } + } catch (error) { + console.error('加载版本列表失败:', error); + } + } + + // 设置表单值 + nextTick(() => { + formRef?.setFieldsValue(formData); + }); + } + openModal(); }; diff --git a/src/views/question/issue/detail.vue b/src/views/question/issue/detail.vue index 9a45043..20512d3 100644 --- a/src/views/question/issue/detail.vue +++ b/src/views/question/issue/detail.vue @@ -107,6 +107,10 @@ import { CopyOutlined } from '@ant-design/icons-vue'; import { copyText } from '@/utils/common'; + defineOptions({ + name: 'IssueDetail', + }); + const props = defineProps({ id: { type: String, diff --git a/src/views/question/issue/formSchemas.tsx b/src/views/question/issue/formSchemas.tsx index 9921164..e755854 100644 --- a/src/views/question/issue/formSchemas.tsx +++ b/src/views/question/issue/formSchemas.tsx @@ -8,7 +8,6 @@ import { stateTypeList } from './data'; import { DictEnum } from '@/enums/dictEnum'; import { getDictionaryByTypeName } from '@/utils/dict'; import { fetchProdList, fetchVersionPageList } from '@/api/prodVersion'; -import component from '@/locales/lang/en-US/component'; const questionTypeList = await getDictionaryByTypeName(DictEnum.QUESTION_TYPE); // 编辑页字段 export const getEditFormSchema: ( @@ -219,11 +218,22 @@ export const getEditFormSchema: ( }, componentProps: { options: stateTypeList, - disabled: true, + // disabled: true, }, vIf: () => !isClient, rules: [{ required: true, type: 'number' }], }, + // 计划解决时间 + { + field: 'resolutionTime', + component: 'Input', + label: '计划解决时间', + colProps: { + span: 6, + }, + vIf: () => !isClient && isDetail, + + }, { field: 'title', @@ -371,7 +381,7 @@ export const getFlowFormSchema: (row?: Partial, state?: any) => F colProps: { span: 24, }, - vIf: () => state === 5, + vIf: () => state === 5 || state === 6, rules: [{ required: true, type: 'string' }], }, { diff --git a/src/views/question/issue/index.vue b/src/views/question/issue/index.vue index 46d88e3..d97b33a 100644 --- a/src/views/question/issue/index.vue +++ b/src/views/question/issue/index.vue @@ -107,12 +107,13 @@ import { useRouter } from 'vue-router'; import { useFormModal } from '@/hooks/useModal/index'; import { getEditFormSchema, getFlowFormSchema } from './formSchemas'; - import { ExclamationCircleOutlined, DeleteOutlinƒed } from '@ant-design/icons-vue'; + import { ExclamationCircleOutlined, DeleteOutlined } from '@ant-design/icons-vue'; import { stateTypeList } from './data'; import { fetchVersionPageList } from '@/api/prodVersion'; import { DraggableModal } from '@/components/core/draggable-modal'; import { useForm } from '@/components/core/schema-form'; import { quillImageUploadCustom } from '../commom/tools'; + import { useDebounceFn } from '@vueuse/core'; defineOptions({ name: 'issue', @@ -244,12 +245,11 @@ visible.value = false; }; - const handleSync = async (record: TableListItem) => { + const handleSync = useDebounceFn(async (record: TableListItem) => { if (!record.id) return; const res = await syncIssue({ id: record.id, }); - console.log('res: ', res); if (res.code === 200) { message.success('同步到禅道成功'); @@ -257,7 +257,7 @@ } else { message.error('同步到禅道失败'); } - }; + }, 300); const columns: any = [ ...baseColumns, diff --git a/src/views/question/knowledge/index.vue b/src/views/question/knowledge/index.vue index 0b4d050..f10edff 100644 --- a/src/views/question/knowledge/index.vue +++ b/src/views/question/knowledge/index.vue @@ -50,7 +50,7 @@ }" :title="`${curRecord.id ? '编辑' : '新增'}知识库`" :mask-closable="false" - :getContainer="() => knowContainerRef" + :getContainer="knowContainerRef || undefined" :destroyOnClose="true" @ok="handleOk" @cancel="handleCancel"