@fecp/mobile
Version:
143 lines (142 loc) • 4.28 kB
JavaScript
;
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
;/* empty css */
;/* empty css */
;/* empty css */
const vue = require("vue");
const dataSourceUtil = require("../../../utils/dataSourceUtil.js");
const index = require("../../../../../../node_modules/.pnpm/vant@4.9.17_vue@3.5.13_typescript@5.7.3_/node_modules/vant/es/list/index.js");
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 = vue.ref();
let isDesigner = false;
vue.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 = vue.computed({
get: () => {
return props.modelValue;
},
set: (val) => {
emit("update:modelValue", val);
}
});
const finished = vue.ref(false);
const error = vue.ref(false);
const loading = vue.ref(false);
let pageNo = 1;
const dataSource = dataSourceUtil.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;
}
}
vue.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 = index.List;
return vue.openBlock(), vue.createBlock(_component_van_list, {
ref_key: "listRef",
ref: listRef,
loading: vue.unref(loading),
"onUpdate:loading": _cache[0] || (_cache[0] = ($event) => vue.isRef(loading) ? loading.value = $event : null),
error: vue.unref(error),
"onUpdate:error": _cache[1] || (_cache[1] = ($event) => vue.isRef(error) ? error.value = $event : null),
finished: vue.unref(finished),
disabled: __props.disabledLoad,
offset: __props.offset,
"finished-text": "没有更多了",
"error-text": "请求失败,点击重新加载",
onLoad
}, {
default: vue.withCtx(() => [
vue.renderSlot(_ctx.$slots, "default")
]),
_: 3
}, 8, ["loading", "error", "finished", "disabled", "offset"]);
};
}
};
exports.default = _sfc_main;