el-plus-powerful-table
Version:
## [DOCS](https://peng-xiao-shuai.github.io/vite-vue-admin-docs/zh-CN/component_directive/component/powerful-table-doc.html)
305 lines (304 loc) • 8.56 kB
JavaScript
import { useGlobalConfig as N, ElMessage as B, ElMessageBox as H } from "element-plus/es";
import { isTypeProtect as I, deepClone as M } from "../../index.mjs";
import { PowerfulTableSymbol as j } from "../../keys.mjs";
import { t as d } from "../../locale/lang.mjs";
import { inject as F, ref as A, reactive as w, watch as T, onBeforeUnmount as $, getCurrentInstance as G } from "vue";
import { LangKey as h } from "../../locale/packages.mjs";
var Q = /* @__PURE__ */ ((e) => (e.BtnPlusChange = "btn-plus-change", e.BtnPlusRefresh = "btn-plus-refresh", e.BtnClick = "btn-click", e.SizeChange = "size-change", e.ComponentEvent = "component-event", e.SortCustom = "sort-custom", e.BatchOperate = "batch-operate", e.Select = "select", e.SelectionChange = "selection-change", e.SelectAll = "select-all", e.CellMouseEnter = "cell-mouse-enter", e.CellMouseLeave = "cell-mouse-leave", e.CellClick = "cell-click", e.CellDblclick = "cell-dblclick", e.CellContextmenu = "cell-contextmenu", e.RowClick = "row-click", e.RowContextmenu = "row-contextmenu", e.RowDblclick = "row-dblclick", e.HeaderClick = "header-click", e.HeaderContextmenu = "header-contextmenu", e.FilterChange = "filter-change", e.CurrentChange = "current-change", e.HeaderDragend = "header-dragend", e.ExpandChange = "expand-change", e))(Q || {});
const Y = {
// 按钮组件配置数据
btnConfig: {
type: Object,
default: void 0
},
// 组件大小
size: {
type: String,
default: "",
validator: (e) => ["", "default", "small", "large"].includes(e)
},
// 当前数据
list: {
type: Array,
default: () => []
},
// 所有选中
selectData: {
type: Array,
default: () => []
},
isSelect: {
type: Boolean,
default: !1
},
selectable: {
type: Function,
default: void 0
},
selectCompare: {
type: Array,
default: () => ["id", "id"]
},
header: {
type: Array,
default: () => []
},
paginationProperty: {
type: Object,
default: () => ({})
},
// 批量操作
operateData: {
type: Object,
default: () => [{}]
},
isPagination: {
type: Boolean,
default: !0
},
tree: {
type: Object,
default: () => ({
props: {
children: "children",
hasChildren: "hasChildren"
}
})
},
property: {
type: Object,
default: () => ({})
},
listRequest: {
type: Object,
default: void 0
}
}, Z = {
row: {
type: Object,
default: () => [{}]
},
index: {
type: Number
},
aligning: {
type: String,
default: "center"
}
}, D = (e, t) => I(
t,
(o) => typeof o != "function"
) ? t : t(e || { row: {}, index: void 0, props: {} }), E = (e, t, o) => ({
REmit: (u, ...r) => {
e(
"component-emit",
{
componentName: t,
eventType: u,
...o
},
...r
);
},
event: (u, ...r) => {
var s;
const i = o.props.data;
I(
i,
(a) => typeof (a == null ? void 0 : a.on) != null
) && ((s = i == null ? void 0 : i.on) == null || s[u](
{ ...o },
...r
));
}
}), ee = (e) => {
var r, i, s, a, n, c;
const t = F(j, {}), o = A(null), y = A(null), p = w({
listLoading: !0,
//页面是否加载中
develop: [],
// 展开
currentPage: 1,
// 当前页
pageSize: (r = e.paginationProperty) != null && r.pageSizes ? (i = e.paginationProperty) == null ? void 0 : i.pageSizes[0] : 10,
//一页多少条
currentSelect: [],
// 当前页选中
otherSelect: [],
// 其他页选中
// 存储 watch 返回
watchCache: [],
operate: {
// 承载props的operateData
value: void 0,
disabled: !1,
icon: "",
prop: "id",
style: void 0,
operates: []
},
total: ((s = e.paginationProperty) == null ? void 0 : s.total) || 0
}), u = w({
tableLists: [],
isPC: !0,
isTable: !0
});
return typeof ((a = e.listRequest) == null ? void 0 : a.listApi) != "function" && p.watchCache.push(
T(
() => e.list,
(l) => {
u.tableLists = l || [];
},
{ immediate: !0, deep: !0 }
)
), $(() => {
p.watchCache.forEach((l) => l());
}), {
Size: e.size || ((c = (n = N()) == null ? void 0 : n.value) == null ? void 0 : c.size) || "default",
multipleTable: o,
filterComponents: y,
powerfulTableData: p,
injectProps: t,
stateData: u
};
}, te = (e, t) => {
const { proxy: o } = G();
return {
handleSelectionChange: (n) => {
t.currentSelect = M(n), e("selection-change", n);
},
returnEmit: (n, c) => {
switch (n) {
case "btn-click":
e("btn-click", c);
break;
}
},
componentEmit: (n, ...c) => {
e("component-event", n, ...c);
},
sortChange: (n) => {
Object.keys(n.column || {}).length && n.column.sortable == "custom" && e("sort-custom", n);
},
batchOperate: () => {
if ((t.operate == null || t.operate == null) && t.operate !== 0) {
B.warning(d(h.SelectOperateType));
return;
}
if (t.currentSelect.length == 0) {
B.warning(d(h.SelectOperateData));
return;
}
const n = t.operate.operates.find(
(c) => c.value == t.operate.value
);
H.confirm(
d(h.BatchOperate)(n.label),
d(h.Hint),
{
confirmButtonText: d(h.Confirm),
cancelButtonText: d(h.Cancel),
type: "warning"
}
).then(() => {
const c = t.otherSelect.concat(t.currentSelect).map((g) => g[t.operate.prop || "id"]), l = t.otherSelect.concat(t.currentSelect).map((g) => g);
e("batch-operate", {
ids: c,
item: n,
rows: l
});
}).catch(() => {
});
},
get: () => {
const n = {
pageNum: t.currentPage,
pageSize: t.pageSize
};
try {
o.$parent._getList({
params: n,
select: t.otherSelect.concat(
t.currentSelect
)
});
} catch {
e("size-change", {
params: n,
select: t.otherSelect.concat(
t.currentSelect
)
});
}
},
matchComponents: (n) => ({
image: "PTImage",
btn: "PTButton",
switch: "PTSwitch",
input: "PTInput",
textarea: "PTInput",
iconfont: "PTIcon",
tag: "PTTags",
rate: "PTRate",
href: "PTLink",
video: "PTVideo"
})[n],
bindAttr(n, c, l) {
var g;
return {
row: c.row,
index: c.$index,
prop: n,
aligning: ((g = l.property) == null ? void 0 : g.align) || l.headerAlign || "center"
};
}
};
}, ne = (e, t, o, y) => {
var i;
const p = (s, a) => {
const n = a.split(".");
let c = s;
return n.forEach((l) => {
c = c[l];
}), c;
};
let u, r;
return typeof ((i = t.listRequest) == null ? void 0 : i.listApi) == "function" ? (r = (s = {}) => {
var f, C, S, v, R, P, b, k, q, x, K, z, m;
const [a, n, c, l, g] = [
((f = t.listRequest) == null ? void 0 : f.pageNoKey) || ((C = o.listRequest) == null ? void 0 : C.pageNoKey) || "pageNo",
((S = t.listRequest) == null ? void 0 : S.pageSizeKey) || ((v = o.listRequest) == null ? void 0 : v.pageSizeKey) || "pageSize",
typeof ((R = t.listRequest) == null ? void 0 : R.responseKey) > "u" ? typeof ((P = o.listRequest) == null ? void 0 : P.responseKey) > "u" ? "data.result" : (b = o.listRequest) == null ? void 0 : b.responseKey : (k = t.listRequest) == null ? void 0 : k.responseKey,
((q = t.listRequest) == null ? void 0 : q.totalKey) || ((x = o.listRequest) == null ? void 0 : x.totalKey) || "total",
((K = t.listRequest) == null ? void 0 : K.listsKey) || ((z = o.listRequest) == null ? void 0 : z.listsKey) || "rows"
];
(m = t.listRequest) == null || m.listApi({
...t.listRequest.listQuery || {},
...s,
[a]: e.currentPage,
[n]: e.pageSize
}).then((O) => {
const L = c ? p(O, c) : O;
y.tableLists = L[g], e.total = Number(L[l]);
});
}, u = (s = {}) => {
e.currentPage = 1, r(s);
}, r(), {
resetList: u,
getListData: r
}) : {
resetList: void 0,
getListData: void 0
};
};
export {
Q as EmitEnum,
D as isProperty,
Z as powerfulTableComponentProp,
Y as powerfulTableProps,
te as useFunction,
ne as useInitiateListRequest,
ee as usePowerfulTableStates,
E as useREmit
};
//# sourceMappingURL=powerful-table-data.mjs.map