vhb-table
Version:
一个基于 vue 的 PC 端表格组件,支持增删改查、虚拟列表、虚拟树、懒加载、快捷菜单、数据校验、树形结构、打印导出、表单渲染、数据分页、弹窗、自定义模板、渲染器、贼灵活的配置项、扩展接口等...
54 lines (46 loc) • 1.48 kB
JavaScript
import XEUtils from 'xe-utils'
import { warnLog } from '../../tools/log'
function toType (type) {
return XEUtils.toValueString(type).replace('_', '').toLowerCase()
}
const eventTypes = 'created,mounted,activated,beforeDestroy,destroyed,event.clearActived,event.clearFilter,event.clearAreas,event.showMenu,event.keydown,event.export,event.import'.split(',').map(toType)
const storeMap = {}
export const interceptor = {
mixin (map) {
XEUtils.each(map, (callback, type) => interceptor.add(type, callback))
return interceptor
},
get (type) {
return storeMap[toType(type)] || []
},
add (type, callback) {
type = toType(type)
// 检测类型
if (process.env.VUE_APP_VHB_TABLE_ENV === 'development') {
if (eventTypes.indexOf(type) === -1) {
warnLog('vhb.error.errProp', [`Interceptor.${type}`, eventTypes.join('|')])
}
}
if (callback && eventTypes.indexOf(type) > -1) {
let eList = storeMap[type]
if (!eList) {
eList = storeMap[type] = []
}
// 检测重复
if (process.env.VUE_APP_VHB_TABLE_ENV === 'development') {
if (eList.indexOf(callback) > -1) {
warnLog('vhb.error.coverProp', ['Interceptor', type])
}
}
eList.push(callback)
}
return interceptor
},
delete (type, callback) {
const eList = storeMap[toType(type)]
if (eList) {
XEUtils.remove(eList, fn => fn === callback)
}
return interceptor
}
}