mirror of
https://gitee.com/dromara/go-view.git
synced 2026-04-23 00:00:12 +08:00
feat: 预览页\JSON编辑页\图表页保存同步更新
This commit is contained in:
@@ -58,17 +58,65 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, computed, h } from 'vue'
|
||||
import { ref, computed, h, onBeforeUnmount } from 'vue'
|
||||
import { useSettingStore } from '@/store/modules/settingStore/settingStore'
|
||||
import { ToolsStatusEnum } from '@/store/modules/settingStore/settingStore.d'
|
||||
import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore'
|
||||
import { fetchPathByName, routerTurnByPath, setSessionStorage, getLocalStorage } from '@/utils'
|
||||
import { EditEnum } from '@/enums/pageEnum'
|
||||
import { StorageEnum } from '@/enums/storageEnum'
|
||||
import { useRoute } from 'vue-router'
|
||||
import { useSync } from '@/views/chart/hooks/useSync.hook'
|
||||
import { SavePageEnum } from '@/enums/editPageEnum'
|
||||
import { GoSystemSet } from '@/components/GoSystemSet/index'
|
||||
import { exportHandle } from './utils'
|
||||
import { useFile } from './hooks/useFile.hooks'
|
||||
import { BtnListType, TypeEnum } from './index.d'
|
||||
import { icon } from '@/plugins'
|
||||
|
||||
const { DownloadIcon, ShareIcon, PawIcon, SettingsSharpIcon } = icon.ionicons5
|
||||
const { DownloadIcon, ShareIcon, PawIcon, SettingsSharpIcon, CodeSlashIcon } = icon.ionicons5
|
||||
const settingStore = useSettingStore()
|
||||
const chartEditStore = useChartEditStore()
|
||||
const routerParamsInfo = useRoute()
|
||||
const { updateComponent } = useSync()
|
||||
|
||||
// 编辑
|
||||
const editHandle = () => {
|
||||
// 获取id路径
|
||||
const path = fetchPathByName(EditEnum.CHART_EDIT_NAME, 'href')
|
||||
if (!path) return
|
||||
let { id } = routerParamsInfo.params as any
|
||||
id = typeof id === 'string' ? id : id[0]
|
||||
updateToSession(id)
|
||||
routerTurnByPath(path, [id], undefined, true)
|
||||
}
|
||||
|
||||
// 把内存中的数据同步到SessionStorage 便于传递给新窗口初始化数据
|
||||
function updateToSession(id: string) {
|
||||
const storageInfo = chartEditStore.getStorageInfo
|
||||
const sessionStorageInfo = getLocalStorage(StorageEnum.GO_CHART_STORAGE_LIST) || []
|
||||
|
||||
if (sessionStorageInfo?.length) {
|
||||
const repeateIndex = sessionStorageInfo.findIndex((e: { id: string }) => e.id === id)
|
||||
// 重复替换
|
||||
if (repeateIndex !== -1) {
|
||||
sessionStorageInfo.splice(repeateIndex, 1, { ...storageInfo, id })
|
||||
setSessionStorage(StorageEnum.GO_CHART_STORAGE_LIST, sessionStorageInfo)
|
||||
} else {
|
||||
sessionStorageInfo.push({ ...storageInfo, id})
|
||||
setSessionStorage(StorageEnum.GO_CHART_STORAGE_LIST, sessionStorageInfo)
|
||||
}
|
||||
} else {
|
||||
setSessionStorage(StorageEnum.GO_CHART_STORAGE_LIST, [{ ...storageInfo, id }])
|
||||
}
|
||||
}
|
||||
|
||||
onBeforeUnmount((() => {
|
||||
// 【监听JSON代码 刷新图表】
|
||||
const updateFn = (e: any) => updateComponent(e!.detail, true, false)
|
||||
addEventListener(SavePageEnum.JSON, updateFn)
|
||||
return () => removeEventListener(SavePageEnum.JSON, updateFn)
|
||||
})())
|
||||
|
||||
// 鼠标悬停定时器
|
||||
let mouseTime: any = null
|
||||
@@ -95,6 +143,13 @@ const btnList: BtnListType[] = [
|
||||
name: '导入',
|
||||
icon: DownloadIcon
|
||||
},
|
||||
{
|
||||
key: 'edit',
|
||||
type: TypeEnum.BUTTON,
|
||||
name: '编辑JSON',
|
||||
icon: CodeSlashIcon,
|
||||
handle: editHandle
|
||||
},
|
||||
{
|
||||
key: 'setting',
|
||||
type: TypeEnum.BUTTON,
|
||||
|
||||
Reference in New Issue
Block a user