mirror of
https://gitee.com/dromara/go-view.git
synced 2025-04-25 23:10:10 +08:00
!95 feat: JSON编辑优化以及兼容后端接口保存
Merge pull request !95 from 潘潘/master-fetch-dev
This commit is contained in:
commit
b79c2b2fdb
@ -6,28 +6,26 @@ import { ChartEnum } from '@/enums/pageEnum'
|
|||||||
import { SavePageEnum } from '@/enums/editPageEnum'
|
import { SavePageEnum } from '@/enums/editPageEnum'
|
||||||
import { editToJsonInterval } from '@/settings/designSetting'
|
import { editToJsonInterval } from '@/settings/designSetting'
|
||||||
|
|
||||||
const { updateComponent } = useSync()
|
const { updateComponent, dataSyncUpdate } = useSync()
|
||||||
const chartEditStore = useChartEditStore()
|
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) {
|
dataSyncUpdate && (await dataSyncUpdate())
|
||||||
dispatchEvent(new CustomEvent(SavePageEnum.CHART, { detail: chartEditStore.getStorageInfo }))
|
dispatchEvent(new CustomEvent(SavePageEnum.CHART, { detail: chartEditStore.getStorageInfo }))
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// 开启侦听
|
// 开启侦听
|
||||||
const use = () => {
|
const use = () => {
|
||||||
// 1、定时同步数据
|
// // 1、定时同步数据
|
||||||
timer = setInterval(() => {
|
// timer = setInterval(() => {
|
||||||
// 窗口激活并且处于工作台
|
// // 窗口激活并且处于工作台
|
||||||
document.hasFocus() && syncData()
|
// document.hasFocus() && syncData()
|
||||||
}, editToJsonInterval)
|
// }, editToJsonInterval)
|
||||||
// 2、失焦同步数据
|
// 2、失焦同步数据
|
||||||
addEventListener('blur', syncData)
|
addEventListener('blur', syncData)
|
||||||
|
|
||||||
@ -37,7 +35,7 @@ const useSyncUpdateHandle = () => {
|
|||||||
|
|
||||||
// 关闭侦听
|
// 关闭侦听
|
||||||
const unUse = () => {
|
const unUse = () => {
|
||||||
clearInterval(timer)
|
// clearInterval(timer)
|
||||||
removeEventListener(SavePageEnum.JSON, updateFn)
|
removeEventListener(SavePageEnum.JSON, updateFn)
|
||||||
removeEventListener('blur', syncData)
|
removeEventListener('blur', syncData)
|
||||||
}
|
}
|
||||||
|
@ -137,7 +137,8 @@ const toolsMouseoutHandle = () => {
|
|||||||
|
|
||||||
// 编辑处理
|
// 编辑处理
|
||||||
const editHandle = () => {
|
const editHandle = () => {
|
||||||
window['$message'].warning('将开启失焦更新与 5 秒同步更新!')
|
window['$message'].warning('将开启失焦更新!')
|
||||||
|
// window['$message'].warning('将开启失焦更新与 5 秒同步更新!')
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
// 获取id路径
|
// 获取id路径
|
||||||
const path = fetchPathByName(EditEnum.CHART_EDIT_NAME, 'href')
|
const path = fetchPathByName(EditEnum.CHART_EDIT_NAME, 'href')
|
||||||
|
@ -238,7 +238,7 @@ export const useSync = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// * 数据保存
|
// * 数据保存
|
||||||
const dataSyncUpdate = throttle(async () => {
|
const dataSyncUpdate = throttle(async (updateImg = true) => {
|
||||||
if(!fetchRouteParamsLocation()) return
|
if(!fetchRouteParamsLocation()) return
|
||||||
|
|
||||||
let projectId = chartEditStore.getProjectInfo[ProjectInfoEnum.PROJECT_ID];
|
let projectId = chartEditStore.getProjectInfo[ProjectInfoEnum.PROJECT_ID];
|
||||||
@ -249,6 +249,9 @@ export const useSync = () => {
|
|||||||
|
|
||||||
chartEditStore.setEditCanvas(EditCanvasTypeEnum.SAVE_STATUS, SyncEnum.START)
|
chartEditStore.setEditCanvas(EditCanvasTypeEnum.SAVE_STATUS, SyncEnum.START)
|
||||||
|
|
||||||
|
// 异常处理:缩略图上传失败不影响JSON的保存
|
||||||
|
try {
|
||||||
|
if (updateImg) {
|
||||||
// 获取缩略图片
|
// 获取缩略图片
|
||||||
const range = document.querySelector('.go-edit-range') as HTMLElement
|
const range = document.querySelector('.go-edit-range') as HTMLElement
|
||||||
// 生成图片
|
// 生成图片
|
||||||
@ -269,6 +272,10 @@ export const useSync = () => {
|
|||||||
indexImage: `${systemStore.getFetchInfo.OSSUrl}${uploadRes.data.fileName}`
|
indexImage: `${systemStore.getFetchInfo.OSSUrl}${uploadRes.data.fileName}`
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.log(e)
|
||||||
|
}
|
||||||
|
|
||||||
// 保存数据
|
// 保存数据
|
||||||
let params = new FormData()
|
let params = new FormData()
|
||||||
|
@ -38,20 +38,23 @@ import { MonacoEditor } from '@/components/Pages/MonacoEditor'
|
|||||||
import { SavePageEnum } from '@/enums/editPageEnum'
|
import { SavePageEnum } from '@/enums/editPageEnum'
|
||||||
import { getSessionStorageInfo } from '../preview/utils'
|
import { getSessionStorageInfo } from '../preview/utils'
|
||||||
import type { ChartEditStorageType } from '../preview/index.d'
|
import type { ChartEditStorageType } from '../preview/index.d'
|
||||||
import { setSessionStorage } from '@/utils'
|
import { setSessionStorage, fetchRouteParamsLocation } from '@/utils'
|
||||||
import { StorageEnum } from '@/enums/storageEnum'
|
import { StorageEnum } from '@/enums/storageEnum'
|
||||||
import { icon } from '@/plugins'
|
import { icon } from '@/plugins'
|
||||||
|
import { useSync } from '@/views/chart/hooks/useSync.hook'
|
||||||
|
import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore'
|
||||||
|
import { ProjectInfoEnum } from '@/store/modules/chartEditStore/chartEditStore.d'
|
||||||
|
const chartEditStore = useChartEditStore()
|
||||||
|
const { dataSyncUpdate } = useSync()
|
||||||
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 unknown 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 +89,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('源窗口已关闭,视图同步失败')
|
||||||
}
|
}
|
||||||
@ -94,6 +97,11 @@ function updateSync() {
|
|||||||
const detail = JSON.parse(content.value)
|
const detail = JSON.parse(content.value)
|
||||||
delete detail.id
|
delete detail.id
|
||||||
// 保持id不变
|
// 保持id不变
|
||||||
|
// 带后端版本额外处理请求
|
||||||
|
if (dataSyncUpdate) {
|
||||||
|
chartEditStore.setProjectInfo(ProjectInfoEnum.PROJECT_ID, fetchRouteParamsLocation())
|
||||||
|
await dataSyncUpdate(false) // JSON界面保存不上传缩略图
|
||||||
|
}
|
||||||
window.opener.dispatchEvent(new CustomEvent(SavePageEnum.JSON, { detail }))
|
window.opener.dispatchEvent(new CustomEvent(SavePageEnum.JSON, { detail }))
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
window['$message'].error('内容格式有误')
|
window['$message'].error('内容格式有误')
|
||||||
|
@ -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 unknown 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()
|
||||||
})
|
})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user