浏览代码

fix: 修复文本设置链接时,字体样式丢失问题,并增加水平对齐配置

tnt group 3 年之前
父节点
当前提交
7c871c775c

+ 7 - 7
src/packages/components/Informations/Texts/TextCommon/config.ts

@@ -5,22 +5,23 @@ import cloneDeep from 'lodash/cloneDeep'
 
 export enum WritingModeEnum {
   HORIZONTAL = '水平',
-  VERTICAL = '垂直',
+  VERTICAL = '垂直'
 }
 
 export const WritingModeObject = {
   [WritingModeEnum.HORIZONTAL]: 'horizontal-tb',
-  [WritingModeEnum.VERTICAL]: 'vertical-rl',
+  [WritingModeEnum.VERTICAL]: 'vertical-rl'
 }
 
 export const option = {
-  link:'',
-  linkHead:'http://',
+  link: '',
+  linkHead: 'http://',
   dataset: '我是文本',
   fontSize: 20,
   fontColor: '#ffffff',
   paddingX: 10,
   paddingY: 10,
+  textAlign: 'center', // 水平对齐方式
 
   // 边框
   borderWidth: 0,
@@ -30,11 +31,10 @@ export const option = {
   // 字间距
   letterSpacing: 5,
   writingMode: 'horizontal-tb',
-  backgroundColor: '#00000000',
+  backgroundColor: '#00000000'
 }
 
-export default class Config extends PublicConfigClass implements CreateComponentType
-{
+export default class Config extends PublicConfigClass implements CreateComponentType {
   public key = TextCommonConfig.key
   public chartConfig = cloneDeep(TextCommonConfig)
   public option = cloneDeep(option)

+ 19 - 15
src/packages/components/Informations/Texts/TextCommon/config.vue

@@ -23,26 +23,30 @@
 
   <collapse-item name="样式" :expanded="true">
     <setting-item-box name="文字">
+      <setting-item name="颜色">
+        <n-color-picker size="small" :modes="['hex']" v-model:value="optionData.fontColor"></n-color-picker>
+      </setting-item>
       <setting-item name="字体大小">
         <n-input-number v-model:value="optionData.fontSize" size="small" placeholder="字体大小"></n-input-number>
       </setting-item>
 
-      <setting-item name="文本方向">
-        <n-select v-model:value="optionData.writingMode" size="small" :options="verticalOptions" />
-      </setting-item>
-
       <setting-item name="X轴内边距">
         <n-input-number v-model:value="optionData.paddingX" size="small" placeholder="输入内边距"></n-input-number>
       </setting-item>
       <setting-item name="Y轴内边距">
         <n-input-number v-model:value="optionData.paddingY" size="small" placeholder="输入内边距"></n-input-number>
       </setting-item>
+
+      <setting-item name="水平对齐">
+        <n-select v-model:value="optionData.textAlign" size="small" :options="textAlignOptions" />
+      </setting-item>
+      <setting-item name="文本方向">
+        <n-select v-model:value="optionData.writingMode" size="small" :options="verticalOptions" />
+      </setting-item>
+
       <setting-item name="字间距">
         <n-input-number v-model:value="optionData.letterSpacing" size="small" placeholder="输入字间距"></n-input-number>
       </setting-item>
-      <setting-item name="颜色">
-        <n-color-picker size="small" :modes="['hex']" v-model:value="optionData.fontColor"></n-color-picker>
-      </setting-item>
     </setting-item-box>
 
     <setting-item-box name="边框">
@@ -86,6 +90,12 @@ const props = defineProps({
   }
 })
 
+const textAlignOptions = [
+  { label: '左对齐', value: 'start' },
+  { label: '居中', value: 'center' },
+  { label: '右对齐', value: 'end' }
+]
+
 const verticalOptions = [
   {
     label: WritingModeEnum.HORIZONTAL,
@@ -100,13 +110,7 @@ const handleLinkClick = () => {
   window.open(props.optionData.linkHead + props.optionData.link)
 }
 const linkHeadOptions = [
-  {
-    label: 'http://',
-    value: 'http://'
-  },
-  {
-    label: 'https://',
-    value: 'https://'
-  }
+  { label: 'http://', value: 'http://' },
+  { label: 'https://', value: 'https://' }
 ]
 </script>

+ 22 - 22
src/packages/components/Informations/Texts/TextCommon/index.vue

@@ -1,27 +1,12 @@
 <template>
   <div class="go-text-box">
-    <div
-      :style="`
-      color: ${fontColor};
-      padding: ${paddingY}px ${paddingX}px;
-      font-size: ${fontSize}px;
-      letter-spacing: ${letterSpacing}px;
-      writing-mode: ${writingMode};
-
-      border-style: solid;
-      border-width: ${borderWidth}px;
-      border-radius: ${borderRadius}px;
-      border-color: ${borderColor};
-
-      background-color:${backgroundColor}`"
-    >
-      <n-button v-if="link" @click="click" text>
-        {{ dataset }}
-      </n-button>
+    <div class="content">
+      <span style="cursor: pointer" v-if="link" @click="click">{{ dataset }}</span>
       <span v-else>{{ dataset }}</span>
     </div>
   </div>
 </template>
+
 <script setup lang="ts">
 import { PropType, toRefs, shallowReactive, watch } from 'vue'
 import { CreateComponentType } from '@/packages/index.d'
@@ -31,12 +16,11 @@ import { option as configOption } from './config'
 
 const props = defineProps({
   chartConfig: {
-    type: Object as PropType<CreateComponentType>,
+    type: Object as PropType<CreateComponentType & typeof option>,
     required: true
   }
 })
 
-const { w, h } = toRefs(props.chartConfig.attr)
 const {
   linkHead,
   link,
@@ -46,6 +30,7 @@ const {
   letterSpacing,
   paddingY,
   paddingX,
+  textAlign,
   borderWidth,
   borderColor,
   borderRadius,
@@ -76,7 +61,7 @@ useChartDataFetch(props.chartConfig, useChartEditStore, (newData: string) => {
 
 //打开链接
 const click = () => {
-  window.open(linkHead.value+link.value)
+  window.open(linkHead.value + link.value)
 }
 </script>
 
@@ -84,6 +69,21 @@ const click = () => {
 @include go('text-box') {
   display: flex;
   align-items: center;
-  justify-content: center;
+  justify-content: v-bind('textAlign');
+
+  .content {
+    color: v-bind('fontColor');
+    padding: v-bind('`${paddingY}px ${paddingX}px`');
+    font-size: v-bind('fontSize + "px"');
+    letter-spacing: v-bind('letterSpacing + "px"');
+    writing-mode: v-bind('writingMode');
+
+    border-style: solid;
+    border-width: v-bind('borderWidth + "px"');
+    border-radius: v-bind('borderRadius + "px"');
+    border-color: v-bind('borderColor');
+
+    background-color: v-bind('backgroundColor');
+  }
 }
 </style>