@aplus-frontend/ui
Version:
200 lines (199 loc) • 6.75 kB
JavaScript
import { defineComponent as Z, ref as _, toRef as x, unref as e, computed as p, watch as ee, createElementBlock as s, openBlock as o, normalizeStyle as h, normalizeClass as i, renderSlot as u, createElementVNode as te, createCommentVNode as P, createVNode as g, Fragment as z, createBlock as C, withCtx as b, renderList as ae, mergeProps as ne } from "vue";
import { Empty as F, Spin as re, Pagination as oe } from "@aplus-frontend/antdv";
import { useTablePaging as ie } from "../ap-table/hooks/use-table-paging-ng.mjs";
import "../config-provider/index.mjs";
import { isUndefined as V, isNumber as le, omit as se } from "lodash-unified";
import { useOfflineList as ue } from "./hooks/use-offline-list.mjs";
import "vue-virtual-scroller/dist/vue-virtual-scroller.css";
import { RecycleScroller as me, DynamicScroller as ce, DynamicScrollerItem as de } from "vue-virtual-scroller";
import fe from "./style/index.mjs";
import { useNamespace as pe } from "../config-provider/hooks/use-namespace.mjs";
const De = /* @__PURE__ */ Z({
name: "ApList",
__name: "index",
props: {
dataSource: {},
loading: { type: Boolean, default: void 0 },
onItem: {},
params: {},
request: {},
defaultData: {},
onLoadingChange: {},
beforeSearchSubmit: {},
pagination: { type: [Boolean, Object], default: void 0 },
manual: { type: Boolean },
containerStyle: { type: [Boolean, null, String, Object, Array] },
contentStyle: { type: [Boolean, null, String, Object, Array] },
footerWarpperStyle: { type: [Boolean, null, String, Object, Array] },
virtual: { default: void 0 },
rowKey: {},
adaptive: { type: Boolean, default: !1 }
},
setup(E, { expose: L }) {
const O = F.PRESENTED_IMAGE_SIMPLE, a = E, { b: d, e: y, bm: R, m: N } = pe("ap-list"), T = fe("ap-list"), k = _(), {
formRef: S,
submit: I,
reset: w,
handleTableChange: $,
data: v,
refresh: A,
refreshByDelete: j,
tableProps: B,
getPaging: q,
setPaging: K
} = ie({
async request(t) {
const n = await a.request?.(t);
return {
data: n?.data || [],
total: n?.total || 0
};
},
params: x(a, "params"),
defaultData: a.defaultData,
manual: a.manual,
pagination: a.pagination,
formatParams: a.beforeSearchSubmit
}), M = { form: S }, {
pagination: D,
dataSource: W,
onChange: G
} = ue(a);
function U(t, n) {
if (e(f)) {
G(t, n);
return;
}
$(
{ current: t, pageSize: n },
{},
{},
{ currentDataSource: [], action: "paginate" }
);
}
const m = p(() => e(f) ? e(W) : e(v).records), c = p(() => V(a.loading) ? e(v).loading : a.loading), H = p(() => a.pagination === !1 || a.virtual ? !1 : a.pagination?.hideOnSinglePage !== !0 ? !0 : e(f) ? (a.dataSource?.length || 0) > e(D).pageSize : e(v).total > e(B).pagination.pageSize), f = p(() => !V(a.dataSource));
ee(
() => e(c),
(t) => {
a.onLoadingChange?.(t);
}
);
function J(t) {
k.value?.querySelector(t || ":first-child")?.scrollIntoView({ behavior: "smooth", block: "center" });
}
function Q(t = !1) {
const n = S.value?.apForm;
return (t ? n?.getFieldsValueTransformed : n?.getFieldsValue)?.() || {};
}
function X(t) {
S.value?.apForm?.setFieldsValue?.(t);
}
return L({
submit: () => I(),
reset: () => w(),
refresh: () => A(),
refreshByDelete: (t) => j(t),
scrollToFirstRow: J,
getSearchFormValuesIfSetted: Q,
setPaging: K,
getPaging: q,
setSearchFormValuesIfSetted: X
}), (t, n) => (o(), s("div", {
class: i([e(d)(), { [e(N)("adaptive")]: t.adaptive }, e(T)]),
style: h(t.containerStyle)
}, [
u(t.$slots, "header", {
formIns: M,
submit: e(I),
reset: e(w)
}),
te("div", {
class: i([
e(d)("content-container"),
{ [e(R)("content-container", "spinning")]: c.value }
])
}, [
c.value ? (o(), s("div", {
key: 0,
class: i(e(y)("spin-wrapper"))
}, [
g(e(re), { spinning: c.value }, null, 8, ["spinning"])
], 2)) : P("", !0),
m.value.length === 0 ? u(t.$slots, "empty", {
key: 1,
loading: c.value
}, () => [
g(e(F), { image: e(O) }, null, 8, ["image"])
]) : (o(), s("div", {
key: 2,
ref_key: "contentRef",
ref: k,
style: h(t.contentStyle),
class: i(e(y)("content"))
}, [
t.virtual ? (o(), s(z, { key: 0 }, [
e(le)(t.virtual) ? (o(), C(e(me), {
key: 0,
class: i(e(d)("scroll-wrapper")),
items: m.value,
"item-size": t.virtual,
"key-field": a.rowKey || "id"
}, {
default: b(({ item: r, index: l }) => [
u(t.$slots, "renderItem", {
item: r,
index: l
})
]),
_: 3
}, 8, ["class", "items", "item-size", "key-field"])) : (o(), C(e(ce), {
key: 1,
items: m.value,
"min-item-size": t.virtual.minItemSize,
class: i(e(d)("scroll-wrapper"))
}, {
default: b(({ item: r, index: l, active: Y }) => [
g(e(de), {
item: r,
active: Y,
"data-index": l,
"size-dependencies": t.virtual.sizeDependencies?.(r)
}, {
default: b(() => [
u(t.$slots, "renderItem", {
item: r,
index: l
})
]),
_: 2
}, 1032, ["item", "active", "data-index", "size-dependencies"])
]),
_: 3
}, 8, ["items", "min-item-size", "class"]))
], 64)) : u(t.$slots, "renderContent", {
key: 1,
dataSource: m.value
}, () => [
(o(!0), s(z, null, ae(m.value, (r, l) => u(t.$slots, "renderItem", {
item: r,
index: l
})), 256))
])
], 6))
], 2),
H.value ? (o(), s("div", {
key: 0,
class: i(e(y)("footer")),
style: h(t.footerWarpperStyle)
}, [
g(e(oe), ne(
f.value ? e(D) : e(se)(e(B).pagination, ["showTotal"]),
{ onChange: U }
), null, 16)
], 6)) : P("", !0)
], 6));
}
});
export {
De as default
};