zhengyiming
20 小时以前 55119aeab85c9dc310ab8bc3de3091a20fa9a684
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
<!--
 * @Author: 秦少卫
 * @Date: 2024-06-10 17:52:40
 * @LastEditors: 秦少卫
 * @LastEditTime: 2024-10-13 17:08:59
 * @Description: 小数点下标上标
-->
 
<template>
  <div v-if="isOne && isMatchType" class="attr-item-box">
    <div class="flex-view">
      <div class="flex-item">
        <span class="label">{{ $t('textFloat') }}</span>
        <div class="content">
          <Select
            v-model="baseAttr.verticalAlign"
            @on-change="(value) => changeCommon('verticalAlign', value)"
          >
            <Option value="null">无</Option>
            <Option value="bottom">下标</Option>
            <Option value="top">上标</Option>
          </Select>
        </div>
      </div>
    </div>
  </div>
</template>
 
<script name="Price" setup>
import useSelect from '@/hooks/select';
 
const baseAttr = reactive({
  verticalAlign: 'null',
});
 
const matchType = ['i-text', 'textbox', 'text'];
const { isMatchType, canvasEditor, isOne } = useSelect(matchType);
 
const getObjectAttr = (e) => {
  const activeObject = canvasEditor.canvas.getActiveObject();
  // 不是当前obj,跳过
  if (e && e.target && e.target !== activeObject) return;
  if (activeObject && isMatchType && activeObject?.text?.includes('.')) {
    baseAttr.verticalAlign = activeObject.get('verticalAlign');
  }
};
 
const changeCommon = (key, value) => {
  const activeObject = canvasEditor.canvas.getActiveObjects()[0];
  if (activeObject && activeObject.text.includes('.')) {
    const [init] = activeObject.text.split('.');
    const startIndex = init.length + 1;
    const endIndex = activeObject.text.length;
    activeObject.styles = [];
    // 上标
    if (value === 'top') {
      activeObject.setSuperscript(startIndex, endIndex);
    } else if (value === 'bottom') {
      // 下标
      activeObject.setSelectionStyles(
        {
          fontSize: activeObject.superscript.size * activeObject.fontSize,
        },
        startIndex,
        endIndex
      );
    }
    activeObject.set(key, value);
    canvasEditor.canvas.renderAll();
  }
};
 
const update = getCurrentInstance();
const selectCancel = () => {
  update?.proxy?.$forceUpdate();
};
 
onMounted(() => {
  // 获取字体数据
  getObjectAttr();
  canvasEditor.on('selectCancel', selectCancel);
  canvasEditor.on('selectOne', getObjectAttr);
  canvasEditor.canvas.on('object:modified', getObjectAttr);
});
 
onBeforeUnmount(() => {
  canvasEditor.off('selectCancel', selectCancel);
  canvasEditor.off('selectOne', getObjectAttr);
  canvasEditor.canvas.off('object:modified', getObjectAttr);
});
</script>
 
<style scoped lang="less">
.flex-view {
  width: 100%;
  margin-bottom: 5px;
  padding: 5px;
  display: inline-flex;
  justify-content: space-between;
  border-radius: 5px;
  background: #f6f7f9;
}
.flex-item {
  display: inline-flex;
  flex: 1;
  .label {
    width: 32px;
    height: 32px;
    line-height: 32px;
    display: inline-block;
    font-size: 14px;
    // color: #333333;
  }
  .content {
    flex: 1;
    // width: 60px;
  }
  .slider-box {
    width: calc(100% - 50px);
    margin-left: 10px;
  }
  .left {
    flex: 1;
  }
  .right {
    flex: 1;
    margin-left: 10px;
    :deep(.ivu-input-number) {
      display: block;
      width: 100%;
    }
  }
  :deep(.ivu-slider-wrap) {
    margin: 13px 0;
  }
  :deep(.ivu-radio-group-button) {
    display: flex;
    flex: 1;
    width: 100%;
    & .ivu-radio-wrapper {
      // width: 48px;
      flex: 1;
      line-height: 40px;
      text-align: center;
      svg {
        vertical-align: baseline;
      }
    }
  }
 
  :deep(.ivu-btn-group) {
    display: flex;
    flex: 1;
    .ivu-btn {
      flex: 1;
    }
  }
 
  :deep(.ivu-btn-group-large) {
    & > .ivu-btn {
      font-size: 24px;
      flex: 1;
    }
  }
 
  :deep(.ivu-radio-group-button) {
    &.ivu-radio-group-large .ivu-radio-wrapper {
      font-size: 24px;
    }
  }
}
</style>