util.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. import XEUtils from 'xe-utils'
  2. import VXETable from '../../v-x-e-table'
  3. import { UtilTools } from '../../tools'
  4. class ItemConfig {
  5. constructor ($xeform, item) {
  6. Object.assign(this, {
  7. id: XEUtils.uniqueId('item_'),
  8. title: item.title,
  9. field: item.field,
  10. span: item.span,
  11. align: item.align,
  12. titleAlign: item.titleAlign,
  13. titleWidth: item.titleWidth,
  14. titlePrefix: item.titlePrefix,
  15. titleSuffix: item.titleSuffix,
  16. titleOverflow: item.titleOverflow,
  17. resetValue: item.resetValue,
  18. visible: item.visible,
  19. visibleMethod: item.visibleMethod,
  20. folding: item.folding,
  21. collapseNode: item.collapseNode,
  22. className: item.className,
  23. itemRender: item.itemRender,
  24. // 渲染属性
  25. showError: false,
  26. errRule: null,
  27. slots: item.slots,
  28. children: []
  29. })
  30. if (process.env.VUE_APP_VXE_TABLE_ENV === 'development') {
  31. const compConf = item.itemRender ? VXETable.renderer.get(item.itemRender.name) : null
  32. if (compConf && !compConf.renderItemContent && compConf.renderItem) {
  33. UtilTools.warn('vxe.error.delProp', ['item-render.renderItem', 'item-render.renderItemContent'])
  34. }
  35. }
  36. }
  37. update (name, value) {
  38. this[name] = value
  39. }
  40. }
  41. export function isItem (option) {
  42. return option instanceof ItemConfig
  43. }
  44. export function getItemConfig ($xeform, _vm, options) {
  45. return isItem(_vm) ? _vm : new ItemConfig($xeform, _vm, options)
  46. }
  47. export function createItem ($xeform, _vm) {
  48. return getItemConfig($xeform, _vm)
  49. }
  50. export function destroyItem (_vm) {
  51. const { $xeform, itemConfig } = _vm
  52. const matchObj = XEUtils.findTree($xeform.staticItems, option => option === itemConfig)
  53. if (matchObj) {
  54. matchObj.items.splice(matchObj.index, 1)
  55. }
  56. }
  57. export function assemItem (_vm) {
  58. const { $el, $xeform, xeformgather, itemConfig } = _vm
  59. const itemGather = xeformgather ? xeformgather.itemConfig : null
  60. itemConfig.slots = _vm.$scopedSlots
  61. if (itemGather) {
  62. if (!itemGather.children) {
  63. itemGather.children = []
  64. }
  65. itemGather.children.splice([].indexOf.call(xeformgather.$el.children, $el), 0, itemConfig)
  66. } else {
  67. $xeform.staticItems.splice([].indexOf.call($xeform.$refs.hideItem.children, $el), 0, itemConfig)
  68. }
  69. }