asp-smart-ui-plus-test
Version:
A Component Library for Vue 3
297 lines (294 loc) • 11.3 kB
JavaScript
import { defineComponent, ref, watch, onMounted, resolveComponent, openBlock, createElementBlock, createVNode, mergeProps, toHandlers, withCtx, createBlock, renderSlot, createCommentVNode, Fragment, renderList, normalizeProps, withDirectives, withModifiers, createTextVNode, toDisplayString, vShow, normalizeClass } from 'vue';
import { aspDeepClone } from '../../../../../utils/common.mjs';
import tableColumn from './table-column.mjs';
import tableColumnParent from './table-column-parent.mjs';
import _export_sfc from '../../../../../_virtual/plugin-vue_export-helper.mjs';
const _hoisted_1 = {
class: "asp-table-list",
style: { "width": "100%" }
};
const _sfc_main = defineComponent({
__name: "table-list",
props: {
attributes: {
type: Object,
default: () => ({})
},
events: {
type: Object,
default: () => ({})
},
options: {
type: Object,
default: () => ({})
},
columns: {
type: Array,
default: () => []
},
operation: {
type: Object,
default: () => ({})
},
tableData: {
type: Array,
default: () => []
},
tableDataTemp: {
type: Array,
default: () => []
},
timeStamp: {
type: [String, Number],
default: ""
}
},
emits: [
"sortChange",
"filterChange",
"filterConfirm",
"filterReset"
],
setup(__props, { emit }) {
const props = __props;
const tData = ref({
tableData: props.tableData
});
const tableSingleSelection = ref();
watch(
() => props.tableData,
(val) => {
tData.value.tableData = val;
},
{
deep: true
}
);
const initTable = () => {
if (props.columns.length > 0) {
const allWidth = props.columns.every((item) => {
return item.width && item.width.length > 0;
});
if (allWidth) {
props.columns[props.columns.length - 1].width = "";
}
}
};
onMounted(initTable);
const handleCommand = (btn, row, index) => {
if (!btn.func) {
return;
}
btn.func(row, index, aspDeepClone(props.tableDataTemp));
};
const handleLabel = (btn, row) => {
if (typeof btn.label === "function") {
return btn.label(row);
}
return btn.label;
};
const handleSelectionChange = (val) => {
if (!props.options.selectionChange) {
return;
}
props.options.selectionChange(val);
};
const handleSingleChange = (val) => {
if (!props.options.singleChange) {
return;
}
props.options.singleChange(val);
};
const rowDblClick = (row) => {
if (!props.options.rowDblClick) {
return;
}
props.options.rowDblClick(row);
};
const operationDisabled = (btn, row) => {
if (typeof btn.disabled === "function") {
return btn.disabled(row);
}
return !!btn.disabled;
};
const operationShow = (btn, row) => {
if (!btn.show) {
return true;
}
if (typeof btn.show === "function") {
return btn.show(row);
}
return btn.show;
};
const columnShow = (column) => {
if (typeof column.show === "function") {
return column.show(column);
}
return column.show === void 0 ? true : column.show;
};
const sortChange = ({
prop,
order
}) => {
emit("sortChange", { prop, order });
};
const handleSingleSelection = () => {
if (!props.options.singleSelection) {
return;
}
props.options.singleSelection(
tData.value.tableData[tableSingleSelection.value]
);
};
const filterChange = (params) => {
emit("filterChange", params);
};
const filterConfirm = () => {
emit("filterConfirm");
};
const filterReset = () => {
emit("filterReset");
};
return (_ctx, _cache) => {
const _component_asp_table_column = resolveComponent("asp-table-column");
const _component_asp_radio = resolveComponent("asp-radio");
const _component_asp_button = resolveComponent("asp-button");
const _component_asp_tooltip = resolveComponent("asp-tooltip");
const _component_asp_table = resolveComponent("asp-table");
return openBlock(), createElementBlock("div", _hoisted_1, [
createVNode(_component_asp_table, mergeProps({ ref: "table" }, __props.attributes, {
class: "asp-table",
"highlight-current-row": __props.options["highlight-current-row"],
height: "100%",
data: tData.value.tableData,
"span-method": __props.options.spanMethod,
"default-sort": __props.options.defaultSort ? { prop: __props.options.defaultSort.prop, order: __props.options.defaultSort.order } : {},
style: { "width": "100%" }
}, toHandlers(__props.events), {
onSortChange: sortChange,
onRowDblclick: rowDblClick,
onCurrentChange: handleSingleChange,
onSelectionChange: handleSelectionChange
}), {
default: withCtx(() => [
__props.options.expand ? (openBlock(), createBlock(_component_asp_table_column, {
key: 0,
type: "expand"
}, {
default: withCtx((scope) => [
renderSlot(_ctx.$slots, "expand", { data: scope })
]),
_: 3
})) : createCommentVNode("v-if", true),
__props.options.type === "selection" ? (openBlock(), createBlock(_component_asp_table_column, {
key: 1,
type: "selection",
fixed: "left",
"class-name": "table_selection",
width: "40"
})) : createCommentVNode("v-if", true),
__props.options.type === "index" ? (openBlock(), createBlock(_component_asp_table_column, {
key: 2,
prop: "index",
fixed: "left",
"class-name": "table_index",
label: "\u5E8F\u53F7",
width: "55"
})) : createCommentVNode("v-if", true),
__props.options.type === "radio" ? (openBlock(), createBlock(_component_asp_table_column, {
key: 3,
fixed: "left",
width: "36"
}, {
default: withCtx((scope) => [
createVNode(_component_asp_radio, {
modelValue: tableSingleSelection.value,
"onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => tableSingleSelection.value = $event),
class: "table-single-selection",
label: scope.$index,
onChange: handleSingleSelection
}, null, 8, ["modelValue", "label"])
]),
_: 1
})) : createCommentVNode("v-if", true),
(openBlock(true), createElementBlock(Fragment, null, renderList(__props.columns, (col, i) => {
return openBlock(), createElementBlock(Fragment, null, [
columnShow(col) ? (openBlock(), createElementBlock(Fragment, { key: 0 }, [
col.isParent ? (openBlock(), createBlock(tableColumnParent, {
key: i,
col
}, null, 8, ["col"])) : (openBlock(), createBlock(tableColumn, {
key: "child-" + i,
col,
onFilterChange: filterChange,
onFilterConfirm: filterConfirm,
onFilterReset: filterReset
}, {
[`${col.key}`]: withCtx((scope) => [
col.type === "slot" ? renderSlot(_ctx.$slots, col.key, normalizeProps(mergeProps({ key: 0 }, scope))) : createCommentVNode("v-if", true),
createCommentVNode(" \u63D2\u69FD\u5185\u5BB9 ")
]),
_: 2
}, 1032, ["col"]))
], 64)) : createCommentVNode("v-if", true)
], 64);
}), 256)),
Object.keys(__props.operation).length > 0 && __props.operation.options.length > 0 && (__props.operation.show || __props.operation.show === void 0) ? (openBlock(), createBlock(_component_asp_table_column, {
key: 4,
"header-align": "left",
fixed: __props.operation.fixed,
label: __props.operation.label,
width: __props.operation.width
}, {
default: withCtx((scope) => [
(openBlock(true), createElementBlock(Fragment, null, renderList(__props.operation.options, (btn, i) => {
return openBlock(), createElementBlock(Fragment, null, [
btn.type === "button" || btn.type === void 0 ? withDirectives((openBlock(), createBlock(_component_asp_button, {
key: btn.label + i + "button",
class: "table-btn",
icon: btn.icon,
size: btn.size || "mini",
type: btn.btnType || "primary",
disabled: operationDisabled(btn, scope.row),
onClick: withModifiers(($event) => handleCommand(btn, scope.row, scope.$index), ["stop"])
}, {
default: withCtx(() => [
createTextVNode(toDisplayString(handleLabel(btn, scope.row)), 1)
]),
_: 2
}, 1032, ["icon", "size", "type", "disabled", "onClick"])), [
[vShow, operationShow(btn, scope.row)]
]) : btn.type === "icon" ? withDirectives((openBlock(), createBlock(_component_asp_tooltip, {
key: btn.label + i + "icon",
class: "item",
effect: "dark",
content: handleLabel(btn, scope.row),
placement: "top-start"
}, {
default: withCtx(() => [
createVNode(_component_asp_button, {
class: normalizeClass(["operation-icon", btn.icon]),
type: "text",
size: "mini",
disabled: operationDisabled(btn, scope.row),
onClick: withModifiers(($event) => handleCommand(btn, scope.row, scope.$index), ["stop"])
}, null, 8, ["class", "disabled", "onClick"])
]),
_: 2
}, 1032, ["content"])), [
[vShow, operationShow(btn, scope.row)]
]) : createCommentVNode("v-if", true)
], 64);
}), 256))
]),
_: 1
}, 8, ["fixed", "label", "width"])) : createCommentVNode("v-if", true)
]),
_: 3
}, 16, ["highlight-current-row", "data", "span-method", "default-sort"])
]);
};
}
});
var TableList = /* @__PURE__ */ _export_sfc(_sfc_main, [["__file", "E:\\code\\SmartUIPlus\\asp-packages\\components\\pc\\advanced\\table-list\\src\\table-list.vue"]]);
export { TableList as default };