Commit 47b08c25c7c27b1c44fb8e5bafbb2f79bb24556c
1 parent
996f4b87
perf(views/chart): 拆分主页面左上角保存内容和缩略图
Showing
2 changed files
with
50 additions
and
33 deletions
| @@ -43,7 +43,22 @@ | @@ -43,7 +43,22 @@ | ||
| 43 | </n-button> | 43 | </n-button> |
| 44 | </div> | 44 | </div> |
| 45 | </template> | 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 | </n-tooltip> | 62 | </n-tooltip> |
| 48 | </n-space> | 63 | </n-space> |
| 49 | </n-space> | 64 | </n-space> |
| @@ -53,7 +68,7 @@ | @@ -53,7 +68,7 @@ | ||
| 53 | import { toRefs, Ref, reactive, computed } from 'vue' | 68 | import { toRefs, Ref, reactive, computed } from 'vue' |
| 54 | import { renderIcon, goDialog, goHome } from '@/utils' | 69 | import { renderIcon, goDialog, goHome } from '@/utils' |
| 55 | import { icon } from '@/plugins' | 70 | import { icon } from '@/plugins' |
| 56 | -import { Save } from '@vicons/carbon' | 71 | +import { Save, Awake } from '@vicons/carbon' |
| 57 | import { useRemoveKeyboard } from '../../../hooks/useKeyboard.hook' | 72 | import { useRemoveKeyboard } from '../../../hooks/useKeyboard.hook' |
| 58 | 73 | ||
| 59 | import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore' | 74 | import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore' |
| @@ -71,7 +86,7 @@ const { setItem } = useChartLayoutStore() | @@ -71,7 +86,7 @@ const { setItem } = useChartLayoutStore() | ||
| 71 | const { getLayers, getCharts, getDetails } = toRefs(useChartLayoutStore()) | 86 | const { getLayers, getCharts, getDetails } = toRefs(useChartLayoutStore()) |
| 72 | const chartEditStore = useChartEditStore() | 87 | const chartEditStore = useChartEditStore() |
| 73 | const chartHistoryStore = useChartHistoryStore() | 88 | const chartHistoryStore = useChartHistoryStore() |
| 74 | -const { dataSyncUpdate } = useSyncRemote() | 89 | +const { dataSyncUpdate ,thumbnailSyncUpdate } = useSyncRemote() |
| 75 | const { isCustomerUser } = useRole() | 90 | const { isCustomerUser } = useRole() |
| 76 | 91 | ||
| 77 | interface ItemType<T> { | 92 | interface ItemType<T> { |
| @@ -70,22 +70,47 @@ export const useSyncRemote = () => { | @@ -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 | if (!fetchRouteParamsLocation()) return | 79 | if (!fetchRouteParamsLocation()) return |
| 76 | 80 | ||
| 77 | // 客户角色只有查看权限 | 81 | // 客户角色只有查看权限 |
| 78 | if (unref(isCustomerUser)) return | 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 | if (dataViewId === null || dataViewId === '') { | 86 | if (dataViewId === null || dataViewId === '') { |
| 83 | window['$message'].error('数据初未始化成功,请刷新页面!') | 87 | window['$message'].error('数据初未始化成功,请刷新页面!') |
| 84 | return | 88 | return |
| 85 | } | 89 | } |
| 86 | projectInfoStore.setSaveStatus(SyncEnum.START) | 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 | if (updateImg) { | 114 | if (updateImg) { |
| 90 | // 获取缩略图片 | 115 | // 获取缩略图片 |
| 91 | const range = document.querySelector('.go-edit-range') as HTMLElement | 116 | const range = document.querySelector('.go-edit-range') as HTMLElement |
| @@ -96,7 +121,6 @@ export const useSyncRemote = () => { | @@ -96,7 +121,6 @@ export const useSyncRemote = () => { | ||
| 96 | useCORS: true, | 121 | useCORS: true, |
| 97 | logging: false | 122 | logging: false |
| 98 | }) | 123 | }) |
| 99 | - | ||
| 100 | // 上传预览图 | 124 | // 上传预览图 |
| 101 | const uploadParams = new FormData() | 125 | const uploadParams = new FormData() |
| 102 | uploadParams.append( | 126 | uploadParams.append( |
| @@ -104,7 +128,6 @@ export const useSyncRemote = () => { | @@ -104,7 +128,6 @@ export const useSyncRemote = () => { | ||
| 104 | base64toFile(canvasImage.toDataURL(), `${fetchRouteParamsLocation()}_index_preview.png`) | 128 | base64toFile(canvasImage.toDataURL(), `${fetchRouteParamsLocation()}_index_preview.png`) |
| 105 | ) | 129 | ) |
| 106 | const uploadRes = await uploadFile(uploadParams) | 130 | const uploadRes = await uploadFile(uploadParams) |
| 107 | - | ||
| 108 | // 保存预览图 | 131 | // 保存预览图 |
| 109 | if (uploadRes) { | 132 | if (uploadRes) { |
| 110 | await saveDataViewList({ | 133 | await saveDataViewList({ |
| @@ -116,28 +139,7 @@ export const useSyncRemote = () => { | @@ -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 | const intervalDataSyncUpdate = () => { | 145 | const intervalDataSyncUpdate = () => { |
| @@ -145,7 +147,6 @@ export const useSyncRemote = () => { | @@ -145,7 +147,6 @@ export const useSyncRemote = () => { | ||
| 145 | // const syncTiming = setInterval(() => { | 147 | // const syncTiming = setInterval(() => { |
| 146 | // dataSyncUpdate() | 148 | // dataSyncUpdate() |
| 147 | // }, saveInterval * 1000) | 149 | // }, saveInterval * 1000) |
| 148 | - | ||
| 149 | // // 销毁 | 150 | // // 销毁 |
| 150 | // onUnmounted(() => { | 151 | // onUnmounted(() => { |
| 151 | // clearInterval(syncTiming) | 152 | // clearInterval(syncTiming) |
| @@ -154,6 +155,7 @@ export const useSyncRemote = () => { | @@ -154,6 +155,7 @@ export const useSyncRemote = () => { | ||
| 154 | return { | 155 | return { |
| 155 | dataSyncFetch, | 156 | dataSyncFetch, |
| 156 | dataSyncUpdate, | 157 | dataSyncUpdate, |
| 158 | + thumbnailSyncUpdate, | ||
| 157 | intervalDataSyncUpdate | 159 | intervalDataSyncUpdate |
| 158 | } | 160 | } |
| 159 | } | 161 | } |