@aplus-frontend/ui
Version:
187 lines (186 loc) • 6.38 kB
JavaScript
import { defineComponent as T, ref as z, computed as $, watch as L, createBlock as Y, openBlock as E, unref as e, withCtx as t, createElementVNode as u, normalizeClass as r, createVNode as a, createSlots as K, toDisplayString as s, createTextVNode as d } from "vue";
import { Popover as R, Tooltip as U, Space as y, Checkbox as j } from "@aplus-frontend/antdv";
import q from "dayjs";
import { cloneDeep as g } from "lodash-unified";
import "../../../ap-button/index.mjs";
import { ApField as B } from "../../../ap-field/index.mjs";
import "../../../ap-form/ap-form.vue.mjs";
import "../../../config-provider/index.mjs";
import { useViewInject as M } from "../hooks/use-view-provide.mjs";
import O from "../icons/line-eye.vue.mjs";
import A from "../style/index.mjs";
import { generateUniqueKey as P } from "../utils/uuid.mjs";
import { useLocale as G } from "../../../config-provider/hooks/use-locale.mjs";
import { useNamespace as H } from "../../../config-provider/hooks/use-namespace.mjs";
import w from "../../../ap-form/ap-form.vue2.mjs";
import x from "../../../ap-button/ap-button.vue.mjs";
const ce = /* @__PURE__ */ T({
__name: "main-button-content",
props: {
maxViewNum: {}
},
setup(N) {
const f = N, { t: o } = G(), { b: i } = H("ap-view"), m = A("ap-view"), V = z(), { tableKey: F, popoverOpen: p, viewList: c, saveDataSource: h, viewListCRUD: b } = M(), _ = $({
get: () => p.value && c.value.length < f.maxViewNum + 1,
set: (l) => {
c.value.length < f.maxViewNum + 1 && (p.value = l);
}
});
L(p, (l) => {
l && (V.value?.resetFields(), setTimeout(() => {
V.value?.setFieldsValue({
isDefault: !c.value.some((n) => n.isDefault)
});
}));
});
const D = async (l) => {
const { viewName: n, isDefault: v } = l, S = P(), k = g(
h?.getSearchFormValues?.(
!!h?.searchFormTransform
)
), C = g(h?.getSearchFormSorterItems?.()), I = {
searchForm: k,
sorterItems: C
};
await b.addView?.({
tableKey: F,
viewKey: S,
viewName: n,
isDefault: v,
viewConfig: I
}), p.value = !1;
};
return (l, n) => (E(), Y(e(R), {
open: _.value,
"onUpdate:open": n[1] || (n[1] = (v) => _.value = v),
placement: "bottom",
trigger: "click",
arrow: !1,
"overlay-inner-style": {
padding: "12px 16px"
}
}, {
content: t(() => [
u("div", {
class: r([e(i)(), e(i)("main-content-popover"), e(m)])
}, [
a(w, {
ref_key: "formRef",
ref: V,
layout: "vertical",
"initial-values": {
viewName: `${e(o)("ap.apView.newView")} ${e(q)().format("YYYY-MM-DD").toString()}`
},
onFinish: D
}, {
default: t(() => [
u("div", {
class: r([e(i)("main-content-popover-title-content"), e(m)])
}, [
u("div", {
class: r([e(i)("main-content-popover-title-content-title")])
}, s(e(o)("ap.apView.saveNewView")), 3),
a(w.FormItem, {
name: "isDefault",
"value-prop-name": "checked"
}, {
default: t(() => [
a(e(j), null, {
default: t(() => [
d(s(e(o)("ap.apView.setDefault")), 1)
]),
_: 1
})
]),
_: 1
})
], 2),
a(w.FormItem, {
label: e(o)("ap.apView.viewName"),
name: "viewName",
rules: [{ required: !0, message: e(o)("ap.apView.notEmpty") }]
}, {
default: t(() => [
a(e(B).Text, {
placeholder: e(o)("ap.apView.viewName"),
maxlength: 20,
"show-count": ""
}, null, 8, ["placeholder"])
]),
_: 1
}, 8, ["label", "rules"]),
a(w.FormItem, {
class: r([e(i)("main-content-popover-btn"), e(m)])
}, {
default: t(() => [
a(e(y), { size: 8 }, {
default: t(() => [
a(e(x), {
size: "small",
onClick: n[0] || (n[0] = (v) => p.value = !1)
}, {
default: t(() => [
d(s(e(o)("ap.apView.cancel")), 1)
]),
_: 1
}),
a(e(x), {
type: "primary",
size: "small",
"html-type": "submit"
}, {
default: t(() => [
d(s(e(o)("ap.apView.save")), 1)
]),
_: 1
})
]),
_: 1
})
]),
_: 1
}, 8, ["class"])
]),
_: 1
}, 8, ["initial-values"])
], 2)
]),
default: t(() => [
u("div", {
class: r({
[e(i)("main-content")]: !0,
[e(i)("main-content-disabled")]: e(c).length >= f.maxViewNum + 1,
hashId: e(m)
})
}, [
a(e(U), { placement: "bottom" }, K({
default: t(() => [
a(e(y), { size: 4 }, {
default: t(() => [
a(O, {
class: r([e(i)("icon"), e(m)])
}, null, 8, ["class"]),
u("div", null, s(e(o)("ap.apView.saveView")), 1)
]),
_: 1
})
]),
_: 2
}, [
e(c).length >= f.maxViewNum + 1 ? {
name: "title",
fn: t(() => [
d(s(e(o)("ap.apView.maxTip")), 1)
]),
key: "0"
} : void 0
]), 1024)
], 2)
]),
_: 1
}, 8, ["open"]));
}
});
export {
ce as default
};