From e0d2e8031d79e1f61cbc7291cebbef5bafea6549 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A7=8B=E5=90=8D=E5=B1=B1=E8=B7=AF=E9=9C=B8?= <1308715179@qq.com> Date: Sun, 18 Sep 2022 11:56:26 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E5=9C=A8=E7=BC=96?= =?UTF-8?q?=E8=BE=91=E9=A1=B9=E7=9B=AE=E4=B9=8B=E5=89=8D=E5=8A=A0=E8=BD=BD?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=BC=82=E5=B8=B8=EF=BC=8C=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E4=BF=9D=E5=AD=98=E5=AF=BC=E8=87=B4=E9=A1=B9=E7=9B=AE=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E6=B8=85=E7=A9=BA=E9=97=AE=E9=A2=98=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../modules/chartEditStore/chartEditStore.d.ts | 5 +++++ .../modules/chartEditStore/chartEditStore.ts | 3 ++- src/views/chart/hooks/useSync.hook.ts | 18 ++++++++++++++---- 3 files changed, 21 insertions(+), 5 deletions(-) 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