vhb-table
Version:
一个基于 vue 的 PC 端表格组件,支持增删改查、虚拟列表、虚拟树、懒加载、快捷菜单、数据校验、树形结构、打印导出、表单渲染、数据分页、弹窗、自定义模板、渲染器、贼灵活的配置项、扩展接口等...
84 lines (75 loc) • 2.49 kB
JavaScript
import XEUtils from 'xe-utils'
import VHBTable from '../../v-h-b-table'
import { warnLog } from '../../tools/log'
class ItemConfig {
constructor ($xeform, item) {
Object.assign(this, {
id: XEUtils.uniqueId('item_'),
title: item.title,
field: item.field,
span: item.span,
align: item.align,
titleAlign: item.titleAlign,
titleWidth: item.titleWidth,
titlePrefix: item.titlePrefix,
titleSuffix: item.titleSuffix,
titleOverflow: item.titleOverflow,
resetValue: item.resetValue,
visible: item.visible,
visibleMethod: item.visibleMethod,
folding: item.folding,
collapseNode: item.collapseNode,
className: item.className,
itemRender: item.itemRender,
// 渲染属性
showError: false,
errRule: null,
slots: item.slots,
children: []
})
if (process.env.VUE_APP_VHB_TABLE_ENV === 'development') {
const compConf = item.itemRender ? VHBTable.renderer.get(item.itemRender.name) : null
if (compConf && !compConf.renderItemContent && compConf.renderItem) {
warnLog('vhb.error.delProp', ['item-render.renderItem', 'item-render.renderItemContent'])
}
}
}
update (name, value) {
this[name] = value
}
}
export function isItem (option) {
return option instanceof ItemConfig
}
export function getItemConfig ($xeform, _vm, options) {
return isItem(_vm) ? _vm : new ItemConfig($xeform, _vm, options)
}
export const handleFieldOrItem = ($xeform, fieldOrItem) => {
if (fieldOrItem) {
return XEUtils.isString(fieldOrItem) ? $xeform.getItemByField(fieldOrItem) : fieldOrItem
}
return null
}
export function createItem ($xeform, _vm) {
return getItemConfig($xeform, _vm)
}
export function destroyItem (_vm) {
const { $xeform, itemConfig } = _vm
const matchObj = XEUtils.findTree($xeform.staticItems, option => option === itemConfig)
if (matchObj) {
matchObj.items.splice(matchObj.index, 1)
}
}
export function assemItem (_vm) {
const { $el, $xeform, xeformgather, itemConfig } = _vm
const itemGather = xeformgather ? xeformgather.itemConfig : null
itemConfig.slots = _vm.$scopedSlots
if (itemGather) {
if (!itemGather.children) {
itemGather.children = []
}
itemGather.children.splice([].indexOf.call(xeformgather.$el.children, $el), 0, itemConfig)
} else {
$xeform.staticItems.splice([].indexOf.call($xeform.$refs.hideItem.children, $el), 0, itemConfig)
}
}