@aplus-frontend/ui
Version:
284 lines (283 loc) • 8.64 kB
JavaScript
import { isVNode as ie, defineComponent as ce, useSlots as ue, ref as B, shallowRef as M, computed as w, unref as a, watch as q, createVNode as o, Fragment as R, createBlock as x, openBlock as p, mergeProps as pe, withCtx as I, resolveDynamicComponent as T, createElementBlock as de, renderList as fe, normalizeStyle as me } from "vue";
import { Col as _, Flex as k, Button as H, Row as he } from "@aplus-frontend/antdv";
import "../ap-form.vue.mjs";
import "../item/index.vue2.mjs";
import { genRealChildren as G } from "../item-group/helper.mjs";
import "../../config-provider/index.mjs";
import { isArray as ge, isBoolean as xe, omit as ye } from "lodash-unified";
import { isDef as J } from "../../utils/index.mjs";
import { execFunc as K, diffFormItem as ve } from "./utils.mjs";
import "./components/popover-filter.vue.mjs";
import { useCountPerRow as Se } from "./hooks/use-count-per-row.mjs";
import "./components/popover-sorter/index.vue.mjs";
import { useSorter as Ce } from "./hooks/use-sorter.mjs";
import { getTargetNode as we } from "./hooks/use-collapse-input-count.mjs";
import { floorWith as Q } from "@fruits-chain/utils";
import { useDevWarning as Re } from "../../utils/warning.mjs";
import { useNamespace as _e } from "../../config-provider/hooks/use-namespace.mjs";
import { useLocale as be } from "../../config-provider/hooks/use-locale.mjs";
import X from "../item/index.vue.mjs";
import Fe from "./components/popover-filter.vue2.mjs";
import Ae from "./components/popover-sorter/index.vue2.mjs";
import Ne from "../ap-form.vue2.mjs";
function Be(d) {
return typeof d == "function" || Object.prototype.toString.call(d) === "[object Object]" && !ie(d);
}
const r = 100, et = /* @__PURE__ */ ce({
name: "ApFormSearchForm",
__name: "index",
props: {
layout: {
default: "horizontal"
},
labelCol: {},
wrapperCol: {},
colon: {
type: Boolean,
default: !0
},
labelAlign: {
default: "right"
},
labelWrap: {
type: Boolean
},
prefixCls: {},
requiredMark: {},
hideRequiredMark: {
type: Boolean,
default: !1
},
rules: {},
validateMessages: {},
validateOnRuleChange: {
type: Boolean,
default: !0
},
scrollToFirstError: {},
onSubmit: {},
name: {},
validateTrigger: {
default: "change"
},
size: {},
disabled: {
type: Boolean
},
onFieldsChange: {},
onFinish: {},
onFinishFailed: {},
onValidate: {},
variant: {},
initialValues: {},
onValuesChange: {},
syncToUrl: {
type: [Boolean, Function]
},
syncToUrlPriority: {
type: Boolean
},
collapse: {
type: Boolean,
default: void 0
},
defaultCollapse: {
type: Boolean,
default: !0
},
"onUpdate:collapse": {},
searchText: {},
resetText: {},
onReset: {},
customReset: {
type: Boolean,
default: !1
},
extraInAction: {
type: Boolean,
default: !1
},
forceExpand: {
type: Boolean,
default: !1
},
countPerRow: {
default: 5
},
submitLoading: {
type: Boolean
},
maxRows: {
default: 2
},
sortable: {
type: Boolean,
default: !0
},
resizeTarget: {},
resize: {},
loadingDelay: {
default: 300
}
},
setup(d, {
expose: Y
}) {
const y = ue(), t = d;
Re("SearchForm").deprecated(typeof t.resizeTarget < "u", "resizeTarget", "resize.target");
const {
b: f
} = _e("ap-form-search-form"), {
t: P
} = be(), v = B(), E = B(), Z = Se(t, E), W = B();
function z() {
const e = v.value?.getFieldsValueTransformed(!0);
K(t.onSubmit, e);
}
function ee() {
t.customReset || v.value?.resetFields?.(), K(t.onReset);
}
const te = (e) => J(e) ? (ge(e) ? e : [e]).join("") : Date.now();
let O = [];
const m = M(G(y.default())), c = M(y.extra?.()), L = w(() => Q(r / a(Z), 4)), {
items: b,
sorted: $,
handleClickConfirm: F
} = Ce(m);
q(() => y.default(), (e) => {
O = m.value, m.value = ve(O, G(e)), $.value = !1;
}), q(() => y.extra?.(), (e) => {
c.value = e;
});
function oe(e) {
return Q(e * (r / 24), 4);
}
const n = w(() => {
const e = m.value, u = [], l = [], g = [], s = a(L);
let S = 0, A = 0;
const le = r * t.maxRows - s * (a(c) && !t.extraInAction ? 2 : 1);
e.forEach((N) => {
const D = we(N);
if (!D)
return;
const i = D.props;
if (xe(i.hidden) ? !!i.hidden : J(i.hidden))
u.push(N);
else {
let C = i.span ? oe(i.span) : s;
const V = {
node: N,
span: C,
key: `ApFormSearchFormItem-${te(i.name)}-${i._signal}`
}, U = r - S % r;
U < C && (C += U), S += C, S > le ? l.push(V) : (A = S, g.push(V));
}
});
const j = r - (A + s) % r, re = Math.ceil(A) % r < s, se = j < s ? r : j;
return {
hideNode: o(R, null, [u]),
nodes: g,
collapseNodes: l,
extraSpan: se,
lastRowOnlyIncludeActionAndExtra: re
};
}), h = (e) => `${e}%`, ae = w(() => {
let e;
const u = n.value.collapseNodes.length || t.sortable && m.value.length, l = o(_, {
flex: h(a(L)),
key: "actionWrapper"
}, {
default: () => [o(X, null, {
default: () => [o(k, {
wrap: "wrap",
justify: n.value.lastRowOnlyIncludeActionAndExtra && !(a(c) && t.extraInAction) ? "flex-end" : "space-between"
}, {
default: () => [o(k, {
gap: 8,
wrap: "wrap"
}, {
default: () => [u ? o("div", {
class: f("column-setting-trigger-wrapper")
}, [n.value.collapseNodes.length ? o(Fe, {
onSubmit: z,
config: n.value.collapseNodes,
submitLoading: t.submitLoading
}, null) : null, t.sortable && b.value.length ? o(Ae, {
ref: W,
items: b.value,
onClickConfirm: F,
sorted: $.value
}, null) : null]) : null, o(H, {
type: "primary",
onClick: z,
loading: t.submitLoading ? {
delay: t.loadingDelay
} : !1,
htmlType: "submit",
class: f("action-btn")
}, {
default: () => [t.searchText || P("ap.apForm.search.search")]
}), o(H, {
onClick: ee,
type: "text",
class: [f("action-btn"), f("action-btn-reset")]
}, {
default: () => [t.resetText || P("ap.apForm.search.reset")]
})]
}), t.extraInAction ? a(c) : null]
})]
})]
}), g = !t.extraInAction && a(c) ? o(_, {
flex: h(n.value.extraSpan),
key: "extraNode"
}, {
default: () => [o(X, null, {
default: () => [o(k, {
justify: n.value.extraSpan === r || n.value.lastRowOnlyIncludeActionAndExtra ? "start" : "flex-end"
}, Be(e = a(c)) ? e : {
default: () => [e]
})]
})]
}) : null, s = o(_, {
flex: h(n.value.extraSpan)
}, null);
return n.value.lastRowOnlyIncludeActionAndExtra ? o(R, null, [g || s, l]) : o(R, null, [l, g]);
});
function ne() {
const e = W.value?.getCachedList();
F(e);
}
return Y({
apForm: w(() => a(v)),
getSorterItems: () => b.value,
setSorterItems: F,
resetSorterItems: ne
}), (e, u) => (p(), x(Ne, pe({
ref_key: "apForm",
ref: v,
class: a(f)()
}, a(ye)(t, ["collapse", "defaultCollapse", "onUpdate:collapse", "searchText", "resetText", "onSubmit", "onReset", "extraInAction", "forceExpand", "countPerRow"])), {
default: I(() => [(p(), x(T(n.value.hideNode))), o(a(he), {
ref_key: "contentWrapperRef",
ref: E,
gutter: 8
}, {
default: I(() => [(p(!0), de(R, null, fe(n.value.nodes, (l) => (p(), x(a(_), {
key: l.key,
flex: h(l.span),
style: me({
maxWidth: h(l.span)
})
}, {
default: I(() => [(p(), x(T(l.node)))]),
_: 2
}, 1032, ["flex", "style"]))), 128)), (p(), x(T(ae.value)))]),
_: 1
}, 512)]),
_: 1
}, 16, ["class"]));
}
});
export {
et as default
};