You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

0 lines
26 KiB

1 month ago
  1. {"ast":null,"code":"import { toRefs, computed, nextTick, watch } from 'vue';\nimport { pick, isEqual, isNil } from 'lodash-unified';\nimport { ElTree } from '../../tree/index.mjs';\nimport component from './tree-select-option.mjs';\nimport { treeEach, toValidArray, treeFind, isValidValue, isValidArray } from './utils.mjs';\nimport { escapeStringRegexp } from '../../../utils/strings.mjs';\nimport { UPDATE_MODEL_EVENT } from '../../../constants/event.mjs';\nimport { isFunction } from '@vue/shared';\nimport { isEmpty } from '../../../utils/types.mjs';\nconst useTree = (props, {\n attrs,\n slots,\n emit\n}, {\n select,\n tree,\n key\n}) => {\n watch(() => props.modelValue, () => {\n if (props.showCheckbox) {\n nextTick(() => {\n const treeInstance = tree.value;\n if (treeInstance && !isEqual(treeInstance.getCheckedKeys(), toValidArray(props.modelValue))) {\n treeInstance.setCheckedKeys(toValidArray(props.modelValue));\n }\n });\n }\n }, {\n immediate: true,\n deep: true\n });\n const propsMap = computed(() => ({\n value: key.value,\n label: \"label\",\n children: \"children\",\n disabled: \"disabled\",\n isLeaf: \"isLeaf\",\n ...props.props\n }));\n const getNodeValByProp = (prop, data) => {\n var _a;\n const propVal = propsMap.value[prop];\n if (isFunction(propVal)) {\n return propVal(data, (_a = tree.value) == null ? void 0 : _a.getNode(getNodeValByProp(\"value\", data)));\n } else {\n return data[propVal];\n }\n };\n const defaultExpandedParentKeys = toValidArray(props.modelValue).map(value => {\n return treeFind(props.data || [], data => getNodeValByProp(\"value\", data) === value, data => getNodeValByProp(\"children\", data), (data, index, array, parent) => parent && getNodeValByProp(\"value\", parent));\n }).filter(item => isValidValue(item));\n const cacheOptions = computed(() => {\n if (!props.renderAfterExpand && !props.lazy) return [];\n const options = [];\n treeEach(props.data.concat(props.cacheData), node => {\n const value = getNodeValByProp(\"value\", node);\n options.push({\n value,\n currentLabel: getNodeValByProp(\"label\", node),\n isDisabled: getNodeValByProp(\"disabled\", node)\n });\n }, data => getNodeValByProp(\"children\", data));\n return options;\n });\n const getChildCheckedKeys = () => {\n var _a;\n return (_a = tree.value) == null ? void 0 : _a.getCheckedKeys().filter(checkedKey => {\n var _a2;\n const node = (_a2 = tree.value) == null ? void 0 : _a2.getNode(checkedKey);\n return !isNil(node) && isEmpty(node.childNodes);\n });\n };\n return {\n ...pick(toRefs(props), Object.keys(ElTree.props)),\n ...attrs,\n nodeKey: key,\n expandOnClickNode: computed(() => {\n return !props.checkStrictly && props.expandOnClickNode;\n }),\n defaultExpandedKeys: computed(() => {\n return props.defaultExpandedKeys ? props.defaultExpandedKeys.concat(defaultExpandedParentKeys) : defaultExpandedParentKeys;\n }),\n renderContent: (h, {\n node,\n data,\n store\n }) => {\n return h(component, {\n value: getNodeValByProp(\"value\", data),\n label: getNodeValByProp(\"label\", data),\n disabled: getNodeValByProp(\"disabled\", data),\n visible: node.visible\n }, props.renderContent ? () => props.renderContent(h, {\n node,\n data,\n store\n }) : slots.default ? () => slots.default({\n node,\n data,\n store\n }) : void 0);\n },\n filterNodeMethod: (value, data, node) => {\n if (props.filterNodeMethod) return props.filterNodeMethod(value, data, node);\n if (!value) return true;\n const regexp = new RegExp(escapeStringRegexp(value), \"i\");\n return regexp.test(getNodeValByProp(\"label\", data) || \"\");\n },\n onNodeClick: (data, node, e) => {\n var _a, _b, _c, _d;\n (_a = attrs.onNodeClick) == null ? void 0 : _a.call(attrs, data, node, e);\n if (prop