瀏覽代碼

update Web/src/components/table/index.vue.
增加分页大小属性,可自定义分页大小,增加获取表格数据方法,增加设置表格数据方法

Signed-off-by: inypeacock <1300856@qq.com>

inypeacock 2 年之前
父節點
當前提交
a6a0e49d95
共有 1 個文件被更改,包括 30 次插入4 次删除
  1. 30 4
      Web/src/components/table/index.vue

+ 30 - 4
Web/src/components/table/index.vue

@@ -74,7 +74,7 @@
 		</el-table>
 		<div v-if="!config.hidePagination && state.showPagination" class="table-footer mt15">
 			<el-pagination v-model:current-page="state.page.page" v-model:page-size="state.page.pageSize" small
-				:pager-count="5" :page-sizes="[10, 30, 50, 100]" :total="state.total"
+				:pager-count="5" :page-sizes="config.pageSizes" :total="state.total"
 				layout="total, sizes, prev, pager, next, jumper" background @size-change="onHandleSizeChange"
 				@current-change="onHandleCurrentChange">
 			</el-pagination>
@@ -94,12 +94,12 @@ import printJs from 'print-js';
 
 // 定义父组件传过来的值
 const props = defineProps({
-	//获取数据的方法,由父组件传递
+	// 获取数据的方法,由父组件传递
 	getData: {
 		type: Function,
 		required: true,
 	},
-	//列属性,和elementUI的Table-column 属性相同,附加属性:isCheck-是否默认勾选展示,hideCheck-是否隐藏该列的可勾选和拖拽
+	// 列属性,和elementUI的Table-column 属性相同,附加属性:isCheck-是否默认勾选展示,hideCheck-是否隐藏该列的可勾选和拖拽
 	columns: {
 		type: Array<any>,
 		default: () => [],
@@ -301,7 +301,6 @@ const onSetTable = () => {
 						if (v.prop === val) headerList.push({ ...v });
 					});
 				});
-				console.log(headerList);
 				emit('sortHeader', headerList);
 			},
 		});
@@ -328,6 +327,31 @@ const toggleSelection = (row: any, statu?: boolean) => {
 	tableRef.value!.toggleRowSelection(row, statu);
 };
 
+const getTableData = () => {
+	return state.data;
+}
+
+const setTableData = (data: Array<EmptyObjectType>, add: boolean = false) => {
+	if (add) { // 追加
+		//去重
+		var repeat = false;
+		for (let newItem of data) {
+			repeat = false;
+			for (let item of state.data) {
+				if (newItem.id === item.id) {
+					repeat = true;
+					break;
+				}
+			}
+			if (!repeat) {
+				state.data.push(newItem);
+			}
+		}
+	} else {
+		state.data = data;
+	}
+}
+
 onMounted(() => {
 	if (props.defaultSort) {
 		state.page.field = props.defaultSort.prop;
@@ -342,6 +366,8 @@ defineExpose({
 	pageReset,
 	handleList,
 	toggleSelection,
+	getTableData,
+	setTableData,
 });
 </script>