@aplus-frontend/ui
Version:
253 lines (252 loc) • 5.95 kB
JavaScript
import { isVNode as R, defineComponent as A, useSlots as F, shallowRef as _, computed as E, unref as e, createVNode as d, Fragment as g, createBlock as v, openBlock as S, resolveDynamicComponent as K, mergeProps as U, createSlots as z, renderList as M, withCtx as w, renderSlot as j, normalizeProps as q, guardReactiveProps as O } from "vue";
import { Space as $, Tag as H, TreeSelect as W, Spin as G } from "@aplus-frontend/antdv";
import { isArray as J, omit as Q } from "lodash-unified";
import "../../hooks/index.mjs";
import { useRequest as X } from "./use-request.mjs";
import { useControllableValue as Y } from "../../hooks/useControllableValue.mjs";
function B(r) {
return typeof r == "function" || Object.prototype.toString.call(r) === "[object Object]" && !R(r);
}
const de = /* @__PURE__ */ A({
name: "ApFieldTreeSelect",
__name: "index",
props: {
mode: {
default: "edit"
},
class: {},
style: {},
suffixIcon: {},
size: {},
bordered: {
type: Boolean,
default: void 0
},
treeLine: {},
replaceFields: {},
placement: {},
status: {},
popupClassName: {},
dropdownClassName: {},
"onUpdate:value": {},
"onUpdate:treeExpandedKeys": {},
"onUpdate:searchValue": {},
variant: {},
switcherLoadingIcon: {},
value: {},
children: {},
listHeight: {},
onMouseenter: {},
onMouseleave: {},
tabindex: {},
onClick: {},
onFocus: {},
onBlur: {},
onChange: {},
onKeydown: {},
onKeyup: {},
onMousedown: {},
onSelect: {},
open: {
type: Boolean,
default: void 0
},
animation: {},
direction: {},
multiple: {
type: Boolean,
default: void 0
},
disabled: {
type: Boolean,
default: void 0
},
prefixCls: {},
id: {},
autofocus: {
type: Boolean,
default: void 0
},
getPopupContainer: {},
virtual: {
type: Boolean,
default: !0
},
dropdownMatchSelectWidth: {
default: !0
},
placeholder: {},
loading: {
type: Boolean,
default: void 0
},
defaultValue: {},
prefix: {},
clearIcon: {},
allowClear: {
type: Boolean,
default: void 0
},
getRawInputElement: {},
fieldNames: {},
inputValue: {},
searchValue: {},
onSearch: {},
autoClearSearchValue: {
type: Boolean,
default: void 0
},
onDeselect: {},
listItemHeight: {},
labelInValue: {
type: Boolean,
default: void 0
},
maxCount: {},
showSearch: {
type: Boolean,
default: void 0
},
tagRender: {},
optionLabelRender: {},
notFoundContent: {},
onClear: {},
choiceTransitionName: {},
defaultOpen: {
type: Boolean,
default: void 0
},
onDropdownVisibleChange: {},
maxTagTextLength: {},
maxTagCount: {},
maxTagPlaceholder: {},
tokenSeparators: {},
removeIcon: {},
transitionName: {},
dropdownStyle: {},
dropdownRender: {},
dropdownAlign: {},
showAction: {},
onPopupScroll: {},
onInputKeyDown: {},
showArrow: {
type: Boolean,
default: void 0
},
showCheckedStrategy: {},
filterTreeNode: {},
treeNodeFilterProp: {},
treeNodeLabelProp: {},
treeCheckable: {
type: Boolean,
default: void 0
},
treeCheckStrictly: {
type: Boolean,
default: void 0
},
treeData: {},
treeDataSimpleMode: {},
treeLoadedKeys: {},
onTreeLoad: {},
treeDefaultExpandAll: {
type: Boolean,
default: void 0
},
treeExpandedKeys: {},
treeDefaultExpandedKeys: {},
onTreeExpand: {},
treeIcon: {},
switcherIcon: {},
treeExpandAction: {},
dropdownPopupAlign: {},
emptyText: {
default: "--"
},
request: {},
lazy: {
type: Boolean
},
params: {},
loadData: {
type: Boolean
}
},
emits: ["update:value"],
setup(r, {
expose: x,
emit: C
}) {
const o = r, N = F(), T = C, p = _(), {
value: f,
updateValue: b
} = Y(o, T), {
treeData: c,
loading: m,
request: y
} = X(o), D = E(() => {
let t;
const u = e(f), i = J(u) ? u : [u].filter(Boolean);
if (!i.length)
return d(g, null, [o.emptyText]);
const n = [], s = o.fieldNames?.label || "label", L = o.fieldNames?.value || "value";
function h(a) {
for (const l of a) {
if (i.find((P) => P === l[L]) && n.push(l[s]), n.length === i.length)
return;
l.children?.length && h(l.children);
}
}
return h(e(c)), n.length ? n.length === 1 ? d("span", null, [n[0]]) : d($, {
size: 4
}, B(t = n.map((a, l) => d(H, {
style: "margin-right: 0px",
key: `${a}-${l}`
}, B(a) ? a : {
default: () => [a]
}))) ? t : {
default: () => [t]
}) : d(g, null, [o.emptyText]);
});
function V() {
p.value?.focus?.();
}
function k() {
p.value?.blur?.();
}
function I(t) {
return y(t);
}
return x({
request: y,
focus: V,
blur: k
}), (t, u) => t.mode === "read" ? (S(), v(K(D.value), {
key: 0
})) : (S(), v(e(W), U({
key: 1
}, e(Q)(o, ["onUpdate:value", "value", "treeData", "loadData"]), {
ref_key: "treeSelectRef",
ref: p,
value: e(f),
"tree-data": e(c),
loading: e(m),
"load-data": t.loadData ? I : void 0,
"onUpdate:value": e(b)
}), z({
_: 2
}, [M(N, (i, n) => ({
name: n,
fn: w((s) => [j(t.$slots, n, q(O(s || {})))])
})), e(m) ? {
name: "notFoundContent",
fn: w(() => [d(e(G), {
size: "small"
})]),
key: "0"
} : void 0]), 1040, ["value", "tree-data", "loading", "load-data", "onUpdate:value"]));
}
});
export {
de as default
};