main.js
2.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/*
* @Descripttion:
* @version: 1.0.0
* @Author: limin
* @Date: 2021-08-13 14:12:11
* @LastEditors: limin
* @LastEditTime: 2021-09-24 10:41:31
* @FilePath: \scrm\scrm-sub-blog\src\main.js
*/
import Vue from 'vue'
import apis from './api'
import './public-path'
import '@/assets/css/public.scss'
// import 'glsx-components/dist/glsx-components.css'
// 针对template模板中使用可选链操作符
import chaining from '@/plugins/chaining'
import { start } from '@/setup'
Vue.use(chaining)
Vue.config.productionTip = false
Vue.prototype.$apis = apis
Vue.directive('preventReClick', {
bind: (el, binding) => {
let time = binding.value // 防抖时间
if (!time) {
// 用户若不设置防抖时间,则默认1s
time = 1000
}
let fun
el.addEventListener(
'click',
event => {
if (!fun) {
// 第一次执行
fun = setTimeout(() => {
fun = null
}, time)
} else {
// 直接取消当前事件
event && event.stopImmediatePropagation()
}
},
true
)
}
})
function adjustColumnWidth(table) {
const colgroup = table.querySelector('colgroup')
const colDefs = [...colgroup.querySelectorAll('col')]
colDefs.forEach(col => {
const clsName = col.getAttribute('name')
const cells = [...table.querySelectorAll(`td.${clsName}`), ...table.querySelectorAll(`th.${clsName}`)]
// 忽略加了"leave-alone"类的列
if (cells[0]?.classList?.contains?.('leave-alone')) {
return
}
const widthList = cells.map(el => {
return el.querySelector('.cell')?.scrollWidth || 0
})
const max = Math.max(...widthList)
const padding = 32
table.querySelectorAll(`col[name=${clsName}]`).forEach(el => {
el.setAttribute('width', max + padding)
})
})
}
Vue.directive('fit-columns', {
update() {},
bind() {},
inserted(el) {
setTimeout(() => {
adjustColumnWidth(el)
}, 300)
},
componentUpdated(el) {
el.classList.add('r-table')
setTimeout(() => {
adjustColumnWidth(el)
}, 300)
},
unbind() {}
})
start()
export { bootstrap, mount, unmount } from '@/setup'
export const http = params => Vue.prototype.$http(params)
export const http_brand = params => Vue.prototype.$http_brand(params)
export const http_common = params => Vue.prototype.$http_common(params)