Commit 47b08c25c7c27b1c44fb8e5bafbb2f79bb24556c
1 parent
996f4b87
perf(views/chart): 拆分主页面左上角保存内容和缩略图
Showing
2 changed files
with
50 additions
and
33 deletions
| ... | ... | @@ -43,7 +43,22 @@ | 
| 43 | 43 | </n-button> | 
| 44 | 44 | </div> | 
| 45 | 45 | </template> | 
| 46 | - <span>保存</span> | |
| 46 | + <span>保存内容</span> | |
| 47 | + </n-tooltip> | |
| 48 | + <!-- 保存缩略图 --> | |
| 49 | + <n-tooltip v-if="!isCustomerUser" placement="bottom" trigger="hover"> | |
| 50 | + <template #trigger> | |
| 51 | + <div class="save-btn"> | |
| 52 | + <n-button size="small" type="primary" ghost @click="thumbnailSyncUpdate()"> | |
| 53 | + <template #icon> | |
| 54 | + <n-icon> | |
| 55 | + <Awake /> | |
| 56 | + </n-icon> | |
| 57 | + </template> | |
| 58 | + </n-button> | |
| 59 | + </div> | |
| 60 | + </template> | |
| 61 | + <span>保存缩略图</span> | |
| 47 | 62 | </n-tooltip> | 
| 48 | 63 | </n-space> | 
| 49 | 64 | </n-space> | 
| ... | ... | @@ -53,7 +68,7 @@ | 
| 53 | 68 | import { toRefs, Ref, reactive, computed } from 'vue' | 
| 54 | 69 | import { renderIcon, goDialog, goHome } from '@/utils' | 
| 55 | 70 | import { icon } from '@/plugins' | 
| 56 | -import { Save } from '@vicons/carbon' | |
| 71 | +import { Save, Awake } from '@vicons/carbon' | |
| 57 | 72 | import { useRemoveKeyboard } from '../../../hooks/useKeyboard.hook' | 
| 58 | 73 | |
| 59 | 74 | import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore' | 
| ... | ... | @@ -71,7 +86,7 @@ const { setItem } = useChartLayoutStore() | 
| 71 | 86 | const { getLayers, getCharts, getDetails } = toRefs(useChartLayoutStore()) | 
| 72 | 87 | const chartEditStore = useChartEditStore() | 
| 73 | 88 | const chartHistoryStore = useChartHistoryStore() | 
| 74 | -const { dataSyncUpdate } = useSyncRemote() | |
| 89 | +const { dataSyncUpdate ,thumbnailSyncUpdate } = useSyncRemote() | |
| 75 | 90 | const { isCustomerUser } = useRole() | 
| 76 | 91 | |
| 77 | 92 | interface ItemType<T> { | ... | ... | 
| ... | ... | @@ -70,22 +70,47 @@ export const useSyncRemote = () => { | 
| 70 | 70 | } | 
| 71 | 71 | } | 
| 72 | 72 | |
| 73 | - // 数据保存 | |
| 74 | - const dataSyncUpdate = throttle(async (updateImg = true) => { | |
| 73 | + /** | |
| 74 | + * 数据保存和缩略图保存逻辑拆分 | |
| 75 | + */ | |
| 76 | + | |
| 77 | + //dataSyncUpdate 数据保存 | |
| 78 | + const dataSyncUpdate = throttle(async () => { | |
| 75 | 79 | if (!fetchRouteParamsLocation()) return | 
| 76 | 80 | |
| 77 | 81 | // 客户角色只有查看权限 | 
| 78 | 82 | if (unref(isCustomerUser)) return | 
| 79 | 83 | |
| 80 | - const { dataViewId, state, organizationId, dataViewName, dataViewContent } = projectInfoStore.getProjectInfo | |
| 84 | + const { dataViewId, dataViewName, dataViewContent } = projectInfoStore.getProjectInfo | |
| 81 | 85 | |
| 82 | 86 | if (dataViewId === null || dataViewId === '') { | 
| 83 | 87 | window['$message'].error('数据初未始化成功,请刷新页面!') | 
| 84 | 88 | return | 
| 85 | 89 | } | 
| 86 | 90 | projectInfoStore.setSaveStatus(SyncEnum.START) | 
| 87 | - // 异常处理:缩略图上传失败不影响JSON的保存 | |
| 88 | - try { | |
| 91 | + // 保存数据 | |
| 92 | + const saveContent = { | |
| 93 | + dataViewContent: { | |
| 94 | + id: dataViewContent.id, | |
| 95 | + content: JSONStringify(chartEditStore.getStorageInfo || {}) | |
| 96 | + }, | |
| 97 | + dataViewName, | |
| 98 | + dataViewId | |
| 99 | + } | |
| 100 | + await contentUpdateApi(saveContent as unknown as BaseUpdateContentParams) | |
| 101 | + window['$message'].success('保存成功!') | |
| 102 | + // 成功状态 | |
| 103 | + setTimeout(() => { | |
| 104 | + projectInfoStore.setSaveStatus(SyncEnum.SUCCESS) | |
| 105 | + }, 1000) | |
| 106 | + return | |
| 107 | + // 失败状态 | |
| 108 | + // chartEditStore.setEditCanvas(EditCanvasTypeEnum.SAVE_STATUS, SyncEnum.FAILURE) | |
| 109 | + }, 3000) | |
| 110 | + | |
| 111 | + //thumbnailSyncUpdate 缩略图保存 | |
| 112 | + const thumbnailSyncUpdate = throttle(async(updateImg = true)=>{ | |
| 113 | + const { state, organizationId, dataViewName } = projectInfoStore.getProjectInfo | |
| 89 | 114 | if (updateImg) { | 
| 90 | 115 | // 获取缩略图片 | 
| 91 | 116 | const range = document.querySelector('.go-edit-range') as HTMLElement | 
| ... | ... | @@ -96,7 +121,6 @@ export const useSyncRemote = () => { | 
| 96 | 121 | useCORS: true, | 
| 97 | 122 | logging: false | 
| 98 | 123 | }) | 
| 99 | - | |
| 100 | 124 | // 上传预览图 | 
| 101 | 125 | const uploadParams = new FormData() | 
| 102 | 126 | uploadParams.append( | 
| ... | ... | @@ -104,7 +128,6 @@ export const useSyncRemote = () => { | 
| 104 | 128 | base64toFile(canvasImage.toDataURL(), `${fetchRouteParamsLocation()}_index_preview.png`) | 
| 105 | 129 | ) | 
| 106 | 130 | const uploadRes = await uploadFile(uploadParams) | 
| 107 | - | |
| 108 | 131 | // 保存预览图 | 
| 109 | 132 | if (uploadRes) { | 
| 110 | 133 | await saveDataViewList({ | 
| ... | ... | @@ -116,28 +139,7 @@ export const useSyncRemote = () => { | 
| 116 | 139 | }) | 
| 117 | 140 | } | 
| 118 | 141 | } | 
| 119 | - } catch (e) { | |
| 120 | - console.log(e) | |
| 121 | - } | |
| 122 | - // 保存数据 | |
| 123 | - const saveContent = { | |
| 124 | - dataViewContent: { | |
| 125 | - id: dataViewContent.id, | |
| 126 | - content: JSONStringify(chartEditStore.getStorageInfo || {}) | |
| 127 | - }, | |
| 128 | - dataViewName, | |
| 129 | - dataViewId | |
| 130 | - } | |
| 131 | - await contentUpdateApi(saveContent as unknown as BaseUpdateContentParams) | |
| 132 | - window['$message'].success('保存成功!') | |
| 133 | - // 成功状态 | |
| 134 | - setTimeout(() => { | |
| 135 | - projectInfoStore.setSaveStatus(SyncEnum.SUCCESS) | |
| 136 | - }, 1000) | |
| 137 | - return | |
| 138 | - // 失败状态 | |
| 139 | - // chartEditStore.setEditCanvas(EditCanvasTypeEnum.SAVE_STATUS, SyncEnum.FAILURE) | |
| 140 | - }, 3000) | |
| 142 | + }) | |
| 141 | 143 | |
| 142 | 144 | // * 定时处理 | 
| 143 | 145 | const intervalDataSyncUpdate = () => { | 
| ... | ... | @@ -145,7 +147,6 @@ export const useSyncRemote = () => { | 
| 145 | 147 | // const syncTiming = setInterval(() => { | 
| 146 | 148 | // dataSyncUpdate() | 
| 147 | 149 | // }, saveInterval * 1000) | 
| 148 | - | |
| 149 | 150 | // // 销毁 | 
| 150 | 151 | // onUnmounted(() => { | 
| 151 | 152 | // clearInterval(syncTiming) | 
| ... | ... | @@ -154,6 +155,7 @@ export const useSyncRemote = () => { | 
| 154 | 155 | return { | 
| 155 | 156 | dataSyncFetch, | 
| 156 | 157 | dataSyncUpdate, | 
| 158 | + thumbnailSyncUpdate, | |
| 157 | 159 | intervalDataSyncUpdate | 
| 158 | 160 | } | 
| 159 | 161 | } | ... | ... |