diff --git a/src/store/modules/chartEditStore/chartEditStore.d.ts b/src/store/modules/chartEditStore/chartEditStore.d.ts index 7a532e7b..8df3bcce 100644 --- a/src/store/modules/chartEditStore/chartEditStore.d.ts +++ b/src/store/modules/chartEditStore/chartEditStore.d.ts @@ -15,6 +15,8 @@ import type { ChartColorsNameType, GlobalThemeJsonType } from '@/settings/chartT // 项目数据枚举 export enum ProjectInfoEnum { + // ID + PROJECT_ID = "projectId", // 名称 PROJECT_NAME = 'projectName', // 描述 @@ -27,6 +29,7 @@ export enum ProjectInfoEnum { // 项目数据 export type ProjectInfoType = { + [ProjectInfoEnum.PROJECT_ID]: string, [ProjectInfoEnum.PROJECT_NAME]: string, [ProjectInfoEnum.REMARKS]: string, [ProjectInfoEnum.THUMBNAIL]: string, @@ -84,6 +87,8 @@ export enum EditCanvasConfigEnum { // 画布属性(需保存) export type EditCanvasConfigType = { + // ID + [EditCanvasConfigEnum.PROJECT_ID]: string, // 项目名称 [EditCanvasConfigEnum.PROJECT_NAME]: string, // 项目描述 diff --git a/src/store/modules/chartEditStore/chartEditStore.ts b/src/store/modules/chartEditStore/chartEditStore.ts index 3c87e155..c12278c1 100644 --- a/src/store/modules/chartEditStore/chartEditStore.ts +++ b/src/store/modules/chartEditStore/chartEditStore.ts @@ -15,7 +15,7 @@ import { HistoryActionTypeEnum, HistoryItemType, HistoryTargetTypeEnum } from '@ // 画布枚举 import { MenuEnum, SyncEnum } from '@/enums/editPageEnum' -import { +import { getUUID, loadingStart, loadingFinish, @@ -46,6 +46,7 @@ export const useChartEditStore = defineStore({ state: (): ChartEditStoreType => ({ // 项目数据 projectInfo: { + projectId: '', projectName: '', remarks: '', thumbnail: '', diff --git a/src/views/chart/hooks/useSync.hook.ts b/src/views/chart/hooks/useSync.hook.ts index 943bbf57..327292cb 100644 --- a/src/views/chart/hooks/useSync.hook.ts +++ b/src/views/chart/hooks/useSync.hook.ts @@ -120,7 +120,7 @@ export const useSync = () => { /** * * 赋值全局数据 * @param projectData 项目数据 - * @returns + * @returns */ const updateStoreInfo = (projectData: { id: string, @@ -129,7 +129,9 @@ export const useSync = () => { remarks: string, state: number }) => { - const { projectName, remarks, indexImage, state } = projectData + const { id, projectName, remarks, indexImage, state } = projectData + // ID + chartEditStore.setProjectInfo(ProjectInfoEnum.PROJECT_ID, id) // 名称 chartEditStore.setProjectInfo(ProjectInfoEnum.PROJECT_NAME, projectName) // 描述 @@ -151,6 +153,8 @@ export const useSync = () => { // 更新全局数据 await updateComponent(JSON.parse(res.data.content)) return + }else { + chartEditStore.setProjectInfo(ProjectInfoEnum.PROJECT_ID, fetchRouteParamsLocation()) } setTimeout(() => { chartEditStore.setEditCanvas(EditCanvasTypeEnum.SAVE_STATUS, SyncEnum.SUCCESS) @@ -173,6 +177,12 @@ export const useSync = () => { return } + let projectId = chartEditStore.getProjectInfo[ProjectInfoEnum.PROJECT_ID]; + if(projectId === null || projectId === ''){ + window['$message'].error('数据初未始化成功,请刷新页面!') + return + } + chartEditStore.setEditCanvas(EditCanvasTypeEnum.SAVE_STATUS, SyncEnum.START) // 获取缩略图片 @@ -183,7 +193,7 @@ export const useSync = () => { allowTaint: true, useCORS: true }) - + // 上传预览图 let uploadParams = new FormData() uploadParams.append('object', base64toFile(canvasImage.toDataURL(), `${fetchRouteParamsLocation()}_index_preview.png`)) @@ -198,7 +208,7 @@ export const useSync = () => { // 保存数据 let params = new FormData() - params.append('projectId', fetchRouteParamsLocation()) + params.append('projectId', projectId) params.append('content', JSON.stringify(chartEditStore.getStorageInfo || {})) const res= await saveProjectApi(params) as unknown as MyResponseType