Browse Source

代码模板,前端排序

CzRger 8 months ago
parent
commit
7e4d2a9078

+ 17 - 12
snowy-admin-web/src/components/Table/index.vue

@@ -124,7 +124,7 @@
 	import { get } from 'lodash-es'
 	const slots = useSlots()
 	const route = useRoute()
-	const emit = defineEmits(['expand'])
+	const emit = defineEmits(['expand', 'update:filterParam'])
 	const renderSlots = Object.keys(slots)
 
 	const props = defineProps(
@@ -194,6 +194,10 @@
 					columnSetting: false,
 					striped: false
 				})
+			},
+		    filterParam: {
+        		type: Object,
+			  	default: () => ({})
 			}
 		})
 	)
@@ -350,20 +354,21 @@
 					props.pageSize ||
 					data.localPagination.pageSize
 			},
-			(sorter &&
-				sorter.field && {
-					sortField: sorter.field
-				}) ||
-				{},
-			(sorter &&
-				sorter.order && {
-					sortOrder: sorter.order
-				}) ||
-				{},
-			{
+		  	{
 				...filters
 			}
 		)
+
+      if (sorter?.order) {
+        parameter.sortField = sorter.field
+        parameter.sortOrder = sorter.order
+        emit('update:filterParam', {
+          sortField: sorter.field,
+          sortOrder: sorter.order
+        })
+      } else {
+        emit('update:filterParam', {})
+      }
 		// 用请求数据请求该列表的返回数据
 		const result = props.data(parameter)
 		if ((typeof result === 'object' || typeof result === 'function') && typeof result.then === 'function') {

+ 5 - 1
snowy-plugin/snowy-plugin-gen/src/main/resources/frontend/index.vue.btl

@@ -89,6 +89,7 @@
 			<% } %>
 			:tool-config="toolConfig"
 			:row-selection="options.rowSelection"
+			v-model:filterParam="filterParam"
 		>
 			<template #operator class="table-operator">
 				<a-space>
@@ -171,6 +172,7 @@
 	const searchFormRef = ref()
 	<% } %>
 	const tableRef = ref()
+	const filterParam = ref({})
 	const formRef = ref()
 	const toolConfig = { refresh: true, height: true, columnSetting: true, striped: false }
 	<% if(searchCount > 3) { %>
@@ -272,7 +274,9 @@
 	}
 	// 批量导出
     const onExport = () => {
-        const params = {}
+        const params = {
+            ...filterParam.value
+        }
         if (selectedRowKeys.value.length > 0) {
             params.ids = selectedRowKeys.value
         } else {

+ 5 - 1
snowy-plugin/snowy-plugin-gen/src/main/resources/frontend/index_inside.vue.btl

@@ -89,6 +89,7 @@
 			<% } %>
 			:tool-config="toolConfig"
 			:row-selection="options.rowSelection"
+			v-model:filterParam="filterParam"
 		>
 			<template #operator class="table-operator">
 				<a-space>
@@ -171,6 +172,7 @@
 	const searchFormRef = ref()
 	<% } %>
 	const tableRef = ref()
+	const filterParam = ref({})
 	const detailRef = ref()
 	const indexShow = ref(true)
 	const toolConfig = { refresh: true, height: true, columnSetting: true, striped: false }
@@ -273,7 +275,9 @@
 	}
 	// 批量导出
     const onExport = () => {
-        const params = {}
+        const params = {
+            ...filterParam.value
+        }
         if (selectedRowKeys.value.length > 0) {
             params.ids = selectedRowKeys.value
         } else {