mirror of
https://gitee.com/dromara/go-view.git
synced 2025-02-24 16:22:57 +08:00
Merge branch 'dev' into dev-commet
This commit is contained in:
commit
c4b6eed3e8
@ -1,4 +1,4 @@
|
|||||||
import { CreateComponentType, EventLife } from '@/packages/index.d'
|
import { CreateComponentType, CreateComponentGroupType, EventLife, BaseEvent } from '@/packages/index.d'
|
||||||
import * as echarts from 'echarts'
|
import * as echarts from 'echarts'
|
||||||
|
|
||||||
// 所有图表组件集合对象
|
// 所有图表组件集合对象
|
||||||
@ -7,26 +7,55 @@ const components: { [K in string]?: any } = {}
|
|||||||
// 项目提供的npm 包变量
|
// 项目提供的npm 包变量
|
||||||
export const npmPkgs = { echarts }
|
export const npmPkgs = { echarts }
|
||||||
|
|
||||||
export const useLifeHandler = (chartConfig: CreateComponentType) => {
|
// 组件事件处理 hook
|
||||||
const events = chartConfig.events || {}
|
export const useLifeHandler = (chartConfig: CreateComponentType | CreateComponentGroupType) => {
|
||||||
|
// 处理基础事件
|
||||||
|
const baseEvent: { [key: string]: any } = {}
|
||||||
|
for (const key in chartConfig.events.baseEvent) {
|
||||||
|
const fnStr: string | undefined = (chartConfig.events.baseEvent as any)[key]
|
||||||
|
// 动态绑定基础事件
|
||||||
|
if (fnStr) {
|
||||||
|
baseEvent[key] = generateBaseFunc(fnStr)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 生成生命周期事件
|
// 生成生命周期事件
|
||||||
|
const events = chartConfig.events.advancedEvents || {}
|
||||||
const lifeEvents = {
|
const lifeEvents = {
|
||||||
[EventLife.BEFORE_MOUNT](e: any) {
|
[EventLife.VNODE_BEFORE_MOUNT](e: any) {
|
||||||
// 存储组件
|
// 存储组件
|
||||||
components[chartConfig.id] = e.component
|
components[chartConfig.id] = e.component
|
||||||
const fnStr = (events[EventLife.BEFORE_MOUNT] || '').trim()
|
const fnStr = (events[EventLife.VNODE_BEFORE_MOUNT] || '').trim()
|
||||||
generateFunc(fnStr, e)
|
generateFunc(fnStr, e)
|
||||||
},
|
},
|
||||||
[EventLife.MOUNTED](e: any) {
|
[EventLife.VNODE_MOUNTED](e: any) {
|
||||||
const fnStr = (events[EventLife.MOUNTED] || '').trim()
|
const fnStr = (events[EventLife.VNODE_MOUNTED] || '').trim()
|
||||||
generateFunc(fnStr, e)
|
generateFunc(fnStr, e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return lifeEvents
|
return { ...baseEvent, ...lifeEvents }
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* 生成基础函数
|
||||||
|
* @param fnStr 用户方法体代码
|
||||||
|
* @param event 鼠标事件
|
||||||
|
*/
|
||||||
|
export function generateBaseFunc(fnStr: string) {
|
||||||
|
try {
|
||||||
|
return new Function(`
|
||||||
|
return (
|
||||||
|
async function(mouseEvent){
|
||||||
|
${fnStr}
|
||||||
|
}
|
||||||
|
)`)()
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 生成高级函数
|
||||||
* @param fnStr 用户方法体代码
|
* @param fnStr 用户方法体代码
|
||||||
* @param e 执行生命周期的动态组件实例
|
* @param e 执行生命周期的动态组件实例
|
||||||
*/
|
*/
|
||||||
|
@ -2,6 +2,7 @@ import { echartOptionProfixHandle, PublicConfigClass } from '@/packages/public'
|
|||||||
import { LineCommonConfig } from './index'
|
import { LineCommonConfig } from './index'
|
||||||
import { CreateComponentType } from '@/packages/index.d'
|
import { CreateComponentType } from '@/packages/index.d'
|
||||||
import { defaultTheme, chartColorsSearch } from '@/settings/chartThemes/index'
|
import { defaultTheme, chartColorsSearch } from '@/settings/chartThemes/index'
|
||||||
|
import cloneDeep from 'lodash/cloneDeep'
|
||||||
import dataJson from './data.json'
|
import dataJson from './data.json'
|
||||||
|
|
||||||
export const includes = ['legend', 'xAxis', 'yAxis', 'grid']
|
export const includes = ['legend', 'xAxis', 'yAxis', 'grid']
|
||||||
@ -47,7 +48,7 @@ export const option = {
|
|||||||
|
|
||||||
export default class Config extends PublicConfigClass implements CreateComponentType {
|
export default class Config extends PublicConfigClass implements CreateComponentType {
|
||||||
public key: string = LineCommonConfig.key
|
public key: string = LineCommonConfig.key
|
||||||
public chartConfig = LineCommonConfig
|
public chartConfig = cloneDeep(LineCommonConfig)
|
||||||
// 图表配置项
|
// 图表配置项
|
||||||
public option = echartOptionProfixHandle(option, includes)
|
public option = echartOptionProfixHandle(option, includes)
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ import { LineGradientSingleConfig } from './index'
|
|||||||
import { CreateComponentType } from '@/packages/index.d'
|
import { CreateComponentType } from '@/packages/index.d'
|
||||||
import { graphic } from 'echarts/core'
|
import { graphic } from 'echarts/core'
|
||||||
import { defaultTheme, chartColorsSearch } from '@/settings/chartThemes/index'
|
import { defaultTheme, chartColorsSearch } from '@/settings/chartThemes/index'
|
||||||
|
import cloneDeep from 'lodash/cloneDeep'
|
||||||
import dataJson from './data.json'
|
import dataJson from './data.json'
|
||||||
|
|
||||||
export const includes = ['legend', 'xAxis', 'yAxis', 'grid']
|
export const includes = ['legend', 'xAxis', 'yAxis', 'grid']
|
||||||
@ -58,7 +59,7 @@ const options = {
|
|||||||
|
|
||||||
export default class Config extends PublicConfigClass implements CreateComponentType {
|
export default class Config extends PublicConfigClass implements CreateComponentType {
|
||||||
public key: string = LineGradientSingleConfig.key
|
public key: string = LineGradientSingleConfig.key
|
||||||
public chartConfig = LineGradientSingleConfig
|
public chartConfig = cloneDeep(LineGradientSingleConfig)
|
||||||
// 图表配置项
|
// 图表配置项
|
||||||
public option = echartOptionProfixHandle(options, includes)
|
public option = echartOptionProfixHandle(options, includes)
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ import { LineGradientsConfig } from './index'
|
|||||||
import { CreateComponentType } from '@/packages/index.d'
|
import { CreateComponentType } from '@/packages/index.d'
|
||||||
import { graphic } from 'echarts/core'
|
import { graphic } from 'echarts/core'
|
||||||
import { defaultTheme, chartColorsSearch } from '@/settings/chartThemes/index'
|
import { defaultTheme, chartColorsSearch } from '@/settings/chartThemes/index'
|
||||||
|
import cloneDeep from 'lodash/cloneDeep'
|
||||||
import dataJson from './data.json'
|
import dataJson from './data.json'
|
||||||
|
|
||||||
export const includes = ['legend', 'xAxis', 'yAxis', 'grid']
|
export const includes = ['legend', 'xAxis', 'yAxis', 'grid']
|
||||||
@ -85,7 +86,7 @@ const option = {
|
|||||||
|
|
||||||
export default class Config extends PublicConfigClass implements CreateComponentType {
|
export default class Config extends PublicConfigClass implements CreateComponentType {
|
||||||
public key: string = LineGradientsConfig.key
|
public key: string = LineGradientsConfig.key
|
||||||
public chartConfig = LineGradientsConfig
|
public chartConfig = cloneDeep(LineGradientsConfig)
|
||||||
// 图表配置项
|
// 图表配置项
|
||||||
public option = echartOptionProfixHandle(option, includes)
|
public option = echartOptionProfixHandle(option, includes)
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ import { echartOptionProfixHandle, PublicConfigClass } from '@/packages/public'
|
|||||||
import { LineLinearSingleConfig } from './index'
|
import { LineLinearSingleConfig } from './index'
|
||||||
import { CreateComponentType } from '@/packages/index.d'
|
import { CreateComponentType } from '@/packages/index.d'
|
||||||
import { defaultTheme, chartColorsSearch } from '@/settings/chartThemes/index'
|
import { defaultTheme, chartColorsSearch } from '@/settings/chartThemes/index'
|
||||||
|
import cloneDeep from 'lodash/cloneDeep'
|
||||||
import dataJson from './data.json'
|
import dataJson from './data.json'
|
||||||
|
|
||||||
export const includes = ['legend', 'xAxis', 'yAxis', 'grid']
|
export const includes = ['legend', 'xAxis', 'yAxis', 'grid']
|
||||||
@ -54,7 +55,7 @@ export const option = {
|
|||||||
|
|
||||||
export default class Config extends PublicConfigClass implements CreateComponentType {
|
export default class Config extends PublicConfigClass implements CreateComponentType {
|
||||||
public key: string = LineLinearSingleConfig.key
|
public key: string = LineLinearSingleConfig.key
|
||||||
public chartConfig = LineLinearSingleConfig
|
public chartConfig = cloneDeep(LineLinearSingleConfig)
|
||||||
// 图表配置项
|
// 图表配置项
|
||||||
public option = echartOptionProfixHandle(option, includes)
|
public option = echartOptionProfixHandle(option, includes)
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ import { echartOptionProfixHandle, PublicConfigClass } from '@/packages/public'
|
|||||||
import { MapBaseConfig } from './index'
|
import { MapBaseConfig } from './index'
|
||||||
import { chartInitConfig } from '@/settings/designSetting'
|
import { chartInitConfig } from '@/settings/designSetting'
|
||||||
import { CreateComponentType } from '@/packages/index.d'
|
import { CreateComponentType } from '@/packages/index.d'
|
||||||
|
import cloneDeep from 'lodash/cloneDeep'
|
||||||
import dataJson from './data.json'
|
import dataJson from './data.json'
|
||||||
|
|
||||||
export const includes = []
|
export const includes = []
|
||||||
@ -151,6 +152,6 @@ export const MapDefaultConfig = { ...option }
|
|||||||
export default class Config extends PublicConfigClass implements CreateComponentType {
|
export default class Config extends PublicConfigClass implements CreateComponentType {
|
||||||
public key: string = MapBaseConfig.key
|
public key: string = MapBaseConfig.key
|
||||||
public attr = { ...chartInitConfig, w: 750, h: 800, zIndex: -1 }
|
public attr = { ...chartInitConfig, w: 750, h: 800, zIndex: -1 }
|
||||||
public chartConfig = MapBaseConfig
|
public chartConfig = cloneDeep(MapBaseConfig)
|
||||||
public option = echartOptionProfixHandle(option, includes)
|
public option = echartOptionProfixHandle(option, includes)
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import { echartOptionProfixHandle, PublicConfigClass } from '@/packages/public'
|
import { echartOptionProfixHandle, PublicConfigClass } from '@/packages/public'
|
||||||
import { PieCircleConfig } from './index'
|
import { PieCircleConfig } from './index'
|
||||||
import { CreateComponentType } from '@/packages/index.d'
|
import { CreateComponentType } from '@/packages/index.d'
|
||||||
|
import cloneDeep from 'lodash/cloneDeep'
|
||||||
|
|
||||||
export const includes = []
|
export const includes = []
|
||||||
|
|
||||||
@ -57,7 +58,7 @@ const option = {
|
|||||||
export default class Config extends PublicConfigClass implements CreateComponentType {
|
export default class Config extends PublicConfigClass implements CreateComponentType {
|
||||||
public key: string = PieCircleConfig.key
|
public key: string = PieCircleConfig.key
|
||||||
|
|
||||||
public chartConfig = PieCircleConfig
|
public chartConfig = cloneDeep(PieCircleConfig)
|
||||||
|
|
||||||
// 图表配置项
|
// 图表配置项
|
||||||
public option = echartOptionProfixHandle(option, includes)
|
public option = echartOptionProfixHandle(option, includes)
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import { echartOptionProfixHandle, PublicConfigClass } from '@/packages/public'
|
import { echartOptionProfixHandle, PublicConfigClass } from '@/packages/public'
|
||||||
import { PieCommonConfig } from './index'
|
import { PieCommonConfig } from './index'
|
||||||
import { CreateComponentType } from '@/packages/index.d'
|
import { CreateComponentType } from '@/packages/index.d'
|
||||||
|
import cloneDeep from 'lodash/cloneDeep'
|
||||||
import dataJson from './data.json'
|
import dataJson from './data.json'
|
||||||
|
|
||||||
export const includes = ['legend']
|
export const includes = ['legend']
|
||||||
@ -61,7 +62,7 @@ const option = {
|
|||||||
export default class Config extends PublicConfigClass implements CreateComponentType {
|
export default class Config extends PublicConfigClass implements CreateComponentType {
|
||||||
public key: string = PieCommonConfig.key
|
public key: string = PieCommonConfig.key
|
||||||
|
|
||||||
public chartConfig = PieCommonConfig
|
public chartConfig = cloneDeep(PieCommonConfig)
|
||||||
|
|
||||||
// 图表配置项
|
// 图表配置项
|
||||||
public option = echartOptionProfixHandle(option, includes)
|
public option = echartOptionProfixHandle(option, includes)
|
||||||
|
23
src/packages/index.d.ts
vendored
23
src/packages/index.d.ts
vendored
@ -90,12 +90,24 @@ export const BlendModeEnumList = [
|
|||||||
{ label: '亮度', value: 'luminosity' }
|
{ label: '亮度', value: 'luminosity' }
|
||||||
]
|
]
|
||||||
|
|
||||||
|
// 基础事件类型(vue不加 on)
|
||||||
|
export enum BaseEvent {
|
||||||
|
// 点击
|
||||||
|
ON_CLICK = 'click',
|
||||||
|
// 双击
|
||||||
|
ON_DBL_CLICK = 'dblclick',
|
||||||
|
// 移入
|
||||||
|
ON_MOUSE_ENTER = 'mouseenter',
|
||||||
|
// 移出
|
||||||
|
ON_MOUSE_LEAVE = 'mouseleave',
|
||||||
|
}
|
||||||
|
|
||||||
// vue3 生命周期事件
|
// vue3 生命周期事件
|
||||||
export enum EventLife {
|
export enum EventLife {
|
||||||
// 渲染之后
|
// 渲染之后
|
||||||
MOUNTED = 'vnodeMounted',
|
VNODE_MOUNTED = 'vnodeMounted',
|
||||||
// 渲染之前
|
// 渲染之前
|
||||||
BEFORE_MOUNT = 'vnodeBeforeMount',
|
VNODE_BEFORE_MOUNT = 'vnodeBeforeMount',
|
||||||
}
|
}
|
||||||
|
|
||||||
// 组件实例类
|
// 组件实例类
|
||||||
@ -123,10 +135,15 @@ export interface PublicConfigType {
|
|||||||
}
|
}
|
||||||
filter?: string
|
filter?: string
|
||||||
status: StatusType
|
status: StatusType
|
||||||
events?: {
|
events: {
|
||||||
|
baseEvent: {
|
||||||
|
[K in BaseEvent]?: string
|
||||||
|
},
|
||||||
|
advancedEvents: {
|
||||||
[K in EventLife]?: string
|
[K in EventLife]?: string
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export interface CreateComponentType extends PublicConfigType, requestConfig {
|
export interface CreateComponentType extends PublicConfigType, requestConfig {
|
||||||
key: string
|
key: string
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
import { getUUID } from '@/utils'
|
import { getUUID } from '@/utils'
|
||||||
import { ChartFrameEnum, PublicConfigType, CreateComponentType, CreateComponentGroupType } from '@/packages/index.d'
|
|
||||||
import { RequestConfigType } from '@/store/modules/chartEditStore/chartEditStore.d'
|
import { RequestConfigType } from '@/store/modules/chartEditStore/chartEditStore.d'
|
||||||
import { groupTitle } from '@/settings/designSetting'
|
import { groupTitle } from '@/settings/designSetting'
|
||||||
import {
|
import {
|
||||||
@ -9,6 +8,14 @@ import {
|
|||||||
RequestContentTypeEnum,
|
RequestContentTypeEnum,
|
||||||
RequestBodyEnum
|
RequestBodyEnum
|
||||||
} from '@/enums/httpEnum'
|
} from '@/enums/httpEnum'
|
||||||
|
import {
|
||||||
|
BaseEvent,
|
||||||
|
EventLife,
|
||||||
|
ChartFrameEnum,
|
||||||
|
PublicConfigType,
|
||||||
|
CreateComponentType,
|
||||||
|
CreateComponentGroupType
|
||||||
|
} from '@/packages/index.d'
|
||||||
import { chartInitConfig } from '@/settings/designSetting'
|
import { chartInitConfig } from '@/settings/designSetting'
|
||||||
import cloneDeep from 'lodash/cloneDeep'
|
import cloneDeep from 'lodash/cloneDeep'
|
||||||
|
|
||||||
@ -82,7 +89,18 @@ export class PublicConfigClass implements PublicConfigType {
|
|||||||
// 数据过滤
|
// 数据过滤
|
||||||
public filter = undefined
|
public filter = undefined
|
||||||
// 事件
|
// 事件
|
||||||
public events = undefined
|
public events = {
|
||||||
|
baseEvent: {
|
||||||
|
[BaseEvent.ON_CLICK]: undefined,
|
||||||
|
[BaseEvent.ON_DBL_CLICK]: undefined,
|
||||||
|
[BaseEvent.ON_MOUSE_ENTER]: undefined,
|
||||||
|
[BaseEvent.ON_MOUSE_LEAVE]: undefined
|
||||||
|
},
|
||||||
|
advancedEvents: {
|
||||||
|
[EventLife.VNODE_MOUNTED]: undefined,
|
||||||
|
[EventLife.VNODE_BEFORE_MOUNT]: undefined
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 多选成组类
|
// 多选成组类
|
||||||
|
@ -108,7 +108,7 @@ export const useChartEditStore = defineStore({
|
|||||||
chartThemeColor: defaultTheme || 'dark',
|
chartThemeColor: defaultTheme || 'dark',
|
||||||
// 全局配置
|
// 全局配置
|
||||||
chartThemeSetting: globalThemeJson,
|
chartThemeSetting: globalThemeJson,
|
||||||
// 预览方式
|
// 适配方式
|
||||||
previewScaleType: previewScaleType
|
previewScaleType: previewScaleType
|
||||||
},
|
},
|
||||||
// 数据请求处理(需存储给后端)
|
// 数据请求处理(需存储给后端)
|
||||||
|
@ -153,6 +153,19 @@ export const fetchRouteParams = () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* * 通过硬解析获取当前路由下的参数
|
||||||
|
* @returns object
|
||||||
|
*/
|
||||||
|
export const fetchRouteParamsLocation = () => {
|
||||||
|
try {
|
||||||
|
return document.location.hash.split('/').pop() || ''
|
||||||
|
} catch (error) {
|
||||||
|
window['$message'].warning('查询路由信息失败,请联系管理员!')
|
||||||
|
return ''
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* * 回到主页面
|
* * 回到主页面
|
||||||
* @param confirm
|
* @param confirm
|
||||||
|
@ -75,7 +75,7 @@
|
|||||||
</n-button>
|
</n-button>
|
||||||
</n-space>
|
</n-space>
|
||||||
<n-space>
|
<n-space>
|
||||||
<n-text>预览方式</n-text>
|
<n-text>适配方式</n-text>
|
||||||
<n-button-group>
|
<n-button-group>
|
||||||
<n-button
|
<n-button
|
||||||
v-for="item in previewTypeList"
|
v-for="item in previewTypeList"
|
||||||
@ -279,7 +279,7 @@ const customRequest = (options: UploadCustomRequestOptions) => {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// 选择预览方式
|
// 选择适配方式
|
||||||
const selectPreviewType = (key: PreviewScaleEnum) => {
|
const selectPreviewType = (key: PreviewScaleEnum) => {
|
||||||
chartEditStore.setEditCanvasConfig(EditCanvasConfigEnum.PREVIEW_SCALE_TYPE, key)
|
chartEditStore.setEditCanvasConfig(EditCanvasConfigEnum.PREVIEW_SCALE_TYPE, key)
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,3 @@
|
|||||||
|
import ChartEventAdvancedHandle from './index.vue'
|
||||||
|
|
||||||
|
export { ChartEventAdvancedHandle }
|
@ -10,13 +10,15 @@
|
|||||||
编辑
|
编辑
|
||||||
</n-button>
|
</n-button>
|
||||||
</template>
|
</template>
|
||||||
<n-card>
|
<n-card class="collapse-show-box">
|
||||||
<!-- 函数体 -->
|
<!-- 函数体 -->
|
||||||
<div v-for="eventName in EventLife" :key="eventName">
|
<div v-for="eventName in EventLife" :key="eventName">
|
||||||
<p>
|
<p>
|
||||||
|
<span class="func-annotate">// {{ EventLifeName[eventName] }}</span>
|
||||||
|
<br />
|
||||||
<span class="func-keyword">async {{ eventName }}</span> (e, components, echarts, node_modules) {
|
<span class="func-keyword">async {{ eventName }}</span> (e, components, echarts, node_modules) {
|
||||||
</p>
|
</p>
|
||||||
<p class="go-ml-4"><n-code :code="(targetData.events || {})[eventName]" language="typescript"></n-code></p>
|
<p class="go-ml-4"><n-code :code="(targetData.events.advancedEvents || {})[eventName]" language="typescript"></n-code></p>
|
||||||
<p>}<span>,</span></p>
|
<p>}<span>,</span></p>
|
||||||
</div>
|
</div>
|
||||||
</n-card>
|
</n-card>
|
||||||
@ -30,13 +32,15 @@
|
|||||||
<n-text>高级事件编辑器(配合源码使用)</n-text>
|
<n-text>高级事件编辑器(配合源码使用)</n-text>
|
||||||
</n-space>
|
</n-space>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<template #header-extra> </template>
|
<template #header-extra> </template>
|
||||||
|
|
||||||
<n-layout has-sider sider-placement="right">
|
<n-layout has-sider sider-placement="right">
|
||||||
<n-layout style="height: 580px; padding-right: 20px">
|
<n-layout style="height: 580px; padding-right: 20px">
|
||||||
<n-tabs v-model:value="editTab" type="card" tab-style="min-width: 100px;">
|
<n-tabs v-model:value="editTab" type="card" tab-style="min-width: 100px;">
|
||||||
<!-- 提示 -->
|
<!-- 提示 -->
|
||||||
<template #suffix>
|
<template #suffix>
|
||||||
<n-text class="tab-tip" type="warning">tips: {{ EventLifeTip[editTab] }}</n-text>
|
<n-text class="tab-tip" type="warning">提示: {{ EventLifeTip[editTab] }}</n-text>
|
||||||
</template>
|
</template>
|
||||||
<n-tab-pane
|
<n-tab-pane
|
||||||
v-for="(eventName, index) in EventLife"
|
v-for="(eventName, index) in EventLife"
|
||||||
@ -50,7 +54,7 @@
|
|||||||
<span class="func-keyNameWord">{{ eventName }}(e, components, echarts, node_modules) {</span>
|
<span class="func-keyNameWord">{{ eventName }}(e, components, echarts, node_modules) {</span>
|
||||||
</p>
|
</p>
|
||||||
<!-- 编辑主体 -->
|
<!-- 编辑主体 -->
|
||||||
<monaco-editor v-model:modelValue="events[eventName]" height="480px" language="javascript" />
|
<monaco-editor v-model:modelValue="advancedEvents[eventName]" height="480px" language="javascript" />
|
||||||
<!-- 函数结束 -->
|
<!-- 函数结束 -->
|
||||||
<p class="go-pl-3 func-keyNameWord">}</p>
|
<p class="go-pl-3 func-keyNameWord">}</p>
|
||||||
</n-tab-pane>
|
</n-tab-pane>
|
||||||
@ -136,7 +140,7 @@
|
|||||||
<template #icon>
|
<template #icon>
|
||||||
<n-icon :component="DocumentTextIcon" />
|
<n-icon :component="DocumentTextIcon" />
|
||||||
</template>
|
</template>
|
||||||
提示
|
说明
|
||||||
</n-tag>
|
</n-tag>
|
||||||
<n-text class="go-ml-2" depth="2">通过提供的参数可为图表增加定制化的tooltip、交互事件等等</n-text>
|
<n-text class="go-ml-2" depth="2">通过提供的参数可为图表增加定制化的tooltip、交互事件等等</n-text>
|
||||||
</div>
|
</div>
|
||||||
@ -158,29 +162,27 @@ import { useTargetData } from '../../../hooks/useTargetData.hook'
|
|||||||
import { templateList } from './importTemplate'
|
import { templateList } from './importTemplate'
|
||||||
import { npmPkgs } from '@/hooks'
|
import { npmPkgs } from '@/hooks'
|
||||||
import { icon } from '@/plugins'
|
import { icon } from '@/plugins'
|
||||||
import { goDialog, toString } from '@/utils'
|
|
||||||
import { CreateComponentType, EventLife } from '@/packages/index.d'
|
import { CreateComponentType, EventLife } from '@/packages/index.d'
|
||||||
import { Script } from 'vm'
|
|
||||||
|
|
||||||
const { targetData, chartEditStore } = useTargetData()
|
const { targetData, chartEditStore } = useTargetData()
|
||||||
const { DocumentTextIcon, ChevronDownIcon, PencilIcon } = icon.ionicons5
|
const { DocumentTextIcon, ChevronDownIcon, PencilIcon } = icon.ionicons5
|
||||||
|
|
||||||
const EventLifeName = {
|
const EventLifeName = {
|
||||||
[EventLife.BEFORE_MOUNT]: '渲染之前',
|
[EventLife.VNODE_BEFORE_MOUNT]: '渲染之前',
|
||||||
[EventLife.MOUNTED]: '渲染之后'
|
[EventLife.VNODE_MOUNTED]: '渲染之后'
|
||||||
}
|
}
|
||||||
|
|
||||||
const EventLifeTip = {
|
const EventLifeTip = {
|
||||||
[EventLife.BEFORE_MOUNT]: '此时组件 DOM 还未存在',
|
[EventLife.VNODE_BEFORE_MOUNT]: '此时组件 DOM 还未存在',
|
||||||
[EventLife.MOUNTED]: '此时组件 DOM 已经存在'
|
[EventLife.VNODE_MOUNTED]: '此时组件 DOM 已经存在'
|
||||||
}
|
}
|
||||||
|
|
||||||
// 受控弹窗
|
// 受控弹窗
|
||||||
const showModal = ref(false)
|
const showModal = ref(false)
|
||||||
// 编辑区域控制
|
// 编辑区域控制
|
||||||
const editTab = ref(EventLife.MOUNTED)
|
const editTab = ref(EventLife.VNODE_MOUNTED)
|
||||||
// events 函数模板
|
// events 函数模板
|
||||||
let events = ref({ ...targetData.value.events })
|
let advancedEvents = ref({ ...targetData.value.events.advancedEvents })
|
||||||
// 事件错误标识
|
// 事件错误标识
|
||||||
const errorFlag = ref(false)
|
const errorFlag = ref(false)
|
||||||
|
|
||||||
@ -190,7 +192,7 @@ const validEvents = () => {
|
|||||||
let message = ''
|
let message = ''
|
||||||
let name = ''
|
let name = ''
|
||||||
|
|
||||||
errorFlag.value = Object.entries(events.value).every(([eventName, str]) => {
|
errorFlag.value = Object.entries(advancedEvents.value).every(([eventName, str]) => {
|
||||||
try {
|
try {
|
||||||
// 支持await,验证语法
|
// 支持await,验证语法
|
||||||
const AsyncFunction = Object.getPrototypeOf(async function () {}).constructor
|
const AsyncFunction = Object.getPrototypeOf(async function () {}).constructor
|
||||||
@ -221,11 +223,14 @@ const saveEvents = () => {
|
|||||||
window['$message'].error('事件函数错误,无法进行保存')
|
window['$message'].error('事件函数错误,无法进行保存')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (Object.values(events.value).join('').trim() === '') {
|
if (Object.values(advancedEvents.value).join('').trim() === '') {
|
||||||
// 清空事件
|
// 清空事件
|
||||||
targetData.value.events = undefined
|
targetData.value.events.advancedEvents = {
|
||||||
|
vnodeBeforeMount: undefined,
|
||||||
|
vnodeMounted: undefined,
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
targetData.value.events = { ...events.value }
|
targetData.value.events.advancedEvents = { ...advancedEvents.value }
|
||||||
}
|
}
|
||||||
closeEvents()
|
closeEvents()
|
||||||
}
|
}
|
||||||
@ -234,52 +239,12 @@ watch(
|
|||||||
() => showModal.value,
|
() => showModal.value,
|
||||||
(newData: boolean) => {
|
(newData: boolean) => {
|
||||||
if (newData) {
|
if (newData) {
|
||||||
events.value = { ...targetData.value.events }
|
advancedEvents.value = { ...targetData.value.events.advancedEvents }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="scss" scoped>
|
<style lang="scss" scoped>
|
||||||
/* 外层也要使用 */
|
@import '../index.scss';
|
||||||
.func-keyword {
|
|
||||||
color: #b478cf;
|
|
||||||
}
|
|
||||||
|
|
||||||
@include go('chart-data-monaco-editor') {
|
|
||||||
.func-keyNameWord {
|
|
||||||
color: #70c0e8;
|
|
||||||
}
|
|
||||||
.tab-tip {
|
|
||||||
font-size: 12px;
|
|
||||||
}
|
|
||||||
&.n-card.n-modal,
|
|
||||||
.n-card {
|
|
||||||
@extend .go-background-filter;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@include deep() {
|
|
||||||
.n-layout,
|
|
||||||
.n-layout-sider {
|
|
||||||
background-color: transparent;
|
|
||||||
}
|
|
||||||
.go-editor-area {
|
|
||||||
max-height: 530px;
|
|
||||||
}
|
|
||||||
.checkbox--hidden:checked {
|
|
||||||
& + label {
|
|
||||||
.n-icon {
|
|
||||||
transition: all 0.3s;
|
|
||||||
transform: rotate(180deg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
& ~ .go-editor-area {
|
|
||||||
display: none;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// 优化代码换行
|
|
||||||
.n-code > pre {
|
|
||||||
white-space: break-spaces;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</style>
|
</style>
|
@ -0,0 +1,3 @@
|
|||||||
|
import ChartEventBaseHandle from './index.vue'
|
||||||
|
|
||||||
|
export { ChartEventBaseHandle }
|
@ -0,0 +1,215 @@
|
|||||||
|
<template>
|
||||||
|
<n-collapse-item title="基础事件配置" name="1">
|
||||||
|
<template #header-extra>
|
||||||
|
<n-button type="primary" tertiary size="small" @click.stop="showModal = true">
|
||||||
|
<template #icon>
|
||||||
|
<n-icon>
|
||||||
|
<pencil-icon />
|
||||||
|
</n-icon>
|
||||||
|
</template>
|
||||||
|
编辑
|
||||||
|
</n-button>
|
||||||
|
</template>
|
||||||
|
<n-card class="collapse-show-box">
|
||||||
|
<!-- 函数体 -->
|
||||||
|
<div v-for="eventName in BaseEvent" :key="eventName">
|
||||||
|
<p>
|
||||||
|
<span class="func-annotate">// {{ EventTypeName[eventName] }}</span>
|
||||||
|
<br />
|
||||||
|
<span class="func-keyword">async {{ eventName }}</span> (mouseEvent, components) {
|
||||||
|
</p>
|
||||||
|
<p class="go-ml-4">
|
||||||
|
<n-code :code="(targetData.events.baseEvent || {})[eventName]" language="typescript"></n-code>
|
||||||
|
</p>
|
||||||
|
<p>}<span>,</span></p>
|
||||||
|
</div>
|
||||||
|
</n-card>
|
||||||
|
</n-collapse-item>
|
||||||
|
|
||||||
|
<!-- 弹窗 -->
|
||||||
|
<n-modal class="go-chart-data-monaco-editor" v-model:show="showModal" :mask-closable="false">
|
||||||
|
<n-card :bordered="false" role="dialog" size="small" aria-modal="true" style="width: 1200px; height: 700px">
|
||||||
|
<template #header>
|
||||||
|
<n-space>
|
||||||
|
<n-text>基础事件编辑器</n-text>
|
||||||
|
</n-space>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<template #header-extra> </template>
|
||||||
|
<n-layout has-sider sider-placement="right">
|
||||||
|
<n-layout style="height: 580px; padding-right: 20px">
|
||||||
|
<n-tabs v-model:value="editTab" type="card" tab-style="min-width: 100px;">
|
||||||
|
<!-- 提示 -->
|
||||||
|
<template #suffix>
|
||||||
|
<n-text class="tab-tip" type="warning">提示: ECharts 组件会拦截鼠标事件</n-text>
|
||||||
|
</template>
|
||||||
|
<n-tab-pane
|
||||||
|
v-for="(eventName, index) in BaseEvent"
|
||||||
|
:key="index"
|
||||||
|
:tab="`${EventTypeName[eventName]}-${eventName}`"
|
||||||
|
:name="eventName"
|
||||||
|
>
|
||||||
|
<!-- 函数名称 -->
|
||||||
|
<p class="go-pl-3">
|
||||||
|
<span class="func-keyword">async function </span>
|
||||||
|
<span class="func-keyNameWord">{{ eventName }}(mouseEvent) {</span>
|
||||||
|
</p>
|
||||||
|
<!-- 编辑主体 -->
|
||||||
|
<monaco-editor v-model:modelValue="baseEvent[eventName]" height="480px" language="javascript" />
|
||||||
|
<!-- 函数结束 -->
|
||||||
|
<p class="go-pl-3 func-keyNameWord">}</p>
|
||||||
|
</n-tab-pane>
|
||||||
|
</n-tabs>
|
||||||
|
</n-layout>
|
||||||
|
<n-layout-sider
|
||||||
|
:collapsed-width="14"
|
||||||
|
:width="340"
|
||||||
|
show-trigger="bar"
|
||||||
|
collapse-mode="transform"
|
||||||
|
content-style="padding: 12px 12px 0px 12px;margin-left: 3px;"
|
||||||
|
>
|
||||||
|
<n-tabs default-value="1" justify-content="space-evenly" type="segment">
|
||||||
|
<!-- 验证结果 -->
|
||||||
|
<n-tab-pane tab="验证结果" name="1" size="small">
|
||||||
|
<n-scrollbar trigger="none" style="max-height: 505px">
|
||||||
|
<n-collapse class="go-px-3" arrow-placement="right" :default-expanded-names="[1, 2, 3]">
|
||||||
|
<template v-for="error in [validEvents()]" :key="error">
|
||||||
|
<n-collapse-item title="错误函数" :name="1">
|
||||||
|
<n-text depth="3">{{ error.errorFn || '暂无' }}</n-text>
|
||||||
|
</n-collapse-item>
|
||||||
|
<n-collapse-item title="错误信息" :name="2">
|
||||||
|
<n-text depth="3">{{ error.name || '暂无' }}</n-text>
|
||||||
|
</n-collapse-item>
|
||||||
|
<n-collapse-item title="堆栈信息" :name="3">
|
||||||
|
<n-text depth="3">{{ error.message || '暂无' }}</n-text>
|
||||||
|
</n-collapse-item>
|
||||||
|
</template>
|
||||||
|
</n-collapse>
|
||||||
|
</n-scrollbar>
|
||||||
|
</n-tab-pane>
|
||||||
|
<!-- 辅助说明 -->
|
||||||
|
<n-tab-pane tab="变量说明" name="2">
|
||||||
|
<n-scrollbar trigger="none" style="max-height: 505px">
|
||||||
|
<n-collapse class="go-px-3" arrow-placement="right" :default-expanded-names="[1, 2]">
|
||||||
|
<n-collapse-item title="mouseEvent" :name="1">
|
||||||
|
<n-text depth="3">鼠标事件对象</n-text>
|
||||||
|
</n-collapse-item>
|
||||||
|
</n-collapse>
|
||||||
|
</n-scrollbar>
|
||||||
|
</n-tab-pane>
|
||||||
|
</n-tabs>
|
||||||
|
</n-layout-sider>
|
||||||
|
</n-layout>
|
||||||
|
|
||||||
|
<template #action>
|
||||||
|
<n-space justify="space-between">
|
||||||
|
<div class="go-flex-items-center">
|
||||||
|
<n-tag :bordered="false" type="primary">
|
||||||
|
<template #icon>
|
||||||
|
<n-icon :component="DocumentTextIcon" />
|
||||||
|
</template>
|
||||||
|
说明
|
||||||
|
</n-tag>
|
||||||
|
<n-text class="go-ml-2" depth="2">编写方式同正常 JavaScript 写法</n-text>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<n-space>
|
||||||
|
<n-button size="medium" @click="closeEvents">取消</n-button>
|
||||||
|
<n-button size="medium" type="primary" @click="saveEvents">保存</n-button>
|
||||||
|
</n-space>
|
||||||
|
</n-space>
|
||||||
|
</template>
|
||||||
|
</n-card>
|
||||||
|
</n-modal>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { ref, computed, watch, toRefs, toRaw } from 'vue'
|
||||||
|
import { MonacoEditor } from '@/components/Pages/MonacoEditor'
|
||||||
|
import { useTargetData } from '../../../hooks/useTargetData.hook'
|
||||||
|
import { CreateComponentType, BaseEvent } from '@/packages/index.d'
|
||||||
|
import { icon } from '@/plugins'
|
||||||
|
|
||||||
|
const { targetData, chartEditStore } = useTargetData()
|
||||||
|
const { DocumentTextIcon, ChevronDownIcon, PencilIcon } = icon.ionicons5
|
||||||
|
|
||||||
|
const EventTypeName = {
|
||||||
|
[BaseEvent.ON_CLICK]: '单击',
|
||||||
|
[BaseEvent.ON_DBL_CLICK]: '双击',
|
||||||
|
[BaseEvent.ON_MOUSE_ENTER]: '鼠标进入',
|
||||||
|
[BaseEvent.ON_MOUSE_LEAVE]: '鼠标移出'
|
||||||
|
}
|
||||||
|
|
||||||
|
// 受控弹窗
|
||||||
|
const showModal = ref(false)
|
||||||
|
// 编辑区域控制
|
||||||
|
const editTab = ref(BaseEvent.ON_CLICK)
|
||||||
|
// events 函数模板
|
||||||
|
let baseEvent = ref({ ...targetData.value.events.baseEvent })
|
||||||
|
// 事件错误标识
|
||||||
|
const errorFlag = ref(false)
|
||||||
|
|
||||||
|
// 验证语法
|
||||||
|
const validEvents = () => {
|
||||||
|
let errorFn = ''
|
||||||
|
let message = ''
|
||||||
|
let name = ''
|
||||||
|
|
||||||
|
errorFlag.value = Object.entries(baseEvent.value).every(([eventName, str]) => {
|
||||||
|
try {
|
||||||
|
// 支持await,验证语法
|
||||||
|
const AsyncFunction = Object.getPrototypeOf(async function () {}).constructor
|
||||||
|
new AsyncFunction(str)
|
||||||
|
return true
|
||||||
|
} catch (error: any) {
|
||||||
|
message = error.message
|
||||||
|
name = error.name
|
||||||
|
errorFn = eventName
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
})
|
||||||
|
return {
|
||||||
|
errorFn,
|
||||||
|
message,
|
||||||
|
name
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 关闭事件
|
||||||
|
const closeEvents = () => {
|
||||||
|
showModal.value = false
|
||||||
|
}
|
||||||
|
|
||||||
|
// 新增事件
|
||||||
|
const saveEvents = () => {
|
||||||
|
if (validEvents().errorFn) {
|
||||||
|
window['$message'].error('事件函数错误,无法进行保存')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (Object.values(baseEvent.value).join('').trim() === '') {
|
||||||
|
// 清空事件
|
||||||
|
targetData.value.events.baseEvent = {
|
||||||
|
[BaseEvent.ON_CLICK]: undefined,
|
||||||
|
[BaseEvent.ON_DBL_CLICK]: undefined,
|
||||||
|
[BaseEvent.ON_MOUSE_ENTER]: undefined,
|
||||||
|
[BaseEvent.ON_MOUSE_LEAVE]: undefined
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
targetData.value.events.baseEvent = { ...baseEvent.value }
|
||||||
|
}
|
||||||
|
closeEvents()
|
||||||
|
}
|
||||||
|
|
||||||
|
watch(
|
||||||
|
() => showModal.value,
|
||||||
|
(newData: boolean) => {
|
||||||
|
if (newData) {
|
||||||
|
baseEvent.value = { ...targetData.value.events.baseEvent }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss" scoped>
|
||||||
|
@import '../index.scss';
|
||||||
|
</style>
|
@ -1,3 +0,0 @@
|
|||||||
import ChartEventMonacoEditor from './index.vue'
|
|
||||||
|
|
||||||
export { ChartEventMonacoEditor }
|
|
@ -0,0 +1,51 @@
|
|||||||
|
/* 外层也要使用 */
|
||||||
|
.func-keyword {
|
||||||
|
color: #b478cf;
|
||||||
|
}
|
||||||
|
|
||||||
|
.func-annotate {
|
||||||
|
color: #70c0e8;
|
||||||
|
}
|
||||||
|
|
||||||
|
@include go('chart-data-monaco-editor') {
|
||||||
|
.func-keyNameWord {
|
||||||
|
color: #70c0e8;
|
||||||
|
}
|
||||||
|
.tab-tip {
|
||||||
|
font-size: 12px;
|
||||||
|
}
|
||||||
|
&.n-card.n-modal,
|
||||||
|
.n-card {
|
||||||
|
@extend .go-background-filter;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@include deep() {
|
||||||
|
.n-layout,
|
||||||
|
.n-layout-sider {
|
||||||
|
background-color: transparent;
|
||||||
|
}
|
||||||
|
.collapse-show-box {
|
||||||
|
.n-card__content {
|
||||||
|
padding-left: 20px;
|
||||||
|
padding-right: 10px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.go-editor-area {
|
||||||
|
max-height: 530px;
|
||||||
|
}
|
||||||
|
.checkbox--hidden:checked {
|
||||||
|
& + label {
|
||||||
|
.n-icon {
|
||||||
|
transition: all 0.3s;
|
||||||
|
transform: rotate(180deg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
& ~ .go-editor-area {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 优化代码换行
|
||||||
|
.n-code > pre {
|
||||||
|
white-space: break-spaces;
|
||||||
|
}
|
||||||
|
}
|
@ -5,20 +5,15 @@
|
|||||||
组件 id:
|
组件 id:
|
||||||
<n-text>{{ targetData.id }}</n-text>
|
<n-text>{{ targetData.id }}</n-text>
|
||||||
</n-text>
|
</n-text>
|
||||||
<n-collapse-item title="基础事件配置" name="1">
|
<chart-event-base-handle></chart-event-base-handle>
|
||||||
<div class="go-event">
|
<chart-event-advanced-handle></chart-event-advanced-handle>
|
||||||
<n-text depth="3">【单击、双击、移入、移出】在开发中,即将上线!</n-text>
|
|
||||||
<br/>
|
|
||||||
<n-text depth="3">(备注:高级事件模块可自行实现上述功能)</n-text>
|
|
||||||
</div>
|
|
||||||
</n-collapse-item>
|
|
||||||
<chart-event-monaco-editor></chart-event-monaco-editor>
|
|
||||||
</n-collapse>
|
</n-collapse>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref } from 'vue'
|
import { ref } from 'vue'
|
||||||
import { ChartEventMonacoEditor } from './components/ChartEventMonacoEditor'
|
import { ChartEventAdvancedHandle } from './components/ChartEventAdvancedHandle'
|
||||||
|
import { ChartEventBaseHandle } from './components/ChartEventBaseHandle'
|
||||||
import { useTargetData } from '../hooks/useTargetData.hook'
|
import { useTargetData } from '../hooks/useTargetData.hook'
|
||||||
|
|
||||||
const { targetData } = useTargetData()
|
const { targetData } = useTargetData()
|
||||||
|
@ -38,6 +38,7 @@ export const useFile = () => {
|
|||||||
await updateComponent(fileData, false, true)
|
await updateComponent(fileData, false, true)
|
||||||
window['$message'].success('导入成功!')
|
window['$message'].success('导入成功!')
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
console.log(error)
|
||||||
window['$message'].error('组件导入失败,请检查文件完整性!')
|
window['$message'].error('组件导入失败,请检查文件完整性!')
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -48,6 +49,7 @@ export const useFile = () => {
|
|||||||
await updateComponent(fileData, true, true)
|
await updateComponent(fileData, true, true)
|
||||||
window['$message'].success('导入成功!')
|
window['$message'].success('导入成功!')
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
console.log(error)
|
||||||
window['$message'].error('组件导入失败,请检查文件完整性!')
|
window['$message'].error('组件导入失败,请检查文件完整性!')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,61 @@
|
|||||||
|
import { watch } from 'vue'
|
||||||
|
import { useRoute } from 'vue-router'
|
||||||
|
import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore'
|
||||||
|
import { useSync } from '@/views/chart/hooks/useSync.hook'
|
||||||
|
import { ChartEnum } from '@/enums/pageEnum'
|
||||||
|
import { SavePageEnum } from '@/enums/editPageEnum'
|
||||||
|
import { editToJsonInterval } from '@/settings/designSetting'
|
||||||
|
|
||||||
|
const { updateComponent } = useSync()
|
||||||
|
const chartEditStore = useChartEditStore()
|
||||||
|
|
||||||
|
// 侦听器更新
|
||||||
|
const useSyncUpdateHandle = () => {
|
||||||
|
const routerParamsInfo = useRoute()
|
||||||
|
// 定义侦听器变量
|
||||||
|
let timer: any
|
||||||
|
const updateFn = (e: any) => updateComponent(e!.detail, true, false)
|
||||||
|
const syncData = () => {
|
||||||
|
if (routerParamsInfo.name == ChartEnum.CHART_HOME_NAME) {
|
||||||
|
dispatchEvent(new CustomEvent(SavePageEnum.CHART, { detail: chartEditStore.getStorageInfo }))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 开启侦听
|
||||||
|
const use = () => {
|
||||||
|
// 1、定时同步数据
|
||||||
|
timer = setInterval(() => {
|
||||||
|
// 窗口激活并且处于工作台
|
||||||
|
document.hasFocus() && syncData()
|
||||||
|
}, editToJsonInterval)
|
||||||
|
// 2、失焦同步数据
|
||||||
|
addEventListener('blur', syncData)
|
||||||
|
|
||||||
|
// 【监听JSON代码 刷新工作台图表】
|
||||||
|
addEventListener(SavePageEnum.JSON, updateFn)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 关闭侦听
|
||||||
|
const unUse = () => {
|
||||||
|
clearInterval(timer)
|
||||||
|
removeEventListener(SavePageEnum.JSON, updateFn)
|
||||||
|
removeEventListener('blur', syncData)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 路由变更时处理
|
||||||
|
const watchHandler = (toName: any, fromName: any) => {
|
||||||
|
if (fromName == ChartEnum.CHART_HOME_NAME) {
|
||||||
|
unUse()
|
||||||
|
}
|
||||||
|
if (toName == ChartEnum.CHART_HOME_NAME) {
|
||||||
|
use()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return watchHandler
|
||||||
|
}
|
||||||
|
|
||||||
|
export const useSyncUpdate = () => {
|
||||||
|
const routerParamsInfo = useRoute()
|
||||||
|
watch(() => routerParamsInfo.name, useSyncUpdateHandle(), { immediate: true })
|
||||||
|
}
|
@ -62,20 +62,18 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref, computed, h, watch } from 'vue'
|
import { ref, computed } from 'vue'
|
||||||
import { useSettingStore } from '@/store/modules/settingStore/settingStore'
|
import { useSettingStore } from '@/store/modules/settingStore/settingStore'
|
||||||
import { ToolsStatusEnum } from '@/store/modules/settingStore/settingStore.d'
|
import { ToolsStatusEnum } from '@/store/modules/settingStore/settingStore.d'
|
||||||
import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore'
|
import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore'
|
||||||
import { fetchPathByName, routerTurnByPath, setSessionStorage, getLocalStorage } from '@/utils'
|
import { fetchRouteParamsLocation, fetchPathByName, routerTurnByPath, setSessionStorage, getLocalStorage } from '@/utils'
|
||||||
import { editToJsonInterval } from '@/settings/designSetting'
|
import { EditEnum } from '@/enums/pageEnum'
|
||||||
import { EditEnum, ChartEnum } from '@/enums/pageEnum'
|
|
||||||
import { StorageEnum } from '@/enums/storageEnum'
|
import { StorageEnum } from '@/enums/storageEnum'
|
||||||
import { useRoute } from 'vue-router'
|
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 { GoSystemSet } from '@/components/GoSystemSet/index'
|
||||||
import { exportHandle } from './utils'
|
import { exportHandle } from './utils'
|
||||||
import { useFile } from './hooks/useFile.hooks'
|
import { useFile } from './hooks/useFile.hooks'
|
||||||
|
import { useSyncUpdate } from './hooks/useSyncUpdate.hook'
|
||||||
import { BtnListType, TypeEnum } from './index.d'
|
import { BtnListType, TypeEnum } from './index.d'
|
||||||
import { icon } from '@/plugins'
|
import { icon } from '@/plugins'
|
||||||
|
|
||||||
@ -83,7 +81,8 @@ const { DownloadIcon, ShareIcon, PawIcon, SettingsSharpIcon, CreateIcon } = icon
|
|||||||
const settingStore = useSettingStore()
|
const settingStore = useSettingStore()
|
||||||
const chartEditStore = useChartEditStore()
|
const chartEditStore = useChartEditStore()
|
||||||
const routerParamsInfo = useRoute()
|
const routerParamsInfo = useRoute()
|
||||||
const { updateComponent } = useSync()
|
// 初始化编辑 JSON 模块
|
||||||
|
useSyncUpdate()
|
||||||
|
|
||||||
// 鼠标悬停定时器
|
// 鼠标悬停定时器
|
||||||
let mouseTime: any = null
|
let mouseTime: any = null
|
||||||
@ -143,8 +142,7 @@ const editHandle = () => {
|
|||||||
// 获取id路径
|
// 获取id路径
|
||||||
const path = fetchPathByName(EditEnum.CHART_EDIT_NAME, 'href')
|
const path = fetchPathByName(EditEnum.CHART_EDIT_NAME, 'href')
|
||||||
if (!path) return
|
if (!path) return
|
||||||
let { id } = routerParamsInfo.params as any
|
const id = fetchRouteParamsLocation()
|
||||||
id = typeof id === 'string' ? id : id[0]
|
|
||||||
updateToSession(id)
|
updateToSession(id)
|
||||||
routerTurnByPath(path, [id], undefined, true)
|
routerTurnByPath(path, [id], undefined, true)
|
||||||
}, 1000)
|
}, 1000)
|
||||||
@ -170,51 +168,6 @@ const updateToSession = (id: string) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 侦听器更新
|
|
||||||
const useSyncUpdate = () => {
|
|
||||||
// 定义侦听器变量
|
|
||||||
let timer: any
|
|
||||||
const updateFn = (e: any) => updateComponent(e!.detail, true, false)
|
|
||||||
const syncData = () => {
|
|
||||||
if (routerParamsInfo.name == ChartEnum.CHART_HOME_NAME) {
|
|
||||||
dispatchEvent(new CustomEvent(SavePageEnum.CHART, { detail: chartEditStore.getStorageInfo }))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 开启侦听
|
|
||||||
const use = () => {
|
|
||||||
// 1、定时同步数据
|
|
||||||
timer = setInterval(() => {
|
|
||||||
// 窗口激活并且处于工作台
|
|
||||||
document.hasFocus() && syncData()
|
|
||||||
}, editToJsonInterval)
|
|
||||||
// 2、失焦同步数据
|
|
||||||
addEventListener('blur', syncData)
|
|
||||||
|
|
||||||
// 【监听JSON代码 刷新工作台图表】
|
|
||||||
addEventListener(SavePageEnum.JSON, updateFn)
|
|
||||||
}
|
|
||||||
|
|
||||||
// 关闭侦听
|
|
||||||
const unUse = () => {
|
|
||||||
clearInterval(timer)
|
|
||||||
removeEventListener(SavePageEnum.JSON, updateFn)
|
|
||||||
removeEventListener('blur', syncData)
|
|
||||||
}
|
|
||||||
|
|
||||||
// 路由变更时处理
|
|
||||||
const watchHandler = (toName: any, fromName: any) => {
|
|
||||||
if (fromName == ChartEnum.CHART_HOME_NAME) {
|
|
||||||
unUse()
|
|
||||||
}
|
|
||||||
if (toName == ChartEnum.CHART_HOME_NAME) {
|
|
||||||
use()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return watchHandler
|
|
||||||
}
|
|
||||||
|
|
||||||
watch(() => routerParamsInfo.name, useSyncUpdate(), { immediate: true })
|
|
||||||
|
|
||||||
// 配置列表
|
// 配置列表
|
||||||
const btnList: BtnListType[] = [
|
const btnList: BtnListType[] = [
|
||||||
@ -234,7 +187,7 @@ const btnList: BtnListType[] = [
|
|||||||
{
|
{
|
||||||
key: 'edit',
|
key: 'edit',
|
||||||
type: TypeEnum.BUTTON,
|
type: TypeEnum.BUTTON,
|
||||||
name: '编辑JSON',
|
name: '编辑',
|
||||||
icon: CreateIcon,
|
icon: CreateIcon,
|
||||||
handle: editHandle
|
handle: editHandle
|
||||||
},
|
},
|
||||||
|
@ -30,7 +30,7 @@
|
|||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref, nextTick, computed } from 'vue'
|
import { ref, nextTick, computed } from 'vue'
|
||||||
import { fetchRouteParams } from '@/utils'
|
import { fetchRouteParamsLocation } from '@/utils'
|
||||||
import { icon } from '@/plugins'
|
import { icon } from '@/plugins'
|
||||||
const { FishIcon } = icon.ionicons5
|
const { FishIcon } = icon.ionicons5
|
||||||
|
|
||||||
@ -39,9 +39,7 @@ const inputInstRef = ref(null)
|
|||||||
|
|
||||||
// 根据路由 id 参数获取项目信息
|
// 根据路由 id 参数获取项目信息
|
||||||
const fetchProhectInfoById = () => {
|
const fetchProhectInfoById = () => {
|
||||||
const routeParamsRes = fetchRouteParams()
|
const id = fetchRouteParamsLocation()
|
||||||
if (!routeParamsRes) return
|
|
||||||
const { id } = routeParamsRes
|
|
||||||
if (id.length) {
|
if (id.length) {
|
||||||
return id[0]
|
return id[0]
|
||||||
}
|
}
|
||||||
|
@ -3,28 +3,68 @@ import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore
|
|||||||
import { ChartEditStoreEnum, ChartEditStorage } from '@/store/modules/chartEditStore/chartEditStore.d'
|
import { ChartEditStoreEnum, ChartEditStorage } from '@/store/modules/chartEditStore/chartEditStore.d'
|
||||||
import { useChartHistoryStore } from '@/store/modules/chartHistoryStore/chartHistoryStore'
|
import { useChartHistoryStore } from '@/store/modules/chartHistoryStore/chartHistoryStore'
|
||||||
import { fetchChartComponent, fetchConfigComponent, createComponent } from '@/packages/index'
|
import { fetchChartComponent, fetchConfigComponent, createComponent } from '@/packages/index'
|
||||||
import { CreateComponentType, CreateComponentGroupType, ConfigType } from '@/packages/index.d'
|
import { CreateComponentType, CreateComponentGroupType } from '@/packages/index.d'
|
||||||
import { PublicGroupConfigClass } from '@/packages/public/publicConfig'
|
import { PublicGroupConfigClass } from '@/packages/public/publicConfig'
|
||||||
import merge from 'lodash/merge'
|
import merge from 'lodash/merge'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 合并处理
|
* * 画布-版本升级对旧数据无法兼容的补丁
|
||||||
* @param object 模板数据
|
* @param object
|
||||||
|
*/
|
||||||
|
const canvasVersionUpdatePolyfill = (object: any) => {
|
||||||
|
return object
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* * 组件-版本升级对旧数据无法兼容的补丁
|
||||||
|
* @param newObject
|
||||||
|
* @param sources
|
||||||
|
*/
|
||||||
|
const componentVersionUpdatePolyfill = (newObject: any, sources: any) => {
|
||||||
|
try {
|
||||||
|
// 判断是否是组件
|
||||||
|
if (sources.id) {
|
||||||
|
// 处理事件补丁
|
||||||
|
const hasVnodeBeforeMount = 'vnodeBeforeMount' in sources.events
|
||||||
|
const hasVnodeMounted = 'vnodeMounted' in sources.events
|
||||||
|
|
||||||
|
if (hasVnodeBeforeMount) {
|
||||||
|
newObject.events.advancedEvents.vnodeBeforeMount = sources?.events.vnodeBeforeMount
|
||||||
|
}
|
||||||
|
if (hasVnodeMounted) {
|
||||||
|
newObject.events.advancedEvents.vnodeMounted = sources?.events.vnodeMounted
|
||||||
|
}
|
||||||
|
if (hasVnodeBeforeMount || hasVnodeMounted) {
|
||||||
|
sources.events = undefined
|
||||||
|
}
|
||||||
|
return newObject
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
return newObject
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* * 合并处理
|
||||||
|
* @param newObject 新的模板数据
|
||||||
* @param sources 新拿到的数据
|
* @param sources 新拿到的数据
|
||||||
* @returns object
|
* @returns object
|
||||||
*/
|
*/
|
||||||
const componentMerge = (object: any, sources: any, notComponent = false) => {
|
const componentMerge = (newObject: any, sources: any, notComponent = false) => {
|
||||||
|
// 处理组件补丁
|
||||||
|
componentVersionUpdatePolyfill(newObject, sources)
|
||||||
|
|
||||||
// 非组件不处理
|
// 非组件不处理
|
||||||
if (notComponent) return merge(object, sources)
|
if (notComponent) return merge(newObject, sources)
|
||||||
// 组件排除 options
|
// 组件排除 newObject
|
||||||
const option = sources.option
|
const option = sources.option
|
||||||
if (!option) return merge(object, sources)
|
if (!option) return merge(newObject, sources)
|
||||||
|
|
||||||
// 为 undefined 的 sources 来源对象属性将被跳过详见 https://www.lodashjs.com/docs/lodash.merge
|
// 为 undefined 的 sources 来源对象属性将被跳过详见 https://www.lodashjs.com/docs/lodash.merge
|
||||||
sources.option = undefined
|
sources.option = undefined
|
||||||
if (option) {
|
if (option) {
|
||||||
return {
|
return {
|
||||||
...merge(object, sources),
|
...merge(newObject, sources),
|
||||||
option: option
|
option: option
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -49,6 +89,9 @@ export const useSync = () => {
|
|||||||
chartHistoryStore.clearBackStack()
|
chartHistoryStore.clearBackStack()
|
||||||
chartHistoryStore.clearForwardStack()
|
chartHistoryStore.clearForwardStack()
|
||||||
}
|
}
|
||||||
|
// 画布补丁处理
|
||||||
|
projectData.editCanvasConfig = canvasVersionUpdatePolyfill(projectData.editCanvasConfig)
|
||||||
|
|
||||||
// 列表组件注册
|
// 列表组件注册
|
||||||
projectData.componentList.forEach(async (e: CreateComponentType | CreateComponentGroupType) => {
|
projectData.componentList.forEach(async (e: CreateComponentType | CreateComponentGroupType) => {
|
||||||
const intComponent = (target: CreateComponentType) => {
|
const intComponent = (target: CreateComponentType) => {
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
>
|
>
|
||||||
<component
|
<component
|
||||||
:is="item.chartConfig.chartKey"
|
:is="item.chartConfig.chartKey"
|
||||||
|
:id="item.id"
|
||||||
:chartConfig="item"
|
:chartConfig="item"
|
||||||
:themeSetting="themeSetting"
|
:themeSetting="themeSetting"
|
||||||
:themeColor="themeColor"
|
:themeColor="themeColor"
|
||||||
@ -29,6 +30,7 @@ import { CreateComponentGroupType } from '@/packages/index.d'
|
|||||||
import { animationsClass, getFilterStyle, getTransformStyle, getBlendModeStyle } from '@/utils'
|
import { animationsClass, getFilterStyle, getTransformStyle, getBlendModeStyle } from '@/utils'
|
||||||
import { getSizeStyle, getComponentAttrStyle, getStatusStyle } from '../../utils'
|
import { getSizeStyle, getComponentAttrStyle, getStatusStyle } from '../../utils'
|
||||||
import { useLifeHandler } from '@/hooks'
|
import { useLifeHandler } from '@/hooks'
|
||||||
|
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
groupData: {
|
groupData: {
|
||||||
type: Object as PropType<CreateComponentGroupType>,
|
type: Object as PropType<CreateComponentGroupType>,
|
||||||
|
@ -25,6 +25,7 @@
|
|||||||
<component
|
<component
|
||||||
v-else
|
v-else
|
||||||
:is="item.chartConfig.chartKey"
|
:is="item.chartConfig.chartKey"
|
||||||
|
:id="item.id"
|
||||||
:chartConfig="item"
|
:chartConfig="item"
|
||||||
:themeSetting="themeSetting"
|
:themeSetting="themeSetting"
|
||||||
:themeColor="themeColor"
|
:themeColor="themeColor"
|
||||||
@ -43,6 +44,7 @@ import { chartColors } from '@/settings/chartThemes/index'
|
|||||||
import { animationsClass, getFilterStyle, getTransformStyle, getBlendModeStyle } from '@/utils'
|
import { animationsClass, getFilterStyle, getTransformStyle, getBlendModeStyle } from '@/utils'
|
||||||
import { getSizeStyle, getComponentAttrStyle, getStatusStyle } from '../../utils'
|
import { getSizeStyle, getComponentAttrStyle, getStatusStyle } from '../../utils'
|
||||||
import { useLifeHandler } from '@/hooks'
|
import { useLifeHandler } from '@/hooks'
|
||||||
|
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
localStorageInfo: {
|
localStorageInfo: {
|
||||||
type: Object as PropType<ChartEditStorageType>,
|
type: Object as PropType<ChartEditStorageType>,
|
||||||
|
Loading…
Reference in New Issue
Block a user