resolver-egretimp-plus 0.0.298 → 0.0.300

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "resolver-egretimp-plus",
3
- "version": "0.0.298",
3
+ "version": "0.0.300",
4
4
  "description": "交付体验渲染",
5
5
  "main": "./dist/web/index.js",
6
6
  "module": "./dist/web/index.js",
@@ -0,0 +1,132 @@
1
+ import { defineComponent, ref, watch, nextTick, onMounted, onUnmounted, computed } from 'vue';
2
+ import { getDomWidth } from '../../utils/dom';
3
+
4
+ export function useToolTip({
5
+ showTooltip,
6
+ offset,
7
+ displayValue,
8
+ calcFn,
9
+ }) {
10
+ const isFocus = ref(false) // 是否是焦点状态
11
+ const isEnter = ref(false) // 鼠标是否在内部
12
+ const triggerRef = ref(null)
13
+ const isOverflow = ref(false)
14
+ const inputWrapRef = ref(null)
15
+ const calcSpanRef = ref(null)
16
+
17
+ function calcDomWidth(node) {
18
+ if (calcFn) {
19
+ return calcFn(node)
20
+ }
21
+ return getDomWidth(node, 0)
22
+ }
23
+
24
+ const tooltipCalc = (() => {
25
+ let unWatch = null
26
+ let onResize = null
27
+ return {
28
+ clear: () => {
29
+ unWatch && unWatch()
30
+ onResize && window.removeEventListener('resize', onResize)
31
+ },
32
+ calc() {
33
+ this.clear()
34
+ let inputWrapWidth = calcDomWidth(inputWrapRef.value, 0)
35
+ let textLengthWidth = getDomWidth(calcSpanRef.value, 0 - offset.value)
36
+ isOverflow.value = inputWrapWidth < textLengthWidth
37
+
38
+ unWatch = watch(() => displayValue.value, (val) => {
39
+ nextTick(() => {
40
+ textLengthWidth = getDomWidth(calcSpanRef.value, 0 - offset.value)
41
+ isOverflow.value = inputWrapWidth < textLengthWidth
42
+ })
43
+ })
44
+ onResize = () => {
45
+ inputWrapWidth = calcDomWidth(inputWrapRef.value, 0)
46
+ isOverflow.value = inputWrapWidth < textLengthWidth
47
+ // console.log('===:', inputWrapWidth, textLengthWidth)
48
+ }
49
+ window.addEventListener('resize', onResize)
50
+ }
51
+ }
52
+ })()
53
+ const inputWrapMouseEvents = computed(() => {
54
+ const ret = {}
55
+ if (showTooltip.value) {
56
+ ret.onMouseenter = (e) => {
57
+ isEnter.value = true
58
+ triggerRef.value = e?.target
59
+ }
60
+ ret.onMouseleave = () => {
61
+ isEnter.value = false
62
+ if (!isFocus.value) {
63
+ triggerRef.value = null
64
+ }
65
+ }
66
+ }
67
+ return ret
68
+ })
69
+ const calcComEvents = computed(() => {
70
+ const ret = {}
71
+ ret['onFocus'] = (...arg) => {
72
+ isFocus.value = true
73
+ if (showTooltip.value) {
74
+ triggerRef.value = arg?.[0]?.target
75
+ }
76
+ }
77
+ ret['onBlur'] = (...arg) => {
78
+ isFocus.value = false
79
+ if (showTooltip.value) {
80
+ if (!isEnter.value) {
81
+ triggerRef.value = null
82
+ }
83
+ }
84
+ }
85
+ return ret
86
+ })
87
+ onMounted(() => {
88
+ watch(showTooltip, (val) => {
89
+ if (val) {
90
+ tooltipCalc?.calc()
91
+ }
92
+ }, {
93
+ immediate: true
94
+ })
95
+ })
96
+ onUnmounted(() => {
97
+ tooltipCalc?.clear()
98
+ })
99
+ function generateTooltipWrap(node, opt) {
100
+ const {
101
+ maintain = false,
102
+ } = opt || {}
103
+ const nodeComp = defineComponent(node)
104
+ if (maintain && !showTooltip.value) {
105
+ <nodeComp></nodeComp>
106
+ }
107
+ return (
108
+ <div class="resolver-calc-contrainer">
109
+ <span ref={(e) => calcSpanRef.value = e} class="resolver-calc-span">{ displayValue.value }</span>
110
+ {
111
+ isOverflow.value ?
112
+ <el-tooltip
113
+ placement="top"
114
+ visible={isOverflow.value && !!triggerRef.value}
115
+ content={displayValue.value}
116
+ virtualTriggering
117
+ virtualRef={triggerRef.value}
118
+ ></el-tooltip>
119
+ : null
120
+ }
121
+ <div class="resolver-calc-wrap" {...inputWrapMouseEvents.value} ref={(e) => inputWrapRef.value = e}>
122
+ <nodeComp {...calcComEvents.value}></nodeComp>
123
+ </div>
124
+ </div>
125
+ )
126
+ }
127
+ return {
128
+ isFocus,
129
+ isEnter,
130
+ generateTooltipWrap
131
+ }
132
+ }
@@ -0,0 +1,393 @@
1
+ import { ElInput } from 'element-plus'
2
+ import { computed, defineProps, useAttrs } from 'vue'
3
+ import { commonPropsType, hasOwn, isElement } from '../../utils/index.js'
4
+ import { ref } from 'vue';
5
+ import { onMounted } from 'vue';
6
+ import { getDomWidth } from '../../utils/dom.js';
7
+ import { watch } from 'vue';
8
+ import { nextTick } from 'vue';
9
+ import { resolveComponent } from 'vue';
10
+ import { onUnmounted } from 'vue';
11
+
12
+ export default {
13
+ inheritAttrs: false,
14
+ props: {
15
+ ...commonPropsType,
16
+ ...ElInput.props,
17
+ textAreaCnt: {
18
+ type: [Number, String],
19
+ default: 2,
20
+ },
21
+ // 是否在超出的时候展示tooltip
22
+ showTooltip: {
23
+ type: [String, Number],
24
+ default: ''
25
+ },
26
+ // 是否使用金额显示
27
+ showMoney: {
28
+ type: [String, Number],
29
+ default: ''
30
+ },
31
+ // 金额显示的分割,默认‘,’
32
+ moneySeg: {
33
+ type: [String],
34
+ default: ','
35
+ },
36
+ // 金额显示的最小值
37
+ min: {
38
+ type: Number,
39
+ default: -Infinity
40
+ },
41
+ // 金额显示的最大值
42
+ max: {
43
+ type: Number,
44
+ default: Infinity
45
+ },
46
+ // 金额显示小数位数
47
+ decimal: {
48
+ type: Number,
49
+ default: 2
50
+ },
51
+ // 金额显示时保留小数点0后缀
52
+ decimalSuffix: {
53
+ type: [Number, String],
54
+ default: '0'
55
+ },
56
+ // 在显示金额的时候,可以显示的符号
57
+ canShowFlag: {
58
+ type: Array,
59
+ default: ['na', '-']
60
+ },
61
+ // 金额显示是否显示货币符号
62
+ showSymbol: {
63
+ type: String,
64
+ default: ''
65
+ },
66
+ // 货币符号
67
+ symbol: {
68
+ type: String,
69
+ default: '¥'
70
+ },
71
+ // 符号位置:before/after
72
+ symbolPosition: {
73
+ type: String,
74
+ default: 'before',
75
+ validator: value => ['before', 'after'].includes(value)
76
+ },
77
+ },
78
+ emits: ['update:modelValue'],
79
+ setup(props, { emit, attrs, expose, slots }) {
80
+ const isFocus = ref(false) // 是否是焦点状态
81
+ const isEnter = ref(false) // 鼠标是否在内部
82
+ const triggerRef = ref(null)
83
+ const isOverflow = ref(false)
84
+ const inputWrapRef = ref(null)
85
+ const calcSpanRef = ref(null)
86
+ const inputProps = computed(() => {
87
+ const ret = Object.keys(ElInput.props).reduce((total, key) => {
88
+ total[key] = props[key]
89
+ return total
90
+ }, {})
91
+ if (props.config?.icon) {
92
+ ret.suffixIcon = props.config?.icon
93
+ }
94
+ if (props.config?.maxLength) {
95
+ ret.maxlength = parseInt(props.config.maxLength)
96
+ }
97
+ if (props.textAreaCnt) {
98
+ ret.rows = parseInt(props.textAreaCnt)
99
+ }
100
+ return ret
101
+ })
102
+ const normalInputProps = computed(() => {
103
+ const ret = {
104
+ ...inputProps.value
105
+ }
106
+ delete ret.modelValue
107
+ delete ret.suffixIcon
108
+ delete ret.prefixIcon
109
+ return ret
110
+ })
111
+ const showTooltip = computed(() => {
112
+ return props?.showTooltip == '1'
113
+ })
114
+ // 这个是真实的值
115
+ const modelValue = computed({
116
+ get() {
117
+ return props.modelValue
118
+ },
119
+ set(val) {
120
+ emit('update:modelValue', val)
121
+ }
122
+ })
123
+ // 开启金额展示的时候需要isFocus来控制格式的转换
124
+ const currentVal = ref('')
125
+ const displayValue = computed(() => {
126
+ return props.showMoney == '1' ? (isFocus.value ? currentVal.value : formatValue(modelValue.value)) : modelValue.value
127
+ })
128
+ const isPagePopupAndSearch = computed(() => {
129
+ return props.config?.lcpPagePopupMapVO && inputProps.value.suffixIcon == 'Search'
130
+ })
131
+ // 弹框是否只能支持点击icon进行触发,默认是
132
+ const isOnlyIconClickFlag = computed(() => {
133
+ return hasOwn(props.config, 'onlyIconClickFlag') ? props.config?.onlyIconClickFlag == '1' : true
134
+ })
135
+ // 输入点击弹框的情况下,是否仍然可以编辑
136
+ const isPagePopupAlwayEdit = computed(() => {
137
+ return props.config?.pagePopupEditFlag == '1'
138
+ })
139
+ const vmodelProps = computed(() => {
140
+ const ret = {
141
+ modelValue: displayValue.value
142
+ }
143
+ if (!(isPagePopupAndSearch.value && !isPagePopupAlwayEdit.value)) {
144
+ ret['onUpdate:modelValue'] = (val) => {
145
+ if (props.showMoney == '1') {
146
+ currentVal.value = val
147
+ } else {
148
+ modelValue.value = val
149
+ }
150
+ }
151
+ if (props.showMoney == '1') {
152
+ ret['onFocus'] = () => {
153
+ currentVal.value = modelValue.value
154
+ }
155
+ ret['onBlur'] = () => {
156
+ modelValue.value = parseValue(formatValue(currentVal.value))
157
+ }
158
+ }
159
+ } else {
160
+ ret['onClear'] = () => {
161
+ attrs?.onClear?.()
162
+ modelValue.value = ''
163
+ }
164
+ }
165
+ return ret
166
+ })
167
+ const inputWrapAttrs = computed(() => {
168
+ return {
169
+ class: attrs?.class,
170
+ style: attrs?.style
171
+ }
172
+ })
173
+ const normalAttrs = computed(() => {
174
+ const ret = {
175
+ ...attrs
176
+ }
177
+ delete ret.class
178
+
179
+ const originFocus = ret['onFocus']
180
+ ret['onFocus'] = (...arg) => {
181
+ isFocus.value = true
182
+ if (showTooltip.value) {
183
+ triggerRef.value = arg?.[0]?.target
184
+ }
185
+ originFocus?.(...arg)
186
+ }
187
+ const originonBlur = ret['onBlur']
188
+ ret['onBlur'] = (...arg) => {
189
+ isFocus.value = false
190
+ if (showTooltip.value) {
191
+ if (!isEnter.value) {
192
+ triggerRef.value = null
193
+ }
194
+ }
195
+ originonBlur?.(...arg)
196
+ }
197
+
198
+ if (isPagePopupAndSearch.value && isOnlyIconClickFlag.value) {
199
+ delete ret.onClick
200
+ }
201
+ if (ret.onWrapClick) {
202
+ if (ret.onClick) {
203
+ const originClick = ret.onClick
204
+ ret.onClick = function(...arg) {
205
+ originClick(...arg)
206
+ ret.onWrapClick(...arg)
207
+ }
208
+ } else {
209
+ ret.onClick = ret.onWrapClick
210
+ }
211
+ }
212
+ return ret
213
+ })
214
+
215
+ const tooltipCalc = (() => {
216
+ let unWatch = null
217
+ let onResize = null
218
+ return {
219
+ clear: () => {
220
+ unWatch && unWatch()
221
+ onResize && window.removeEventListener('resize', onResize)
222
+ },
223
+ calc() {
224
+ this.clear()
225
+ let offset = 20
226
+ if (!props.disabled && props.clearable) {
227
+ offset = 50
228
+ }
229
+ let inputWrapWidth = getDomWidth(inputWrapRef.value, 0)
230
+ let textLengthWidth = getDomWidth(calcSpanRef.value, 0 - offset)
231
+ isOverflow.value = inputWrapWidth < textLengthWidth
232
+
233
+ unWatch = watch(() => displayValue.value, (val) => {
234
+ nextTick(() => {
235
+ textLengthWidth = getDomWidth(calcSpanRef.value, 0 - offset)
236
+ isOverflow.value = inputWrapWidth < textLengthWidth
237
+ })
238
+ })
239
+ onResize = () => {
240
+ inputWrapWidth = getDomWidth(inputWrapRef.value, 0)
241
+ isOverflow.value = inputWrapWidth < textLengthWidth
242
+ }
243
+ window.addEventListener('resize', onResize)
244
+ }
245
+ }
246
+ })()
247
+
248
+ onMounted(() => {
249
+ watch(showTooltip, (val) => {
250
+ if (val) {
251
+ tooltipCalc?.calc()
252
+ }
253
+ }, {
254
+ immediate: true
255
+ })
256
+ })
257
+ onUnmounted(() => {
258
+ tooltipCalc?.clear()
259
+ })
260
+ const getInputSolts = () => {
261
+ const ret = {
262
+ ...slots
263
+ }
264
+ if (inputProps.value?.suffixIcon) {
265
+ const suffixIcon = resolveComponent(inputProps.value.suffixIcon)
266
+ ret.suffix = () => {
267
+ const iconProps = {}
268
+ if (isPagePopupAndSearch.value) {
269
+ if (!props.disabled) {
270
+ iconProps.onClick = attrs.onClick
271
+ iconProps.style = {
272
+ cursor: 'pointer'
273
+ }
274
+ }
275
+ }
276
+
277
+ return <el-icon {...iconProps}><suffixIcon /></el-icon>
278
+ }
279
+ }
280
+ if (inputProps.value?.prefixIcon) {
281
+ const prefixIcon = resolveComponent(inputProps.value.prefixIcon)
282
+ ret.prefix = () => {
283
+ return <el-icon><prefixIcon /></el-icon>
284
+ }
285
+ }
286
+ return ret
287
+ }
288
+
289
+ // 格式化显示
290
+ function formatValue(value) {
291
+ if (props.canShowFlag?.includes(String(value).toLowerCase())) {
292
+ return value
293
+ }
294
+ if (value === null || value === undefined) return ''
295
+ let val = `${value}`.replace(props.moneySeg, '')
296
+ val = parseFloat(val)
297
+ if (isNaN(val)) {
298
+ return ''
299
+ }
300
+
301
+ // 转换数字并限制范围
302
+ val = Math.max(props.min, Math.min(props.max, val))
303
+
304
+ // 处理千分位
305
+ if (props.decimal != '-1') {
306
+ val = val.toFixed(props.decimal)
307
+ }
308
+ if (props.decimalSuffix != '1') {
309
+ val = parseFloat(val)
310
+ }
311
+ const parts = `${val}`.split('.')
312
+ parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, props.moneySeg)
313
+
314
+ // 添加货币符号
315
+ const formatted = parts.join('.')
316
+ return props.showSymbol == '1'
317
+ ? props.symbolPosition === 'before'
318
+ ? `${props.symbol} ${formatted}`
319
+ : `${formatted} ${props.symbol}`
320
+ : formatted
321
+ }
322
+
323
+ // 解析输入值
324
+ function parseValue(value) {
325
+ if (props.canShowFlag?.includes(String(value).toLowerCase())) {
326
+ return value
327
+ }
328
+ if (value === undefined || value === null || value === '') {
329
+ return ''
330
+ }
331
+ // 移除所有非数字字符(保留负号和小数点)
332
+ let pointCount = 0
333
+ const repVal = `${value}`.replace(/[^\d.-]/g, '').replace(/(\.\d*)/g, (a) => {
334
+ const count = pointCount
335
+ pointCount ++
336
+ if (!count) {
337
+ return a
338
+ }
339
+ return ''
340
+ })
341
+ const parsed = Number(repVal)
342
+ return isNaN(parsed) ? '' : parsed
343
+ }
344
+
345
+ const inputWrapMouseEvents = computed(() => {
346
+ const ret = {}
347
+ if (showTooltip.value) {
348
+ ret.onMouseenter = (e) => {
349
+ isEnter.value = true
350
+ triggerRef.value = e?.target
351
+ }
352
+ ret.onMouseleave = () => {
353
+ isEnter.value = false
354
+ if (!isFocus.value) {
355
+ triggerRef.value = null
356
+ }
357
+ }
358
+ }
359
+ return ret
360
+ })
361
+ expose({
362
+ click: (params) => {
363
+ attrs?.onClick?.(null, params)
364
+ }
365
+ })
366
+ return () => {
367
+ return (
368
+ <div class="input-contrainer" {...inputWrapAttrs.value}>
369
+ <span ref={(e) => calcSpanRef.value = e} class="calc-span">{ displayValue.value }</span>
370
+ {
371
+ isOverflow.value ?
372
+ <el-tooltip
373
+ placement="top"
374
+ visible={isOverflow.value && !!triggerRef.value}
375
+ content={displayValue.value}
376
+ virtualTriggering
377
+ virtualRef={triggerRef.value}
378
+ ></el-tooltip>
379
+ : null
380
+ }
381
+ <div class="input-wrap" {...inputWrapMouseEvents.value} ref={(e) => inputWrapRef.value = e}>
382
+ <ElInput {...vmodelProps.value} {...{...normalAttrs.value, ...normalInputProps.value}}>
383
+ {
384
+ getInputSolts()
385
+ }
386
+ </ElInput>
387
+ </div>
388
+ </div>
389
+ )
390
+ }
391
+ }
392
+ }
393
+