tdesign-pro-component
Version:
ProComponents tdesign-vue-next + Vue3 + TS
314 lines (313 loc) • 9.05 kB
JavaScript
import "lodash-es";
import { g as y, w as W } from "./utils-CIySOLoe.js";
import { defineComponent as $, ref as f, computed as x, createVNode as n, createTextVNode as q, onMounted as X, resolveComponent as G, watch as H, Fragment as L, withDirectives as Q, resolveDirective as Y, mergeProps as Z } from "vue";
import { Card as k, Space as O, Button as N, Icon as ee, Table as te, Pagination as ae } from "tdesign-vue-next";
import { P as ne } from "./ProForm-tiWSlLM0.js";
import "./ProTableBuilder-DpDPpn43.js";
const le = /* @__PURE__ */ $((e, {
emit: l,
slots: t,
expose: p
}) => {
const v = f(), F = y("formHeader", t, e), S = x(() => {
var o;
return ((o = e.options) == null ? void 0 : o.filter((g) => !g.hidden)) || [];
}), D = e.showNum;
let R = {};
const s = f(!1), T = x(() => s.value ? S.value : S.value.slice(0, D)), m = x(() => S.value.length > D), i = () => {
var o;
s.value = !s.value, s.value && ((o = v.value) == null || o.resetRequest());
};
async function r(o) {
return l("search", o), !0;
}
function d(o, g) {
R[o] = g;
}
async function b() {
return R;
}
function w() {
var o;
R = {}, (o = v.value) == null || o.reset(), e.onReset && e.onReset();
}
return p({
getSearchValue: () => {
var o;
return (o = v.value) == null ? void 0 : o.getFormValue();
},
reset: w,
resetForm: () => {
var o;
return (o = v.value) == null ? void 0 : o.reset();
}
}), () => n(k, null, {
default: () => [F() && F(), n(ne, {
ref: v,
request: b,
onSubmit: r,
gap: 16,
filterEmptyStr: !0,
filterEmptyArray: !0,
options: T.value,
hideFooter: !0,
onChange: d,
footer: () => n("div", {
style: "display: flex; justify-content: flex-end; width: 100%;"
}, [n(O, null, {
default: () => [n(N, {
onClick: w,
theme: "default",
variant: "outline"
}, {
default: () => [q("重置")]
}), n(N, {
loading: e.loading,
type: "submit"
}, {
default: () => [q("查询")]
}), m.value && n(N, {
variant: "text",
onClick: i
}, {
default: () => [n("div", {
style: "display: flex; align-items: center;"
}, [s.value ? "收起" : "展开", n(ee, {
name: s.value ? "chevron-up" : "chevron-down"
}, null)])]
})]
})])
}, null)]
});
}, {
name: "ProTableHeader",
emit: ["search"],
props: {
formProps: Object,
options: Array,
cardProps: Object,
showNum: {
type: Number,
default: 3
},
formHeader: [String, Object, Function],
loading: Boolean,
onReset: Function
}
}), oe = (e) => {
const l = [];
return e.forEach((t) => {
l.push({
name: t.key,
label: typeof t.title == "string" ? t.title : t.title.formTitle,
type: t.type,
span: t.span || 3,
hidden: t.hideInSearch,
placeholder: t.placeholder,
data: t.data || []
});
}), l;
}, ie = (e) => {
const l = [];
return e.forEach((t) => {
const p = {
...t.tableColumnsProps,
foot: t.footer,
colKey: t.key,
title: typeof t.title == "string" ? t.title : t.title.tableTitle,
ellipsis: t.ellipsis,
ellipsisTitle: t.ellipsisTitle,
fixed: t.fixed,
sorter: t.sorter,
width: t.width,
render: t.titleRender,
type: t.tableType
};
t.render && (p.cell = (v, { row: F, rowIndex: S }) => t.render(F, S)), l.push(p);
}), l;
}, re = /* @__PURE__ */ $((e, {
slots: l,
emit: t,
expose: p
}) => {
var V, z;
const v = y("empty", l, e), F = (a) => y("expanedRow", l, e, a)(), S = (a, u) => y(`table-${u}`, l, e, a)(), D = y("actions", l, e), R = y("footerActions", l, e), s = y("title", l, e), T = f([]), m = f(!1), i = f([]), r = f({
pageNum: 1,
pageSize: 10,
total: 0
}), d = f([]), b = f(), w = f([]), o = x(() => d.value.filter((a) => w.value.includes(a[e.rowKey]))), g = y("dataActions", l, e), M = x(() => {
const a = {};
return i.value.map((u) => u.colKey).forEach((u) => {
a[u] = e[`table-${u}`] || l[`table-${u}`] ? (A) => S(A, u) : void 0;
}), a;
}), U = x(() => T.value.filter((a) => a.hidden).length == T.value.length);
X(() => {
j(), B(), E();
});
function j() {
T.value = oe(e.options || []);
}
function B() {
i.value = ie(e.options.filter((h) => !h.hideInTable) || []), A(), u(), a();
function a() {
i.value.filter((h) => h.colKey === "drag").length > 0 || e.dragAble && i.value.unshift({
colKey: "drag",
cell: () => n("span", null, [n(G("t-icon"), {
name: "move"
}, null)]),
width: 46
});
}
function u() {
i.value.filter((h) => h.colKey === "row-select").length > 0 || e.selectAble && i.value.unshift({
colKey: "row-select",
type: e.selectType,
width: 46
});
}
function A() {
e.editAble && (i.value = i.value.map((h) => {
const c = e.options.find((C) => h.colKey == C.key);
return {
...h,
edit: {
...c.edit ? c.edit : {},
onEdited: (C) => {
if (c && c.edit) {
let I = function() {
const P = [...d.value];
P.splice(C.rowIndex, 1, C.newRowData), d.value = P, c.edit.onEditSuccess && c.edit.onEditSuccess(C);
};
c.edit.beforeEdit ? c.edit.beforeEdit().then(() => {
I();
}).catch((P) => {
c.edit && c.edit.onEditFail && c.edit.onEditFail(P);
}) : I();
}
}
}
};
}));
}
}
function _(a) {
w.value = a;
}
function K() {
r.value.pageNum = 1, E();
}
function E() {
e.request && (m.value = !0, e.request({
form: b.value ? b.value.getSearchValue() : {},
pageNum: r.value.pageNum,
pageSize: r.value.pageSize
}).then((a) => {
a.success !== !1 && (d.value = a.list || [], r.value.total = a.total);
}).catch(() => {
}).finally(() => {
m.value = !1;
}));
}
const J = (a) => {
const {
newData: u,
sort: A
} = a;
e.dragHandler ? A === "col" ? i.value = e.dragHandler(a) : d.value = e.dragHandler(a) : A === "col" ? i.value = u : d.value = u;
};
return H(() => r.value.pageNum, () => {
E();
}), H(() => r.value.pageSize, () => {
E();
}), H(w, (a) => {
t("update:selectData", a);
}), H(() => e.selectData, (a) => {
w.value = e.selectData || [];
}), H(() => e.options, () => {
B(), j();
}, {
deep: !0
}), p({
reload: (V = b.value) == null ? void 0 : V.reset,
getTableData: () => d,
reset: E,
getFormValue: (z = b.value) == null ? void 0 : z.getSearchValue
}), () => n("div", null, [!U.value && !e.hideForm && n("div", {
style: "margin-bottom: 16px;"
}, [n(le, {
formHeader: e.formHeader,
ref: b,
loading: m.value,
onSearch: K,
onReset: K,
options: T.value
}, null)]), n("div", null, [n(k, null, {
title: s() ? s() : void 0,
actions: D() ? D() : void 0,
default: () => n(L, null, [n("div", {
style: "display: flex; margin-bottom: 16px;"
}, [g() && e.dataActionsAlign === "left" && n("div", null, [g()]), n("div", null, [l.card ? Q(n("div", null, [l.card({
list: d.value
})]), [[Y("loading"), m.value]]) : n(te, Z({
onSelectChange: _,
onDragSort: J,
"drag-sort": e.dragType,
loading: m.value,
data: d.value,
columns: i.value
}, e.tableProps), {
empty: v(),
expandedRow: e.expanedRow || l.expanedRow ? F : void 0,
...l,
...M.value
}), R() && n("div", null, [R()])]), g() && e.dataActionsAlign === "right" && n("div", null, [g({
data: o.value
})])]), !e.hideFooter && n("div", null, [n(ae, {
modelValue: r.value.pageNum,
"onUpdate:modelValue": (a) => r.value.pageNum = a,
pageSize: r.value.pageSize,
"onUpdate:pageSize": (a) => r.value.pageSize = a,
disabled: m.value,
total: r.value.total
}, null)])])
})])]);
}, {
name: "ProTable",
emits: ["update:selectData"],
props: {
options: Array,
request: Function,
dragSort: [Boolean, String],
dragHandler: Function,
empty: [String, Function, Object],
formHeader: [String, Function, Object],
tableProps: [Object],
dragAble: Boolean,
dragType: {
type: String,
default: "row-handler"
},
selectData: Array,
selectAble: Boolean,
selectType: {
type: String,
default: "multiple"
},
editAble: Boolean,
hideFooter: Boolean,
expanedRow: Function,
hideForm: Boolean,
rowKey: {
type: String,
default: "id"
},
dataActionsAlign: {
type: String,
default: "left"
}
}
}), me = W(re);
export {
re as P,
me as a
};