Commit 87ea8d38b0a90643d15c4a80facf945aa5ca393d
1 parent
1dde260d
feat(packages/external): 信息下自定义文字新增跳转方式选择
Showing
5 changed files
with
319 additions
and
0 deletions
| 1 | +import { PublicConfigClass } from '@/packages/public' | ||
| 2 | +import { CreateComponentType } from '@/packages/index.d' | ||
| 3 | +import { OverrideTextCommonConfig } from './index' | ||
| 4 | +import cloneDeep from 'lodash/cloneDeep' | ||
| 5 | + | ||
| 6 | +export enum WritingModeEnum { | ||
| 7 | + HORIZONTAL = '水平', | ||
| 8 | + VERTICAL = '垂直' | ||
| 9 | +} | ||
| 10 | + | ||
| 11 | +export const WritingModeObject = { | ||
| 12 | + [WritingModeEnum.HORIZONTAL]: 'horizontal-tb', | ||
| 13 | + [WritingModeEnum.VERTICAL]: 'vertical-rl' | ||
| 14 | +} | ||
| 15 | + | ||
| 16 | +export enum FontWeightEnum { | ||
| 17 | + NORMAL = '常规', | ||
| 18 | + BOLD = '加粗' | ||
| 19 | +} | ||
| 20 | + | ||
| 21 | +export const FontWeightObject = { | ||
| 22 | + [FontWeightEnum.NORMAL]: 'normal', | ||
| 23 | + [FontWeightEnum.BOLD]: 'bold' | ||
| 24 | +} | ||
| 25 | + | ||
| 26 | +export const option = { | ||
| 27 | + link: '', | ||
| 28 | + linkHead: 'http://', | ||
| 29 | + dataset: '我是文本', | ||
| 30 | + fontSize: 20, | ||
| 31 | + fontColor: '#ffffff', | ||
| 32 | + paddingX: 10, | ||
| 33 | + paddingY: 10, | ||
| 34 | + textAlign: 'center', // 水平对齐方式 | ||
| 35 | + fontWeight: 'normal', | ||
| 36 | + | ||
| 37 | + // 边框 | ||
| 38 | + borderWidth: 0, | ||
| 39 | + borderColor: '#ffffff', | ||
| 40 | + borderRadius: 5, | ||
| 41 | + | ||
| 42 | + // 字间距 | ||
| 43 | + letterSpacing: 5, | ||
| 44 | + writingMode: 'horizontal-tb', | ||
| 45 | + backgroundColor: '#00000000', | ||
| 46 | + | ||
| 47 | + //跳转方式 | ||
| 48 | + linkMethod: 'default' | ||
| 49 | +} | ||
| 50 | + | ||
| 51 | +export default class Config extends PublicConfigClass implements CreateComponentType { | ||
| 52 | + public key = OverrideTextCommonConfig.key | ||
| 53 | + public chartConfig = cloneDeep(OverrideTextCommonConfig) | ||
| 54 | + public option = cloneDeep(option) | ||
| 55 | +} |
| 1 | +<template> | ||
| 2 | + <collapse-item name="信息" :expanded="true"> | ||
| 3 | + <setting-item-box name="文字" :alone="true"> | ||
| 4 | + <setting-item> | ||
| 5 | + <n-input v-model:value="optionData.dataset" size="small"></n-input> | ||
| 6 | + </setting-item> | ||
| 7 | + </setting-item-box> | ||
| 8 | + <setting-item-box name="链接" :alone="true"> | ||
| 9 | + <setting-item> | ||
| 10 | + <n-input-group> | ||
| 11 | + <n-select | ||
| 12 | + v-model:value="optionData.linkHead" | ||
| 13 | + size="small" | ||
| 14 | + :style="{ width: '80%' }" | ||
| 15 | + :options="linkHeadOptions" | ||
| 16 | + /> | ||
| 17 | + <n-input v-model:value="optionData.link" size="small"></n-input> | ||
| 18 | + </n-input-group> | ||
| 19 | + </setting-item> | ||
| 20 | + </setting-item-box> | ||
| 21 | + <setting-item-box name="跳转方式" :alone="true"> | ||
| 22 | + <setting-item> | ||
| 23 | + <n-input-group> | ||
| 24 | + <n-select | ||
| 25 | + v-model:value="optionData.linkMethod" | ||
| 26 | + size="small" | ||
| 27 | + :style="{ width: '80%' }" | ||
| 28 | + :options="linkMethodOptions" | ||
| 29 | + /> | ||
| 30 | + <n-button | ||
| 31 | + :disabled="!optionData.linkMethod" | ||
| 32 | + secondary | ||
| 33 | + size="small" | ||
| 34 | + @click="handleLinkClick(optionData.linkMethod)" | ||
| 35 | + >跳转</n-button | ||
| 36 | + > | ||
| 37 | + </n-input-group> | ||
| 38 | + </setting-item> | ||
| 39 | + </setting-item-box> | ||
| 40 | + </collapse-item> | ||
| 41 | + | ||
| 42 | + <collapse-item name="样式" :expanded="true"> | ||
| 43 | + <setting-item-box name="文字"> | ||
| 44 | + <setting-item name="颜色"> | ||
| 45 | + <n-color-picker size="small" :modes="['hex']" v-model:value="optionData.fontColor"></n-color-picker> | ||
| 46 | + </setting-item> | ||
| 47 | + <setting-item name="字体大小"> | ||
| 48 | + <n-input-number v-model:value="optionData.fontSize" size="small" placeholder="字体大小"></n-input-number> | ||
| 49 | + </setting-item> | ||
| 50 | + <setting-item name="字体粗细"> | ||
| 51 | + <n-select v-model:value="optionData.fontWeight" size="small" :options="fontWeightOptions" /> | ||
| 52 | + </setting-item> | ||
| 53 | + <setting-item name="X轴内边距"> | ||
| 54 | + <n-input-number v-model:value="optionData.paddingX" size="small" placeholder="输入内边距"></n-input-number> | ||
| 55 | + </setting-item> | ||
| 56 | + <setting-item name="Y轴内边距"> | ||
| 57 | + <n-input-number v-model:value="optionData.paddingY" size="small" placeholder="输入内边距"></n-input-number> | ||
| 58 | + </setting-item> | ||
| 59 | + | ||
| 60 | + <setting-item name="水平对齐"> | ||
| 61 | + <n-select v-model:value="optionData.textAlign" size="small" :options="textAlignOptions" /> | ||
| 62 | + </setting-item> | ||
| 63 | + <setting-item name="文本方向"> | ||
| 64 | + <n-select v-model:value="optionData.writingMode" size="small" :options="verticalOptions" /> | ||
| 65 | + </setting-item> | ||
| 66 | + | ||
| 67 | + <setting-item name="字间距"> | ||
| 68 | + <n-input-number v-model:value="optionData.letterSpacing" size="small" placeholder="输入字间距"></n-input-number> | ||
| 69 | + </setting-item> | ||
| 70 | + </setting-item-box> | ||
| 71 | + | ||
| 72 | + <setting-item-box name="边框"> | ||
| 73 | + <setting-item name="宽度"> | ||
| 74 | + <n-input-number | ||
| 75 | + v-model:value="optionData.borderWidth" | ||
| 76 | + size="small" | ||
| 77 | + :min="0" | ||
| 78 | + placeholder="宽度" | ||
| 79 | + ></n-input-number> | ||
| 80 | + </setting-item> | ||
| 81 | + <setting-item name="颜色"> | ||
| 82 | + <n-color-picker size="small" :modes="['hex']" v-model:value="optionData.borderColor"></n-color-picker> | ||
| 83 | + </setting-item> | ||
| 84 | + <setting-item name="圆角"> | ||
| 85 | + <n-input-number | ||
| 86 | + v-model:value="optionData.borderRadius" | ||
| 87 | + size="small" | ||
| 88 | + :min="0" | ||
| 89 | + placeholder="圆角" | ||
| 90 | + ></n-input-number> | ||
| 91 | + </setting-item> | ||
| 92 | + </setting-item-box> | ||
| 93 | + | ||
| 94 | + <setting-item-box name="背景" :alone="true"> | ||
| 95 | + <setting-item name="背景颜色"> | ||
| 96 | + <n-color-picker size="small" :modes="['hex']" v-model:value="optionData.backgroundColor"></n-color-picker> | ||
| 97 | + </setting-item> | ||
| 98 | + </setting-item-box> | ||
| 99 | + </collapse-item> | ||
| 100 | +</template> | ||
| 101 | + | ||
| 102 | +<script setup lang="ts"> | ||
| 103 | +import { PropType } from 'vue' | ||
| 104 | +import { option, WritingModeEnum, WritingModeObject, FontWeightEnum, FontWeightObject } from './config' | ||
| 105 | +import { CollapseItem, SettingItemBox, SettingItem } from '@/components/Pages/ChartItemSetting' | ||
| 106 | +const props = defineProps({ | ||
| 107 | + optionData: { | ||
| 108 | + type: Object as PropType<typeof option>, | ||
| 109 | + required: true | ||
| 110 | + } | ||
| 111 | +}) | ||
| 112 | + | ||
| 113 | +const textAlignOptions = [ | ||
| 114 | + { label: '左对齐', value: 'start' }, | ||
| 115 | + { label: '居中', value: 'center' }, | ||
| 116 | + { label: '右对齐', value: 'end' } | ||
| 117 | +] | ||
| 118 | + | ||
| 119 | +const linkMethodOptions = [ | ||
| 120 | + { label: '默认', value: 'default' }, | ||
| 121 | + { label: '新开窗口', value: 'open' } | ||
| 122 | +] | ||
| 123 | + | ||
| 124 | +const verticalOptions = [ | ||
| 125 | + { | ||
| 126 | + label: WritingModeEnum.HORIZONTAL, | ||
| 127 | + value: WritingModeObject[WritingModeEnum.HORIZONTAL] | ||
| 128 | + }, | ||
| 129 | + { | ||
| 130 | + label: WritingModeEnum.VERTICAL, | ||
| 131 | + value: WritingModeObject[WritingModeEnum.VERTICAL] | ||
| 132 | + } | ||
| 133 | +] | ||
| 134 | +const fontWeightOptions = [ | ||
| 135 | + { | ||
| 136 | + label: FontWeightEnum.NORMAL, | ||
| 137 | + value: FontWeightObject[FontWeightEnum.NORMAL] | ||
| 138 | + }, | ||
| 139 | + { | ||
| 140 | + label: FontWeightEnum.BOLD, | ||
| 141 | + value: FontWeightObject[FontWeightEnum.BOLD] | ||
| 142 | + } | ||
| 143 | +] | ||
| 144 | +const handleLinkClick = (target: string) => { | ||
| 145 | + const hrefStr = props.optionData.linkHead + props.optionData.link | ||
| 146 | + if (target === 'open') window.open(hrefStr) | ||
| 147 | + else window.location.href = hrefStr | ||
| 148 | +} | ||
| 149 | +const linkHeadOptions = [ | ||
| 150 | + { label: 'http://', value: 'http://' }, | ||
| 151 | + { label: 'https://', value: 'https://' } | ||
| 152 | +] | ||
| 153 | +</script> |
| 1 | +import { ConfigType, PackagesCategoryEnum, ChartFrameEnum } from '@/packages/index.d' | ||
| 2 | +import { ChatCategoryEnum, ChatCategoryEnumName } from '@/packages/components/Informations/index.d' | ||
| 3 | +import { useWidgetKey } from '@/packages/external/useWidgetKey' | ||
| 4 | + | ||
| 5 | +const { key, conKey, chartKey } = useWidgetKey('OverrideTextCommon', true) | ||
| 6 | + | ||
| 7 | +export const OverrideTextCommonConfig: ConfigType = { | ||
| 8 | + key, | ||
| 9 | + chartKey, | ||
| 10 | + conKey, | ||
| 11 | + title: '自定义文字', | ||
| 12 | + category: ChatCategoryEnum.MORE, | ||
| 13 | + categoryName: ChatCategoryEnumName.MORE, | ||
| 14 | + package: PackagesCategoryEnum.INFORMATIONS, | ||
| 15 | + chartFrame: ChartFrameEnum.COMMON, | ||
| 16 | + image: 'text_static.png' | ||
| 17 | +} |
| 1 | +<template> | ||
| 2 | + <div class="go-text-box"> | ||
| 3 | + <div class="content"> | ||
| 4 | + <span style="cursor: pointer" v-if="link" @click="click">{{ option.dataset }}</span> | ||
| 5 | + <span v-else>{{ option.dataset }}</span> | ||
| 6 | + </div> | ||
| 7 | + </div> | ||
| 8 | +</template> | ||
| 9 | + | ||
| 10 | +<script setup lang="ts"> | ||
| 11 | +import { PropType, toRefs, shallowReactive, watch } from 'vue' | ||
| 12 | +import { CreateComponentType } from '@/packages/index.d' | ||
| 13 | +import { useChartDataFetch } from '@/hooks' | ||
| 14 | +import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore' | ||
| 15 | +import { option as configOption } from './config' | ||
| 16 | + | ||
| 17 | +const props = defineProps({ | ||
| 18 | + chartConfig: { | ||
| 19 | + type: Object as PropType<CreateComponentType & typeof option>, | ||
| 20 | + required: true | ||
| 21 | + } | ||
| 22 | +}) | ||
| 23 | + | ||
| 24 | +const { | ||
| 25 | + linkHead, | ||
| 26 | + link, | ||
| 27 | + fontColor, | ||
| 28 | + fontSize, | ||
| 29 | + letterSpacing, | ||
| 30 | + paddingY, | ||
| 31 | + paddingX, | ||
| 32 | + textAlign, | ||
| 33 | + borderWidth, | ||
| 34 | + borderColor, | ||
| 35 | + borderRadius, | ||
| 36 | + writingMode, | ||
| 37 | + backgroundColor, | ||
| 38 | + fontWeight, | ||
| 39 | + linkMethod | ||
| 40 | +} = toRefs(props.chartConfig.option) | ||
| 41 | + | ||
| 42 | +const option = shallowReactive({ | ||
| 43 | + dataset: configOption.dataset | ||
| 44 | +}) | ||
| 45 | + | ||
| 46 | +// 手动更新 | ||
| 47 | +watch( | ||
| 48 | + () => props.chartConfig.option.dataset, | ||
| 49 | + (newData: any) => { | ||
| 50 | + option.dataset = newData | ||
| 51 | + }, | ||
| 52 | + { | ||
| 53 | + immediate: true, | ||
| 54 | + deep: false | ||
| 55 | + } | ||
| 56 | +) | ||
| 57 | + | ||
| 58 | +// 预览更新 | ||
| 59 | +useChartDataFetch(props.chartConfig, useChartEditStore, (newData: string) => { | ||
| 60 | + option.dataset = newData | ||
| 61 | +}) | ||
| 62 | + | ||
| 63 | +//打开链接 | ||
| 64 | +const click = () => { | ||
| 65 | + const hrefStr = linkHead.value + link.value | ||
| 66 | + if (linkMethod.value === 'open') window.open(hrefStr) | ||
| 67 | + else window.location.href = hrefStr | ||
| 68 | +} | ||
| 69 | +</script> | ||
| 70 | + | ||
| 71 | +<style lang="scss" scoped> | ||
| 72 | +@include go('text-box') { | ||
| 73 | + display: flex; | ||
| 74 | + align-items: center; | ||
| 75 | + justify-content: v-bind('textAlign'); | ||
| 76 | + | ||
| 77 | + .content { | ||
| 78 | + color: v-bind('fontColor'); | ||
| 79 | + padding: v-bind('`${paddingY}px ${paddingX}px`'); | ||
| 80 | + font-size: v-bind('fontSize + "px"'); | ||
| 81 | + letter-spacing: v-bind('letterSpacing + "px"'); | ||
| 82 | + writing-mode: v-bind('writingMode'); | ||
| 83 | + font-weight: v-bind('fontWeight'); | ||
| 84 | + border-style: solid; | ||
| 85 | + border-width: v-bind('borderWidth + "px"'); | ||
| 86 | + border-radius: v-bind('borderRadius + "px"'); | ||
| 87 | + border-color: v-bind('borderColor'); | ||
| 88 | + | ||
| 89 | + background-color: v-bind('backgroundColor'); | ||
| 90 | + } | ||
| 91 | +} | ||
| 92 | +</style> |
| @@ -8,6 +8,7 @@ import { OverrideCarouselConfig } from '@/packages/components/external/Informati | @@ -8,6 +8,7 @@ import { OverrideCarouselConfig } from '@/packages/components/external/Informati | ||
| 8 | import { OverrideSelectConfig } from '@/packages/components/external/Informations/Mores/OverrideSelect' | 8 | import { OverrideSelectConfig } from '@/packages/components/external/Informations/Mores/OverrideSelect' |
| 9 | import { OverrideInputsDateConfig } from '@/packages/components/external/Informations/Mores/OverrideInputsDate' | 9 | import { OverrideInputsDateConfig } from '@/packages/components/external/Informations/Mores/OverrideInputsDate' |
| 10 | import { OverrideInputsTabConfig } from '@/packages/components/external/Informations/Mores/OverrideInputsTab' | 10 | import { OverrideInputsTabConfig } from '@/packages/components/external/Informations/Mores/OverrideInputsTab' |
| 11 | +import { OverrideTextCommonConfig } from '@/packages/components/external/Informations/Mores/OverrideTextCommon' | ||
| 11 | 12 | ||
| 12 | export function useInjectLib(packagesList: EPackagesType) { | 13 | export function useInjectLib(packagesList: EPackagesType) { |
| 13 | 14 | ||
| @@ -20,6 +21,7 @@ export function useInjectLib(packagesList: EPackagesType) { | @@ -20,6 +21,7 @@ export function useInjectLib(packagesList: EPackagesType) { | ||
| 20 | addWidgetToCategoryByCategoryName(packagesList, PackagesCategoryEnum.INFORMATIONS, OverrideSelectConfig) | 21 | addWidgetToCategoryByCategoryName(packagesList, PackagesCategoryEnum.INFORMATIONS, OverrideSelectConfig) |
| 21 | addWidgetToCategoryByCategoryName(packagesList, PackagesCategoryEnum.INFORMATIONS, OverrideInputsDateConfig) | 22 | addWidgetToCategoryByCategoryName(packagesList, PackagesCategoryEnum.INFORMATIONS, OverrideInputsDateConfig) |
| 22 | addWidgetToCategoryByCategoryName(packagesList, PackagesCategoryEnum.INFORMATIONS, OverrideInputsTabConfig) | 23 | addWidgetToCategoryByCategoryName(packagesList, PackagesCategoryEnum.INFORMATIONS, OverrideInputsTabConfig) |
| 24 | + addWidgetToCategoryByCategoryName(packagesList, PackagesCategoryEnum.INFORMATIONS, OverrideTextCommonConfig) | ||
| 23 | } | 25 | } |
| 24 | 26 | ||
| 25 | /** | 27 | /** |