Commit fc088fa340bd9d73396e9e6c8dbf19e2b2fb4df8
1 parent
8a9d9091
perf(src/packages): 重新图表更多里的自定义native-ui进度,修改绑定数值未改变问题
Showing
5 changed files
with
217 additions
and
0 deletions
| 1 | +import { PublicConfigClass } from '@/packages/public' | |
| 2 | +import { CreateComponentType } from '@/packages/index.d' | |
| 3 | +import { OverrideProcessConfig } from './index' | |
| 4 | +import { chartInitConfig } from '@/settings/designSetting' | |
| 5 | +import cloneDeep from 'lodash/cloneDeep' | |
| 6 | + | |
| 7 | + | |
| 8 | +export const types = [ | |
| 9 | + { | |
| 10 | + label: '线形', | |
| 11 | + value: 'line' | |
| 12 | + }, | |
| 13 | + { | |
| 14 | + label: '圆形', | |
| 15 | + value: 'circle' | |
| 16 | + }, | |
| 17 | + { | |
| 18 | + label: '仪表盘', | |
| 19 | + value: 'dashboard' | |
| 20 | + }, | |
| 21 | +] | |
| 22 | + | |
| 23 | +export const indicatorPlacements = [ | |
| 24 | + { | |
| 25 | + label: '内部', | |
| 26 | + value: 'inside' | |
| 27 | + }, | |
| 28 | + { | |
| 29 | + label: '外部', | |
| 30 | + value: 'outside' | |
| 31 | + } | |
| 32 | +] | |
| 33 | + | |
| 34 | +export const option = { | |
| 35 | + dataset: 36, | |
| 36 | + // 默认类型 | |
| 37 | + type: types[2].value, | |
| 38 | + // 进行时效果 | |
| 39 | + processing: true, | |
| 40 | + // 主颜色 | |
| 41 | + color: '#4992FFFF', | |
| 42 | + // 轨道颜色 | |
| 43 | + railColor: '#3e3e3f', | |
| 44 | + // 指标 | |
| 45 | + unit: '%', | |
| 46 | + // 指标大小 | |
| 47 | + indicatorTextSize: 34, | |
| 48 | + // 指标位置(线条时可用) | |
| 49 | + indicatorPlacement: 'outside', | |
| 50 | + // 指标颜色 | |
| 51 | + indicatorTextColor: '#FFFFFFFF', | |
| 52 | + // 偏移角度 | |
| 53 | + offsetDegree: 0 | |
| 54 | +} | |
| 55 | + | |
| 56 | +export default class Config extends PublicConfigClass implements CreateComponentType { | |
| 57 | + public key = OverrideProcessConfig.key | |
| 58 | + public attr = { ...chartInitConfig, h: 500, zIndex: -1 } | |
| 59 | + public chartConfig = cloneDeep(OverrideProcessConfig) | |
| 60 | + public option = cloneDeep(option) | |
| 61 | +} | |
| \ No newline at end of file | ... | ... |
| 1 | +<template> | |
| 2 | + <!-- 默认展开 --> | |
| 3 | + <CollapseItem name="进度条" :expanded="true"> | |
| 4 | + <SettingItemBox name="内容"> | |
| 5 | + <SettingItem name="数值"> | |
| 6 | + <!-- 与 config.ts 里的 option 对应 --><!-- n-input-number 是 NaiveUI 的控件 --> | |
| 7 | + <n-input-number v-model:value="optionData.dataset" size="small" :min="0" placeholder="进度值"></n-input-number> | |
| 8 | + </SettingItem> | |
| 9 | + <setting-item name="单位"> | |
| 10 | + <n-input v-model:value="optionData.unit" size="small"></n-input> | |
| 11 | + </setting-item> | |
| 12 | + </SettingItemBox> | |
| 13 | + | |
| 14 | + <SettingItemBox name="轨道"> | |
| 15 | + <SettingItem name="形状"> | |
| 16 | + <n-select v-model:value="optionData.type" :options="types" placeholder="选择形状" /> | |
| 17 | + </SettingItem> | |
| 18 | + | |
| 19 | + <!-- 颜色粗细等等... --> | |
| 20 | + <SettingItem name="进度条颜色"> | |
| 21 | + <n-color-picker size="small" :modes="['hex']" v-model:value="optionData.color"></n-color-picker> | |
| 22 | + </SettingItem> | |
| 23 | + <SettingItem name="轨道颜色"> | |
| 24 | + <n-color-picker size="small" :modes="['hex']" v-model:value="optionData.railColor"></n-color-picker> | |
| 25 | + </SettingItem> | |
| 26 | + <setting-item name="偏移角度" v-if="optionData.type !== types[0].value"> | |
| 27 | + <n-input-number v-model:value="optionData.offsetDegree" size="small"></n-input-number> | |
| 28 | + </setting-item> | |
| 29 | + <SettingItem v-if="optionData.type == types[0].value"> | |
| 30 | + <n-space> | |
| 31 | + <n-switch v-model:value="optionData.processing" size="small" /> | |
| 32 | + <n-text>进行时动画</n-text> | |
| 33 | + </n-space> | |
| 34 | + </SettingItem> | |
| 35 | + </SettingItemBox> | |
| 36 | + | |
| 37 | + <SettingItemBox name="指标"> | |
| 38 | + <SettingItem name="位置" v-if="optionData.type == types[0].value"> | |
| 39 | + <n-select v-model:value="optionData.indicatorPlacement" :options="indicatorPlacements" placeholder="选择形状" /> | |
| 40 | + </SettingItem> | |
| 41 | + <SettingItem name="文本颜色"> | |
| 42 | + <n-color-picker size="small" :modes="['hex']" v-model:value="optionData.indicatorTextColor"></n-color-picker> | |
| 43 | + </SettingItem> | |
| 44 | + <setting-item name="文本大小"> | |
| 45 | + <n-input-number v-model:value="optionData.indicatorTextSize" size="small"></n-input-number> | |
| 46 | + </setting-item> | |
| 47 | + </SettingItemBox> | |
| 48 | + </CollapseItem> | |
| 49 | +</template> | |
| 50 | + | |
| 51 | +<script setup lang="ts"> | |
| 52 | +import { PropType } from 'vue' | |
| 53 | +// 以下是封装的设置模块布局组件,具体效果可在官网查看 | |
| 54 | +import { CollapseItem, SettingItemBox, SettingItem } from '@/components/Pages/ChartItemSetting' | |
| 55 | + | |
| 56 | +// 获取 option 的数据,便于使用 typeof 获取类型 | |
| 57 | +import { option, types, indicatorPlacements } from './config' | |
| 58 | + | |
| 59 | +defineProps({ | |
| 60 | + optionData: { | |
| 61 | + type: Object as PropType<typeof option>, | |
| 62 | + required: true | |
| 63 | + } | |
| 64 | +}) | |
| 65 | +</script> | ... | ... |
| 1 | + | |
| 2 | + | |
| 3 | +import { ConfigType, PackagesCategoryEnum, ChartFrameEnum } from '@/packages/index.d' | |
| 4 | +import { ChatCategoryEnum, ChatCategoryEnumName } from '@/packages/components/Charts/index.d' | |
| 5 | +import { useWidgetKey } from '@/packages/external/useWidgetKey' | |
| 6 | + | |
| 7 | +const { key, conKey, chartKey } = useWidgetKey('OverrideProcess', true) | |
| 8 | + | |
| 9 | +export const OverrideProcessConfig: ConfigType = { | |
| 10 | + key, | |
| 11 | + chartKey, | |
| 12 | + conKey, | |
| 13 | + title: '自定义NaiveUI-进度', | |
| 14 | + category: ChatCategoryEnum.MORE, | |
| 15 | + categoryName: ChatCategoryEnumName.MORE, | |
| 16 | + package: PackagesCategoryEnum.CHARTS, | |
| 17 | + chartFrame: ChartFrameEnum.ECHARTS, | |
| 18 | + image: 'process.png' | |
| 19 | +} | ... | ... |
| 1 | +<template> | |
| 2 | + <n-progress | |
| 3 | + :type="type" | |
| 4 | + :height="h" | |
| 5 | + :processing="processing" | |
| 6 | + :percentage="dataset" | |
| 7 | + :indicator-placement="indicatorPlacement" | |
| 8 | + :color="color" | |
| 9 | + :rail-color="railColor" | |
| 10 | + :offset-degree="offsetDegree" | |
| 11 | + > | |
| 12 | + <n-text | |
| 13 | + :style="{ | |
| 14 | + color: indicatorTextColor, | |
| 15 | + fontSize: `${indicatorTextSize}px` | |
| 16 | + }" | |
| 17 | + > | |
| 18 | + {{ dataset }} {{ unit }} | |
| 19 | + </n-text> | |
| 20 | + </n-progress> | |
| 21 | +</template> | |
| 22 | + | |
| 23 | +<script setup lang="ts"> | |
| 24 | +import { PropType, toRefs, watch } from 'vue' | |
| 25 | +import { useChartDataFetch } from '@/hooks' | |
| 26 | +import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore' | |
| 27 | +import config from './config' | |
| 28 | +import { toNumber } from '@/utils' | |
| 29 | + | |
| 30 | +const props = defineProps({ | |
| 31 | + chartConfig: { | |
| 32 | + type: Object as PropType<config>, | |
| 33 | + required: true | |
| 34 | + } | |
| 35 | +}) | |
| 36 | + | |
| 37 | +// 取配置数据 | |
| 38 | +const { w, h } = toRefs(props.chartConfig.attr) | |
| 39 | +const { | |
| 40 | + type, | |
| 41 | + unit, | |
| 42 | + color, | |
| 43 | + processing, | |
| 44 | + railColor, | |
| 45 | + indicatorTextColor, | |
| 46 | + indicatorPlacement, | |
| 47 | + indicatorTextSize, | |
| 48 | + offsetDegree, | |
| 49 | + dataset | |
| 50 | +} = toRefs(props.chartConfig.option) | |
| 51 | + | |
| 52 | +// 手动更新 | |
| 53 | +watch( | |
| 54 | + () => props.chartConfig.option.dataset, | |
| 55 | + (newData: any) => { | |
| 56 | + try { | |
| 57 | + dataset.value = toNumber(newData, 2) | |
| 58 | + } catch (error) { | |
| 59 | + console.log(error) | |
| 60 | + } | |
| 61 | + }, | |
| 62 | + { | |
| 63 | + deep: false | |
| 64 | + } | |
| 65 | +) | |
| 66 | +// 预览更新 | |
| 67 | +useChartDataFetch(props.chartConfig, useChartEditStore, (newData: number) => { | |
| 68 | + dataset.value = toNumber(newData, 2) | |
| 69 | +}) | |
| 70 | +</script> | ... | ... |
| ... | ... | @@ -16,6 +16,7 @@ import { OverrideTextGradientConfig } from '@/packages/components/external/Infor |
| 16 | 16 | import { OverrideBarCommonConfig } from '@/packages/components/external/Charts/Bars/OverrideBarCommon' |
| 17 | 17 | import { OverrideLineCommonConfig } from '@/packages/components/external/Charts/Lines/OverrideLineCommon' |
| 18 | 18 | import { OverrideLineGradientsConfig } from '@/packages/components/external/Charts/Lines/OverrideLineGradients' |
| 19 | +import { OverrideProcessConfig } from '@/packages/components/external/Charts/Mores/OverrideProcess' | |
| 19 | 20 | |
| 20 | 21 | export function useInjectLib(packagesList: EPackagesType) { |
| 21 | 22 | packagesList[EPackagesCategoryEnum.COMPOSES] = ComposesList |
| ... | ... | @@ -35,6 +36,7 @@ export function useInjectLib(packagesList: EPackagesType) { |
| 35 | 36 | addWidgetToCategoryByCategoryName(packagesList, PackagesCategoryEnum.CHARTS, OverrideBarCommonConfig) |
| 36 | 37 | addWidgetToCategoryByCategoryName(packagesList, PackagesCategoryEnum.CHARTS, OverrideLineCommonConfig) |
| 37 | 38 | addWidgetToCategoryByCategoryName(packagesList, PackagesCategoryEnum.CHARTS, OverrideLineGradientsConfig) |
| 39 | + addWidgetToCategoryByCategoryName(packagesList, PackagesCategoryEnum.CHARTS, OverrideProcessConfig) | |
| 38 | 40 | } |
| 39 | 41 | |
| 40 | 42 | /** | ... | ... |