@yqg/low-code-component-lib
Version:
fintopia web lowcode component library
284 lines (283 loc) • 10.1 kB
JavaScript
import { defineComponent as _, inject as ee, ref as m, computed as N, onMounted as te, createElementBlock as P, openBlock as k, createCommentVNode as $, createVNode as M, createBlock as oe, unref as K, withCtx as L, createTextVNode as ae, createSlots as se, renderList as ne, renderSlot as le, normalizeProps as re, guardReactiveProps as ue } from "vue";
import { Button as ce, Table as ie } from "ant-design-vue";
import de from "./custom-column-modal.vue.js";
const me = { class: "bigfish-dynamic-table" }, fe = {
key: 0,
class: "table-header-actions"
}, he = /* @__PURE__ */ _({
__name: "index",
props: {
rowKey: { default: "id" },
bordered: { type: Boolean, default: !1 },
size: { default: "middle" },
showCustomColumnButton: { type: Boolean, default: !0 },
levelCode: { default: 100 },
columnsRequestConfig: {},
listRequestConfig: {},
sumRequestConfig: {},
getColumnEnumsRequestConfig: {},
saveColumnsRequestConfig: {},
pageSize: { default: 10 },
pageSizeOptions: { default: () => ["10", "20", "50", "100"] },
prohibitPagination: { type: Boolean },
scrollX: {},
requestOnMount: { type: Boolean, default: !0 },
loading: { type: Boolean },
customSlotNames: { default: () => [] }
},
emits: ["change", "custom-column-change"],
setup(f, { expose: A, emit: U }) {
const X = (e, ...t) => {
const a = { ...e };
return t.forEach((o) => {
delete a[o];
}), a;
};
let B;
try {
window.lcRequest && (B = window.lcRequest);
} catch {
console.warn("未找到 lcRequest,将使用 axios 作为后备方案");
}
const r = f, x = U, l = ee("formRef", m(null)), h = m(!1), E = m({}), g = m([]), p = m(!1), V = m([]), y = m(1), z = m(r.pageSize || 10), D = m(0), R = m({}), I = m({}), j = N(() => {
if (r.scrollX)
return { x: r.scrollX };
}), G = N(() => {
const e = new Set(r.customSlotNames || []);
return g.value.forEach((t) => {
var a, o;
t.dataIndex && e.add(t.dataIndex), (a = t.slots) != null && a.customRender && e.add(t.slots.customRender), (o = t.slots) != null && o.title && e.add(t.slots.title);
}), Array.from(e);
}), H = N(() => r.prohibitPagination ? !1 : {
current: y.value,
pageSize: z.value,
total: D.value,
showSizeChanger: !0,
pageSizeOptions: r.pageSizeOptions || ["10", "20", "50", "100"],
showTotal: (e, t) => `${t[0]}-${t[1]}行,共${e}行`
}), F = async (e, t) => {
if (!e || !e.url)
throw new Error("requestConfig is required");
const a = B || window.lcRequest;
if (a)
return a(e, t);
const o = window.axios;
if (!o)
throw new Error("需要配置 axios 或 lcRequest");
const u = {
url: e.url,
method: e.method || "POST",
baseURL: e.baseURL,
headers: e.headers || {}
};
return e.method === "GET" ? u.params = t : u.data = t, o(u);
}, q = async () => {
var e, t, a, o, u, i;
if (!((e = r.columnsRequestConfig) != null && e.url)) {
console.warn("未配置列请求接口");
return;
}
try {
h.value = !0;
const d = {
levelCode: r.levelCode
}, c = await F(
{
...r.columnsRequestConfig,
formInstance: l.value ? {
setFormState: (t = l.value) == null ? void 0 : t.setFormState,
getFormState: (a = l.value) == null ? void 0 : a.getFormState,
submit: (o = l.value) == null ? void 0 : o.submit,
reset: (u = l.value) == null ? void 0 : u.reset,
getValues: (i = l.value) == null ? void 0 : i.getValues
} : {}
},
d
), { body: n } = c.data || c, { columns: C } = n || {}, w = (C || []).map((s) => {
const v = {
title: s.msg || s.label,
dataIndex: s.enumName || s.field,
key: s.enumName || s.field,
code: s.code,
sorter: s.sorter !== !1,
// 默认支持排序
...s.width && { width: s.width },
...s.fixed && { fixed: s.fixed },
...s.align && { align: s.align }
};
if (s.field || s.enumName) {
const S = s.enumName || s.field;
v.slots = {
customRender: S
};
}
return v;
});
g.value = w, E.value = n;
} catch (d) {
console.error("获取列配置失败:", d), g.value = [];
} finally {
h.value = !1;
}
}, T = async (e) => {
var t, a, o, u, i, d;
if (!((t = r.sumRequestConfig) != null && t.url))
return null;
try {
const c = X(e, "pageNo", "pageSize", "total"), n = await F(
{
...r.sumRequestConfig,
formInstance: l.value ? {
setFormState: (a = l.value) == null ? void 0 : a.setFormState,
getFormState: (o = l.value) == null ? void 0 : o.getFormState,
submit: (u = l.value) == null ? void 0 : u.submit,
reset: (i = l.value) == null ? void 0 : i.reset,
getValues: (d = l.value) == null ? void 0 : d.getValues
} : {}
},
c
), { body: C } = n.data || n;
return {
...(C || [])[0] || {},
// 汇总行标识
isSumRow: !0
};
} catch (c) {
return console.error("获取汇总数据失败:", c), null;
}
}, O = async (e) => {
var t, a, o, u, i, d;
if (!((t = r.listRequestConfig) != null && t.url))
return console.warn("未配置列表请求接口"), { count: 0, data: [] };
try {
const c = await F(
{
...r.listRequestConfig,
formInstance: l.value ? {
setFormState: (a = l.value) == null ? void 0 : a.setFormState,
getFormState: (o = l.value) == null ? void 0 : o.getFormState,
submit: (u = l.value) == null ? void 0 : u.submit,
reset: (i = l.value) == null ? void 0 : i.reset,
getValues: (d = l.value) == null ? void 0 : d.getValues
} : {}
},
e
), { body: n } = c.data || c;
return {
count: (n == null ? void 0 : n.count) || (n == null ? void 0 : n.total) || 0,
data: (n == null ? void 0 : n.data) || []
};
} catch (c) {
return console.error("获取列表数据失败:", c), { count: 0, data: [] };
}
}, b = async (e) => {
var t, a;
if ((t = r.listRequestConfig) != null && t.url)
try {
h.value = !0;
const { formValues: o = {}, refresh: u = !1 } = e || {};
Object.keys(o).length > 0 && (I.value = o), u && (y.value = 1);
const i = {
...I.value,
pageNo: y.value,
pageSize: z.value
};
if (R.value.order) {
const v = {
ascend: 1,
descend: 0
}, S = (a = g.value.find(
(Z) => Z.dataIndex === R.value.field
)) == null ? void 0 : a.code;
i.orderColumn = S, i.orderType = v[R.value.order];
}
const [d, c] = await Promise.all([
O(i),
T(i)
]), { count: n, data: C } = d, w = c ? [c, ...C] : C, s = Date.now();
w.forEach((v, S) => {
!v[r.rowKey] && !v.isSumRow && (v[r.rowKey] = `${s}_${S}`);
}), V.value = w, D.value = n;
} catch (o) {
console.error("刷新数据失败:", o);
} finally {
h.value = !1;
}
}, J = (e, t, a) => {
var u;
const o = Array.isArray(a) ? a[0] : a;
if (e.current && (y.value = e.current), e.pageSize && (z.value = e.pageSize), R.value = o, b(), o != null && o.order) {
const i = {
ascend: 1,
descend: 0
}, d = (u = g.value.find(
(n) => n.dataIndex === o.field
)) == null ? void 0 : u.code, c = {
...o,
sortInfo: {
orderColumn: d,
orderType: i[o.order]
}
};
x("change", e, t, c);
} else
x("change", e, t, o);
}, Q = () => {
p.value = !0;
}, W = async () => {
await q(), await b(), x("custom-column-change", g.value);
}, Y = async () => {
await q(), await b();
};
return te(() => {
r.requestOnMount !== !1 && Y();
}), A({
getColumns: q,
refreshColumns: q,
refreshData: b,
getListData: O,
getSumData: T
}), (e, t) => (k(), P("div", me, [
f.showCustomColumnButton ? (k(), P("div", fe, [
M(K(ce), { onClick: Q }, {
default: L(() => [...t[1] || (t[1] = [
ae(" 自定义指标 ", -1)
])]),
_: 1
})
])) : $("", !0),
M(K(ie), {
columns: g.value,
"data-source": V.value,
"row-key": f.rowKey,
loading: h.value,
pagination: H.value,
bordered: f.bordered,
size: f.size,
scroll: j.value,
onChange: J
}, se({ _: 2 }, [
ne(G.value, (a) => ({
name: a,
fn: L((o) => [
le(e.$slots, a, re(ue(o)), void 0, !0)
])
}))
]), 1032, ["columns", "data-source", "row-key", "loading", "pagination", "bordered", "size", "scroll"]),
p.value ? (k(), oe(de, {
key: 1,
visible: p.value,
"onUpdate:visible": t[0] || (t[0] = (a) => p.value = a),
source: E.value,
"level-code": f.levelCode,
"get-column-enums-request-config": f.getColumnEnumsRequestConfig,
"save-columns-request-config": f.saveColumnsRequestConfig,
onConfirm: W
}, null, 8, ["visible", "source", "level-code", "get-column-enums-request-config", "save-columns-request-config"])) : $("", !0)
]));
}
});
export {
he as default
};
//# sourceMappingURL=index.vue2.js.map