util.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import XEUtils from 'xe-utils/ctor'
  2. class OptionConfig {
  3. constructor ($xeselect, _vm) {
  4. Object.assign(this, {
  5. value: _vm.value,
  6. label: _vm.label,
  7. visible: _vm.visible,
  8. disabled: _vm.disabled
  9. })
  10. }
  11. update (name, value) {
  12. this[name] = value
  13. }
  14. }
  15. export function isOption (option) {
  16. return option instanceof OptionConfig
  17. }
  18. export function getOptionConfig ($xeselect, _vm, options) {
  19. return isOption(_vm) ? _vm : new OptionConfig($xeselect, _vm, options)
  20. }
  21. export function createOption ($xeselect, _vm) {
  22. return getOptionConfig($xeselect, _vm)
  23. }
  24. export function destroyOption (_vm) {
  25. const { $xeselect, optionConfig } = _vm
  26. const matchObj = XEUtils.findTree($xeselect.collectOption, option => option === optionConfig)
  27. if (matchObj) {
  28. matchObj.items.splice(matchObj.index, 1)
  29. }
  30. }
  31. export function assemOption (_vm) {
  32. const { $el, $xeselect, $xeoptgroup, optionConfig } = _vm
  33. const groupConfig = $xeoptgroup ? $xeoptgroup.optionConfig : null
  34. optionConfig.slots = _vm.$scopedSlots
  35. if (groupConfig) {
  36. if (!groupConfig.options) {
  37. groupConfig.options = []
  38. }
  39. groupConfig.options.splice([].indexOf.call($xeoptgroup.$el.children, $el), 0, optionConfig)
  40. } else {
  41. $xeselect.collectOption.splice([].indexOf.call($xeselect.$refs.hideOption.children, $el), 0, optionConfig)
  42. }
  43. }