UNPKG

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)

310 lines (309 loc) 8.78 kB
import { useGlobalConfig as N, ElMessage as B, ElMessageBox as j } from "element-plus/es"; import { isTypeProtect as I, deepClone as H } from "../../index.mjs"; import { PowerfulTableSymbol as M } from "../../keys.mjs"; import { t as p } from "../../locale/lang.mjs"; import { inject as F, ref as w, reactive as A, 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 Z = { // 按钮组件配置数据 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 } }, D = { row: { type: Object, default: () => [{}] }, index: { type: Number }, aligning: { type: String, default: "center" } }, U = (e, t) => I( t, (o) => typeof o != "function" ) ? t : t(e || { row: {}, index: void 0, props: {} }), E = (e, t) => I( t, (o) => typeof o != "function" ) ? t : t(e || { row: {}, index: void 0, props: {} }), ee = (e, t, o) => ({ REmit: (a, ...l) => { e( "component-emit", { componentName: t, eventType: a, ...o }, ...l ); }, event: (a, ...l) => { var r, u; const s = U( { row: o.row, index: o.index, props: o.props }, o.props.data ); typeof (s == null ? void 0 : s.on) == "object" && ((u = (r = s == null ? void 0 : s.on) == null ? void 0 : r[a]) == null || u.call( r, { ...o }, ...l )); } }), te = (e) => { var l, s, r, u, n, c; const t = F(M, {}), o = w(null), y = w(null), g = A({ listLoading: !0, //页面是否加载中 develop: [], // 展开 currentPage: 1, // 当前页 pageSize: (l = e.paginationProperty) != null && l.pageSizes ? (s = e.paginationProperty) == null ? void 0 : s.pageSizes[0] : 10, //一页多少条 currentSelect: [], // 当前页选中 otherSelect: [], // 其他页选中 // 存储 watch 返回 watchCache: [], operate: { // 承载props的operateData value: void 0, disabled: !1, icon: "", prop: "id", style: void 0, operates: [] }, total: ((r = e.paginationProperty) == null ? void 0 : r.total) || 0 }), a = A({ tableLists: [], isPC: !0, isTable: !0 }); return typeof ((u = e.listRequest) == null ? void 0 : u.listApi) != "function" && g.watchCache.push( T( () => e.list, (i) => { a.tableLists = i || []; }, { immediate: !0, deep: !0 } ) ), $(() => { g.watchCache.forEach((i) => i()); }), { Size: e.size || ((c = (n = N()) == null ? void 0 : n.value) == null ? void 0 : c.size) || "default", multipleTable: o, filterComponents: y, powerfulTableData: g, injectProps: t, stateData: a }; }, ne = (e, t) => { const { proxy: o } = G(); return { handleSelectionChange: (n) => { t.currentSelect = H(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(p(h.SelectOperateType)); return; } if (t.currentSelect.length == 0) { B.warning(p(h.SelectOperateData)); return; } const n = t.operate.operates.find( (c) => c.value == t.operate.value ); j.confirm( p(h.BatchOperate)(n.label), p(h.Hint), { confirmButtonText: p(h.Confirm), cancelButtonText: p(h.Cancel), type: "warning" } ).then(() => { const c = t.otherSelect.concat(t.currentSelect).map((d) => d[t.operate.prop || "id"]), i = t.otherSelect.concat(t.currentSelect).map((d) => d); e("batch-operate", { ids: c, item: n, rows: i }); }).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, i) { var d; return { row: c.row, index: c.$index, prop: n, aligning: ((d = i.property) == null ? void 0 : d.align) || i.headerAlign || "center" }; } }; }, oe = (e, t, o, y) => { var s; const g = (r, u) => { const n = u.split("."); let c = r; return n.forEach((i) => { c = c[i]; }), c; }; let a, l; return typeof ((s = t.listRequest) == null ? void 0 : s.listApi) == "function" ? (l = (r = {}) => { var f, C, S, v, R, P, b, x, k, q, K, z, m; const [u, n, c, i, d] = [ ((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 : (x = t.listRequest) == null ? void 0 : x.responseKey, ((k = t.listRequest) == null ? void 0 : k.totalKey) || ((q = o.listRequest) == null ? void 0 : q.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 || {}, ...r, [u]: e.currentPage, [n]: e.pageSize }).then((O) => { const L = c ? g(O, c) : O; y.tableLists = L[d], e.total = Number(L[i]); }); }, a = (r = {}) => { e.currentPage = 1, l(r); }, l(), { resetList: a, getListData: l }) : { resetList: void 0, getListData: void 0 }; }; export { Q as EmitEnum, U as isData, E as isProperty, D as powerfulTableComponentProp, Z as powerfulTableProps, ne as useFunction, oe as useInitiateListRequest, te as usePowerfulTableStates, ee as useREmit }; //# sourceMappingURL=powerful-table-data.mjs.map