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