@fecp/mobile
Version:
555 lines (554 loc) • 20.8 kB
JavaScript
;
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
;/* empty css */
;/* empty css */
;/* empty css */
;/* empty css */
const vue = require("vue");
const vxeTable = require("vxe-table");
const dataSourceUtil = require("../../../utils/dataSourceUtil.js");
;/* empty css */
const formatterUtil = require("../../../utils/formatterUtil.js");
;/* empty css */
;/* empty css */
;/* empty css */
;/* empty css */
;/* empty css */
;/* empty css */
;/* empty css */
;/* empty css */
;/* empty css */
const _pluginVue_exportHelper = require("../../../../../../_virtual/_plugin-vue_export-helper.js");
const index = require("../../../../../../node_modules/.pnpm/vant@4.9.17_vue@3.5.13_typescript@5.7.3_/node_modules/vant/es/swipe-cell/index.js");
const index$1 = require("../../../../../../node_modules/.pnpm/vant@4.9.17_vue@3.5.13_typescript@5.7.3_/node_modules/vant/es/button/index.js");
const functionCall = require("../../../../../../node_modules/.pnpm/vant@4.9.17_vue@3.5.13_typescript@5.7.3_/node_modules/vant/es/dialog/function-call.js");
const index$2 = require("../../../../../../node_modules/.pnpm/vant@4.9.17_vue@3.5.13_typescript@5.7.3_/node_modules/vant/es/cell-group/index.js");
const index$3 = require("../../../../../../node_modules/.pnpm/vant@4.9.17_vue@3.5.13_typescript@5.7.3_/node_modules/vant/es/list/index.js");
const _hoisted_1 = {
key: 0,
class: "van-list__finished-text"
};
const _hoisted_2 = {
key: 1,
class: "van-list__loading"
};
const _sfc_main = {
__name: "Table",
props: {
modelValue: {
//数据
type: Array,
default: []
},
columns: {
//列配置
type: Array,
default: []
},
size: {
//大小尺寸: medium / small / mini
type: String,
default: "medium"
},
isFixedHead: {
//固定表头
type: Boolean,
default: true
},
autoHeight: {
//高度自适应
type: Boolean,
default: true
},
height: {
//高度
type: String,
default: "300"
},
border: {
//default:默认边框, full:完整边框,outer 显示外边框,inner 显示内边框,none 隐藏边框
type: String,
default: "default"
},
round: {
//显示圆角
type: Boolean,
default: false
},
stripe: {
//斑马线样式
type: Boolean,
default: false
},
showHeader: {
//显示表头
type: Boolean,
default: true
},
scrollLoad: {
//是否滚动加载
type: Boolean,
default: false
},
dataSource: {
type: String,
default: ""
},
params: {
type: Object,
default: {}
},
pageSize: {
type: String,
default: "10"
},
isCard: {
//卡片风格
type: Boolean,
default: false
},
isShadow: {
//卡片阴影
type: Boolean,
default: true
},
swipeDelete: {
//左滑删除
type: Boolean,
default: false
},
swipeEdit: {
//左滑编辑
type: Boolean,
default: false
}
},
emits: [
"update:modelValue",
"deleteRow",
"editRow",
"clickCell"
],
setup(__props, { emit: __emit }) {
const props = __props;
const emit = __emit;
function cellClickEvent({ row, column }) {
emit("clickCell", { row, column });
}
const compHeight = vue.computed(() => {
if (props.autoHeight) {
return "100%";
} else {
return props.height + "px";
}
});
const columnOptions = vue.computed(() => {
const columns = [...props.columns];
columns.forEach((col) => {
switch (col.dataType) {
case "select":
col.formatter = ({ cellValue }) => {
if (isEmpty(cellValue)) {
return emptyHandler(col.emptyFormatter);
}
return formatterUtil.selectFormatter(cellValue, col.options);
};
break;
case "multiple":
col.formatter = ({ cellValue }) => {
if (isEmpty(cellValue)) {
return emptyHandler(col.emptyFormatter);
}
return formatterUtil.multipleFormatter(cellValue, col.options);
};
break;
case "cascade":
col.formatter = ({ cellValue }) => {
if (isEmpty(cellValue)) {
return emptyHandler(col.emptyFormatter);
}
return formatterUtil.cascadeFormatter(cellValue, col.treeOptions);
};
break;
case "date":
col.formatter = ({ cellValue }) => {
if (isEmpty(cellValue)) {
return emptyHandler(col.emptyFormatter);
}
return formatterUtil.dateFormatter(cellValue, col.dateType, col.dateFormatter);
};
break;
default:
col.formatter = ({ cellValue }) => {
if (isEmpty(cellValue)) {
return emptyHandler(col.emptyFormatter);
}
return formatterUtil.textFormatter(cellValue, col.dataFormatter);
};
break;
}
col.showOverflow = true;
col.showHeaderOverflow = true;
col.showFooterOverflow = true;
});
return columns;
});
function isEmpty(cellValue) {
return !cellValue && cellValue !== 0;
}
function emptyHandler(emptyFormatter) {
if (isEmpty(emptyFormatter)) {
return "";
} else {
return emptyFormatter;
}
}
const gridRef = vue.ref();
const listRef = vue.ref();
let isDesigner = false;
vue.onMounted(() => {
var _a, _b;
const uid = (_b = (_a = listRef.value) == null ? void 0 : _a.$el) == null ? void 0 : _b.getAttribute("data-uid");
if (uid) {
isDesigner = true;
}
setTimeout(() => {
initSwipeCells();
}, 500);
});
const initSwipeCells = () => {
if (props.swipeDelete || props.swipeEdit) {
const tableBody = gridRef.value.getEl().querySelector(".vxe-table--body");
tableBody.offsetWidth;
const tableRows = tableBody.querySelectorAll(".vxe-body--row");
tableRows.forEach((row, index$22) => {
if (!row.parentElement.classList.contains("van-swipe-cell__wrapper")) {
const swipeCell = vue.createVNode(
index.SwipeCell,
{
class: `fec-table-row-swipe`,
// style: `width:${offsetWidth}px`,
style: `width:100%`
// beforeClose: ({ position }) => {
// switch (position) {
// case "left":
// case "cell":
// case "outside":
// return true;
// case "right":
// return new Promise(resolve => {
// showConfirmDialog({
// title: "确定删除吗?",
// })
// .then(() => {
// emit("delete");
// resolve(true);
// })
// .catch(() => resolve(false));
// });
// }
// },
},
{
right: () => [
vue.createVNode(index$1.Button, {
square: true,
type: "primary",
text: "编辑",
style: `height:100%;display:${props.swipeEdit ? "inline-block" : "none"}`,
onClick: () => {
const rowData = gridRef.value.getData(index$22);
emit("editRow", rowData, index$22);
}
}),
vue.createVNode(index$1.Button, {
square: true,
type: "danger",
text: "删除",
style: `height:100%;display:${props.swipeDelete ? "inline-block" : "none"}`,
onClick: () => {
functionCall.showConfirmDialog({
title: "确定删除吗?"
}).then(() => {
const rowData = gridRef.value.getData(index$22);
emit("deleteRow", rowData, index$22);
}).catch(() => {
});
}
})
]
}
);
const container = document.createElement("div");
vue.render(swipeCell, container);
const swipeCellElement = container.firstElementChild;
const colgroupElement = row.parentNode.parentNode.querySelector("colgroup");
const cloneColgroupElement = colgroupElement.cloneNode(true);
swipeCellElement.appendChild(cloneColgroupElement);
row.parentNode.replaceChild(swipeCellElement, row);
swipeCellElement.querySelector(".van-swipe-cell__wrapper").appendChild(row);
}
});
}
};
const virtualYConfig = {
enabled: false,
gt: 0,
threshold: 0
};
const tableData = vue.computed({
get: () => {
return props.modelValue;
},
set: (val) => {
emit("update:modelValue", val);
}
});
const dataSource = dataSourceUtil.useDataSource(props.dataSource);
let pageNo = 1;
const initLoading = vue.ref(false);
const loading = vue.ref(false);
const finished = vue.ref(false);
const listFinished = vue.ref(false);
const error = vue.ref(false);
const listError = vue.ref(false);
if (dataSource && !isDesigner) {
tableData.value = [];
if (props.isFixedHead) {
initLoading.value = true;
call();
} else if (!props.scrollLoad) {
call();
} else {
pageNo = 0;
}
} else {
loading.value = false;
}
function onScrollLoads({ direction }) {
const isBottom = direction == "bottom";
if (finished.value || loading.value || error.value) {
return;
}
if (props.scrollLoad && isBottom && dataSource) {
pageNo++;
loading.value = true;
error.value = false;
call();
}
}
vue.watch(
() => props.params,
(newParams, oldParams) => {
const isParamsChanged = Object.keys(newParams).some(
(key) => newParams[key] !== oldParams[key]
);
if (isParamsChanged) {
tableData.value = [];
loading.value = false;
finished.value = false;
listFinished.value = false;
error.value = false;
listError.value = false;
pageNo = 1;
if (props.isFixedHead) {
initLoading.value = true;
call();
} else if (!props.scrollLoad) {
call();
}
}
},
{ deep: true }
);
function call() {
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) {
if (props.isFixedHead) {
finished.value = true;
} else {
listFinished.value = true;
}
}
loading.value = false;
initLoading.value = false;
setTimeout(() => {
vue.nextTick(() => {
checkHasScroll();
});
}, 300);
setTimeout(() => {
initSwipeCells();
}, 500);
}).catch((err) => {
console.error(err);
if (props.isFixedHead) {
error.value = isDesigner ? false : true;
} else {
listError.value = isDesigner ? false : true;
}
loading.value = false;
initLoading.value = false;
});
}
function errReload() {
call();
}
function checkHasScroll() {
if (!props.isFixedHead) {
return;
}
if (finished.value) {
return;
}
const scrollHeight = gridRef.value.getEl().querySelector(".vxe-table--body").scrollHeight;
const clientHeight = gridRef.value.getEl().querySelector(".vxe-table--body-inner-wrapper").clientHeight;
if (scrollHeight < clientHeight) {
onScrollLoads({ direction: "bottom" });
}
}
function onLoad() {
console.log("onload");
if (!props.isFixedHead) {
loading.value = true;
pageNo++;
if (pageNo == 1) {
initLoading.value = false;
} else {
loading.value = true;
}
listError.value = false;
call();
}
}
return (_ctx, _cache) => {
const _component_van_list = index$3.List;
const _component_van_cell_group = index$2.CellGroup;
return vue.openBlock(), vue.createBlock(_component_van_cell_group, {
class: vue.normalizeClass(["mTableContent", {
notAutoHeight: !__props.autoHeight,
isShadow: __props.isCard && __props.isShadow,
isCard: __props.isCard
}]),
style: vue.normalizeStyle("height:" + vue.unref(compHeight)),
ref_key: "listRef",
ref: listRef,
inset: __props.isCard
}, {
default: vue.withCtx(() => [
vue.createVNode(_component_van_list, {
class: vue.normalizeClass({ fixedHead: __props.isFixedHead }),
loading: vue.unref(loading),
"onUpdate:loading": _cache[0] || (_cache[0] = ($event) => vue.isRef(loading) ? loading.value = $event : null),
error: vue.unref(listError),
"onUpdate:error": _cache[1] || (_cache[1] = ($event) => vue.isRef(listError) ? listError.value = $event : null),
finished: vue.unref(listFinished),
disabled: !__props.scrollLoad || __props.isFixedHead,
offset: 0,
"finished-text": "没有更多了",
"error-text": "请求失败,点击重新加载",
onLoad
}, {
default: vue.withCtx(() => [
vue.createVNode(vue.unref(vxeTable.VxeGrid), {
ref_key: "gridRef",
ref: gridRef,
class: "fec-table",
width: "100%",
"auto-resize": "",
data: vue.unref(tableData),
columns: vue.unref(columnOptions),
size: __props.size,
headerAlign: "center",
footerAlign: "center",
align: "center",
border: __props.border,
round: __props.round || __props.isCard,
stripe: __props.stripe,
height: __props.isFixedHead ? vue.unref(compHeight) : "",
minHeight: 200,
loading: vue.unref(initLoading),
showHeader: __props.showHeader,
onScrollBoundary: onScrollLoads,
virtualYConfig,
onCellClick: cellClickEvent
}, vue.createSlots({
loading: vue.withCtx(() => [
_cache[2] || (_cache[2] = vue.createElementVNode("div", {
class: "custom-loading van-loading van-loading--circular van-list__loading-icon",
"aria-live": "polite",
"aria-busy": "true"
}, [
vue.createElementVNode("span", { class: "van-loading__spinner van-loading__spinner--circular" }, [
vue.createElementVNode("svg", {
class: "van-loading__circular",
viewBox: "25 25 50 50"
}, [
vue.createElementVNode("circle", {
cx: "50",
cy: "50",
r: "20",
fill: "none"
})
])
]),
vue.createElementVNode("span", { class: "van-loading__text" }, "加载中...")
], -1))
]),
bottom: vue.withCtx(() => [
__props.scrollLoad && __props.isFixedHead ? (vue.openBlock(), vue.createElementBlock(vue.Fragment, { key: 0 }, [
vue.unref(finished) ? (vue.openBlock(), vue.createElementBlock("div", _hoisted_1, " 没有更多了 ")) : vue.createCommentVNode("", true),
vue.unref(loading) ? (vue.openBlock(), vue.createElementBlock("div", _hoisted_2, _cache[3] || (_cache[3] = [
vue.createElementVNode("div", {
class: "van-loading van-loading--circular van-list__loading-icon",
"aria-live": "polite",
"aria-busy": "true"
}, [
vue.createElementVNode("span", { class: "van-loading__spinner van-loading__spinner--circular" }, [
vue.createElementVNode("svg", {
class: "van-loading__circular",
viewBox: "25 25 50 50"
}, [
vue.createElementVNode("circle", {
cx: "50",
cy: "50",
r: "20",
fill: "none"
})
])
]),
vue.createElementVNode("span", { class: "van-loading__text" }, "加载中...")
], -1)
]))) : vue.createCommentVNode("", true),
vue.unref(error) ? (vue.openBlock(), vue.createElementBlock("div", {
key: 2,
class: "van-list__error-text",
onClick: errReload
}, " 请求失败,点击重新加载 ")) : vue.createCommentVNode("", true)
], 64)) : vue.createCommentVNode("", true)
]),
_: 2
}, [
vue.renderList(_ctx.$slots, (item, key) => {
return {
name: key,
fn: vue.withCtx(() => [
key != "bottom" ? vue.renderSlot(_ctx.$slots, key, { key: 0 }, void 0, true) : vue.createCommentVNode("", true)
])
};
})
]), 1032, ["data", "columns", "size", "border", "round", "stripe", "height", "loading", "showHeader"])
]),
_: 3
}, 8, ["class", "loading", "error", "finished", "disabled"])
]),
_: 3
}, 8, ["class", "style", "inset"]);
};
}
};
const _Table = /* @__PURE__ */ _pluginVue_exportHelper.default(_sfc_main, [["__scopeId", "data-v-82cfdaef"]]);
exports.default = _Table;