@aplus-frontend/ui
Version:
62 lines (61 loc) • 2.25 kB
JavaScript
import { defineComponent as w, computed as d, createElementBlock as f, openBlock as s, normalizeClass as r, unref as e, createBlock as B, createCommentVNode as _, resolveDynamicComponent as D, createVNode as C } from "vue";
import { useToken as O } from "@aplus-frontend/antdv/es/theme/internal";
import { CaretUpOutlined as V, CaretDownOutlined as j } from "@ant-design/icons-vue";
import { getTableTitle as z } from "../../../ap-table/utils.mjs";
import "../../../config-provider/index.mjs";
import { useInjectSorter as A } from "../../context.mjs";
import { useNamespace as g } from "../../../config-provider/hooks/use-namespace.mjs";
const K = /* @__PURE__ */ w({
__name: "index",
props: {
params: {}
},
setup(S) {
const o = S, { b: v, e: n } = g("ag-custom-header"), { be: b, bem: k } = g("ap-grid"), [, I] = O(), { sorter: c, setSorter: T } = A(), a = d(() => o.params.column.sorter);
function h(t) {
return t ? t === "asc" ? "desc" : null : "asc";
}
const m = d(() => o.params?.column?.getColId?.());
function x() {
if (!a.value)
return;
const l = o.params.column.getColId(), y = o.params.column.getSort(), u = h(y), p = o.params.api, N = p.getColumnState().map((i) => ({
...i,
sort: i.colId === l ? u : null
}));
p.applyColumnState({
state: N
}), T({ [l]: u });
}
return (t, l) => (s(), f("div", {
class: r([e(v)(), { sortable: a.value }, `align-${t.params.column.align || "left"}`]),
onClick: x
}, [
(s(), B(D(
e(z)(
t.params.column,
[
e(b)("table-header", "title"),
t.params.column.tooltip ? "" : e(k)("table-header", "title", "single")
],
void 0,
e(I).colorTextTertiary
)
))),
a.value ? (s(), f("span", {
key: 0,
class: r(e(n)("sort-wrapper"))
}, [
C(e(V), {
class: r({ [e(n)("sorter-up")]: !0, active: e(c)[m.value] === "asc" })
}, null, 8, ["class"]),
C(e(j), {
class: r({ [e(n)("sorter-down")]: !0, active: e(c)[m.value] === "desc" })
}, null, 8, ["class"])
], 2)) : _("", !0)
], 2));
}
});
export {
K as default
};