xianniu-ui 0.4.5 → 0.5.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": "xianniu-ui",
3
- "version": "0.4.5",
3
+ "version": "0.5.1",
4
4
  "private": false,
5
5
  "main": "lib/xianniu-ui.umd.min.js",
6
6
  "scripts": {
@@ -0,0 +1,7 @@
1
+ import XnEllipsis from './main.vue'
2
+
3
+ XnEllipsis.install = function (Vue) {
4
+ Vue.component(XnEllipsis.name, XnEllipsis)
5
+ }
6
+
7
+ export default XnEllipsis
@@ -0,0 +1,142 @@
1
+ <template>
2
+ <div class="xn-ellipsis" ref="root">
3
+ {{ expanded ? content : text }}
4
+ <span class="xn-ellipsis__action" v-if="hasAction" @click="onClickAction">{{
5
+ expanded ? collapseText : expandText
6
+ }}</span>
7
+ </div>
8
+ </template>
9
+
10
+ <script>
11
+ export default {
12
+ name: "XnEllipsis",
13
+ props: {
14
+ rows: {
15
+ type: Number,
16
+ default: 1,
17
+ },
18
+ content: {
19
+ type: String,
20
+ default:
21
+ "阿三大苏打实打实的啊啊实打实的阿三大苏打实打实的啊啊实打实的阿三大苏打实打实的啊啊实打实的阿三大苏打实打实的啊啊实打实的阿三大苏打实打实的啊啊实打实的阿三大苏打实打实的啊啊实打实的阿三大苏打实打实的啊啊实打实的阿三大苏打实打实的啊啊实打实的阿三大苏打实打实的啊啊实打实的阿三大苏打实打实的啊啊实打实的阿三大苏打实打实的啊啊实打实的阿三大苏打实打实的啊啊实打实的阿三大苏打实打实的啊啊实打实的阿三大苏打实打实的啊啊实打实的",
22
+ },
23
+ expandText: {
24
+ type: String,
25
+ default: "展开",
26
+ },
27
+ collapseText: {
28
+ type: String,
29
+ default: "收起",
30
+ },
31
+ },
32
+ data() {
33
+ return {
34
+ text: "",
35
+ expanded: false,
36
+ hasAction: false,
37
+ };
38
+ },
39
+ computed: {
40
+ root() {
41
+ return this.$refs.root;
42
+ },
43
+ },
44
+ watch: {
45
+ content: {
46
+ handler() {
47
+ this.calcEllipsised();
48
+ },
49
+ immediate: true,
50
+ },
51
+ rows: {
52
+ handler() {
53
+ this.calcEllipsised();
54
+ },
55
+ immediate: true,
56
+ },
57
+ },
58
+ methods: {
59
+ pxToNum(value) {
60
+ if (!value) return 0;
61
+ const match = value.match(/^\d*(\.\d*)?/);
62
+ return match ? Number(match[0]) : 0;
63
+ },
64
+ calcEllipsised() {
65
+ const { root } = this.$refs;
66
+ const cloneContainer = () => {
67
+ if (!root) return;
68
+ const originStyle = window.getComputedStyle(root);
69
+ const container = document.createElement("div");
70
+ const styleNames = Array.prototype.slice.apply(originStyle);
71
+ styleNames.forEach((name) => {
72
+ container.style.setProperty(name, originStyle.getPropertyValue(name));
73
+ });
74
+
75
+ container.style.position = "fixed";
76
+ container.style.zIndex = "-9999";
77
+ container.style.top = "-9999px";
78
+ container.style.height = "auto";
79
+ container.style.minHeight = "auto";
80
+ container.style.maxHeight = "auto";
81
+
82
+ container.innerText = this.content;
83
+ document.body.appendChild(container);
84
+ return container;
85
+ };
86
+ const calcEllipsisText = (container, maxHeight) => {
87
+ const { content, expandText } = this;
88
+
89
+ const dot = "...";
90
+ let left = 0;
91
+ let right = content.length;
92
+ let res = -1;
93
+
94
+ while (left <= right) {
95
+ const mid = Math.floor((left + right) / 2);
96
+ container.innerText = content.slice(0, mid) + dot + expandText;
97
+ if (container.offsetHeight <= maxHeight) {
98
+ left = mid + 1;
99
+ res = mid;
100
+ } else {
101
+ right = mid - 1;
102
+ }
103
+ }
104
+ return content.slice(0, res) + dot;
105
+ };
106
+
107
+ const container = cloneContainer();
108
+ if (!container) return;
109
+ const { paddingBottom, paddingTop, lineHeight } = container.style;
110
+
111
+ const { rows, content } = this;
112
+
113
+ const maxHeight =
114
+ (Number(rows) + 0.5) * this.pxToNum(lineHeight) +
115
+ this.pxToNum(paddingTop) +
116
+ this.pxToNum(paddingBottom);
117
+ if (maxHeight < container.offsetHeight) {
118
+ this.hasAction = true;
119
+ this.text = calcEllipsisText(container, maxHeight);
120
+ } else {
121
+ this.hasAction = false;
122
+ this.text = content;
123
+ }
124
+ document.body.removeChild(container);
125
+ },
126
+ onClickAction(event) {
127
+ this.expanded = !this.expanded;
128
+ this.$emit("clickAction", event);
129
+ },
130
+ },
131
+ mounted() {
132
+ this.calcEllipsised();
133
+ window.addEventListener("resize", () => {
134
+ this.calcEllipsised();
135
+ });
136
+ },
137
+ };
138
+ </script>
139
+
140
+ <style lang="scss" scoped>
141
+
142
+ </style>
@@ -0,0 +1,11 @@
1
+ @import "./theme/theme.scss";
2
+ .xn-ellipsis {
3
+ white-space: pre-wrap;
4
+ word-break: break-word;
5
+ line-height: 1.6;
6
+ font-size: 14px;
7
+ &__action {
8
+ color: $--color-primary;
9
+ cursor: pointer;
10
+ }
11
+ }
@@ -11,6 +11,7 @@
11
11
  @import './flex.scss';
12
12
  @import './footer.scss';
13
13
  @import './tag.scss';
14
+ @import './ellipsis.scss';
14
15
 
15
16
 
16
17
 
@@ -2,7 +2,6 @@
2
2
  <el-table-column
3
3
  v-bind="$attrs"
4
4
  v-on="$listeners"
5
- :showOverflowTooltip="$attrs.showOverflowTooltip !== false"
6
5
  v-if="isShowColumn($attrs)"
7
6
  >
8
7
  <template v-if="$attrs.labelMsg">
package/src/index.js CHANGED
@@ -14,6 +14,7 @@ import XnExport from '../packages/export/index'
14
14
  import XnFooter from '../packages/footer/index'
15
15
  import XnEmpty from '../packages/empty/index'
16
16
  import XnTag from '../packages/tag/index'
17
+ import XnEllipsis from '../packages/ellipsis/index'
17
18
 
18
19
  import Utils from 'xn-ui/src/utils/index'
19
20
  const doc = 'http://lzwr.gitee.io/xn-ui/#/'
@@ -32,7 +33,8 @@ const components = [
32
33
  XnExport,
33
34
  XnFooter,
34
35
  XnEmpty,
35
- XnTag
36
+ XnTag,
37
+ XnEllipsis
36
38
  ]
37
39
  const version = require('../package.json').version
38
40
  const install = function (Vue) {
@@ -75,5 +77,8 @@ export default {
75
77
  XnTree,
76
78
  XnImport,
77
79
  XnExport,
78
- XnFooter
80
+ XnFooter,
81
+ XnEmpty,
82
+ XnTag,
83
+ XnEllipsis
79
84
  }