From 8ee18819c5218b2827424de6bcec66800156a659 Mon Sep 17 00:00:00 2001 From: mtruning <1262327911@qq.com> Date: Sat, 19 Mar 2022 23:28:33 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E6=A0=A1=E9=AA=8C=EF=BC=8C=E6=95=B0=E6=8D=AE=E5=AF=BC=E5=85=A5?= =?UTF-8?q?=E5=AF=BC=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/GoSkeleton/index.vue | 16 +- src/enums/fileTypeEnum.ts | 10 + .../Charts/Bars/BarCommon/config.ts | 4 +- .../Charts/Bars/BarCommon/index.vue | 3 +- src/plugins/icon.ts | 10 +- src/plugins/naive.ts | 2 + .../chartEditStore/chartEditStore.d.ts | 14 +- src/utils/file.ts | 43 ++++ src/utils/index.ts | 3 +- .../components/ChartData/index.d.ts | 19 ++ .../components/ChartData/index.vue | 212 +++++++++++++----- 11 files changed, 270 insertions(+), 66 deletions(-) create mode 100644 src/enums/fileTypeEnum.ts create mode 100644 src/utils/file.ts create mode 100644 src/views/chart/ContentConfigurations/components/ChartData/index.d.ts diff --git a/src/components/GoSkeleton/index.vue b/src/components/GoSkeleton/index.vue index 2d4b454b..3e3826da 100644 --- a/src/components/GoSkeleton/index.vue +++ b/src/components/GoSkeleton/index.vue @@ -1,16 +1,16 @@ @@ -27,3 +27,11 @@ defineProps({ } }) + + \ No newline at end of file diff --git a/src/enums/fileTypeEnum.ts b/src/enums/fileTypeEnum.ts new file mode 100644 index 00000000..bbc50db4 --- /dev/null +++ b/src/enums/fileTypeEnum.ts @@ -0,0 +1,10 @@ +// 文件上传时的格式映射 +export enum FileTypeEnum { + // 文档 + TXT = 'text/plain', + JSON = 'application/json', + // 图片 + PNG = 'image/png', + JPEG = 'image/jpeg', + GIF = 'image/gif', +} diff --git a/src/packages/components/Charts/Bars/BarCommon/config.ts b/src/packages/components/Charts/Bars/BarCommon/config.ts index fc8ca4ff..ac6272dd 100644 --- a/src/packages/components/Charts/Bars/BarCommon/config.ts +++ b/src/packages/components/Charts/Bars/BarCommon/config.ts @@ -2,8 +2,9 @@ import { echartOptionProfixHandle, publicConfig } from '@/packages/public' import { BarCommonConfig } from './index' import { CreateComponentType } from '@/packages/index.d' import cloneDeep from 'lodash/cloneDeep' +import dataJson from './data.json' -export const includes = ['legend', 'xAxis', 'yAxis', 'dataset'] +export const includes = ['legend', 'xAxis', 'yAxis'] export const option = { tooltip: { @@ -25,6 +26,7 @@ export const option = { show: true, type: 'value' }, + dataset: { ...dataJson }, series: [ { type: 'bar', diff --git a/src/packages/components/Charts/Bars/BarCommon/index.vue b/src/packages/components/Charts/Bars/BarCommon/index.vue index a76e9aef..caa3bde3 100644 --- a/src/packages/components/Charts/Bars/BarCommon/index.vue +++ b/src/packages/components/Charts/Bars/BarCommon/index.vue @@ -43,6 +43,7 @@ use([ ]) const option = computed(() => { - return setData(mergeTheme(props.chartConfig.option, props.themeSetting, includes), dataJson) + // TODO dataset的数据要设计一下,不能这样把数据进行监听,太耗性能 + return mergeTheme(props.chartConfig.option, props.themeSetting, includes) }) diff --git a/src/plugins/icon.ts b/src/plugins/icon.ts index 3f163953..5239db98 100644 --- a/src/plugins/icon.ts +++ b/src/plugins/icon.ts @@ -69,7 +69,9 @@ import { AlignVerticalTop as AlignVerticalTopIcon, AlignHorizontalCenter as AlignHorizontalCenterIcon, AlignHorizontalRight as AlignHorizontalRightIcon, - AlignVerticalBottom as AlignVerticalBottomIcon + AlignVerticalBottom as AlignVerticalBottomIcon, + DocumentAdd as DocumentAddIcon, + DocumentDownload as DocumentDownloadIcon, } from '@vicons/carbon' const ionicons5 = { @@ -205,7 +207,11 @@ const carbon = { AlignVerticalTopIcon, AlignHorizontalCenterIcon, AlignHorizontalRightIcon, - AlignVerticalBottomIcon + AlignVerticalBottomIcon, + // 添加文件 + DocumentAddIcon, + // 下载文件 + DocumentDownloadIcon } // https://www.xicons.org/#/ 还有很多 diff --git a/src/plugins/naive.ts b/src/plugins/naive.ts index 3a5949e3..8fc203a2 100644 --- a/src/plugins/naive.ts +++ b/src/plugins/naive.ts @@ -7,6 +7,7 @@ import { NH2, NH3, NH4, + NCode, NText, NTime, NEllipsis, @@ -101,6 +102,7 @@ const naive = create({ NH2, NH3, NH4, + NCode, NText, NTime, NEllipsis, diff --git a/src/store/modules/chartEditStore/chartEditStore.d.ts b/src/store/modules/chartEditStore/chartEditStore.d.ts index 12b65527..50fbc8e8 100644 --- a/src/store/modules/chartEditStore/chartEditStore.d.ts +++ b/src/store/modules/chartEditStore/chartEditStore.d.ts @@ -2,7 +2,7 @@ import { CreateComponentType } from '@/packages/index.d' import { HistoryActionTypeEnum } from '@/store/modules/chartHistoryStore/chartHistoryStore.d' import type { ChartColorsNameType, - GlobalThemeJsonType + GlobalThemeJsonType, } from '@/settings/chartThemes/index' // 编辑画布属性 @@ -13,7 +13,7 @@ export enum EditCanvasTypeEnum { SCALE = 'scale', USER_SCALE = 'userScale', LOCK_SCALE = 'lockScale', - IS_DRAG = 'isDrag' + IS_DRAG = 'isDrag', } // 编辑区域 @@ -46,7 +46,7 @@ export enum EditCanvasConfigEnum { CHART_THEME_SETTING = 'chartThemeSetting', BACKGROUND = 'background', BACKGROUND_IAMGE = 'backgroundImage', - SELECT_COLOR = 'selectColor' + SELECT_COLOR = 'selectColor', } export interface EditCanvasConfigType { @@ -80,7 +80,7 @@ export enum EditCanvasTypeEnum { START_X = 'startX', START_Y = 'startY', X = 'x', - Y = 'y' + Y = 'y', } // 鼠标位置 @@ -118,15 +118,15 @@ export enum ChartEditStoreEnum { // 以下需要存储 EDIT_CANVAS_CONFIG = 'editCanvasConfig', REQUEST_CONFIG = 'requestConfig', - COMPONENT_LIST = 'componentList' + COMPONENT_LIST = 'componentList', } // 数据相关 export enum RequestDataTypeEnum { // 静态数据 - STATIC, + STATIC = 0, // 请求数据 - AJAX + AJAX = 1, } // 数据配置 diff --git a/src/utils/file.ts b/src/utils/file.ts new file mode 100644 index 00000000..1967dfee --- /dev/null +++ b/src/utils/file.ts @@ -0,0 +1,43 @@ +/** + * *获取上传的文件数据 + * @param { File } file 文件对象 + */ +export const readFile = (file: File) => { + return new Promise((resolve: Function) => { + try { + const reader = new FileReader() + reader.onload = (evt: ProgressEvent) => { + if (evt.target) { + resolve(evt.target.result) + } + } + reader.readAsText(file) + } catch (error) { + window['$message'].error('文件读取失败!') + } + }) +} + +/** + * 下载数据 + * @param { string } content 数据内容 + * @param { ?string } filename 文件名称(默认随机字符) + * @param { ?string } fileSuffix 文件名称(默认随机字符) + */ +export const downloadFile = ( + content: string, + filename = new Date().getDate().toString(), + fileSuffix?: string +) => { + const ele = document.createElement('a') // 创建下载链接 + ele.download = `${filename}.${fileSuffix}` //设置下载的名称 + ele.style.display = 'none' // 隐藏的可下载链接 + // 字符内容转变成blob地址 + const blob = new Blob([content]) + ele.href = URL.createObjectURL(blob) + // 绑定点击时间 + document.body.appendChild(ele) + ele.click() + // 然后移除 + document.body.removeChild(ele) +} diff --git a/src/utils/index.ts b/src/utils/index.ts index dce187b9..fa9fa055 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -5,4 +5,5 @@ export * from '@/utils/storage' export * from '@/utils/style' export * from '@/utils/plugin' export * from '@/utils/componets' -export * from '@/utils/type' \ No newline at end of file +export * from '@/utils/type' +export * from '@/utils/file' diff --git a/src/views/chart/ContentConfigurations/components/ChartData/index.d.ts b/src/views/chart/ContentConfigurations/components/ChartData/index.d.ts new file mode 100644 index 00000000..c0c9908f --- /dev/null +++ b/src/views/chart/ContentConfigurations/components/ChartData/index.d.ts @@ -0,0 +1,19 @@ +import { RequestDataTypeEnum } from '@/store/modules/chartEditStore/chartEditStore.d' + +// 匹配结果 +export enum DataResultEnum { + NULL = 0, + SUCCESS = 1, + FAILURE = 2, +} + +export enum SelcetOptionsLableEnum { + STATIC = '静态数据', + AJAX = '动态请求', +} + +export interface SelectOptionsType { + label: SelcetOptionsLableEnum + value: RequestDataTypeEnum + disabled?: boolean +} diff --git a/src/views/chart/ContentConfigurations/components/ChartData/index.vue b/src/views/chart/ContentConfigurations/components/ChartData/index.vue index 749b6ad7..7db9a4f5 100644 --- a/src/views/chart/ContentConfigurations/components/ChartData/index.vue +++ b/src/views/chart/ContentConfigurations/components/ChartData/index.vue @@ -1,33 +1,33 @@ - + +