xt-element-ui 2.0.0 → 2.0.1

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": "xt-element-ui",
3
- "version": "2.0.0",
3
+ "version": "2.0.1",
4
4
  "description": "基于 Vue 2.7 + ElementUI 的企业级组件库,提供丰富的自定义组件和扩展组件",
5
5
  "main": "lib/index.common.js",
6
6
  "module": "lib/index.esm.js",
@@ -1,8 +1,8 @@
1
- import XtButton from './index.vue'
2
-
3
- XtButton.install = function (Vue) {
4
- Vue.component(XtButton.name, XtButton)
5
- }
6
-
7
- export default XtButton
1
+ import XtButton from './index.vue'
2
+
3
+ XtButton.install = function (Vue) {
4
+ Vue.component(XtButton.name, XtButton)
5
+ }
6
+
7
+ export default XtButton
8
8
  export { XtButton }
@@ -1,7 +1,7 @@
1
- import XtCard from './index.vue'
2
-
3
- XtCard.install = function (Vue) {
4
- Vue.component(XtCard.name, XtCard)
5
- }
6
-
1
+ import XtCard from './index.vue'
2
+
3
+ XtCard.install = function (Vue) {
4
+ Vue.component(XtCard.name, XtCard)
5
+ }
6
+
7
7
  export default XtCard
@@ -1,8 +1,8 @@
1
- import XtChart from './index.vue'
2
-
3
- XtChart.install = function (Vue) {
4
- Vue.component(XtChart.name, XtChart)
5
- }
6
-
7
- export default XtChart
1
+ import XtChart from './index.vue'
2
+
3
+ XtChart.install = function (Vue) {
4
+ Vue.component(XtChart.name, XtChart)
5
+ }
6
+
7
+ export default XtChart
8
8
  export { XtChart }
@@ -1,8 +1,8 @@
1
- import XtDatePicker from './index.vue'
2
-
3
- XtDatePicker.install = function (Vue) {
4
- Vue.component(XtDatePicker.name, XtDatePicker)
5
- }
6
-
7
- export default XtDatePicker
1
+ import XtDatePicker from './index.vue'
2
+
3
+ XtDatePicker.install = function (Vue) {
4
+ Vue.component(XtDatePicker.name, XtDatePicker)
5
+ }
6
+
7
+ export default XtDatePicker
8
8
  export { XtDatePicker }
@@ -1,8 +1,8 @@
1
- import XtIcon from './index.vue'
2
-
3
- XtIcon.install = function (Vue) {
4
- Vue.component(XtIcon.name, XtIcon)
5
- }
6
-
7
- export default XtIcon
1
+ import XtIcon from './index.vue'
2
+
3
+ XtIcon.install = function (Vue) {
4
+ Vue.component(XtIcon.name, XtIcon)
5
+ }
6
+
7
+ export default XtIcon
8
8
  export { XtIcon }
@@ -1,8 +1,8 @@
1
- import XtPage from './index.vue'
2
-
3
- XtPage.install = function (Vue) {
4
- Vue.component(XtPage.name, XtPage)
5
- }
6
-
7
- export default XtPage
1
+ import XtPage from './index.vue'
2
+
3
+ XtPage.install = function (Vue) {
4
+ Vue.component(XtPage.name, XtPage)
5
+ }
6
+
7
+ export default XtPage
8
8
  export { XtPage }
@@ -1,8 +1,8 @@
1
- import XtSelectTree from './index.vue'
2
-
3
- XtSelectTree.install = function (Vue) {
4
- Vue.component(XtSelectTree.name, XtSelectTree)
5
- }
6
-
7
- export default XtSelectTree
1
+ import XtSelectTree from './index.vue'
2
+
3
+ XtSelectTree.install = function (Vue) {
4
+ Vue.component(XtSelectTree.name, XtSelectTree)
5
+ }
6
+
7
+ export default XtSelectTree
8
8
  export { XtSelectTree }
@@ -154,6 +154,7 @@ export default {
154
154
  if (next) {
155
155
  let curMax = this.safeNumber(cur[this.keyMax], curMin + stepVal)
156
156
  if (curMax <= curMin) curMax = curMin + stepVal
157
+ curMax = Number(curMax.toFixed(this.precision))
157
158
  cur[this.keyMax] = curMax
158
159
  next[this.keyMin] = curMax
159
160
  } else {
@@ -173,13 +174,19 @@ export default {
173
174
  onItemInput(val, idx) {
174
175
  const cur = this.localItems[idx]
175
176
  if (!cur) return
176
- if (val && val[this.keyPrice] !== undefined) cur[this.keyPrice] = this.safeNumber(val[this.keyPrice], 0)
177
+ if (val && val[this.keyPrice] !== undefined) {
178
+ let p = this.safeNumber(val[this.keyPrice], 0)
179
+ p = Number(p.toFixed(this.precision))
180
+ cur[this.keyPrice] = p
181
+ }
177
182
  },
178
183
 
179
184
  onMaxChange(val, idx) {
180
185
  const cur = this.localItems[idx]
181
186
  if (!cur) return
182
- const n = this.safeNumber(val, this.safeNumber(cur[this.keyMin], 0) + 1)
187
+ const stepVal = this.safeNumber(this.step, 1)
188
+ let n = this.safeNumber(val, this.safeNumber(cur[this.keyMin], 0) + stepVal)
189
+ n = Number(n.toFixed(this.precision))
183
190
  cur[this.keyMax] = n
184
191
  const next = this.localItems[idx + 1]
185
192
  if (next) next[this.keyMin] = n
@@ -192,7 +199,10 @@ export default {
192
199
  if (idx === 0) {
193
200
  cur[this.keyMin] = 0
194
201
  } else {
195
- const n = this.safeNumber(val, this.safeNumber(cur[this.keyMin], 0))
202
+ let n = this.safeNumber(val, this.safeNumber(cur[this.keyMin], 0))
203
+ if (n !== 0) {
204
+ n = Number(n.toFixed(this.precision))
205
+ }
196
206
  cur[this.keyMin] = n
197
207
  const prev = this.localItems[idx - 1]
198
208
  if (prev) prev[this.keyMax] = n
@@ -155,7 +155,10 @@ export default {
155
155
  },
156
156
 
157
157
  onMinBlur() {
158
- const v = this.safeNumber(this.minInput, 0)
158
+ let v = this.safeNumber(this.minInput, 0)
159
+ if (v !== 0) {
160
+ v = Number(v.toFixed(this.precision))
161
+ }
159
162
  this.minInput = v
160
163
  this.$emit('min-change', v, this.index)
161
164
  this.emitChange({ [this.keyMin]: v })
@@ -164,8 +167,10 @@ export default {
164
167
  onMaxBlur() {
165
168
  if (this.isLast) return
166
169
  const minVal = this.safeNumber(this.minInput, 0)
167
- let v = this.safeNumber(this.maxInput, minVal + 1)
168
- if (v <= minVal) v = minVal + 1
170
+ const stepVal = this.safeNumber(this.step, 1)
171
+ let v = this.safeNumber(this.maxInput, minVal + stepVal)
172
+ if (v <= minVal) v = minVal + stepVal
173
+ v = Number(v.toFixed(this.precision))
169
174
  this.maxInput = v
170
175
  this.$emit('max-change', v, this.index)
171
176
  this.emitChange({ [this.keyMax]: v })
@@ -1,8 +1,8 @@
1
- import XtTable from './index.vue'
2
-
3
- XtTable.install = function (Vue) {
4
- Vue.component(XtTable.name, XtTable)
5
- }
6
-
7
- export default XtTable
1
+ import XtTable from './index.vue'
2
+
3
+ XtTable.install = function (Vue) {
4
+ Vue.component(XtTable.name, XtTable)
5
+ }
6
+
7
+ export default XtTable
8
8
  export { XtTable }
@@ -1,5 +1,35 @@
1
1
  <template>
2
+ <el-tooltip
3
+ v-if="showTooltip && ellipsis"
4
+ :content="displayTooltipContent"
5
+ :placement="tooltipPlacement"
6
+ :disabled="!isOverflow"
7
+ effect="dark"
8
+ >
9
+ <span
10
+ ref="textRef"
11
+ class="xt-text"
12
+ :class="[
13
+ type ? 'xt-text--' + type : '',
14
+ 'xt-text--' + size,
15
+ { 'xt-text--bold': bold },
16
+ { 'xt-text--money': format === 'money' },
17
+ { 'xt-text--ellipsis': ellipsis },
18
+ { 'xt-text--ellipsis-multiline': ellipsis && ellipsisRows > 1 }
19
+ ]"
20
+ :style="customStyle"
21
+ @mouseenter="handleMouseEnter"
22
+ >
23
+ <slot name="prefix">{{ prefix }}</slot>
24
+ <slot>
25
+ <template v-if="formattedValue !== undefined">{{ formattedValue }}</template>
26
+ </slot>
27
+ <slot name="suffix">{{ suffix }}</slot>
28
+ </span>
29
+ </el-tooltip>
2
30
  <span
31
+ v-else
32
+ ref="textRef"
3
33
  class="xt-text"
4
34
  :class="[
5
35
  type ? 'xt-text--' + type : '',
@@ -54,6 +84,19 @@ export default {
54
84
  default: 1,
55
85
  validator: (val) => val >= 1 && val <= 10
56
86
  },
87
+ showTooltip: {
88
+ type: Boolean,
89
+ default: true
90
+ },
91
+ tooltipPlacement: {
92
+ type: String,
93
+ default: 'top',
94
+ validator: (val) => ['top', 'bottom', 'left', 'right', 'top-start', 'top-end', 'bottom-start', 'bottom-end', 'left-start', 'left-end', 'right-start', 'right-end'].includes(val)
95
+ },
96
+ tooltipContent: {
97
+ type: String,
98
+ default: ''
99
+ },
57
100
 
58
101
  // 格式化模式:normal 普通 | thousand 千分位 | money 金额
59
102
  format: {
@@ -98,6 +141,11 @@ export default {
98
141
  default: ''
99
142
  }
100
143
  },
144
+ data() {
145
+ return {
146
+ isOverflow: false
147
+ }
148
+ },
101
149
  computed: {
102
150
  // 兼容旧 money 属性:如果传了 money=true,自动切为金额模式
103
151
  realFormat() {
@@ -115,6 +163,19 @@ export default {
115
163
  return style
116
164
  },
117
165
 
166
+ displayTooltipContent() {
167
+ if (this.tooltipContent) {
168
+ return this.tooltipContent
169
+ }
170
+ if (this.formattedValue !== undefined) {
171
+ return this.formattedValue
172
+ }
173
+ if (this.$slots.default && this.$slots.default.length > 0) {
174
+ return this.extractSlotText(this.$slots.default)
175
+ }
176
+ return this.value
177
+ },
178
+
118
179
  formattedValue() {
119
180
  const fmt = this.realFormat
120
181
  const { value } = this
@@ -163,6 +224,75 @@ export default {
163
224
  return value
164
225
  }
165
226
  }
227
+ },
228
+ methods: {
229
+ handleMouseEnter() {
230
+ this.checkOverflow()
231
+ },
232
+ checkOverflow() {
233
+ const el = this.$refs.textRef
234
+ if (!el) {
235
+ this.isOverflow = false
236
+ return
237
+ }
238
+
239
+ if (this.ellipsisRows > 1) {
240
+ this.isOverflow = el.scrollHeight > el.clientHeight
241
+ } else {
242
+ this.isOverflow = el.scrollWidth > el.clientWidth
243
+ }
244
+ },
245
+ extractSlotText(nodes) {
246
+ let text = ''
247
+ nodes.forEach(node => {
248
+ if (typeof node.children === 'string') {
249
+ text += node.children
250
+ } else if (typeof node.text === 'string') {
251
+ text += node.text
252
+ } else if (node.children && Array.isArray(node.children)) {
253
+ text += this.extractSlotText(node.children)
254
+ }
255
+ })
256
+ return text.trim()
257
+ }
258
+ },
259
+ mounted() {
260
+ if (this.ellipsis && this.showTooltip) {
261
+ this.$nextTick(() => {
262
+ this.checkOverflow()
263
+ })
264
+ }
265
+ this._resizeObserver = new ResizeObserver(() => {
266
+ if (this.ellipsis && this.showTooltip) {
267
+ this.checkOverflow()
268
+ }
269
+ })
270
+ this.$nextTick(() => {
271
+ if (this.$refs.textRef) {
272
+ this._resizeObserver.observe(this.$refs.textRef)
273
+ }
274
+ })
275
+ },
276
+ beforeDestroy() {
277
+ if (this._resizeObserver) {
278
+ this._resizeObserver.disconnect()
279
+ }
280
+ },
281
+ watch: {
282
+ value() {
283
+ if (this.ellipsis && this.showTooltip) {
284
+ this.$nextTick(() => {
285
+ this.checkOverflow()
286
+ })
287
+ }
288
+ },
289
+ ellipsis(newVal) {
290
+ if (newVal && this.showTooltip) {
291
+ this.$nextTick(() => {
292
+ this.checkOverflow()
293
+ })
294
+ }
295
+ }
166
296
  }
167
297
  }
168
298
  </script>