@lx-frontend/wrap-element-ui 0.4.0-beta.3 → 0.4.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.
@@ -1,94 +1,119 @@
1
- <template>
2
- <div class="ellipsis-popover">
3
- <ElPopover
4
- :disabled="showPopover === 'off' || (showPopover !== 'always' && !isOverflow)"
5
- :popper-class="popoverName"
6
- placement="top-start"
7
- trigger="hover">
8
- <div class="popover-content">
9
- <slot name="popover">
10
- <div v-for="(item, index) in contentArr" :key="getKey(item, index)">{{ item }}</div>
11
- </slot>
12
- </div>
13
- <div slot="reference">
14
- <template v-for="(item, index) in contentArr">
15
- <MultilineEllipsis
16
- :key="getKey(item, index)"
17
- :content="item"
18
- :fontSize="fontSize"
19
- :color="color"
20
- :lineCount="lineCount"
21
- :isOverflow.sync="overflowArr[index]">
22
- </MultilineEllipsis>
23
- </template>
24
- </div>
25
- </ElPopover>
26
- </div>
27
- </template>
28
-
29
- <script>
30
- import MultilineEllipsis from './MultilineEllipsis.vue'
31
-
32
- export default {
33
- name: 'Ellipsis',
34
- components: {
35
- MultilineEllipsis
36
- },
37
- props: {
38
- fontSize: {
39
- type: Number,
40
- default: 12
41
- },
42
- color: {
43
- type: String,
44
- default: '#000000'
45
- },
46
- lineCount: {
47
- type: Number,
48
- default: 1
49
- },
50
- content: {
51
- type: [String, Array],
52
- default: ''
53
- },
54
- popoverName: String,
55
- showPopover: {
56
- type: String,
57
- default: 'auto' // 可选值 auto, always, off
58
- }
59
- },
60
- data () {
61
- return {
62
- overflowArr: []
63
- }
64
- },
65
- computed: {
66
- contentArr () {
67
- return typeof (this.content) === 'string' ? [this.content] : [...this.content]
68
- },
69
- isOverflow () {
70
- return this.overflowArr.includes(true)
71
- }
72
- },
73
- watch: {
74
- contentArr (val) {
75
- this.overflowArr.length = val.length
76
- }
77
- },
78
- methods: {
79
- getKey (item, index) {
80
- return btoa(escape(`${item}_${index}`))
81
- }
82
- }
83
- }
84
- </script>
85
-
86
- <style lang="scss">
87
- .ellipsis-popover {
88
- width: 100%;
89
- }
90
-
91
- .popover-content {
92
- padding: 18px 20px;
93
- }
94
- </style>
1
+ <template>
2
+ <div class="ellipsis-popover">
3
+ <ElPopover
4
+ :disabled="showPopover === 'off' || (showPopover !== 'always' && !isOverflow)"
5
+ :popper-class="popoverName"
6
+ placement="top-start"
7
+ trigger="hover">
8
+ <div class="popover-content">
9
+ <slot name="popover">
10
+ <div v-for="(item, index) in contentArr" :key="getKey(item, index)">{{ item }}</div>
11
+ </slot>
12
+ </div>
13
+ <div slot="reference">
14
+ <template v-for="(item, index) in contentArr">
15
+ <MultilineEllipsis
16
+ :key="getKey(item, index)"
17
+ :content="item"
18
+ :fontSize="fontSize"
19
+ :color="color"
20
+ :lineCount="lineCount"
21
+ :iconName="iconName"
22
+ :showIconObj="{
23
+ isShowIcon: showIconObj.isShowIcon,
24
+ length: showIconObj.length,
25
+ }"
26
+ :overCountTip="{
27
+ index: index + 1,
28
+ length: contentArr.length,
29
+ }"
30
+ :isOverflow.sync="overflowArr[index]">
31
+ </MultilineEllipsis>
32
+ </template>
33
+ </div>
34
+ </ElPopover>
35
+ </div>
36
+ </template>
37
+
38
+ <script>
39
+ import MultilineEllipsis from './MultilineEllipsis.vue'
40
+
41
+ export default {
42
+ name: 'Ellipsis',
43
+ components: {
44
+ MultilineEllipsis
45
+ },
46
+ props: {
47
+ fontSize: {
48
+ type: Number,
49
+ default: 12
50
+ },
51
+ color: {
52
+ type: String,
53
+ default: '#000000'
54
+ },
55
+ lineCount: {
56
+ type: Number,
57
+ default: 1
58
+ },
59
+ iconName: {
60
+ type: String,
61
+ default: 'el-icon-arrow-down'
62
+ },
63
+ overCountTip: {
64
+ type: Object
65
+ },
66
+ showIconObj: {
67
+ type: Object,
68
+ default: () => {
69
+ return {
70
+ isShowIcon: false,
71
+ length: 0
72
+ }
73
+ },
74
+ },
75
+ content: {
76
+ type: [String, Array],
77
+ default: ''
78
+ },
79
+ popoverName: String,
80
+ showPopover: {
81
+ type: String,
82
+ default: 'auto' // 可选值 auto, always, off
83
+ }
84
+ },
85
+ data () {
86
+ return {
87
+ overflowArr: []
88
+ }
89
+ },
90
+ computed: {
91
+ contentArr () {
92
+ return typeof (this.content) === 'string' ? [this.content] : [...this.content]
93
+ },
94
+ isOverflow () {
95
+ return this.overflowArr.includes(true)
96
+ }
97
+ },
98
+ watch: {
99
+ contentArr (val) {
100
+ this.overflowArr.length = val.length
101
+ }
102
+ },
103
+ methods: {
104
+ getKey (item, index) {
105
+ return btoa(escape(`${item}_${index}`))
106
+ }
107
+ }
108
+ }
109
+ </script>
110
+
111
+ <style lang="scss">
112
+ .ellipsis-popover {
113
+ width: 100%;
114
+ }
115
+
116
+ .popover-content {
117
+ padding: 18px 20px;
118
+ }
119
+ </style>
@@ -1,114 +1,141 @@
1
- <template>
2
- <div class="ellipsis">
3
- <div class="ellipsis__container" :style="{ 'font-size': `${fontSize}px`, 'line-height': lineHeight, color }">
4
- <div class="ellipsis__content" ref="contentEl" :style="{ height: `${preHeight}px`, 'align-items': alignItems }">{{ preContent }}</div>
5
- <div class="ellipsis__last-line" ref="lastLineEl" :style="{ height: `${lastLineHeight}px` }">{{ restContent }}</div>
6
- </div>
7
- </div>
8
- </template>
9
-
10
- <script>
11
- export default {
12
- name: 'MultilineEllipsis',
13
- props: {
14
- fontSize: {
15
- type: Number,
16
- default: 12
17
- },
18
- color: {
19
- type: String,
20
- default: '#000000'
21
- },
22
- lineCount: {
23
- type: Number,
24
- default: 1
25
- },
26
- content: {
27
- type: String,
28
- default: ''
29
- },
30
- isOverflow: {
31
- type: Boolean,
32
- default: false
33
- }
34
- },
35
- data () {
36
- return {
37
- restContent: '',
38
- preContent: '',
39
- lastLineHeight: 0,
40
- alignItems: 'center'
41
- }
42
- },
43
- computed: {
44
- preHeight () {
45
- return (this.fontSize + 2) * (this.lineCount - 1)
46
- },
47
- lineHeight () {
48
- return `${this.fontSize + 2}px`
49
- }
50
- },
51
- mounted () {
52
- // 由于在 element table 中,渲染计算时的宽度可能与实际展示时的宽度可能存在偏差,在此把宽度固定为组件挂载时获取到的宽度
53
- this.$refs.contentEl.style.width = `${this.$refs.contentEl.offsetWidth}px`
54
- // 处理长度为1的数据不用走截取逻辑减少计算
55
- if (this.content.length === 1) {
56
- this.restContent = this.content;
57
- this.$refs.contentEl.remove();
58
- this.lastLineHeight = (this.fontSize + 2);
59
- return;
60
- }
61
- this.bsearch(this.content)
62
- this.lastLineHeight = (this.fontSize + 2)
63
- },
64
- methods: {
65
- bsearch (data, pre = 0) {
66
- const len = data.length
67
- const half = Math.floor((len - pre) / 2) + pre
68
- if (len - pre <= 1) {
69
- const restContent = pre === 0 ? this.content.slice(pre) : this.content.slice(pre + 1)
70
- this.preContent = pre === 0 ? '' : data.slice(0, pre + 1)
71
- if (!restContent) {
72
- this.lastLineHeight = 0
73
- this.$emit('update:isOverflow', false)
74
- return false
75
- }
76
- this.restContent = restContent
77
- this.$nextTick(() => {
78
- this.$emit('update:isOverflow', this.$refs.lastLineEl.scrollWidth !== this.$refs.lastLineEl.offsetWidth)
79
- })
80
- return true
81
- }
82
- this.preContent = data.slice(0, half + 1)
83
- this.$nextTick(() => {
84
- const isEqual = this.$refs.contentEl.scrollHeight === this.preHeight
85
- if (isEqual) {
86
- this.alignItems = 'center'
87
- return this.bsearch(data, half)
88
- }
89
- this.alignItems = 'flex-start'
90
- return this.bsearch(data.slice(0, half), pre)
91
- })
92
- return true
93
- }
94
- }
95
- }
96
- </script>
97
-
98
- <style lang="scss">
99
- .ellipsis {
100
- width: 100%;
101
- margin: 5px auto;
102
- &__content {
103
- width: 100%;
104
- overflow: hidden;
105
- display: flex;
106
- }
107
- &__last-line {
108
- width: 100%;
109
- overflow: hidden;
110
- white-space: nowrap;
111
- text-overflow: ellipsis;
112
- }
113
- }
114
- </style>
1
+ <template>
2
+ <div class="ellipsis">
3
+ <div class="ellipsis__container" :style="{ 'font-size': `${fontSize}px`, 'line-height': lineHeight, color }">
4
+ <div class="ellipsis__content" ref="contentEl" :style="{ height: `${preHeight}px`, 'align-items': alignItems }">{{ preContent }}</div>
5
+ <div class="ellipsis__last-line" ref="lastLineEl" :style="{ height: `${lastLineHeight}px` }">{{ restContent }}
6
+ <span v-if="isShowIconMethod()" :class="iconName"></span>
7
+ </div>
8
+ </div>
9
+ </div>
10
+ </template>
11
+
12
+ <script>
13
+ export default {
14
+ name: 'MultilineEllipsis',
15
+ props: {
16
+ fontSize: {
17
+ type: Number,
18
+ default: 12
19
+ },
20
+ color: {
21
+ type: String,
22
+ default: '#000000'
23
+ },
24
+ lineCount: {
25
+ type: Number,
26
+ default: 1
27
+ },
28
+ content: {
29
+ type: String,
30
+ default: ''
31
+ },
32
+ isOverflow: {
33
+ type: Boolean,
34
+ default: false
35
+ },
36
+ iconName: {
37
+ type: String,
38
+ default: 'el-icon-arrow-down'
39
+ },
40
+ overCountTip: {
41
+ type: Object,
42
+ },
43
+ showIconObj: {
44
+ type: Object,
45
+ default: () => {
46
+ return {
47
+ isShowIcon: false,
48
+ length: 0,
49
+ }
50
+ },
51
+ },
52
+ },
53
+ data () {
54
+ return {
55
+ restContent: '',
56
+ preContent: '',
57
+ lastLineHeight: 0,
58
+ alignItems: 'center'
59
+ }
60
+ },
61
+ computed: {
62
+ preHeight () {
63
+ return (this.fontSize + 2) * (this.lineCount - 1)
64
+ },
65
+ lineHeight () {
66
+ return `${this.fontSize + 2}px`
67
+ }
68
+ },
69
+ mounted () {
70
+ // 由于在 element table 中,渲染计算时的宽度可能与实际展示时的宽度可能存在偏差,在此把宽度固定为组件挂载时获取到的宽度
71
+ this.$refs.contentEl.style.width = `${this.$refs.contentEl.offsetWidth}px`
72
+ // 处理长度为1的数据不用走截取逻辑减少计算
73
+ if (this.content.length === 1) {
74
+ this.restContent = this.content;
75
+ this.$refs.contentEl.remove();
76
+ this.lastLineHeight = (this.fontSize + 2);
77
+ return;
78
+ }
79
+ this.bsearch(this.content)
80
+ this.lastLineHeight = (this.fontSize + 2)
81
+ },
82
+ methods: {
83
+ bsearch (data, pre = 0) {
84
+ const len = data.length
85
+ const half = Math.floor((len - pre) / 2) + pre
86
+ if (len - pre <= 1) {
87
+ const restContent = pre === 0 ? this.content.slice(pre) : this.content.slice(pre + 1)
88
+ this.preContent = pre === 0 ? '' : data.slice(0, pre + 1)
89
+ if (!restContent) {
90
+ this.lastLineHeight = 0
91
+ this.$emit('update:isOverflow', false)
92
+ return false
93
+ }
94
+ this.restContent = restContent
95
+ this.$nextTick(() => {
96
+ this.$emit('update:isOverflow', this.$refs.lastLineEl.scrollWidth !== this.$refs.lastLineEl.offsetWidth)
97
+ })
98
+ return true
99
+ }
100
+ this.preContent = data.slice(0, half + 1)
101
+ this.$nextTick(() => {
102
+ const isEqual = this.$refs.contentEl.scrollHeight === this.preHeight
103
+ if (isEqual) {
104
+ this.alignItems = 'center'
105
+ return this.bsearch(data, half)
106
+ }
107
+ this.alignItems = 'flex-start'
108
+ return this.bsearch(data.slice(0, half), pre)
109
+ })
110
+ return true
111
+ },
112
+ isShowIconMethod() {
113
+ /**
114
+ * 1、isShowIcon--是否展示icon; length-- 所有传入数据总数量
115
+ * 2、this.overCountTip.index === this.overCountTip.length 当前列表展示个数(最后一个列)
116
+ * 3、length > this.overCountTip.length 满足总个数大于当前列表展示个数
117
+ **/
118
+ const { isShowIcon, length } = this.showIconObj;
119
+ return (isShowIcon && this.overCountTip.index === this.overCountTip.length && this.content.length && (length > this.overCountTip.length));
120
+ }
121
+ }
122
+ }
123
+ </script>
124
+
125
+ <style lang="scss">
126
+ .ellipsis {
127
+ width: 100%;
128
+ margin: 5px auto;
129
+ &__content {
130
+ width: 100%;
131
+ overflow: hidden;
132
+ display: flex;
133
+ }
134
+ &__last-line {
135
+ width: 100%;
136
+ overflow: hidden;
137
+ white-space: nowrap;
138
+ text-overflow: ellipsis;
139
+ }
140
+ }
141
+ </style>
@@ -1,11 +1,11 @@
1
- /**
2
- * @author monkeywang
3
- * Date: 17/11/9
4
- */
5
- import LxTable from './src/LxTable.vue';
6
-
7
- LxTable.install = function (Vue) {
8
- Vue.component(LxTable.name, LxTable)
9
- }
10
-
11
- export default LxTable
1
+ /**
2
+ * @author monkeywang
3
+ * Date: 17/11/9
4
+ */
5
+ import LxTable from './src/LxTable.vue';
6
+
7
+ LxTable.install = function (Vue) {
8
+ Vue.component(LxTable.name, LxTable)
9
+ }
10
+
11
+ export default LxTable