UNPKG

@fecp/mobile

Version:

143 lines (142 loc) 4.16 kB
/* empty css */ /* empty css */ /* empty css */ import { ref, onMounted, computed, watch, createBlock, openBlock, unref, isRef, withCtx, renderSlot } from "vue"; import { useDataSource } from "../../../utils/dataSourceUtil.mjs"; import { List } from "../../../../../../node_modules/.pnpm/vant@4.9.17_vue@3.5.13_typescript@5.7.3_/node_modules/vant/es/list/index.mjs"; const _sfc_main = { __name: "List", props: { modelValue: { type: Array, default: [] }, disabledLoad: { type: Boolean, default: false }, offset: { type: String, default: "0" }, direction: { type: String, default: "down" }, dataSource: { type: String, default: "" }, params: { type: Object, default: {} }, pageSize: { type: String, default: "10" } }, emits: ["update:modelValue"], setup(__props, { emit: __emit }) { const props = __props; const listRef = ref(); let isDesigner = false; onMounted(() => { var _a, _b; try { const uid = (_b = (_a = listRef.value) == null ? void 0 : _a.$el) == null ? void 0 : _b.getAttribute("data-uid"); if (uid) { isDesigner = true; } } catch (error2) { } }); const emit = __emit; const tableData = computed({ get: () => { return props.modelValue; }, set: (val) => { emit("update:modelValue", val); } }); const finished = ref(false); const error = ref(false); const loading = ref(false); let pageNo = 1; const dataSource = useDataSource(props.dataSource); if (dataSource && !isDesigner) { if (props.disabledLoad) { tableData.value = []; call(); } else { pageNo = 0; } } else { loading.value = false; } function onLoad() { if (dataSource && !isDesigner) { loading.value = true; pageNo++; call(); } else { loading.value = false; } } watch( () => props.params, () => { tableData.value = []; pageNo = 1; finished.value = false; loading.value = true; call(); }, { deep: true } ); function call() { error.value = false; dataSource == null ? void 0 : dataSource.load({ ...props.params, pageNo, pageSize: props.pageSize }).then((res) => { var _a; const data = ((_a = res == null ? void 0 : res.data) == null ? void 0 : _a.records) || (res == null ? void 0 : res.data) || res || []; tableData.value.push(...data); if (data.length < props.pageSize) { finished.value = true; } loading.value = false; }).catch((err) => { console.error(err); error.value = true; loading.value = false; }); } return (_ctx, _cache) => { const _component_van_list = List; return openBlock(), createBlock(_component_van_list, { ref_key: "listRef", ref: listRef, loading: unref(loading), "onUpdate:loading": _cache[0] || (_cache[0] = ($event) => isRef(loading) ? loading.value = $event : null), error: unref(error), "onUpdate:error": _cache[1] || (_cache[1] = ($event) => isRef(error) ? error.value = $event : null), finished: unref(finished), disabled: __props.disabledLoad, offset: __props.offset, "finished-text": "没有更多了", "error-text": "请求失败,点击重新加载", onLoad }, { default: withCtx(() => [ renderSlot(_ctx.$slots, "default") ]), _: 3 }, 8, ["loading", "error", "finished", "disabled", "offset"]); }; } }; export { _sfc_main as default };