UNPKG

@aplus-frontend/ui

Version:

194 lines (193 loc) 5.57 kB
import { defineComponent as A, ref as w, unref as n, computed as O, watch as $, createElementBlock as k, openBlock as u, normalizeClass as c, createVNode as m, createElementVNode as v, withCtx as g, toDisplayString as y, createTextVNode as q, createCommentVNode as p, createBlock as b } from "vue"; import { Flex as G, Typography as H, Divider as J } from "@aplus-frontend/antdv"; import N from "vuedraggable"; import "../../../../config-provider/index.mjs"; import "../sortable/index.vue.mjs"; import { useProvideSorterMethods as K } from "./context.mjs"; import { useNamespace as P } from "../../../../config-provider/hooks/use-namespace.mjs"; import { useLocale as Q } from "../../../../config-provider/hooks/use-locale.mjs"; import R from "../sortable/index.vue2.mjs"; const W = { key: 0 }, X = { key: 1 }, Y = { key: 2 }, ue = /* @__PURE__ */ A({ __name: "index", props: { value: {}, onReset: { type: Function } }, emits: ["update:value"], setup(V, { emit: S }) { const l = w([]), i = w([]), s = w([]), { b: r } = P("ap-column-setting-sorter"), { t: h } = Q(), x = V, B = S; K({ fixedToLeft: I, fixedToRight: M, unFixed: U }); function F(e, t) { const o = t[0].findIndex( (a) => a.key === e.key ); if (~o) t[0].splice(o, 1); else { const a = t[1].findIndex( (d) => d.key === e.key ); t[1].splice(a, 1); } } function _(e, t) { const o = [...n(l.value)], a = [...n(s.value)], d = [...n(i.value)], L = { left: { target: o, search: [d, a] }, right: { target: a, search: [d, o] }, normal: { target: d, search: [o, a] } }[t]; return t === "right" ? L.target.unshift(e) : L.target.push(e), F( e, L.search ), [...o, ...d, ...a]; } function I(e) { const t = _(e, "left"); f(t); } function M(e) { const t = _(e, "right"); f(t); } function U(e) { const t = _(e, "normal"); f(t); } function C(e) { return e.children?.length ? e.children.some((t) => t.show) : e.show; } function T(e, t) { e.value ? e.value.push(t) : e.value = [t]; } const D = O(() => { let e = 0; function t(o) { for (const a of o) a.children?.length ? t(a.children) : a.show && (e += 1); } return t(x.value), e; }); function E(e) { f([...e, ...n(i), ...n(s)]); } function j(e) { f([...n(l), ...e, ...n(s)]); } function z(e) { f([...n(l), ...n(i), ...e]); } function f(e) { B("update:value", e); } return $( () => x.value, (e) => { if (e) { l.value = [], i.value = [], s.value = []; for (const t of e) t.fixed === "left" ? T(l, t) : t.fixed === "right" ? T(s, t) : T(i, t); } }, { immediate: !0 } ), (e, t) => (u(), k("div", { class: c(n(r)()) }, [ m(n(G), { class: c(n(r)("header")), align: "center", justify: "space-between" }, { default: g(() => [ v("span", { class: c(n(r)("header-title")), style: { flex: "1" } }, y(n(h)("ap.apTable.setting.selectCount", { count: D.value })), 3), m(n(H).Link, { onClick: x.onReset }, { default: g(() => [ q(y(n(h)("ap.apTable.setting.reset")), 1) ]), _: 1 }, 8, ["onClick"]) ]), _: 1 }, 8, ["class"]), m(n(J), { style: { margin: "0px" } }), v("div", { class: c(n(r)("content")) }, [ l.value.length ? (u(), k("div", W, [ v("span", { class: c(n(r)("section-title")) }, y(n(h)("ap.apTable.setting.fixToLeft")), 3), m(n(N), { "model-value": l.value, "item-key": "key", "onUpdate:modelValue": E }, { item: g(({ element: o }) => [ C(o) ? (u(), b(R, { key: 0, value: o }, null, 8, ["value"])) : p("", !0) ]), _: 1 }, 8, ["model-value"]) ])) : p("", !0), i.value.length ? (u(), k("div", X, [ v("span", { class: c(n(r)("section-title")) }, y(n(h)("ap.apTable.setting.unFixed")), 3), m(n(N), { "model-value": i.value, "item-key": "key", "onUpdate:modelValue": j }, { item: g(({ element: o }) => [ C(o) ? (u(), b(R, { key: 0, value: o }, null, 8, ["value"])) : p("", !0) ]), _: 1 }, 8, ["model-value"]) ])) : p("", !0), s.value.length ? (u(), k("div", Y, [ v("span", { class: c(n(r)("section-title")) }, y(n(h)("ap.apTable.setting.fixToRight")), 3), m(n(N), { "model-value": s.value, "item-key": "key", "onUpdate:modelValue": z }, { item: g(({ element: o }) => [ C(o) ? (u(), b(R, { key: 0, value: o }, null, 8, ["value"])) : p("", !0) ]), _: 1 }, 8, ["model-value"]) ])) : p("", !0) ], 2) ], 2)); } }); export { ue as default };