mirror of
https://gitee.com/dromara/go-view.git
synced 2025-04-06 03:58:04 +08:00
feat: 合并dev
This commit is contained in:
commit
ec5bed5b13
@ -6,6 +6,13 @@
|
||||
"name": "碧空绿",
|
||||
"pinyin": "bikonlv"
|
||||
},
|
||||
{
|
||||
"CMYK": [73, 17, 20, 1],
|
||||
"RGB": [102, 169, 201],
|
||||
"hex": "#66a9c9",
|
||||
"name": "涧石蓝",
|
||||
"pinyin": "jianshilan"
|
||||
},
|
||||
{
|
||||
"CMYK": [4, 13, 67, 0],
|
||||
"RGB": [248, 223, 114],
|
||||
@ -19,12 +26,5 @@
|
||||
"hex": "#3c7eff",
|
||||
"name": "深海蓝",
|
||||
"pinyin": "shenhailan"
|
||||
},
|
||||
{
|
||||
"CMYK": [59, 12, 19, 0],
|
||||
"RGB": [138, 188, 209],
|
||||
"hex": "#8abcd1",
|
||||
"name": "秋波蓝",
|
||||
"pinyin": "qiubolan"
|
||||
}
|
||||
]
|
||||
|
@ -268,3 +268,37 @@ export const setKeyboardDressShow = (keyCode?: number) => {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* * JSON序列化,支持函数和 undefined
|
||||
* @param data
|
||||
*/
|
||||
export const JSONStringify = (data: object) => {
|
||||
return JSON.stringify(
|
||||
data,
|
||||
(key, val) => {
|
||||
// 处理函数丢失问题
|
||||
if (typeof val === 'function') {
|
||||
return `${val}`
|
||||
}
|
||||
// 处理 undefined 丢失问题
|
||||
if (typeof val === 'undefined') {
|
||||
return 'undefined'
|
||||
}
|
||||
return val
|
||||
},
|
||||
2
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* * JSON反序列化,支持函数和 undefined
|
||||
* @param data
|
||||
*/
|
||||
export const JSONParse = (data: string) => {
|
||||
return JSON.parse(data, (k, v) => {
|
||||
if (typeof v === 'string' && v.indexOf && (v.indexOf('function') > -1 || v.indexOf('=>') > -1)) {
|
||||
return eval(`(function(){return ${v}})()`)
|
||||
}
|
||||
return v
|
||||
})
|
||||
}
|
||||
|
@ -41,12 +41,13 @@ import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore
|
||||
import { EditCanvasTypeEnum } from '@/store/modules/chartEditStore/chartEditStore.d'
|
||||
import { ChartModeEnum } from '@/store/modules/chartLayoutStore/chartLayoutStore.d'
|
||||
import { useChartLayoutStore } from '@/store/modules/chartLayoutStore/chartLayoutStore'
|
||||
import { componentInstall, loadingStart, loadingFinish, loadingError } from '@/utils'
|
||||
import { componentInstall, loadingStart, loadingFinish, loadingError, JSONStringify } from '@/utils'
|
||||
import { DragKeyEnum } from '@/enums/editPageEnum'
|
||||
import { createComponent } from '@/packages'
|
||||
import { ConfigType, CreateComponentType } from '@/packages/index.d'
|
||||
import { fetchConfigComponent, fetchChartComponent } from '@/packages/index'
|
||||
import omit from 'lodash/omit'
|
||||
|
||||
const chartEditStore = useChartEditStore()
|
||||
|
||||
defineProps({
|
||||
@ -70,7 +71,7 @@ const dragStartHandle = (e: DragEvent, item: ConfigType) => {
|
||||
componentInstall(item.chartKey, fetchChartComponent(item))
|
||||
componentInstall(item.conKey, fetchConfigComponent(item))
|
||||
// 将配置项绑定到拖拽属性上
|
||||
e!.dataTransfer!.setData(DragKeyEnum.DRAG_KEY, JSON.stringify(omit(item, ['image'])))
|
||||
e!.dataTransfer!.setData(DragKeyEnum.DRAG_KEY, JSONStringify(omit(item, ['image'])))
|
||||
// 修改状态
|
||||
chartEditStore.setEditCanvas(EditCanvasTypeEnum.IS_CREATE, true)
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { ref, toRef, nextTick } from 'vue'
|
||||
import { UploadCustomRequestOptions } from 'naive-ui'
|
||||
import { FileTypeEnum } from '@/enums/fileTypeEnum'
|
||||
import { readFile, downloadTextFile } from '@/utils'
|
||||
import { readFile, downloadTextFile, JSONStringify, JSONParse } from '@/utils'
|
||||
|
||||
export const useFile = (targetData: any) => {
|
||||
const uploadFileListRef = ref()
|
||||
@ -23,7 +23,7 @@ export const useFile = (targetData: any) => {
|
||||
nextTick(() => {
|
||||
if (file.file) {
|
||||
readFile(file.file).then((fileData: any) => {
|
||||
targetData.value.option.dataset = JSON.parse(fileData)
|
||||
targetData.value.option.dataset = JSONParse(fileData)
|
||||
})
|
||||
} else {
|
||||
window['$message'].error('导入数据失败,请稍后重试或联系管理员!')
|
||||
@ -35,7 +35,7 @@ export const useFile = (targetData: any) => {
|
||||
const download = () => {
|
||||
try {
|
||||
window['$message'].success('下载中,请耐心等待...')
|
||||
downloadTextFile(JSON.stringify(targetData.value.option.dataset), undefined, 'json')
|
||||
downloadTextFile(JSONStringify(targetData.value.option.dataset), undefined, 'json')
|
||||
} catch (error) {
|
||||
window['$message'].error('下载失败,数据错误!')
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { ref, nextTick } from 'vue'
|
||||
import { UploadCustomRequestOptions } from 'naive-ui'
|
||||
import { FileTypeEnum } from '@/enums/fileTypeEnum'
|
||||
import { readFile, goDialog } from '@/utils'
|
||||
import { readFile, goDialog, JSONParse } from '@/utils'
|
||||
import { useSync } from '@/views/chart/hooks/useSync.hook'
|
||||
|
||||
export const useFile = () => {
|
||||
@ -33,7 +33,7 @@ export const useFile = () => {
|
||||
// 新增
|
||||
onPositiveCallback: async () => {
|
||||
try {
|
||||
fileData = JSON.parse(fileData)
|
||||
fileData = JSONParse(fileData)
|
||||
await updateComponent(fileData, false, true)
|
||||
window['$message'].success('导入成功!')
|
||||
} catch (error) {
|
||||
@ -44,7 +44,7 @@ export const useFile = () => {
|
||||
// 覆盖
|
||||
onNegativeCallback: async () => {
|
||||
try {
|
||||
fileData = JSON.parse(fileData)
|
||||
fileData = JSONParse(fileData)
|
||||
await updateComponent(fileData, true, true)
|
||||
window['$message'].success('导入成功!')
|
||||
} catch (error) {
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore'
|
||||
import { canvasCut, downloadTextFile } from '@/utils'
|
||||
import { canvasCut, downloadTextFile, JSONStringify } from '@/utils'
|
||||
const chartEditStore = useChartEditStore()
|
||||
|
||||
// 导出
|
||||
@ -9,9 +9,7 @@ export const exportHandle = () => {
|
||||
|
||||
// 导出数据
|
||||
downloadTextFile(
|
||||
JSON.stringify(chartEditStore.getStorageInfo || {}, (k, v) => {
|
||||
return v === undefined ? null : v
|
||||
}),
|
||||
JSONStringify(chartEditStore.getStorageInfo || []),
|
||||
undefined,
|
||||
'json'
|
||||
)
|
||||
|
@ -6,7 +6,7 @@ import { CreateComponentType, CreateComponentGroupType, PickCreateComponentType
|
||||
import { useContextMenu } from '@/views/chart/hooks/useContextMenu.hook'
|
||||
import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore'
|
||||
import { EditCanvasTypeEnum } from '@/store/modules/chartEditStore/chartEditStore.d'
|
||||
import { loadingStart, loadingFinish, loadingError, setComponentPosition } from '@/utils'
|
||||
import { loadingStart, loadingFinish, loadingError, setComponentPosition, JSONParse } from '@/utils'
|
||||
import { throttle, cloneDeep } from 'lodash'
|
||||
|
||||
const chartEditStore = useChartEditStore()
|
||||
@ -28,7 +28,7 @@ export const dragHandle = async (e: DragEvent) => {
|
||||
|
||||
// 修改状态
|
||||
chartEditStore.setEditCanvas(EditCanvasTypeEnum.IS_CREATE, false)
|
||||
const dropData: Exclude<ConfigType, ['image']> = JSON.parse(drayDataString)
|
||||
const dropData: Exclude<ConfigType, ['image']> = JSONParse(drayDataString)
|
||||
|
||||
// 创建新图表组件
|
||||
let newComponent: CreateComponentType = await createComponent(dropData)
|
||||
|
@ -38,7 +38,7 @@ import { MonacoEditor } from '@/components/Pages/MonacoEditor'
|
||||
import { SavePageEnum } from '@/enums/editPageEnum'
|
||||
import { getSessionStorageInfo } from '../preview/utils'
|
||||
import type { ChartEditStorageType } from '../preview/index.d'
|
||||
import { setSessionStorage, fetchRouteParamsLocation } from '@/utils'
|
||||
import { setSessionStorage, fetchRouteParamsLocation, JSONStringify, JSONParse } from '@/utils'
|
||||
import { StorageEnum } from '@/enums/storageEnum'
|
||||
import { icon } from '@/plugins'
|
||||
import { useSync } from '@/views/chart/hooks/useSync.hook'
|
||||
@ -52,7 +52,7 @@ const content = ref('')
|
||||
// 从sessionStorage 获取数据
|
||||
async function getDataBySession() {
|
||||
const localStorageInfo: ChartEditStorageType = await getSessionStorageInfo() as unknown as ChartEditStorageType
|
||||
content.value = JSON.stringify(localStorageInfo, undefined, 2)
|
||||
content.value = JSONStringify(localStorageInfo)
|
||||
}
|
||||
setTimeout(getDataBySession)
|
||||
|
||||
@ -76,7 +76,7 @@ async function importJSON() {
|
||||
// 同步 [画布页失去焦点时同步数据到JSON页,JSON页Ctrl+S 时同步数据到画布页]
|
||||
window.opener.addEventListener(SavePageEnum.CHART, (e: any) => {
|
||||
setSessionStorage(StorageEnum.GO_CHART_STORAGE_LIST, [e.detail])
|
||||
content.value = JSON.stringify(e.detail, undefined, 2)
|
||||
content.value = JSONStringify(e.detail)
|
||||
})
|
||||
|
||||
// 窗口失焦 + 保存 => 同步数据
|
||||
@ -94,7 +94,7 @@ async function updateSync() {
|
||||
return window['$message'].error('源窗口已关闭,视图同步失败')
|
||||
}
|
||||
try {
|
||||
const detail = JSON.parse(content.value)
|
||||
const detail = JSONParse(content.value)
|
||||
delete detail.id
|
||||
// 保持id不变
|
||||
// 带后端版本额外处理请求
|
||||
|
Loading…
x
Reference in New Issue
Block a user