Showing
4 changed files
with
118 additions
and
18 deletions
... | ... | @@ -97,7 +97,8 @@ import { |
97 | 97 | Carbon3DSoftware as Carbon3DSoftwareIcon, |
98 | 98 | Filter as FilterIcon, |
99 | 99 | FilterEdit as FilterEditIcon, |
100 | - Laptop as LaptopIcon | |
100 | + Laptop as LaptopIcon, | |
101 | + Save as SaveIcon | |
101 | 102 | } from '@vicons/carbon' |
102 | 103 | |
103 | 104 | const ionicons5 = { |
... | ... | @@ -231,7 +232,7 @@ const ionicons5 = { |
231 | 232 | // 眼睛 |
232 | 233 | EyeOutlineIcon, |
233 | 234 | EyeOffOutlineIcon, |
234 | - // 图表列表 | |
235 | + // 图表列表 | |
235 | 236 | AlbumsIcon |
236 | 237 | } |
237 | 238 | |
... | ... | @@ -285,7 +286,9 @@ const carbon = { |
285 | 286 | FilterIcon, |
286 | 287 | FilterEditIcon, |
287 | 288 | // 图层 |
288 | - LaptopIcon | |
289 | + LaptopIcon, | |
290 | + // 保存 | |
291 | + SaveIcon | |
289 | 292 | } |
290 | 293 | |
291 | 294 | // https://www.xicons.org/#/ 还有很多 | ... | ... |
... | ... | @@ -6,10 +6,10 @@ import designColor from './designColor.json' |
6 | 6 | export const lang = LangEnum.ZH |
7 | 7 | |
8 | 8 | // 水印文字 |
9 | -export const watermarkText = "GoView 低代码平台" | |
9 | +export const watermarkText = 'GoView 低代码平台' | |
10 | 10 | |
11 | 11 | // 分组名称 |
12 | -export const groupTitle = "分组" | |
12 | +export const groupTitle = '分组' | |
13 | 13 | |
14 | 14 | // 主题配置 |
15 | 15 | export const theme = { |
... | ... | @@ -17,7 +17,7 @@ export const theme = { |
17 | 17 | darkTheme: false, |
18 | 18 | //默认主题色 |
19 | 19 | appTheme: '#51d6a9', |
20 | - appThemeDetail: null, | |
20 | + appThemeDetail: null | |
21 | 21 | } |
22 | 22 | |
23 | 23 | // 图表初始配置(px) |
... | ... | @@ -28,7 +28,7 @@ export const chartInitConfig = { |
28 | 28 | h: 300, |
29 | 29 | // 不建议动 offset |
30 | 30 | offsetX: 0, |
31 | - offsetY: 0, | |
31 | + offsetY: 0 | |
32 | 32 | } |
33 | 33 | |
34 | 34 | // dialog 图标的大小 |
... | ... | @@ -72,3 +72,6 @@ export const canvasModelIndex = 9999 |
72 | 72 | |
73 | 73 | // 框选时蒙层的 z-index,需比所有图表高 |
74 | 74 | export const selectBoxIndex = canvasModelIndex + 10 |
75 | + | |
76 | +// 工作台自动保存间隔(s) | |
77 | +export const saveInterval = 120 | ... | ... |
... | ... | @@ -29,6 +29,22 @@ |
29 | 29 | </template> |
30 | 30 | <span>{{ item.title }}</span> |
31 | 31 | </n-tooltip> |
32 | + <n-divider vertical /> | |
33 | + <!-- 保存 --> | |
34 | + <n-tooltip placement="bottom" trigger="hover"> | |
35 | + <template #trigger> | |
36 | + <div class="save-btn"> | |
37 | + <n-button size="small" type="primary" ghost @click="dataSyncUpdate()"> | |
38 | + <template #icon> | |
39 | + <n-icon> | |
40 | + <SaveIcon></SaveIcon> | |
41 | + </n-icon> | |
42 | + </template> | |
43 | + </n-button> | |
44 | + </div> | |
45 | + </template> | |
46 | + <span>保存</span> | |
47 | + </n-tooltip> | |
32 | 48 | </n-space> |
33 | 49 | </n-space> |
34 | 50 | </template> |
... | ... | @@ -43,12 +59,14 @@ import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore |
43 | 59 | |
44 | 60 | import { useChartHistoryStore } from '@/store/modules/chartHistoryStore/chartHistoryStore' |
45 | 61 | import { HistoryStackEnum } from '@/store/modules/chartHistoryStore/chartHistoryStore.d' |
46 | - | |
62 | +import { useSync } from '../../hooks/useSync.hook' | |
47 | 63 | import { useChartLayoutStore } from '@/store/modules/chartLayoutStore/chartLayoutStore' |
48 | 64 | import { ChartLayoutStoreEnum } from '@/store/modules/chartLayoutStore/chartLayoutStore.d' |
49 | 65 | |
50 | 66 | const { LayersIcon, BarChartIcon, PrismIcon, HomeIcon, ArrowBackIcon, ArrowForwardIcon } = icon.ionicons5 |
67 | +const { SaveIcon } = icon.carbon | |
51 | 68 | const { setItem } = useChartLayoutStore() |
69 | +const { dataSyncUpdate } = useSync() | |
52 | 70 | const { getLayers, getCharts, getDetails } = toRefs(useChartLayoutStore()) |
53 | 71 | const chartEditStore = useChartEditStore() |
54 | 72 | const chartHistoryStore = useChartHistoryStore() |
... | ... | @@ -81,9 +99,9 @@ const btnList = reactive<ItemType<ChartLayoutStoreEnum>[]>([ |
81 | 99 | } |
82 | 100 | ]) |
83 | 101 | |
84 | -const isBackStack = computed(()=> chartHistoryStore.getBackStack.length> 1) | |
102 | +const isBackStack = computed(() => chartHistoryStore.getBackStack.length > 1) | |
85 | 103 | |
86 | -const isForwardStack = computed(()=> chartHistoryStore.getForwardStack.length> 0) | |
104 | +const isForwardStack = computed(() => chartHistoryStore.getForwardStack.length > 0) | |
87 | 105 | |
88 | 106 | const historyList = reactive<ItemType<HistoryStackEnum>[]>([ |
89 | 107 | { |
... | ... | @@ -101,7 +119,6 @@ const historyList = reactive<ItemType<HistoryStackEnum>[]>([ |
101 | 119 | } |
102 | 120 | ]) |
103 | 121 | |
104 | - | |
105 | 122 | // store 描述的是展示的值,所以和 ContentConfigurations 的 collapsed 是相反的 |
106 | 123 | const styleHandle = (item: ItemType<ChartLayoutStoreEnum>) => { |
107 | 124 | if (item.key === ChartLayoutStoreEnum.DETAILS) { |
... | ... | @@ -120,10 +137,10 @@ const clickHistoryHandle = (item: ItemType<HistoryStackEnum>) => { |
120 | 137 | switch (item.key) { |
121 | 138 | case HistoryStackEnum.BACK_STACK: |
122 | 139 | chartEditStore.setBack() |
123 | - break; | |
140 | + break | |
124 | 141 | case HistoryStackEnum.FORWARD_STACK: |
125 | 142 | chartEditStore.setForward() |
126 | - break; | |
143 | + break | |
127 | 144 | } |
128 | 145 | } |
129 | 146 | |
... | ... | @@ -142,5 +159,5 @@ const goHomeHandle = () => { |
142 | 159 | <style lang="scss" scoped> |
143 | 160 | .header-left-btn { |
144 | 161 | margin-left: -37px; |
145 | - } | |
162 | +} | |
146 | 163 | </style> | ... | ... |
1 | -import { getUUID } from '@/utils' | |
1 | +import { getUUID, fetchRouteParamsLocation } from '@/utils' | |
2 | 2 | import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore' |
3 | 3 | import { ChartEditStoreEnum, ChartEditStorage } from '@/store/modules/chartEditStore/chartEditStore.d' |
4 | 4 | import { useChartHistoryStore } from '@/store/modules/chartHistoryStore/chartHistoryStore' |
... | ... | @@ -9,6 +9,10 @@ import { CreateComponentType, CreateComponentGroupType } from '@/packages/index. |
9 | 9 | import { BaseEvent, EventLife } from '@/enums/eventEnum' |
10 | 10 | import { PublicGroupConfigClass } from '@/packages/public/publicConfig' |
11 | 11 | import merge from 'lodash/merge' |
12 | +import { onUnmounted } from 'vue' | |
13 | +import { saveInterval } from '@/settings/designSetting' | |
14 | +import throttle from 'lodash/throttle' | |
15 | +import html2canvas from 'html2canvas' | |
12 | 16 | |
13 | 17 | /** |
14 | 18 | * * 画布-版本升级对旧数据无法兼容的补丁 |
... | ... | @@ -116,7 +120,7 @@ export const useSync = () => { |
116 | 120 | } |
117 | 121 | |
118 | 122 | if (e.isGroup) { |
119 | - (e as CreateComponentGroupType).groupList.forEach(groupItem => { | |
123 | + ;(e as CreateComponentGroupType).groupList.forEach(groupItem => { | |
120 | 124 | intComponent(groupItem) |
121 | 125 | }) |
122 | 126 | } else { |
... | ... | @@ -155,7 +159,7 @@ export const useSync = () => { |
155 | 159 | // 组件 |
156 | 160 | if (key === ChartEditStoreEnum.COMPONENT_LIST) { |
157 | 161 | let loadIndex = 0 |
158 | - const listLength = projectData[key].length; | |
162 | + const listLength = projectData[key].length | |
159 | 163 | for (const comItem of projectData[key]) { |
160 | 164 | // 设置加载数量 |
161 | 165 | let percentage = parseInt((parseFloat(`${++loadIndex / listLength}`) * 100).toString()) |
... | ... | @@ -196,7 +200,80 @@ export const useSync = () => { |
196 | 200 | chartLayoutStore.setItemUnHandle(ChartLayoutStoreEnum.PERCENTAGE, 0) |
197 | 201 | } |
198 | 202 | |
203 | + // 数据保存 | |
204 | + const dataSyncUpdate = throttle(async (updateImg = true) => { | |
205 | + if (!fetchRouteParamsLocation()) return | |
206 | + window['$message'].success('保存成功!') | |
207 | + // let projectId = chartEditStore.getProjectInfo[ProjectInfoEnum.PROJECT_ID] | |
208 | + // if (projectId === null || projectId === '') { | |
209 | + // window['$message'].error('数据初未始化成功,请刷新页面!') | |
210 | + // return | |
211 | + // } | |
212 | + | |
213 | + // chartEditStore.setEditCanvas(EditCanvasTypeEnum.SAVE_STATUS, SyncEnum.START) | |
214 | + | |
215 | + // 异常处理:缩略图上传失败不影响JSON的保存 | |
216 | + try { | |
217 | + if (updateImg) { | |
218 | + // 获取缩略图片 | |
219 | + const range = document.querySelector('.go-edit-range') as HTMLElement | |
220 | + // 生成图片 | |
221 | + const canvasImage: HTMLCanvasElement = await html2canvas(range, { | |
222 | + backgroundColor: null, | |
223 | + allowTaint: true, | |
224 | + useCORS: true | |
225 | + }) | |
226 | + | |
227 | + // 上传预览图 | |
228 | + // let uploadParams = new FormData() | |
229 | + // uploadParams.append( | |
230 | + // 'object', | |
231 | + // base64toFile(canvasImage.toDataURL(), `${fetchRouteParamsLocation()}_index_preview.png`) | |
232 | + // ) | |
233 | + // const uploadRes = await uploadFile(uploadParams) | |
234 | + // 保存预览图 | |
235 | + // if (uploadRes && uploadRes.code === ResultEnum.SUCCESS) { | |
236 | + // await updateProjectApi({ | |
237 | + // id: fetchRouteParamsLocation(), | |
238 | + // indexImage: `${systemStore.getFetchInfo.OSSUrl}${uploadRes.data.fileName}` | |
239 | + // }) | |
240 | + // } | |
241 | + } | |
242 | + } catch (e) { | |
243 | + console.log(e) | |
244 | + } | |
245 | + | |
246 | + // 保存数据 | |
247 | + // let params = new FormData() | |
248 | + // params.append('projectId', projectId) | |
249 | + // params.append('content', JSONStringify(chartEditStore.getStorageInfo || {})) | |
250 | + // const res = await saveProjectApi(params) | |
251 | + | |
252 | + // if (res && res.code === ResultEnum.SUCCESS) { | |
253 | + // // 成功状态 | |
254 | + // setTimeout(() => { | |
255 | + // chartEditStore.setEditCanvas(EditCanvasTypeEnum.SAVE_STATUS, SyncEnum.SUCCESS) | |
256 | + // }, 1000) | |
257 | + // return | |
258 | + // } | |
259 | + // 失败状态 | |
260 | + // chartEditStore.setEditCanvas(EditCanvasTypeEnum.SAVE_STATUS, SyncEnum.FAILURE) | |
261 | + }, 3000) | |
262 | + // * 定时处理 | |
263 | + const intervalDataSyncUpdate = () => { | |
264 | + // 定时获取数据 | |
265 | + const syncTiming = setInterval(() => { | |
266 | + dataSyncUpdate() | |
267 | + }, saveInterval * 1000) | |
268 | + | |
269 | + // 销毁 | |
270 | + onUnmounted(() => { | |
271 | + clearInterval(syncTiming) | |
272 | + }) | |
273 | + } | |
199 | 274 | return { |
200 | - updateComponent | |
275 | + updateComponent, | |
276 | + dataSyncUpdate, | |
277 | + intervalDataSyncUpdate | |
201 | 278 | } |
202 | 279 | } | ... | ... |