ocpview-pro 0.1.3 → 0.1.5

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": "ocpview-pro",
3
- "version": "0.1.3",
3
+ "version": "0.1.5",
4
4
  "title": "ocpviewPlus",
5
5
  "description": "A high quality Service UI components Library with Vue.js",
6
6
  "homepage": "",
@@ -1,95 +1,162 @@
1
- <template>
2
- <Tooltip transfer :content="labeltext" :disabled="!showTooltip" :max-width="maxWidth" class="ivu-table-cell-tooltip" >
3
- <template v-if="textLink">
4
- <a href="#" style="text-decoration:underline" @click.prevent="linkTo"><span ref="content" class="ivu-table-cell-tooltip-content" v-html="showText" :style="'text-align:'+ contentAlign" @mouseenter="handleTooltipIn" @mouseleave="handleTooltipOut"/> </a>
5
- </template>
6
- <template v-else>
7
- <span ref="content" class="ivu-table-cell-tooltip-content" v-html="showText" :style="'text-align:'+ contentAlign" @mouseenter="handleTooltipIn" @mouseleave="handleTooltipOut"/>
8
- </template>
9
- </Tooltip>
1
+ <template>
2
+ <component
3
+ :is="showTooltip ? 'Tooltip' : 'div'"
4
+ v-bind="showTooltip ? { transfer: true, content: labeltext, maxWidth: maxWidth, disabled: tooltipDisabled } : {}"
5
+ class="ivu-table-cell-tooltip"
6
+ >
7
+ <template v-if="showTooltip" #content>
8
+ <span class="showtext-tooltip-content">{{ labeltext }}</span>
9
+ </template>
10
+ <span
11
+ ref="content"
12
+ class="ivu-table-cell-tooltip-content"
13
+ :class="{ 'showtext-link': textLink }"
14
+ v-html="displayText"
15
+ :style="{ textAlign: contentAlign, width: '100%' }"
16
+ v-on="hasOverflow ? { mouseenter: handleTooltipIn, mouseleave: handleTooltipOut } : {}"
17
+ @click.prevent="textLink && linkTo()"
18
+ />
19
+ </component>
10
20
  </template>
11
21
  <script>
12
- export default {
13
- name: 'showText',
14
- data () {
15
- return {
16
- showTooltip:false,
17
- labeltext: '',
18
- showIcon:false,
19
- iconWidth:0,
20
- textLink:false
21
- };
22
+ export default {
23
+ name: "showText",
24
+ data() {
25
+ return {
26
+ showTooltip: false,
27
+ tooltipDisabled: true,
28
+ tooltipTimer: null,
29
+ hasOverflow: false,
30
+ };
31
+ },
32
+ props: {
33
+ label: {
34
+ type: [String, Number],
35
+ default: "",
22
36
  },
23
- props:{
24
- label:{
25
- type: [String,Number],
26
- default: ''
27
- },
28
- maxWidth:{
29
- type: [String,Number],
30
- default: 300
31
- },
32
- contentAlign: {
33
- type: String,
34
- default: 'center'
35
- },
36
- resetText: {
37
- type: Function,
38
- default: null
39
- },
40
- config: {
41
- type: Object,
42
- default: () => {},
43
- },
44
- rowIndex: {
45
- type: [String,Number],
46
- default: ''
37
+ maxWidth: {
38
+ type: [String, Number],
39
+ default: 300,
40
+ },
41
+ contentAlign: {
42
+ type: String,
43
+ default: "center",
44
+ },
45
+ resetText: {
46
+ type: Function,
47
+ default: null,
48
+ },
49
+ config: {
50
+ type: Object,
51
+ default: () => ({}),
52
+ },
53
+ rowIndex: {
54
+ type: [String, Number],
55
+ default: "",
56
+ },
57
+ },
58
+ computed: {
59
+ labeltext() {
60
+ return this.label;
61
+ },
62
+ textLink() {
63
+ return !!(this.config && this.config.textLink);
64
+ },
65
+ displayText() {
66
+ if (this.resetText) {
67
+ return this.resetText(
68
+ this.doSpecialSymbols(this.label),
69
+ this.label
70
+ );
71
+ }
72
+ return this.doSpecialSymbols(this.label);
73
+ },
74
+ },
75
+ mounted() {
76
+ this.$nextTick(() => {
77
+ this.checkOverflow();
78
+ this.setupResizeObserver();
79
+ });
80
+ },
81
+ beforeUnmount() {
82
+ if (this.tooltipTimer) {
83
+ clearTimeout(this.tooltipTimer);
84
+ this.tooltipTimer = null;
85
+ }
86
+ if (this.resizeObserver) {
87
+ this.resizeObserver.disconnect();
88
+ this.resizeObserver = null;
89
+ }
90
+ if (this.checkOverflowDebounced) {
91
+ this.checkOverflowDebounced.cancel();
92
+ this.checkOverflowDebounced = null;
93
+ }
94
+ },
95
+ methods: {
96
+ checkOverflow() {
97
+ const content = this.$refs.content;
98
+ this.hasOverflow = !!(
99
+ content && content.scrollWidth > content.offsetWidth
100
+ );
101
+ },
102
+ setupResizeObserver() {
103
+ const content = this.$refs.content;
104
+ if (!content || !window.ResizeObserver) return;
105
+ this.checkOverflowDebounced = this.$utils.debounce(
106
+ this.checkOverflow, 150
107
+ );
108
+ this.resizeObserver = new ResizeObserver(
109
+ this.checkOverflowDebounced
110
+ );
111
+ this.resizeObserver.observe(content.parentElement);
112
+ },
113
+ handleTooltipIn() {
114
+ if (this.tooltipTimer) {
115
+ clearTimeout(this.tooltipTimer);
116
+ this.tooltipTimer = null;
47
117
  }
118
+ this.showTooltip = true;
119
+ this.tooltipTimer = setTimeout(() => {
120
+ this.tooltipDisabled = false;
121
+ this.tooltipTimer = null;
122
+ }, 300);
48
123
  },
49
- created() {
50
- if (this.config && this.config.textLink !== undefined) {
51
- this.textLink = this.config.textLink;
124
+ handleTooltipOut() {
125
+ if (this.tooltipTimer) {
126
+ clearTimeout(this.tooltipTimer);
127
+ this.tooltipTimer = null;
52
128
  }
129
+ this.tooltipDisabled = true;
130
+ this.tooltipTimer = setTimeout(() => {
131
+ this.showTooltip = false;
132
+ this.tooltipTimer = null;
133
+ }, 300);
53
134
  },
54
- methods:{
55
- handleTooltipIn () {
56
- const $content = this.$refs.content;
57
- this.showTooltip = $content.scrollWidth > $content.offsetWidth;
58
- },
59
- handleTooltipOut () {
60
- this.showTooltip = false;
61
- },
62
- doSpecialSymbols(str) {
63
- if (str) {
64
- str = str + '';
65
- //替换所有的换行符
66
- str = str.replace(/\r\n/g,'<br>');
67
- str = str.replace(/\n/g,'<br>');
68
- //替换所有的空格(中文空格、英文空格都会被替换)
69
- str = str.replace(/\s/g,'&nbsp;');
70
- }
71
- return str;
72
- },
73
- linkTo() {
74
- if (this.config.onLinkTo) {
75
- let obj = this.$Method.copy(this.config);
76
- obj.rowIndex = this.rowIndex;
77
- this.config.onLinkTo(obj);
78
- }
135
+ doSpecialSymbols(str) {
136
+ if (str) {
137
+ str = str + "";
138
+ str = str.replace(/\r\n/g, "<br>");
139
+ str = str.replace(/\n/g, "<br>");
140
+ str = str.replace(/\s/g, "&nbsp;");
79
141
  }
142
+ return str;
80
143
  },
81
- watch:{
82
- label: {
83
- handler (data) {
84
- this.labeltext = data;
85
- if (this.resetText) {
86
- this.showText = this.resetText(this.doSpecialSymbols(data),data);
87
- } else {
88
- this.showText = this.doSpecialSymbols(data);
89
- }
90
- },
91
- immediate: true
144
+ linkTo() {
145
+ if (this.config && this.config.onLinkTo) {
146
+ let obj = this.$Method.copy(this.config);
147
+ obj.rowIndex = this.rowIndex;
148
+ this.config.onLinkTo(obj);
92
149
  }
93
- }
94
- };
95
- </script>
150
+ },
151
+ },
152
+ };
153
+ </script>
154
+ <style scoped>
155
+ .showtext-tooltip-content {
156
+ white-space: pre-wrap;
157
+ }
158
+ .showtext-link {
159
+ text-decoration: underline;
160
+ cursor: pointer;
161
+ }
162
+ </style>