|
|
@@ -49960,15 +49960,26 @@ const _sfc_main$10 = {
|
|
|
const fieldValue = ref("");
|
|
|
const cascaderValue = ref("");
|
|
|
const show2 = ref(false);
|
|
|
+ function normalizeTree(list) {
|
|
|
+ return (list || []).map((node) => {
|
|
|
+ var _a2, _b;
|
|
|
+ return {
|
|
|
+ value: node.value,
|
|
|
+ text: (_b = (_a2 = node.text) != null ? _a2 : node.label) != null ? _b : node.name,
|
|
|
+ children: node.children && node.children.length ? normalizeTree(node.children) : void 0
|
|
|
+ };
|
|
|
+ });
|
|
|
+ }
|
|
|
+ const normalizedOptions = computed(() => normalizeTree(props2.options));
|
|
|
watchEffect(() => {
|
|
|
var _a2;
|
|
|
if (props2.isPathValue) {
|
|
|
const values = Array.isArray(props2.modelValue) ? props2.modelValue : [props2.modelValue];
|
|
|
- fieldValue.value = getCascaderText([...values], props2.options).join("/");
|
|
|
+ fieldValue.value = getCascaderText([...values], normalizedOptions.value).join("/");
|
|
|
cascaderValue.value = values.length > 0 ? values[values.length - 1] : "";
|
|
|
} else {
|
|
|
const value = Array.isArray(props2.modelValue) ? (_a2 = props2.modelValue) == null ? void 0 : _a2[0] : props2.modelValue;
|
|
|
- fieldValue.value = getTreeText(value, props2.options);
|
|
|
+ fieldValue.value = getTreeText(value, normalizedOptions.value);
|
|
|
cascaderValue.value = value;
|
|
|
}
|
|
|
});
|
|
|
@@ -50052,7 +50063,7 @@ const _sfc_main$10 = {
|
|
|
createVNode(_component_van_cascader, mergeProps({
|
|
|
modelValue: cascaderValue.value,
|
|
|
"onUpdate:modelValue": _cache[1] || (_cache[1] = ($event) => cascaderValue.value = $event),
|
|
|
- options: __props.options,
|
|
|
+ options: normalizedOptions.value,
|
|
|
title: __props.publicProps.label,
|
|
|
onClose: _cache[2] || (_cache[2] = ($event) => show2.value = false),
|
|
|
onFinish
|
|
|
@@ -50426,24 +50437,22 @@ const _sfc_main$_ = {
|
|
|
function selectedLeafSet() {
|
|
|
const set = /* @__PURE__ */ new Set();
|
|
|
props2.modelValue.forEach((p) => {
|
|
|
- if (Array.isArray(p))
|
|
|
- set.add(p[p.length - 1]);
|
|
|
- else
|
|
|
- set.add(p);
|
|
|
+ const leaf = Array.isArray(p) ? p[p.length - 1] : p;
|
|
|
+ set.add(String(leaf));
|
|
|
});
|
|
|
return set;
|
|
|
}
|
|
|
function pathKey(p) {
|
|
|
- return Array.isArray(p) ? p.join("/") : String(p);
|
|
|
+ return Array.isArray(p) ? p.map(String).join("/") : String(p);
|
|
|
}
|
|
|
function state(node) {
|
|
|
if (!hasChildren(node)) {
|
|
|
- return { checked: selectedLeafSet().has(node.value), indeterminate: false };
|
|
|
+ return { checked: selectedLeafSet().has(String(node.value)), indeterminate: false };
|
|
|
}
|
|
|
const leaves = collectLeaves(node);
|
|
|
if (leaves.length === 0)
|
|
|
return { checked: false, indeterminate: false };
|
|
|
- const sel = leaves.filter((v) => selectedLeafSet().has(v));
|
|
|
+ const sel = leaves.filter((v) => selectedLeafSet().has(String(v)));
|
|
|
return {
|
|
|
checked: sel.length === leaves.length,
|
|
|
indeterminate: sel.length > 0 && sel.length < leaves.length
|
|
|
@@ -50452,17 +50461,14 @@ const _sfc_main$_ = {
|
|
|
function toggle2(node) {
|
|
|
const paths = collectPaths(node, props2.prefix);
|
|
|
const isChecked = state(node).checked;
|
|
|
- const set = new Set(props2.modelValue.map(pathKey));
|
|
|
+ const pathMap = new Map(props2.modelValue.map((p) => [pathKey(p), p]));
|
|
|
if (isChecked) {
|
|
|
const rm = new Set(paths.map(pathKey));
|
|
|
- set.forEach((k) => {
|
|
|
- if (rm.has(k))
|
|
|
- set.delete(k);
|
|
|
- });
|
|
|
+ rm.forEach((k) => pathMap.delete(k));
|
|
|
} else {
|
|
|
- paths.forEach((p) => set.add(pathKey(p)));
|
|
|
+ paths.forEach((p) => pathMap.set(pathKey(p), p));
|
|
|
}
|
|
|
- emitChange([...set].map((k) => k.split("/")));
|
|
|
+ emitChange([...pathMap.values()]);
|
|
|
}
|
|
|
function emitChange(val) {
|
|
|
emit2("update:modelValue", val);
|
|
|
@@ -50511,7 +50517,7 @@ const _sfc_main$_ = {
|
|
|
};
|
|
|
}
|
|
|
};
|
|
|
-var DeptCascaderTree = /* @__PURE__ */ _export_sfc(_sfc_main$_, [["__scopeId", "data-v-d69faff4"]]);
|
|
|
+var DeptCascaderTree = /* @__PURE__ */ _export_sfc(_sfc_main$_, [["__scopeId", "data-v-1ec09c66"]]);
|
|
|
var DeptCascader_vue_vue_type_style_index_0_scoped_true_lang = "";
|
|
|
const _hoisted_1$z = { class: "dept-cascader__header" };
|
|
|
const _hoisted_2$w = { class: "dept-cascader__title" };
|
|
|
@@ -50550,10 +50556,24 @@ const _sfc_main$Z = {
|
|
|
function isLeaf(node) {
|
|
|
return !node.children || node.children.length === 0;
|
|
|
}
|
|
|
+ function normalizeTree(list) {
|
|
|
+ return (list || []).map((node) => {
|
|
|
+ var _a2, _b;
|
|
|
+ return {
|
|
|
+ value: node.value,
|
|
|
+ text: (_b = (_a2 = node.text) != null ? _a2 : node.label) != null ? _b : node.name,
|
|
|
+ children: node.children && node.children.length ? normalizeTree(node.children) : void 0
|
|
|
+ };
|
|
|
+ });
|
|
|
+ }
|
|
|
+ const normalizedOptions = computed(() => normalizeTree(props2.options));
|
|
|
+ function sameVal(a, b) {
|
|
|
+ return String(a) === String(b);
|
|
|
+ }
|
|
|
function getTreeText(value, options) {
|
|
|
for (let i = 0; i < options.length; i++) {
|
|
|
const cur = options[i];
|
|
|
- if (cur.value === value)
|
|
|
+ if (sameVal(cur.value, value))
|
|
|
return cur.text;
|
|
|
if (!isLeaf(cur)) {
|
|
|
const res = getTreeText(value, cur.children);
|
|
|
@@ -50565,7 +50585,7 @@ const _sfc_main$Z = {
|
|
|
}
|
|
|
function getCascaderText(values, options, texts = []) {
|
|
|
if (values.length >= 1) {
|
|
|
- const cur = options == null ? void 0 : options.find((opt) => opt.value === values[0]);
|
|
|
+ const cur = options == null ? void 0 : options.find((opt) => sameVal(opt.value, values[0]));
|
|
|
if (cur)
|
|
|
texts.push(cur.text);
|
|
|
values.splice(0, 1);
|
|
|
@@ -50576,7 +50596,7 @@ const _sfc_main$Z = {
|
|
|
function findPath(value, options, prefix = []) {
|
|
|
for (const opt of options) {
|
|
|
const cur = [...prefix, opt.value];
|
|
|
- if (opt.value === value)
|
|
|
+ if (sameVal(opt.value, value))
|
|
|
return cur;
|
|
|
if (opt.children && opt.children.length) {
|
|
|
const r = findPath(value, opt.children, cur);
|
|
|
@@ -50590,7 +50610,7 @@ const _sfc_main$Z = {
|
|
|
const texts = [];
|
|
|
let cur = options;
|
|
|
for (const v of path) {
|
|
|
- const node = cur == null ? void 0 : cur.find((o) => o.value === v);
|
|
|
+ const node = cur == null ? void 0 : cur.find((o) => sameVal(o.value, v));
|
|
|
if (!node)
|
|
|
break;
|
|
|
texts.push(node.text);
|
|
|
@@ -50598,27 +50618,28 @@ const _sfc_main$Z = {
|
|
|
}
|
|
|
return texts.join("/");
|
|
|
}
|
|
|
- watch(
|
|
|
- () => props2.modelValue,
|
|
|
- (val) => {
|
|
|
- if (props2.multiple) {
|
|
|
- const arr = Array.isArray(val) ? val : val ? [val] : [];
|
|
|
- selectedValues.value = arr.map(
|
|
|
- (item2) => Array.isArray(item2) ? item2 : findPath(item2, props2.options) || [item2]
|
|
|
- );
|
|
|
- fieldValue.value = selectedValues.value.map((p) => Array.isArray(p) ? getPathText(p, props2.options) : getTreeText(p, props2.options)).filter(Boolean).join("\u3001");
|
|
|
- } else if (props2.isPathValue) {
|
|
|
- const values = Array.isArray(val) ? val : val ? [val] : [];
|
|
|
- cascaderValue.value = values.length ? values[values.length - 1] : "";
|
|
|
- fieldValue.value = getCascaderText([...values], props2.options).join("/");
|
|
|
- } else {
|
|
|
- const value = Array.isArray(val) ? val[0] : val;
|
|
|
- cascaderValue.value = value;
|
|
|
- fieldValue.value = getTreeText(value, props2.options);
|
|
|
- }
|
|
|
- },
|
|
|
- { immediate: true }
|
|
|
- );
|
|
|
+ function computeMultiText(paths) {
|
|
|
+ return paths.map((p) => Array.isArray(p) ? getPathText(p, normalizedOptions.value) : getTreeText(p, normalizedOptions.value)).filter(Boolean).join("\u3001");
|
|
|
+ }
|
|
|
+ function applyModelValue(val) {
|
|
|
+ if (props2.multiple) {
|
|
|
+ const arr = Array.isArray(val) ? val : val ? [val] : [];
|
|
|
+ selectedValues.value = arr.map(
|
|
|
+ (item2) => Array.isArray(item2) ? item2 : findPath(item2, normalizedOptions.value) || [item2]
|
|
|
+ );
|
|
|
+ fieldValue.value = computeMultiText(selectedValues.value);
|
|
|
+ } else if (props2.isPathValue) {
|
|
|
+ const values = Array.isArray(val) ? val : val ? [val] : [];
|
|
|
+ cascaderValue.value = values.length ? values[values.length - 1] : "";
|
|
|
+ fieldValue.value = getCascaderText([...values], normalizedOptions.value).join("/");
|
|
|
+ } else {
|
|
|
+ const value = Array.isArray(val) ? val[0] : val;
|
|
|
+ cascaderValue.value = value;
|
|
|
+ fieldValue.value = getTreeText(value, normalizedOptions.value);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ watch(() => props2.modelValue, (val) => applyModelValue(val), { immediate: true });
|
|
|
+ watch(() => props2.options, () => applyModelValue(props2.modelValue), { deep: true });
|
|
|
function onFinish({ selectedOptions }) {
|
|
|
if (props2.isPathValue) {
|
|
|
emit2("update:modelValue", selectedOptions.map((i) => i.value));
|
|
|
@@ -50632,7 +50653,7 @@ const _sfc_main$Z = {
|
|
|
function onMultiChange(val) {
|
|
|
emit2("update:modelValue", val);
|
|
|
selectedValues.value = val;
|
|
|
- fieldValue.value = val.map((p) => Array.isArray(p) ? getPathText(p, props2.options) : getTreeText(p, props2.options)).filter(Boolean).join("\u3001");
|
|
|
+ fieldValue.value = computeMultiText(val);
|
|
|
}
|
|
|
function onShowPicker() {
|
|
|
if (props2.printRead || props2.disabled)
|
|
|
@@ -50704,7 +50725,7 @@ const _sfc_main$Z = {
|
|
|
]),
|
|
|
__props.multiple ? (openBlock(), createElementBlock("div", _hoisted_4$l, [
|
|
|
createVNode(DeptCascaderTree, {
|
|
|
- nodes: __props.options,
|
|
|
+ nodes: normalizedOptions.value,
|
|
|
"model-value": selectedValues.value,
|
|
|
"expand-all": expandAll.value,
|
|
|
"onUpdate:modelValue": onMultiChange
|
|
|
@@ -50713,7 +50734,7 @@ const _sfc_main$Z = {
|
|
|
key: 1,
|
|
|
modelValue: cascaderValue.value,
|
|
|
"onUpdate:modelValue": _cache[2] || (_cache[2] = ($event) => cascaderValue.value = $event),
|
|
|
- options: __props.options,
|
|
|
+ options: normalizedOptions.value,
|
|
|
title: __props.title || ((_b = __props.publicProps) == null ? void 0 : _b.label),
|
|
|
onClose: _cache[3] || (_cache[3] = ($event) => show2.value = false),
|
|
|
onFinish
|
|
|
@@ -50726,7 +50747,7 @@ const _sfc_main$Z = {
|
|
|
};
|
|
|
}
|
|
|
};
|
|
|
-var FmVantDeptCascader = /* @__PURE__ */ _export_sfc(_sfc_main$Z, [["__scopeId", "data-v-bb4c6c32"]]);
|
|
|
+var FmVantDeptCascader = /* @__PURE__ */ _export_sfc(_sfc_main$Z, [["__scopeId", "data-v-0333cc83"]]);
|
|
|
const _sfc_main$Y = {
|
|
|
components: {
|
|
|
FmVantSelect,
|