gunter-kgd 1.0.0 → 1.0.2

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.
@@ -0,0 +1,349 @@
1
+ <!--表格最外层-->
2
+ <template>
3
+ <div ref="gante_table" @mousewheel.passive="gun" @DOMMouseScroll.passive="gun" class="gante-table">
4
+ <div class="gante-thead">
5
+ <div class="gante-th" :data-key="key" v-show="th.show != false" @mousedown="th_down" @mousemove="th_move" @mouseout="th_out" :key="index" v-for="(th,key,index) in th_data">
6
+ <div class="cell" :style="{width:th.width ? th.width+'px' : '80px',textAlign: th.is_op ? 'center' : 'left'}">
7
+ {{th.value}}
8
+ <!-- <span v-if="th.sort_type || th.sort_type == null" :class="{ascend:th.sort_type == 'asc',descend:th.sort_type == 'desc'}" class="caret-wrapper">-->
9
+ <!-- <i @click.stop="sortCaret(1,key)" class="sort-caret ascending"></i>-->
10
+ <!-- <i @click.stop="sortCaret(2,key)" class="sort-caret descending"></i>-->
11
+ <!-- </span>-->
12
+ </div>
13
+ </div>
14
+ </div>
15
+ <div class="gante-tbody">
16
+ <gante-tr :all_data="data" :data="data" :th_data="th_data"></gante-tr>
17
+ <!-- <loading :showLoading="showLoading">没有更多了</loading>-->
18
+ </div>
19
+ <div v-show="show_proxy" :style="{left:proxy_left+'px'}" id="gante-table__column-resize-proxy"></div>
20
+ </div>
21
+ </template>
22
+ <script>
23
+ import ganteTr from './gante-table-tr.vue'
24
+ import loading from '../../components/common/loading'
25
+ export default{
26
+ data(){
27
+ return{
28
+ oldx:0, //记录鼠标按下的位置
29
+ old_width:0, //记录鼠标按下的初始宽度
30
+ tTD:{
31
+ current_index:null,
32
+ mouseDown:false
33
+ },
34
+ proxy_left:0,
35
+ show_proxy:false,
36
+ }
37
+ },
38
+ props:{
39
+ th_data:Object,
40
+ data:Array,
41
+ showLoading:Boolean,
42
+ },
43
+ methods:{
44
+ //排序
45
+ sortCaret(mode,key){
46
+ let cla = 'asc',assign_key = key
47
+ if(mode == 2){
48
+ cla = 'desc'
49
+ }
50
+ for(let i in this.th_data){
51
+ if(this.th_data[i].sort_type || this.th_data[i].sort_type == null){
52
+ if(i == key){
53
+ //如果再次点击之前的排序,就取消排序
54
+ if(this.th_data[i].sort_type == cla){
55
+ this.$set(this.th_data[i], 'sort_type' , null)
56
+ assign_key = ''
57
+ }else{
58
+ if(this.th_data[i].time_mode){
59
+ assign_key = this.th_data[i].time_mode == 1 ? 'start_time' : 'end_time'
60
+ }
61
+ this.$set(this.th_data[i], 'sort_type' , cla)
62
+ }
63
+ }else{
64
+ this.$set(this.th_data[i], 'sort_type' , null)
65
+ }
66
+ }
67
+ }
68
+ this.$emit('sort',assign_key,cla)
69
+ },
70
+ // 获取元素距离浏览器的距离
71
+ getPos(ele){
72
+ var p=ele.offsetParent;
73
+ var left=ele.offsetLeft;
74
+ var top=ele.offsetTop
75
+ while(p){
76
+ if(window.navigator.userAgent.indexOf("MSIE 8")>-1){
77
+ left+=p.offsetLeft;
78
+ top+=p.offsetTop;
79
+ }else{
80
+ left+=p.offsetLeft+p.clientLeft;
81
+ top+=p.offsetTop+p.clientTop;
82
+ }
83
+ p=p.offsetParent;
84
+ }
85
+ var obj={};
86
+ obj.x=left;
87
+ obj.y=top;
88
+ return obj;
89
+ },
90
+ // 监听表格的鼠标滚轴事件,从而让甘特图上下滚动
91
+ gun(e){
92
+ // 检测是否为垂直滚动
93
+ const isVerticalScroll = Math.abs(e.wheelDeltaY || e.deltaY || e.wheelDelta) > Math.abs(e.wheelDeltaX || e.deltaX || 0);
94
+
95
+ if (!isVerticalScroll) {
96
+ return; // 如果是水平滚动,直接返回不处理
97
+ }
98
+ let speed = -200
99
+ let scrollTop = document.getElementsByClassName('ganteview')[0].scrollTop,
100
+ ganteview = document.getElementsByClassName('ganteview')[0]
101
+ if(e.wheelDelta && e.wheelDelta < 0){//兼容IE,Opera,Chrome
102
+ speed = 200
103
+ }else if(e.detail > 0){
104
+ speed = 200
105
+ }
106
+ this.mark = false
107
+ this.autoScroll(scrollTop,scrollTop + speed ,4,(value)=>{
108
+ ganteview.scrollTop = value
109
+ })
110
+ },
111
+ /**
112
+ *
113
+ * @param start 起始位置
114
+ * @param end 目标位置
115
+ * @param rate 缓动速率
116
+ * @param callback 变化的位置回调,支持两个参数,value和isEnding,表示当前的位置值(数值)以及是否动画结束了(布尔值);
117
+ */
118
+ autoScroll(start, end, rate, callback) {
119
+ if (start == end || typeof start != 'number') {
120
+ return;
121
+ }
122
+ end = end || 0;
123
+ rate = rate || 2;
124
+ var step = function () {
125
+ start = start + (end - start) / rate;
126
+ if (Math.abs(start - end) <= 1) {
127
+ callback(end, true);
128
+ return;
129
+ }
130
+ callback(start, false);
131
+ if(!window.requestAnimationFrame){
132
+ setTimeout(step, 17);
133
+ }else{
134
+ requestAnimationFrame(step);
135
+ }
136
+ };
137
+ step();
138
+ },
139
+ // 让表头可以拉动,改变宽度
140
+ doc_move(e){
141
+ var _body = document.getElementsByTagName('body')[0]
142
+ if(this.tTD.mouseDown){
143
+ var gante_left = this.getPos(this.$refs.gante_table).x,cel = e.clientX,gante_table_box = document.getElementsByClassName('gante-table-box')[0]
144
+ if(gante_table_box.scrollLeft){
145
+ cel = cel + gante_table_box.scrollLeft
146
+ }
147
+ let _left = cel - gante_left+3
148
+ // 最小的宽度只能是30
149
+ if(_left - 30<= this.oldx + 3 -this.th_data[this.tTD.current_index].width){
150
+ _left = this.oldx + 3 -this.th_data[this.tTD.current_index].width + 30
151
+ }
152
+ this.proxy_left = _left
153
+ _body.style.cursor = 'col-resize'
154
+ }
155
+ },
156
+ // 表头鼠标按下
157
+ th_down(e){
158
+ if(e.target.tagName === 'SPAN' ||e.target.tagName === 'I'){
159
+ return;
160
+ }
161
+ var table_width = this.getPos(this.$refs.gante_table).x,target=e.target,client_x = e.clientX,gante_table_box = document.getElementsByClassName('gante-table-box')[0]
162
+ if(target.classList.contains('cell')){
163
+ target = target.parentNode
164
+ }
165
+ if(gante_table_box.scrollLeft){
166
+ client_x = client_x + gante_table_box.scrollLeft
167
+ }
168
+ this.oldx = client_x - table_width
169
+ if(client_x > this.getPos(target).x + target.offsetWidth - 10){
170
+ this.old_width = target.offsetWidth
171
+ this.show_proxy = true
172
+ this.tTD.current_index = target.dataset.key //记录拖动的是哪个th
173
+ this.proxy_left = this.oldx+3 //必须要加上3像素,不然拖动会有问题
174
+ this.tTD.mouseDown = true
175
+ // 给document绑定事件
176
+ document.addEventListener('mousemove',this.doc_move,{passive:false})
177
+ document.addEventListener('mouseup',this.doc_up,{passive:false})
178
+ }
179
+ },
180
+ doc_up(){
181
+ document.getElementsByTagName('body')[0].style.cursor = null
182
+ if(this.tTD.mouseDown && this.oldx && this.tTD.current_index){
183
+ // 设置拖动后的宽度
184
+ this.th_data[this.tTD.current_index].width = this.old_width+(this.proxy_left - this.oldx)
185
+ // 获取到左边表格所有td加起来的宽度
186
+ let str = 0,_width = document.getElementsByClassName('gante-table-box')[0].offsetWidth;
187
+ for(let key in this.th_data){
188
+ if(this.th_data[key].show != false){
189
+ str += this.th_data[key].width ? Number(this.th_data[key].width) + 1 : 81;
190
+ }
191
+ }
192
+ if(str < _width){
193
+ this.$parent.tabe_width = (str + 2) <= 480 ? 480 : (str + 2) + 'px';
194
+ }
195
+
196
+ // 初始化所有的值
197
+ this.tTD.mouseDown = false
198
+ this.show_proxy = false
199
+ this.oldx = 0
200
+ this.old_width = 0
201
+ this.tTD.current_index = null
202
+ // 给document移除绑定事件
203
+ document.removeEventListener('mousemove',this.doc_move,false)
204
+ document.removeEventListener('mouseup',this.doc_up,false)
205
+ }
206
+ },
207
+ // 给表格头部加上鼠标悬浮可以拉动效果
208
+ th_move(e){
209
+ if(e.target.tagName === 'SPAN' ||e.target.tagName === 'I'){
210
+ return;
211
+ }
212
+
213
+ var target = e.target,_body = document.getElementsByTagName('body')[0],client_x = e.clientX,gante_table_box = document.getElementsByClassName('gante-table-box')[0]
214
+ if(target.classList.contains('cell')){
215
+ target = e.target.parentNode
216
+ }
217
+ if(gante_table_box.scrollLeft){
218
+ client_x = client_x + gante_table_box.scrollLeft
219
+ }
220
+ if(client_x > this.getPos(target).x + target.offsetWidth - 10 ){
221
+ _body.style.cursor = 'col-resize'
222
+ }else{
223
+ _body.style.cursor = null
224
+ }
225
+ },
226
+ th_out(){
227
+ document.getElementsByTagName('body')[0].style.cursor = null
228
+ }
229
+ },
230
+ components:{
231
+ ganteTr,loading
232
+ }
233
+ }
234
+
235
+ </script>
236
+ <style lang="less" type="text/less">
237
+ .gante-table{
238
+ font-size: 14px;
239
+ display: table;
240
+ table-layout: fixed;
241
+ word-break: break-all;
242
+ position: relative;
243
+ color: #666;
244
+ width: 100%;
245
+ }
246
+ .gante-thead{
247
+ position: absolute;
248
+ top:0;
249
+ left:0;
250
+ width: 100%;
251
+ z-index:2;
252
+
253
+ }
254
+ .gante-tbody{
255
+ position: relative;
256
+ padding-top:50px;
257
+ }
258
+ .gante-th{
259
+ display: table-cell;
260
+ white-space: nowrap;
261
+ overflow: hidden;
262
+ -webkit-user-select: none;
263
+ -moz-user-select: none;
264
+ -ms-user-select: none;
265
+ user-select: none;
266
+ text-align: left;
267
+ background: #fff;
268
+ box-sizing: border-box;
269
+ }
270
+ /*.gante-tr{*/
271
+ /*display: table-row;*/
272
+ /*}*/
273
+ .gante-td{
274
+ display: table-cell;
275
+ position: relative;
276
+ }
277
+ .gante-th,.gante-td{
278
+ word-break:keep-all;
279
+ /*padding: 12px 0;*/
280
+ min-width: 0;
281
+ -webkit-box-sizing: border-box;
282
+ box-sizing: border-box;
283
+ -o-text-overflow: ellipsis;
284
+ text-overflow: ellipsis;
285
+ vertical-align: middle;
286
+ white-space: nowrap;
287
+ border-bottom: 1px solid #ebeef5;
288
+ border-right: 1px solid #ebeef5;
289
+ line-height: 50px;
290
+ }
291
+ .gante-th .cell ,.gante-td .cell{
292
+ position: relative;
293
+ word-wrap: normal;
294
+ overflow: hidden;
295
+ text-overflow: ellipsis;
296
+ vertical-align: middle;
297
+ width: 100%;
298
+ box-sizing: border-box;
299
+ padding: 0 10px;
300
+ /*min-height: 16px;*/
301
+ height:50px;
302
+ line-height: 50px;
303
+ }
304
+ .gante-th .cell{
305
+ border-top: 1px solid #ebeef5;
306
+ }
307
+ .cell .caret-wrapper{
308
+ display: inline-flex;
309
+ flex-direction: column;
310
+ align-items: center;
311
+ height: 34px;
312
+ width: 24px;
313
+ vertical-align: middle;
314
+ cursor: pointer;
315
+ overflow: initial;
316
+ position: relative;
317
+ }
318
+ .sort-caret {
319
+ width: 0;
320
+ height: 0;
321
+ border: 5px solid transparent;
322
+ position: absolute;
323
+ left: 7px;
324
+ }
325
+ .ascend .sort-caret.ascending{
326
+ border-bottom-color:#3396fb;
327
+ }
328
+ .descend .sort-caret.descending{
329
+ border-top-color:#3396fb;
330
+ }
331
+ .sort-caret.ascending {
332
+ border-bottom-color: #c0c4cc;
333
+ top: 5px;
334
+ }
335
+ .sort-caret.descending {
336
+ border-top-color: #c0c4cc;
337
+ bottom: 7px;
338
+ }
339
+ #gante-table__column-resize-proxy{
340
+ position: absolute;
341
+ top:0;
342
+ left: 0;
343
+ border-left: 1px solid #ebeef5;
344
+ width: 0;
345
+ bottom: 0;
346
+ z-index:5;
347
+ }
348
+
349
+ </style>