usePreview.ts
3.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import { fetchRouteParamsLocation, JSONParse, } from '@/utils'
import { getDataView } from '@/api/external/contentSave/content'
import { ChartEditStorageType } from '..'
import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore'
import { useRoute } from 'vue-router'
import { ShareEnum } from '@/enums/external/pageEnum'
import { nextTick } from 'vue'
const isSharePageMode = () => {
const ROUTE = useRoute()
return ROUTE.matched.find(item => item.path === ShareEnum.SHARE_PATH)
}
// THINGS_KIT 兼容之前的用户数据
const compatibleOldUserDataHook = (fileData:object)=>{
if(!fileData) return
let userData:Recordable = fileData
if(!Reflect.get(fileData,'pageConfig')){
userData={
pageConfig:{
currentActiveId: "1",
currentActiveIndex: 1,
pageList:[
{
...fileData,
id:"1",
title:"页面 1",
editCanvas: {
// 编辑区域 Dom
editLayoutDom: null,
editContentDom: null,
// 偏移量
offset: 20,
// 系统控制缩放
scale: 0.5,
// 用户控制的缩放
userScale: 0.5,
// 锁定缩放
lockScale: false,
// 初始化
isCreate: false,
// 拖拽中
isDrag: false,
// 框选中
isSelect: false,
// 同步中
// saveStatus: SyncEnum.PENDING,
// 代码编辑中
isCodeEdit: false
},
// 右键菜单
rightMenuShow: false,
// 鼠标定位
mousePosition: {
startX: 0,
startY: 0,
x: 0,
y: 0
},
// 目标图表
targetChart: {
hoverId: undefined,
selectId: []
},
// 记录临时数据(复制等)
recordChart: undefined,
}
]
}
}
}
return userData
}
//
export const getSessionStorageInfo = async () => {
if (isSharePageMode()) return
const id = fetchRouteParamsLocation()
const chartEditStore = useChartEditStore()
const res = await getDataView(id)
if (res) {
const { dataViewContent } = res
let content = JSONParse(dataViewContent.content) as ChartEditStorageType
content = compatibleOldUserDataHook(content) as ChartEditStorageType
if (content) {
// const { editCanvasConfig, requestGlobalConfig, componentList } = content
// chartEditStore.editCanvasConfig = editCanvasConfig
// chartEditStore.requestGlobalConfig = requestGlobalConfig
// chartEditStore.componentList = componentList
await nextTick()
const { pageConfig } = content
chartEditStore.setPageConfig(pageConfig)
chartEditStore.setCurrentPageSelectId(pageConfig.pageList[0].id)
// chartEditStore.setPageList(pageConfig.pageList)
// pageConfig.pageList.forEach(pageItem => {
// if(pageItem.id===chartEditStore.pageConfig.currentActiveId){
// chartEditStore.setPageEditCanvasConfig(pageItem.editCanvasConfig)
// chartEditStore.setPageRequestGlobalConfig(pageItem.requestGlobalConfig)
// chartEditStore.setPageComponentList(pageItem.componentList)
// }
// })
}
}
}