@aplus-frontend/ui
Version:
252 lines (251 loc) • 5.91 kB
JavaScript
import { isVNode as F, defineComponent as L, useSlots as R, ref as _, computed as E, unref as e, createVNode as r, Fragment as g, createBlock as v, openBlock as S, resolveDynamicComponent as K, mergeProps as U, createSlots as z, renderList as M, withCtx as B, 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 "../../hooks/index.mjs";
import { isArray as J, omit as Q } from "lodash-unified";
import { useRequest as X } from "./use-request.mjs";
import { useControllableValue as Y } from "../../hooks/useControllableValue.mjs";
function x(d) {
return typeof d == "function" || Object.prototype.toString.call(d) === "[object Object]" && !F(d);
}
const re = /* @__PURE__ */ L({
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: {},
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(d, {
expose: C,
emit: w
}) {
const o = d, N = R(), T = w, 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 r(g, null, [o.emptyText]);
const n = [], s = o.fieldNames?.label || "label", P = o.fieldNames?.value || "value";
function h(a) {
for (const l of a) {
if (i.find((A) => A === l[P]) && n.push(l[s]), n.length === i.length)
return;
l.children?.length && h(l.children);
}
}
return h(e(c)), n.length ? n.length === 1 ? r("span", null, [n[0]]) : r($, {
size: 4
}, x(t = n.map((a, l) => r(H, {
style: "margin-right: 0px",
key: `${a}-${l}`
}, x(a) ? a : {
default: () => [a]
}))) ? t : {
default: () => [t]
}) : r(g, null, [o.emptyText]);
});
function V() {
p.value?.focus?.();
}
function k() {
p.value?.blur?.();
}
function I(t) {
return y(t);
}
return C({
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: B((s) => [j(t.$slots, n, q(O(s || {})))])
})), e(m) ? {
name: "notFoundContent",
fn: B(() => [r(e(G), {
size: "small"
})]),
key: "0"
} : void 0]), 1040, ["value", "tree-data", "loading", "load-data", "onUpdate:value"]));
}
});
export {
re as default
};