perf: 编辑JSON优化

This commit is contained in:
潘潘 2022-11-15 16:21:35 +08:00 committed by 奔跑的面条
parent 649ab1fe8c
commit 03a2efe3c6
3 changed files with 11 additions and 15 deletions

View File

@ -11,15 +11,12 @@ const chartEditStore = useChartEditStore()
// 侦听器更新 // 侦听器更新
const useSyncUpdateHandle = () => { const useSyncUpdateHandle = () => {
const routerParamsInfo = useRoute()
// 定义侦听器变量 // 定义侦听器变量
let timer: any let timer: any
const updateFn = (e: any) => updateComponent(e!.detail, true, false) const updateFn = (e: any) => updateComponent(e!.detail, true, false)
const syncData = () => { const syncData = async () => {
if (routerParamsInfo.name == ChartEnum.CHART_HOME_NAME) {
dispatchEvent(new CustomEvent(SavePageEnum.CHART, { detail: chartEditStore.getStorageInfo })) dispatchEvent(new CustomEvent(SavePageEnum.CHART, { detail: chartEditStore.getStorageInfo }))
} }
}
// 开启侦听 // 开启侦听
const use = () => { const use = () => {

View File

@ -44,14 +44,13 @@ import { icon } from '@/plugins'
const { ChevronBackOutlineIcon, DownloadIcon } = icon.ionicons5 const { ChevronBackOutlineIcon, DownloadIcon } = icon.ionicons5
const showOpenFilePicker: Function = (window as any).showOpenFilePicker const showOpenFilePicker: Function = (window as any).showOpenFilePicker
let content = ref('') const content = ref('')
// sessionStorage // sessionStorage
function getDataBySession() { async function getDataBySession() {
const localStorageInfo: ChartEditStorageType = getSessionStorageInfo() as ChartEditStorageType const localStorageInfo: ChartEditStorageType = await getSessionStorageInfo() as unknown as ChartEditStorageType
content.value = JSON.stringify(localStorageInfo, undefined, 2) content.value = JSON.stringify(localStorageInfo, undefined, 2)
} }
getDataBySession() setTimeout(getDataBySession)
// //
function back() { function back() {
@ -86,7 +85,7 @@ document.addEventListener('keydown', function (e) {
addEventListener('blur', updateSync) addEventListener('blur', updateSync)
// //
function updateSync() { async function updateSync() {
if (!window.opener) { if (!window.opener) {
return window['$message'].error('源窗口已关闭,视图同步失败') return window['$message'].error('源窗口已关闭,视图同步失败')
} }

View File

@ -12,12 +12,12 @@ import { ref } from 'vue'
import Preview from './index.vue' import Preview from './index.vue'
let key = ref(Date.now()) let key = ref(Date.now())
let localStorageInfo: ChartEditStorageType = getSessionStorageInfo() as ChartEditStorageType
// -> sessionStorage -> reload Mounted // ->
;[SavePageEnum.JSON, SavePageEnum.CHART].forEach((saveEvent: string) => { ;[SavePageEnum.JSON, SavePageEnum.CHART].forEach((saveEvent: string) => {
if (!window.opener) return if (!window.opener) return
window.opener.addEventListener(saveEvent, (e: any) => { window.opener.addEventListener(saveEvent, async (e: any) => {
const localStorageInfo: ChartEditStorageType = await getSessionStorageInfo() as unknown as ChartEditStorageType
setSessionStorage(StorageEnum.GO_CHART_STORAGE_LIST, [{ ...e.detail, id: localStorageInfo.id }]) setSessionStorage(StorageEnum.GO_CHART_STORAGE_LIST, [{ ...e.detail, id: localStorageInfo.id }])
key.value = Date.now() key.value = Date.now()
}) })