Merge branch 'dev' into dev-feat-multi-select

This commit is contained in:
奔跑的面条 2022-07-06 21:51:11 +08:00
commit 84c9e73e7b
27 changed files with 671 additions and 132 deletions

View File

@ -1,4 +1,7 @@
export const OUTPUT_DIR = 'dist'; export const OUTPUT_DIR = 'dist'
// monaco-editor 路径
export const prefix = `monaco-editor/esm/vs`
// chunk 警告大小 // chunk 警告大小
export const chunkSizeWarningLimit = 2000 export const chunkSizeWarningLimit = 2000
@ -11,7 +14,14 @@ export const rollupOptions = {
output: { output: {
chunkFileNames: 'static/js/[name]-[hash].js', chunkFileNames: 'static/js/[name]-[hash].js',
entryFileNames: 'static/js/[name]-[hash].js', entryFileNames: 'static/js/[name]-[hash].js',
assetFileNames: 'static/[ext]/[name]-[hash].[ext]' assetFileNames: 'static/[ext]/[name]-[hash].[ext]',
manualChunks: {
jsonWorker: [`${prefix}/language/json/json.worker`],
cssWorker: [`${prefix}/language/css/css.worker`],
htmlWorker: [`${prefix}/language/html/html.worker`],
tsWorker: [`${prefix}/language/typescript/ts.worker`],
editorWorker: [`${prefix}/editor/editor.worker`]
}
} }
} }

View File

@ -20,6 +20,7 @@
"highlight.js": "^11.5.0", "highlight.js": "^11.5.0",
"html2canvas": "^1.4.1", "html2canvas": "^1.4.1",
"keymaster": "^1.6.2", "keymaster": "^1.6.2",
"monaco-editor": "^0.33.0",
"naive-ui": "2.30.3", "naive-ui": "2.30.3",
"pinia": "^2.0.13", "pinia": "^2.0.13",
"screenfull": "^6.0.1", "screenfull": "^6.0.1",
@ -63,6 +64,7 @@
"vite-plugin-compression": "^0.5.1", "vite-plugin-compression": "^0.5.1",
"vite-plugin-importer": "^0.2.5", "vite-plugin-importer": "^0.2.5",
"vite-plugin-mock": "^2.9.6", "vite-plugin-mock": "^2.9.6",
"vite-plugin-monaco-editor": "^1.1.0",
"vue-echarts": "^6.0.2", "vue-echarts": "^6.0.2",
"vue-tsc": "^0.28.10" "vue-tsc": "^0.28.10"
} }

16
pnpm-lock.yaml generated
View File

@ -34,6 +34,7 @@ specifiers:
keymaster: ^1.6.2 keymaster: ^1.6.2
lodash: ~4.17.21 lodash: ~4.17.21
mockjs: ^1.1.0 mockjs: ^1.1.0
monaco-editor: ^0.33.0
naive-ui: 2.30.3 naive-ui: 2.30.3
pinia: ^2.0.13 pinia: ^2.0.13
plop: ^3.0.5 plop: ^3.0.5
@ -46,6 +47,7 @@ specifiers:
vite-plugin-compression: ^0.5.1 vite-plugin-compression: ^0.5.1
vite-plugin-importer: ^0.2.5 vite-plugin-importer: ^0.2.5
vite-plugin-mock: ^2.9.6 vite-plugin-mock: ^2.9.6
vite-plugin-monaco-editor: ^1.1.0
vue: ^3.2.31 vue: ^3.2.31
vue-demi: ^0.13.1 vue-demi: ^0.13.1
vue-echarts: ^6.0.2 vue-echarts: ^6.0.2
@ -68,6 +70,7 @@ dependencies:
highlight.js: 11.5.1 highlight.js: 11.5.1
html2canvas: 1.4.1 html2canvas: 1.4.1
keymaster: 1.6.2 keymaster: 1.6.2
monaco-editor: 0.33.0
naive-ui: 2.30.3_vue@3.2.37 naive-ui: 2.30.3_vue@3.2.37
pinia: 2.0.14_vcmyupim4cga7k7f5hngmth5py pinia: 2.0.14_vcmyupim4cga7k7f5hngmth5py
screenfull: 6.0.1 screenfull: 6.0.1
@ -111,6 +114,7 @@ devDependencies:
vite-plugin-compression: 0.5.1_vite@2.9.5 vite-plugin-compression: 0.5.1_vite@2.9.5
vite-plugin-importer: 0.2.5 vite-plugin-importer: 0.2.5
vite-plugin-mock: 2.9.6_mockjs@1.1.0+vite@2.9.5 vite-plugin-mock: 2.9.6_mockjs@1.1.0+vite@2.9.5
vite-plugin-monaco-editor: 1.1.0_monaco-editor@0.33.0
vue-echarts: 6.0.3_echarts@5.3.3+vue@3.2.37 vue-echarts: 6.0.3_echarts@5.3.3+vue@3.2.37
vue-tsc: 0.28.10_typescript@4.7.3 vue-tsc: 0.28.10_typescript@4.7.3
@ -3756,6 +3760,10 @@ packages:
commander: 9.3.0 commander: 9.3.0
dev: true dev: true
/monaco-editor/0.33.0:
resolution: {integrity: sha512-VcRWPSLIUEgQJQIE0pVT8FcGBIgFoxz7jtqctE+IiCxWugD0DwgyQBcZBhdSrdMC84eumoqMZsGl2GTreOzwqw==}
dev: false
/ms/2.0.0: /ms/2.0.0:
resolution: {integrity: sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==} resolution: {integrity: sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==}
dev: true dev: true
@ -5105,6 +5113,14 @@ packages:
- supports-color - supports-color
dev: true dev: true
/vite-plugin-monaco-editor/1.1.0_monaco-editor@0.33.0:
resolution: {integrity: sha512-IvtUqZotrRoVqwT0PBBDIZPNraya3BxN/bfcNfnxZ5rkJiGcNtO5eAOWWSgT7zullIAEqQwxMU83yL9J5k7gww==}
peerDependencies:
monaco-editor: '>=0.33.0'
dependencies:
monaco-editor: 0.33.0
dev: true
/vite/2.9.5_sass@1.52.3: /vite/2.9.5_sass@1.52.3:
resolution: {integrity: sha512-dvMN64X2YEQgSXF1lYabKXw3BbN6e+BL67+P3Vy4MacnY+UzT1AfkHiioFSi9+uiDUiaDy7Ax/LQqivk6orilg==} resolution: {integrity: sha512-dvMN64X2YEQgSXF1lYabKXw3BbN6e+BL67+P3Vy4MacnY+UzT1AfkHiioFSi9+uiDUiaDy7Ax/LQqivk6orilg==}
engines: {node: '>=12.2.0'} engines: {node: '>=12.2.0'}

View File

@ -0,0 +1,20 @@
<template></template>
<script setup>
import * as monaco from 'monaco-editor'
import editorWorker from 'monaco-editor/esm/vs/editor/editor.worker?worker'
import jsonWorker from 'monaco-editor/esm/vs/language/json/json.worker?worker'
import tsWorker from 'monaco-editor/esm/vs/language/typescript/ts.worker?worker'
self.MonacoEnvironment = {
getWorker(workerId, label) {
if (label === 'json') {
return new jsonWorker()
}
if (label === 'typescript' || label === 'javascript') {
return new tsWorker()
}
return new editorWorker()
}
}
</script>

View File

@ -0,0 +1,76 @@
import { ref, onBeforeUnmount, nextTick } from 'vue'
import { useDesignStore } from '@/store/modules/designStore/designStore'
import * as monaco from 'monaco-editor/esm/vs/editor/editor.api.js'
export const useMonacoEditor = (language = 'javascript') => {
const designStore = useDesignStore()
let monacoEditor: monaco.editor.IStandaloneCodeEditor | null = null
let initReadOnly = false
const el = ref<HTMLElement | null>(null)
// 格式化
const onFormatDoc = async () => {
await monacoEditor?.getAction('monacoEditor.action.formatDocument')?.run()
}
// 更新
const updateVal = (val: string) => {
nextTick(async () => {
monacoEditor?.setValue(val)
initReadOnly && monacoEditor?.updateOptions({ readOnly: false })
await onFormatDoc()
initReadOnly && monacoEditor?.updateOptions({ readOnly: true })
})
}
// 创建实例
const createEditor = (editorOption: monaco.editor.IStandaloneEditorConstructionOptions = {}) => {
if (!el.value) return
const javascriptModel = monaco.editor.createModel('', language)
initReadOnly = !!editorOption.readOnly
// 创建
monacoEditor = monaco.editor.create(el.value, {
model: javascriptModel,
// 是否启用预览图
minimap: { enabled: false },
// 圆角
roundedSelection: true,
// 主题
theme: designStore.getDarkTheme ? 'vs-dark' : 'vs',
// 主键
multiCursorModifier: 'ctrlCmd',
// 滚动条
scrollbar: {
verticalScrollbarSize: 8,
horizontalScrollbarSize: 8
},
// 行号
lineNumbers: 'off',
// tab大小
tabSize: 2,
//字体大小
fontSize: 16,
// 控制编辑器在用户键入、粘贴、移动或缩进行时是否应自动调整缩进
autoIndent: 'advanced',
// 自动布局
automaticLayout: true,
...editorOption
})
return monacoEditor
}
// 卸载
onBeforeUnmount(() => {
if (monacoEditor) monacoEditor.dispose()
})
return {
el,
updateVal,
getEditor: () => monacoEditor,
createEditor,
onFormatDoc
}
}

View File

@ -0,0 +1,4 @@
import MonacoEditor from './index.vue';
import EditorWorker from './EditorWorker.vue';
export { MonacoEditor, EditorWorker };

View File

@ -0,0 +1,92 @@
<template>
<div ref="el" class="go-editor-area" :style="{ width, height }"></div>
<EditorWorker></EditorWorker>
</template>
<script lang="ts" setup>
import { onMounted, watch, PropType } from 'vue'
import { useMonacoEditor } from './index.hook'
import { EditorWorker } from './index'
const props = defineProps({
width: {
type: String as PropType<string>,
default: '100%'
},
height: {
type: String as PropType<string>,
default: '90vh'
},
language: {
type: String as PropType<string>,
default: 'typescript'
},
preComment: {
type: String as PropType<string>,
default: ''
},
modelValue: {
type: String as PropType<string>,
default: ''
},
editorOptions: {
type: Object as PropType<object>,
default: () => ({})
}
})
const emits = defineEmits(['blur', 'update:modelValue'])
const { el, updateVal, getEditor, createEditor } = useMonacoEditor(props.language)
const updateMonacoVal = (_val?: string) => {
const { modelValue, preComment } = props
const val = preComment ? `${preComment}\n${_val || modelValue}` : _val || modelValue
updateVal(val)
}
onMounted(() => {
const monacoEditor = createEditor(props.editorOptions)
monacoEditor!.onDidChangeModelContent(() => {
emits('update:modelValue', monacoEditor!.getValue())
})
monacoEditor!.onDidBlurEditorText(() => {
emits('blur')
})
updateMonacoVal()
})
watch(
() => props.modelValue,
(val: string) => {
val !== getEditor()?.getValue() && updateMonacoVal(val)
}
)
</script>
<style lang="scss" scoped>
.go-editor-area {
position: relative;
border-radius: 4px;
overflow: hidden;
padding: 5px;
padding-left: 0;
box-sizing: border-box;
background-color: rgba(0, 0, 0, 0);
@include deep() {
.margin,
.monaco-editor,
.inputarea.ime-input {
background-color: rgba(0, 0, 0, 0);
}
.monaco-editor-background {
background-color: rgba(0, 0, 0, 0);
@include fetch-bg-color('filter-color-shallow');
}
.margin {
@include fetch-bg-color('filter-color-shallow');
}
}
}
</style>

View File

@ -20,7 +20,7 @@
<div class="content-right"> <div class="content-right">
<div class="color-name-detail"> <div class="color-name-detail">
<n-text v-if="appThemeDetail" class="color-name">{{ appThemeDetail.name }}</n-text> <n-text v-if="appThemeDetail" class="color-name">{{ appThemeDetail.name }}</n-text>
<n-text v-else="appThemeDetail" class="color-name">中国色</n-text> <n-text v-else class="color-name">中国色</n-text>
<n-text <n-text
v-if="appThemeDetail" v-if="appThemeDetail"
class="color-name-Pinyin" class="color-name-Pinyin"

View File

@ -4,11 +4,12 @@ import { http } from '@/api/http'
import { CreateComponentType, ChartFrameEnum } from '@/packages/index.d' import { CreateComponentType, ChartFrameEnum } from '@/packages/index.d'
import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore' import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore'
import { RequestDataTypeEnum } from '@/enums/httpEnum' import { RequestDataTypeEnum } from '@/enums/httpEnum'
import { isPreview } from '@/utils' import { isPreview, newFunctionHandle } from '@/utils'
// 获取类型 // 获取类型
type ChartEditStoreType = typeof useChartEditStore type ChartEditStoreType = typeof useChartEditStore
/** /**
* setdata * setdata
* @param targetComponent * @param targetComponent
@ -23,38 +24,36 @@ export const useChartDataFetch = (
const vChartRef = ref<typeof VChart | null>(null) const vChartRef = ref<typeof VChart | null>(null)
let fetchInterval: any = 0 let fetchInterval: any = 0
const requestInterval = () => { const requestIntervalFn = () => {
const chartEditStore = useChartEditStore() const chartEditStore = useChartEditStore()
const { requestOriginUrl, requestInterval } = toRefs( const { requestOriginUrl, requestInterval } = toRefs(chartEditStore.getRequestGlobalConfig)
chartEditStore.getRequestGlobalConfig
)
// 组件类型 // 组件类型
const { chartFrame } = targetComponent.chartConfig const { chartFrame } = targetComponent.chartConfig
// 请求配置 // 请求配置
const { requestDataType, requestHttpType, requestUrl } = toRefs( const { requestDataType, requestHttpType, requestUrl } = toRefs(targetComponent.data)
targetComponent.data
)
// 非请求类型 // 非请求类型
if (requestDataType.value !== RequestDataTypeEnum.AJAX) return if (requestDataType.value !== RequestDataTypeEnum.AJAX) return
// 处理地址 // 处理地址
if (requestUrl?.value && requestInterval.value > 0) { if (requestUrl?.value && requestInterval.value > 0) {
// requestOriginUrl 允许为空 // requestOriginUrl 允许为空
const completePath = const completePath = requestOriginUrl && requestOriginUrl.value + requestUrl.value
requestOriginUrl && requestOriginUrl.value + requestUrl.value
if (!completePath) return if (!completePath) return
clearInterval(fetchInterval)
const fetchFn = async () => { const fetchFn = async () => {
const res: any = await http(requestHttpType.value)(completePath || '', {}) const res: any = await http(requestHttpType.value)(completePath || '', {})
if (res.data) { if (res.data) {
try { try {
const filter = targetComponent.filter
// 更新回调函数 // 更新回调函数
if (updateCallback) { if (updateCallback) {
updateCallback(res.data) updateCallback(newFunctionHandle(res.data, filter))
} else { } else {
// eCharts 组件配合 vChart 库更新方式 // eCharts 组件配合 vChart 库更新方式
if (chartFrame === ChartFrameEnum.ECHARTS) { if (chartFrame === ChartFrameEnum.ECHARTS) {
if (vChartRef.value) { if (vChartRef.value) {
vChartRef.value.setOption({ dataset: res.data }) vChartRef.value.setOption({ dataset: newFunctionHandle(res.data, filter) })
} }
} }
} }
@ -67,12 +66,11 @@ export const useChartDataFetch = (
// 立即调用 // 立即调用
fetchFn() fetchFn()
// 开启定时 // 开启定时
setInterval(fetchFn, requestInterval.value * 1000) fetchInterval = setInterval(fetchFn, requestInterval.value * 1000)
} }
} }
isPreview() && requestInterval() isPreview() && requestIntervalFn()
return { vChartRef } return { vChartRef }
} }

View File

@ -25,6 +25,7 @@ import { PropType, toRefs, watch, shallowReactive } from 'vue'
import { useChartDataFetch } from '@/hooks' import { useChartDataFetch } from '@/hooks'
import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore' import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore'
import config, { option as configOption } from './config' import config, { option as configOption } from './config'
import { toNumber } from '@/utils'
const props = defineProps({ const props = defineProps({
chartConfig: { chartConfig: {
@ -39,7 +40,6 @@ const {
type, type,
unit, unit,
color, color,
fontSize,
processing, processing,
railColor, railColor,
indicatorTextColor, indicatorTextColor,
@ -57,11 +57,11 @@ const option = shallowReactive({
watch( watch(
() => props.chartConfig.option.dataset, () => props.chartConfig.option.dataset,
(newData: any) => { (newData: any) => {
option.dataset = newData option.dataset = toNumber(newData, 2)
} }
) )
// //
useChartDataFetch(props.chartConfig, useChartEditStore, (newData: number) => { useChartDataFetch(props.chartConfig, useChartEditStore, (newData: number) => {
option.dataset = newData option.dataset = toNumber(newData, 2)
}) })
</script> </script>

View File

@ -10,7 +10,7 @@ import 'echarts-liquidfill/src/liquidFill.js'
import { CanvasRenderer } from 'echarts/renderers' import { CanvasRenderer } from 'echarts/renderers'
import { GridComponent } from 'echarts/components' import { GridComponent } from 'echarts/components'
import config from './config' import config from './config'
import { isPreview } from '@/utils' import { isPreview, isString } from '@/utils'
import { chartColorsSearch, defaultTheme } from '@/settings/chartThemes/index' import { chartColorsSearch, defaultTheme } from '@/settings/chartThemes/index'
import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore' import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore'
import { useChartDataFetch } from '@/hooks' import { useChartDataFetch } from '@/hooks'
@ -66,7 +66,8 @@ watch(
) )
// //
const dataHandle = (newData: number) => { const dataHandle = (newData: number | string) => {
newData = isString(newData) ? parseFloat(newData) : newData
return parseFloat(newData.toFixed(2)) return parseFloat(newData.toFixed(2))
} }
@ -74,7 +75,6 @@ const dataHandle = (newData: number) => {
watch( watch(
() => props.chartConfig.option.dataset, () => props.chartConfig.option.dataset,
newData => { newData => {
console.log(dataHandle(newData))
props.chartConfig.option.series[0].data = [dataHandle(newData)] props.chartConfig.option.series[0].data = [dataHandle(newData)]
option.value = props.chartConfig.option option.value = props.chartConfig.option
}, },

View File

@ -2,9 +2,14 @@ import type { GlobalThemeJsonType } from '@/settings/chartThemes/index'
import type { RequestConfigType } from '@/store/modules/chartEditStore/chartEditStore.d' import type { RequestConfigType } from '@/store/modules/chartEditStore/chartEditStore.d'
export enum ChartFrameEnum { export enum ChartFrameEnum {
COMMON = 'common', // echarts 框架
ECHARTS = 'echarts', ECHARTS = 'echarts',
NAIVE_UI = 'naiveUI' // UI 组件框架
NAIVE_UI = 'naiveUI',
// 自定义带数据组件
COMMON = 'common',
// 无数据变更
STATIC = 'static'
} }
// 组件配置 // 组件配置
@ -77,6 +82,7 @@ export interface PublicConfigType extends requestConfig {
// 动画 // 动画
animations: string[] animations: string[]
} }
filter?: string
setPosition: Function setPosition: Function
} }

View File

@ -45,6 +45,8 @@ export class publicConfig implements PublicConfigType {
public data = { ...requestConfig } public data = { ...requestConfig }
// 数据获取 // 数据获取
public requestData = [] public requestData = []
// 数据过滤
public filter = undefined
// 设置坐标 // 设置坐标
public setPosition(x: number, y: number): void { public setPosition(x: number, y: number): void {

View File

@ -52,7 +52,8 @@ import {
ArrowBack as ArrowBackIcon, ArrowBack as ArrowBackIcon,
ArrowForward as ArrowForwardIcon, ArrowForward as ArrowForwardIcon,
Planet as PawIcon, Planet as PawIcon,
Search as SearchIcon Search as SearchIcon,
Filter as FilterIcon
} from '@vicons/ionicons5' } from '@vicons/ionicons5'
import { import {
@ -192,7 +193,9 @@ const ionicons5 = {
// 狗爪 // 狗爪
PawIcon, PawIcon,
// 搜索(放大镜) // 搜索(放大镜)
SearchIcon SearchIcon,
// 过滤器
FilterIcon
} }
const carbon = { const carbon = {

View File

@ -167,6 +167,9 @@ export const useChartEditStore = defineStore({
}, },
// * 设置目标数据 select // * 设置目标数据 select
setTargetSelectChart(selectId?: string | string[], push: boolean = false) { setTargetSelectChart(selectId?: string | string[], push: boolean = false) {
// 重复选中
if(this.targetChart.selectId.find((e: string) => e === selectId)) return
// 无 id 清空 // 无 id 清空
if(!selectId) { if(!selectId) {
this.targetChart.selectId = [] this.targetChart.selectId = []

View File

@ -24,7 +24,7 @@ export const getFilterStyle = (styles: StylesType | EditCanvasConfigType) => {
} }
// 变换 // 变换
export const getTranstormStyle = (styles: StylesType) => { export const getTransformStyle = (styles: StylesType) => {
const { rotateZ, rotateX, rotateY, skewX, skewY } = styles const { rotateZ, rotateX, rotateY, skewX, skewY } = styles
return { return {
transform: `rotateZ(${rotateZ || 0}deg) rotateX(${rotateX || 0}deg) rotateY(${rotateY || 0}deg) skewX(${skewX || 0}deg) skewY(${skewY || 0}deg)`, transform: `rotateZ(${rotateZ || 0}deg) rotateX(${rotateX || 0}deg) rotateY(${rotateY || 0}deg) skewX(${skewX || 0}deg) skewY(${skewY || 0}deg)`,

View File

@ -1,3 +1,5 @@
import isObject from 'lodash/isObject'
export function isString(p: any): p is string { export function isString(p: any): p is string {
return typeof p === 'string' return typeof p === 'string'
} }
@ -21,3 +23,11 @@ export function isNull(p: any): p is null {
export function isArray(p: any): p is [] { export function isArray(p: any): p is [] {
return Array.isArray(p) return Array.isArray(p)
} }
export const toNumber = (number: number | string, toFixedNumber = 2) => {
return isString(number) ? parseFloat(parseFloat(number).toFixed(2)) : number
}
export const toString = (str: any) => {
return isNumber(str) ? `${str}` : (isObject(str) ? JSON.stringify(str) : str)
}

View File

@ -5,6 +5,8 @@ import throttle from 'lodash/throttle'
import Image_404 from '../assets/images/exception/image-404.png' import Image_404 from '../assets/images/exception/image-404.png'
import html2canvas from 'html2canvas' import html2canvas from 'html2canvas'
import { downloadByA } from './file' import { downloadByA } from './file'
import { toString } from './type'
import cloneDeep from 'lodash/cloneDeep';
/** /**
* * * *
@ -19,9 +21,7 @@ export const isDev = () => {
* @param { Number } randomLength * @param { Number } randomLength
*/ */
export const getUUID = (randomLength = 10) => { export const getUUID = (randomLength = 10) => {
return Number( return Number(Math.random().toString().substr(2, randomLength) + Date.now()).toString(36)
Math.random().toString().substr(2, randomLength) + Date.now()
).toString(36)
} }
/** /**
@ -90,10 +90,7 @@ export const screenfullFn = (isFullscreen?: boolean, isEnabled?: boolean) => {
* @param key * @param key
* @param value * @param value
*/ */
export const setDomAttribute = < export const setDomAttribute = <K extends keyof CSSStyleDeclaration, V extends CSSStyleDeclaration[K]>(
K extends keyof CSSStyleDeclaration,
V extends CSSStyleDeclaration[K]
>(
HTMLElement: HTMLElement, HTMLElement: HTMLElement,
key: K, key: K,
value: V value: V
@ -149,7 +146,7 @@ export const addEventListener = <K extends keyof WindowEventMap>(
type, type,
throttle(listener, delay || 300, { throttle(listener, delay || 300, {
leading: true, leading: true,
trailing: false, trailing: false
}), }),
options options
) )
@ -186,3 +183,34 @@ export const canvasCut = (html: HTMLElement | null, callback?: Function) => {
if (callback) callback() if (callback) callback()
}) })
} }
/**
* *
* @param data
* @param funcStr
* @param toString
* @param errorCallBack
* @param successCallBack
* @returns
*/
export const newFunctionHandle = (
data: any,
funcStr?: string,
isToString?: boolean,
errorCallBack?: Function,
successCallBack?: Function
) => {
try {
if (!funcStr) return data
const fn = new Function('data', funcStr)
const fnRes = fn( cloneDeep(data))
const resHandle = isToString ? toString(fnRes) : fnRes
// 成功回调
successCallBack && successCallBack(resHandle)
return resHandle
} catch (error) {
// 失败回调
errorCallBack && errorCallBack(error)
return '函数执行错误'
}
}

View File

@ -1,10 +1,7 @@
<template> <template>
<div class="go-chart-configurations-data-ajax"> <div class="go-chart-configurations-data-ajax">
<setting-item-box name="类型" :alone="true"> <setting-item-box name="类型" :alone="true">
<n-select <n-select v-model:value="targetData.data.requestHttpType" :options="selectOptions" />
v-model:value="targetData.data.requestHttpType"
:options="selectOptions"
/>
</setting-item-box> </setting-item-box>
<setting-item-box name="源地址:" :alone="true"> <setting-item-box name="源地址:" :alone="true">
@ -28,14 +25,21 @@
</ul> </ul>
</n-tooltip> </n-tooltip>
</template> </template>
<n-input <n-input v-model:value.trim="targetData.data.requestUrl" :min="1" placeholder="请输入地址(去除源)" />
v-model:value.trim="targetData.data.requestUrl"
:min="1"
placeholder="请输入地址(去除源)"
/>
</setting-item-box> </setting-item-box>
<setting-item-box name="测试" :alone="true"> <setting-item-box :alone="true">
<template #name>
测试
<n-tooltip trigger="hover">
<template #trigger>
<n-icon size="21" :depth="3">
<help-outline-icon></help-outline-icon>
</n-icon>
</template>
默认赋值给 dataset 字段
</n-tooltip>
</template>
<n-space> <n-space>
<n-button @click="sendHandle"> <n-button @click="sendHandle">
<template #icon> <template #icon>
@ -48,17 +52,13 @@
</n-space> </n-space>
</setting-item-box> </setting-item-box>
<chart-data-matching-and-show :show="showMatching && !loading" :ajax="true"></chart-data-matching-and-show>
<go-skeleton :load="loading" :repeat="3"></go-skeleton> <go-skeleton :load="loading" :repeat="3"></go-skeleton>
<chart-data-matching-and-show
v-show="showMatching && !loading"
:ajax="true"
></chart-data-matching-and-show>
</div> </div>
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { ref, toRefs } from 'vue' import { ref, toRefs, onBeforeUnmount, watchEffect } from 'vue'
import { icon } from '@/plugins' import { icon } from '@/plugins'
import { SettingItemBox } from '@/components/Pages/ChartItemSetting' import { SettingItemBox } from '@/components/Pages/ChartItemSetting'
import { RequestHttpEnum, ResultEnum } from '@/enums/httpEnum' import { RequestHttpEnum, ResultEnum } from '@/enums/httpEnum'
@ -67,15 +67,15 @@ import { http } from '@/api/http'
import { SelectHttpType } from '../../index.d' import { SelectHttpType } from '../../index.d'
import { ChartDataMatchingAndShow } from '../ChartDataMatchingAndShow' import { ChartDataMatchingAndShow } from '../ChartDataMatchingAndShow'
import { useTargetData } from '../../../hooks/useTargetData.hook' import { useTargetData } from '../../../hooks/useTargetData.hook'
import { isDev } from '@/utils' import { isDev, newFunctionHandle } from '@/utils'
const { HelpOutlineIcon, FlashIcon } = icon.ionicons5 const { HelpOutlineIcon, FlashIcon } = icon.ionicons5
const { targetData, chartEditStore } = useTargetData() const { targetData, chartEditStore } = useTargetData()
const { requestOriginUrl } = toRefs(chartEditStore.getRequestGlobalConfig) const { requestOriginUrl } = toRefs(chartEditStore.getRequestGlobalConfig)
// //
const loading = ref(false) const loading = ref(false)
const showMatching = ref(false) const showMatching = ref(false)
let lastFilter: any = undefined
const apiList = [ const apiList = [
{ {
@ -98,25 +98,25 @@ const apiList = [
}, },
{ {
value: `【滚动表格】${scrollBoardUrl}` value: `【滚动表格】${scrollBoardUrl}`
}, }
] ]
// //
const selectOptions: SelectHttpType[] = [ const selectOptions: SelectHttpType[] = [
{ {
label: RequestHttpEnum.GET, label: RequestHttpEnum.GET,
value: RequestHttpEnum.GET, value: RequestHttpEnum.GET
}, },
{ {
label: RequestHttpEnum.POST, label: RequestHttpEnum.POST,
value: RequestHttpEnum.POST, value: RequestHttpEnum.POST
}, }
] ]
// //
const sendHandle = async () => { const sendHandle = async () => {
loading.value = true loading.value = true
if(!targetData.value) return
const { requestUrl, requestHttpType } = targetData.value.data const { requestUrl, requestHttpType } = targetData.value.data
if (!requestUrl) { if (!requestUrl) {
window['$message'].warning('请求参数不正确,请检查!') window['$message'].warning('请求参数不正确,请检查!')
@ -124,17 +124,26 @@ const sendHandle = async () => {
} }
const completePath = requestOriginUrl && requestOriginUrl.value + requestUrl const completePath = requestOriginUrl && requestOriginUrl.value + requestUrl
const res = await http(requestHttpType)(completePath || '', {}) const res = await http(requestHttpType)(completePath || '', {})
setTimeout(() => {
loading.value = false loading.value = false
if (res.status === ResultEnum.SUCCESS) { if (res.status === ResultEnum.SUCCESS) {
// @ts-ignore targetData.value.option.dataset = newFunctionHandle(res.data, targetData.value.filter)
targetData.value.option.dataset = res.data
showMatching.value = true showMatching.value = true
return return
} }
window['$message'].warning('数据异常,请检查接口数据!') window['$message'].warning('数据异常,请检查接口数据!')
}, 500)
} }
watchEffect(() => {
const filter = targetData.value?.filter
if (lastFilter !== filter) {
lastFilter = filter
sendHandle()
}
})
onBeforeUnmount(() => {
lastFilter = null
})
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>

View File

@ -1,6 +1,6 @@
<template> <template>
<n-timeline class="go-chart-configurations-timeline"> <n-timeline class="go-chart-configurations-timeline">
<n-timeline-item v-if="isCharts && dimensionsAndSource" type="info" :title="TimelineTitleEnum.MAPPING"> <n-timeline-item v-show="isCharts && dimensionsAndSource" type="info" :title="TimelineTitleEnum.MAPPING">
<n-table striped> <n-table striped>
<thead> <thead>
<tr> <tr>
@ -25,6 +25,12 @@
</tbody> </tbody>
</n-table> </n-table>
</n-timeline-item> </n-timeline-item>
<n-timeline-item v-show="filterShow" color="#97846c" :title="TimelineTitleEnum.FILTER">
<n-space vertical>
<n-text depth="3">点击{{ targetData.filter ? '「编辑」' : '「新增」' }}查看过滤规则</n-text>
<chart-data-monaco-editor></chart-data-monaco-editor>
</n-space>
</n-timeline-item>
<n-timeline-item type="success" :title="TimelineTitleEnum.CONTENT"> <n-timeline-item type="success" :title="TimelineTitleEnum.CONTENT">
<n-space vertical> <n-space vertical>
<n-text depth="3">ECharts 图表需符合 ECharts-setdata 数据规范</n-text> <n-text depth="3">ECharts 图表需符合 ECharts-setdata 数据规范</n-text>
@ -65,8 +71,8 @@
</n-tooltip> </n-tooltip>
</div> </div>
</n-space> </n-space>
<n-card> <n-card size="small">
<n-code :code="getSource" language="json"></n-code> <n-code :code="filterRes(source)" language="json"></n-code>
</n-card> </n-card>
</n-space> </n-space>
</n-timeline-item> </n-timeline-item>
@ -76,14 +82,22 @@
<script setup lang="ts"> <script setup lang="ts">
import { ref, computed, watch } from 'vue' import { ref, computed, watch } from 'vue'
import { CreateComponentType, PackagesCategoryEnum } from '@/packages/index.d' import { CreateComponentType, PackagesCategoryEnum } from '@/packages/index.d'
import { RequestDataTypeEnum } from '@/enums/httpEnum'
import { icon } from '@/plugins' import { icon } from '@/plugins'
import { DataResultEnum, TimelineTitleEnum } from '../../index.d' import { DataResultEnum, TimelineTitleEnum } from '../../index.d'
import { ChartDataMonacoEditor } from '../ChartDataMonacoEditor'
import { useFile } from '../../hooks/useFile.hooks' import { useFile } from '../../hooks/useFile.hooks'
import { useTargetData } from '../../../hooks/useTargetData.hook' import { useTargetData } from '../../../hooks/useTargetData.hook'
import isObject from 'lodash/isObject' import isObject from 'lodash/isObject'
const { targetData } = useTargetData() import cloneDeep from 'lodash/cloneDeep'
import { toString } from '@/utils'
const { targetData } = useTargetData()
const props = defineProps({ const props = defineProps({
show: {
type: Boolean,
required: false
},
ajax: { ajax: {
type: Boolean, type: Boolean,
required: true required: true
@ -102,16 +116,16 @@ const dimensionsAndSource = ref()
const { uploadFileListRef, customRequest, beforeUpload, download } = useFile(targetData) const { uploadFileListRef, customRequest, beforeUpload, download } = useFile(targetData)
//
const filterShow = computed(() => {
return targetData.value.data.requestDataType === RequestDataTypeEnum.AJAX
})
// //
const isCharts = computed(() => { const isCharts = computed(() => {
return targetData.value.chartConfig.package === PackagesCategoryEnum.CHARTS return targetData.value.chartConfig.package === PackagesCategoryEnum.CHARTS
}) })
//
const getSource = computed(() => {
return JSON.stringify(source.value)
})
// //
const matchingHandle = (mapping: string) => { const matchingHandle = (mapping: string) => {
let res = DataResultEnum.SUCCESS let res = DataResultEnum.SUCCESS
@ -129,15 +143,16 @@ const dimensionsAndSourceHandle = () => {
try { try {
// //
return dimensions.value.map((dimensionsItem: string, index: number) => { return dimensions.value.map((dimensionsItem: string, index: number) => {
return index === 0 ? return index === 0
{ ? {
// //
field: '通用标识', field: '通用标识',
// //
mapping: dimensionsItem, mapping: dimensionsItem,
// //
result: DataResultEnum.NULL result: DataResultEnum.NULL
} : { }
: {
field: `数据项-${index}`, field: `数据项-${index}`,
mapping: dimensionsItem, mapping: dimensionsItem,
result: matchingHandle(dimensionsItem) result: matchingHandle(dimensionsItem)
@ -148,13 +163,31 @@ const dimensionsAndSourceHandle = () => {
} }
} }
watch(() => targetData.value?.option?.dataset, (newData: { //
source: any, const filterRes = (data: any) => {
try {
if(targetData.value.filter) {
const fn = new Function('data', targetData.value.filter)
const res = fn(cloneDeep(data))
return toString(res)
}
return toString(cloneDeep(data))
} catch (error) {
return '过滤函数错误'
}
}
watch(
() => targetData.value?.option?.dataset,
(
newData: {
source: any
dimensions: any dimensions: any
} | null) => { } | null
) => {
if (newData && isObject(newData)) { if (newData && isObject(newData)) {
// Echarts // Echarts
source.value = isCharts.value ? newData.source : newData source.value = newData
if (isCharts.value) { if (isCharts.value) {
dimensions.value = newData.dimensions dimensions.value = newData.dimensions
dimensionsAndSource.value = dimensionsAndSourceHandle() dimensionsAndSource.value = dimensionsAndSourceHandle()
@ -163,13 +196,15 @@ watch(() => targetData.value?.option?.dataset, (newData: {
dimensionsAndSource.value = null dimensionsAndSource.value = null
source.value = newData source.value = newData
} }
}, { },
{
immediate: true immediate: true
}) }
)
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
@include go("chart-configurations-timeline") { @include go('chart-configurations-timeline') {
@include deep() { @include deep() {
pre { pre {
white-space: pre-wrap; white-space: pre-wrap;

View File

@ -0,0 +1,3 @@
import ChartDataMonacoEditor from './index.vue'
export { ChartDataMonacoEditor }

View File

@ -0,0 +1,217 @@
<template>
<template v-if="targetData.filter">
<n-card>
<p><span class="func-keyword">function</span>&nbsp;&nbsp;filter(data)&nbsp;&nbsp;{</p>
<!-- 函数体 -->
<div class="go-ml-4">
<n-code :code="targetData.filter" language="typescript"></n-code>
</div>
<p>}</p>
<template #footer>
<n-space justify="end">
<n-button tertiary size="small" @click="delFilter">
<template #icon>
<n-icon>
<trash-icon />
</n-icon>
</template>
删除
</n-button>
<n-button type="info" tertiary size="small" @click="addFilter">
<template #icon>
<n-icon>
<pencil-icon />
</n-icon>
</template>
编辑
</n-button>
</n-space>
</template>
</n-card>
</template>
<template v-else>
<n-space justify="space-around">
<n-button @click="addFilter">
<template #icon>
<n-icon>
<filter-icon />
</n-icon>
</template>
新增过滤器
</n-button>
</n-space>
</template>
<!-- 弹窗 -->
<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: 1000px; height: 600px">
<template #header>
<n-space>
<n-text>过滤器函数编辑器</n-text>
</n-space>
</template>
<template #header-extra> </template>
<n-space size="small" vertical>
<n-space justify="space-between">
<div>
<n-space vertical>
<n-tag type="info">
<span class="func-keyword">function</span>&nbsp;&nbsp;filter(data)&nbsp;&nbsp;{
</n-tag>
<monaco-editor v-model:modelValue="filter" width="460px" height="380px" language="javascript" />
<n-tag type="info">}</n-tag>
</n-space>
</div>
<n-divider vertical style="height: 480px" />
<n-scrollbar style="max-height: 480px">
<n-space :size="15" vertical>
<div class="editor-data-show">
<n-space>
<n-text depth="3">目标数据</n-text>
<n-code :code="toString(sourceData)" language="json" :word-wrap="true"></n-code>
</n-space>
</div>
<div class="editor-data-show">
<n-space>
<n-text depth="3">过滤器结果</n-text>
<n-code :code="filterRes" language="json" :word-wrap="true"></n-code>
</n-space>
</div>
</n-space>
</n-scrollbar>
</n-space>
</n-space>
<template #action>
<n-space justify="space-between">
<div class="go-flex-items-center">
<n-tag :bordered="false" type="success">
<template #icon>
<n-icon :component="DocumentTextIcon" />
</template>
规则
</n-tag>
<n-text class="go-ml-2" depth="2">过滤器将对接口返回值的data字段进行处理</n-text>
</div>
<n-space>
<n-button size="medium" @click="closeFilter">取消</n-button>
<n-button size="medium" type="primary" @click="saveFilter">保存</n-button>
</n-space>
</n-space>
</template>
</n-card>
</n-modal>
</template>
<script lang="ts" setup>
import { ref, computed, watch, toRefs } from 'vue'
import { MonacoEditor } from '@/components/Pages/MonacoEditor'
import { useTargetData } from '../../../hooks/useTargetData.hook'
import { RequestHttpEnum, RequestDataTypeEnum, ResultEnum } from '@/enums/httpEnum'
import { icon } from '@/plugins'
import { goDialog, toString } from '@/utils'
import { http } from '@/api/http'
import cloneDeep from 'lodash/cloneDeep'
const { PencilIcon, TrashIcon, FilterIcon, DocumentTextIcon } = icon.ionicons5
const { targetData, chartEditStore } = useTargetData()
const { requestDataType } = toRefs(targetData.value.data)
const { requestOriginUrl } = toRefs(chartEditStore.getRequestGlobalConfig)
//
const showModal = ref(false)
// filter
const filter = ref(targetData.value.filter || `return data`)
//
const errorFlag = ref(false)
// /
const sourceData = ref<any>('')
//
const fetchTargetData = async () => {
try {
const { requestUrl, requestHttpType } = targetData.value.data
if (!requestUrl) {
window['$message'].warning('请求参数不正确,请检查!')
sourceData.value = '请求参数不正确,请检查!'
return
}
const completePath = requestOriginUrl && requestOriginUrl.value + requestUrl
const res = await http(requestHttpType)(completePath || '', {})
if (res.status === ResultEnum.SUCCESS) {
sourceData.value = res.data
return
}
} catch (error) {
window['$message'].warning('数据异常,请检查接口数据!')
}
}
//
const filterRes = computed(() => {
try {
const fn = new Function('data', filter.value)
const res = fn(cloneDeep(sourceData.value))
errorFlag.value = false
return toString(res)
} catch (error) {
errorFlag.value = true
return '过滤函数错误'
}
})
//
const addFilter = () => {
showModal.value = true
}
//
const delFilter = () => {
goDialog({
message: '是否删除过滤器',
onPositiveCallback: () => {
targetData.value.filter = undefined
}
})
}
//
const closeFilter = () => {
showModal.value = false
}
//
const saveFilter = () => {
if (errorFlag.value) {
window['$message'].error('过滤函数错误,无法进行保存')
return
}
targetData.value.filter = filter.value
closeFilter()
}
watch(
() => showModal.value,
(newData: boolean) => {
if (newData) fetchTargetData()
}
)
</script>
<style lang="scss" scoped>
.func-keyword {
color: #b478cf;
}
@include go('chart-data-monaco-editor') {
&.n-card.n-modal,
.n-card {
@extend .go-background-filter;
}
.editor-data-show {
@include fetch-bg-color('filter-color');
width: 420px;
padding: 20px;
border-radius: 5px;
}
}
</style>

View File

@ -1,6 +1,6 @@
<template> <template>
<div class="go-chart-configurations-data-static"> <div class="go-chart-configurations-data-static">
<chart-data-matching-and-show :ajax="false"></chart-data-matching-and-show> <chart-data-matching-and-show :show="false" :ajax="false"></chart-data-matching-and-show>
</div> </div>
</template> </template>

View File

@ -8,6 +8,7 @@ export enum DataResultEnum {
} }
export enum TimelineTitleEnum { export enum TimelineTitleEnum {
FILTER = '数据过滤',
MAPPING = '数据映射', MAPPING = '数据映射',
CONTENT = '数据内容', CONTENT = '数据内容',
} }

View File

@ -43,7 +43,7 @@
:style="{ :style="{
...useSizeStyle(item.attr), ...useSizeStyle(item.attr),
...getFilterStyle(item.styles), ...getFilterStyle(item.styles),
...getTranstormStyle(item.styles), ...getTransformStyle(item.styles),
}" }"
></component> ></component>
</edit-shape-box> </edit-shape-box>
@ -66,7 +66,7 @@
<script lang="ts" setup> <script lang="ts" setup>
import { onMounted, computed } from 'vue' import { onMounted, computed } from 'vue'
import { chartColors } from '@/settings/chartThemes/index' import { chartColors } from '@/settings/chartThemes/index'
import { animationsClass, getFilterStyle, getTranstormStyle } from '@/utils' import { animationsClass, getFilterStyle, getTransformStyle } from '@/utils'
import { useContextMenu } from '@/views/chart/hooks/useContextMenu.hook' import { useContextMenu } from '@/views/chart/hooks/useContextMenu.hook'
import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore' import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore'

View File

@ -7,7 +7,7 @@
:style="{ :style="{
...getComponentAttrStyle(item.attr, index), ...getComponentAttrStyle(item.attr, index),
...getFilterStyle(item.styles), ...getFilterStyle(item.styles),
...getTranstormStyle(item.styles) ...getTransformStyle(item.styles)
}" }"
> >
<component <component
@ -24,7 +24,7 @@
import { PropType, computed } from 'vue' import { PropType, computed } from 'vue'
import { ChartEditStorageType } from '../../index.d' import { ChartEditStorageType } from '../../index.d'
import { chartColors } from '@/settings/chartThemes/index' import { chartColors } from '@/settings/chartThemes/index'
import { animationsClass, getFilterStyle, getTranstormStyle } from '@/utils' import { animationsClass, getFilterStyle, getTransformStyle } from '@/utils'
import { getSizeStyle, getComponentAttrStyle } from '../../utils' import { getSizeStyle, getComponentAttrStyle } from '../../utils'
const props = defineProps({ const props = defineProps({

View File

@ -3,7 +3,8 @@ import vue from '@vitejs/plugin-vue'
import { resolve } from 'path' import { resolve } from 'path'
import { OUTPUT_DIR, brotliSize, chunkSizeWarningLimit, terserOptions, rollupOptions } from './build/constant' import { OUTPUT_DIR, brotliSize, chunkSizeWarningLimit, terserOptions, rollupOptions } from './build/constant'
import viteCompression from 'vite-plugin-compression' import viteCompression from 'vite-plugin-compression'
import { viteMockServe} from "vite-plugin-mock"; import { viteMockServe } from 'vite-plugin-mock'
import monacoEditorPlugin from 'vite-plugin-monaco-editor'
function pathResolve(dir: string) { function pathResolve(dir: string) {
return resolve(process.cwd(), '.', dir) return resolve(process.cwd(), '.', dir)
@ -36,8 +37,11 @@ export default defineConfig({
}, },
plugins: [ plugins: [
vue(), vue(),
monacoEditorPlugin({
languageWorkers: ['editorWorkerService', 'typescript', 'json']
}),
viteMockServe({ viteMockServe({
mockPath: "/src/api/mock", mockPath: '/src/api/mock',
// 开发打包开关 // 开发打包开关
localEnabled: true, localEnabled: true,
// 生产打包开关 // 生产打包开关
@ -45,7 +49,7 @@ export default defineConfig({
// 打开后,可以读取 ts 文件模块。 请注意,打开后将无法监视.js 文件 // 打开后,可以读取 ts 文件模块。 请注意,打开后将无法监视.js 文件
supportTs: true, supportTs: true,
// 监视文件更改 // 监视文件更改
watchFiles: true, watchFiles: true
}), }),
// 压缩 // 压缩
viteCompression({ viteCompression({