diff --git a/apps/cube-admin/src/pages/admin/access-rule/index.vue b/apps/cube-admin/src/pages/admin/access-rule/index.vue
index 8a27522..46eb4b8 100644
--- a/apps/cube-admin/src/pages/admin/access-rule/index.vue
+++ b/apps/cube-admin/src/pages/admin/access-rule/index.vue
@@ -11,7 +11,7 @@
<CubeListToolbarSearch
:on-search="SearchData"
:on-reset="ResetData"
- :on-callback="loadData"
+ :on-callback="callback"
/>
<el-table :data="tableData" border style="width: 100%" v-loading="loading">
@@ -49,12 +49,12 @@
</el-table>
<CubeListPager
- :total="total"
- :current-page="currentPage"
- :page-size="pageSize"
+ :total="queryParams.total"
+ :current-page="queryParams.pageIndex"
+ :page-size="queryParams.pageSize"
:on-current-change="CurrentPageChange"
:on-size-change="PageSizeChange"
- :on-callback="loadData"
+ :on-callback="callback"
/>
</el-card>
@@ -122,11 +122,12 @@
<script setup lang="ts">
import { ref, reactive, onMounted } from 'vue';
-import { ElMessageBox } from 'element-plus';
import type { FormInstance, FormRules } from 'element-plus';
import { request } from '@core/utils/request';
+import { apiDataToList, handleDeleteOperation, handleFormSubmit } from '@core/utils/api-helpers';
import CubeListToolbarSearch from '@core/components/CubeListToolbarSearch.vue';
import CubeListPager from '@core/components/CubeListPager.vue';
+import { pageInfoDefault } from '@core/types/common';
// 定义访问规则类型接口
interface AccessRule {
@@ -156,12 +157,12 @@ interface AccessRule {
// 表格数据
const tableData = ref<AccessRule[]>([]);
const loading = ref(false);
-const total = ref(0);
-const currentPage = ref(1);
-const pageSize = ref(10);
-// 查询表单数据 - 用于存储搜索条件
-const searchForm = reactive({ p: '' });
+// 页面请求参数
+const queryParams = reactive({
+ q: '',// 搜索关键字
+ ...pageInfoDefault,// 分页参数
+});
// 表单相关
const dialogVisible = ref(false);
@@ -224,63 +225,54 @@ const getActionKindType = (actionKind: number) => {
return map[actionKind] || '';
};
-// 加载数据
-const loadData = async (searchData?: { p: string }) => {
- // 如果传入了搜索数据,则更新本地搜索条件
- if (searchData !== undefined) {
- searchForm.p = searchData.p;
- }
+// 组件回调函数
+const callback = (e?: Record<string, unknown>) => {
+ console.log(e?.type, e?.params);
+ const query = Object.assign(queryParams, e?.params || {});
+ console.log('queryParams:', query);
+ loadData();
+};
+// 查询请求
+const loadData = async () => {
loading.value = true;
try {
const data = await request.get('/Admin/AccessRule', {
- params: {
- pageIndex: currentPage.value,
- pageSize: pageSize.value,
- q: searchForm.p
- }
+ params: queryParams
});
- // 处理不同的响应格式
- if (data && typeof data === 'object' && 'data' in data && 'page' in data) {
- // 包含分页信息的响应
- tableData.value = Array.isArray(data.data) ? data.data : [];
- total.value = data.page?.totalCount || tableData.value.length;
- } else if (Array.isArray(data)) {
- // 直接返回数组的响应(无分页信息)
- tableData.value = data;
- total.value = data.length;
- } else {
- tableData.value = [];
- total.value = 0;
- }
+ const { list, page } = apiDataToList<AccessRule>(data);
+ tableData.value = list;
+ queryParams.total = page?.totalCount; // 更新总数
} catch {
tableData.value = [];
- total.value = 0;
+ queryParams.total = 0;
} finally {
loading.value = false;
}
};
// 搜索数据处理
-const SearchData = () => {
- currentPage.value = 1;
+const SearchData = (e?: Record<string, unknown>) => {
+ Object.assign(queryParams, { pageIndex: 1 }, e || {});
+ console.log('SearchData:', queryParams);
};
// 重置数据处理
-const ResetData = () => {
- currentPage.value = 1;
+const ResetData = (e?: Record<string, unknown>) => {
+ Object.assign(queryParams, { pageIndex: 1 }, e || {});
+ console.log('ResetData:', queryParams);
};
// 页码变更处理
const CurrentPageChange = (page: number) => {
- currentPage.value = page;
+ queryParams.pageIndex = page;
};
// 每页显示条数变更处理
const PageSizeChange = (size: number) => {
- pageSize.value = size;
- currentPage.value = 1;
+ queryParams.pageSize = size;
+ queryParams.pageIndex = 1;
};
// 新增
@@ -321,43 +313,29 @@ const handleEdit = (row: AccessRule) => {
// 删除
const handleDelete = (row: AccessRule) => {
- ElMessageBox.confirm('确认删除该访问规则吗?', '提示', {
- confirmButtonText: '确定',
- cancelButtonText: '取消',
- type: 'warning'
- })
- .then(async () => {
- try {
- await request.delete('/Admin/AccessRule', {
- params: { id: row.id }
- });
- loadData();
- } catch {
- // 错误提示已经在 request 拦截器中自动处理
- }
- })
- .catch(() => { });
+ handleDeleteOperation(
+ () => request.delete('/Admin/AccessRule', { params: { id: row.id } }),
+ loadData,
+ '确认删除该访问规则吗?'
+ );
};
// 提交表单
const submitForm = async () => {
- if (!formRef.value) return;
-
- formRef.value.validate(async (valid: boolean) => {
- if (valid) {
- try {
- if (formType.value === 'add') {
- await request.post('/Admin/AccessRule', form);
- } else {
- await request.put('/Admin/AccessRule', form);
- }
- dialogVisible.value = false;
- loadData();
- } catch {
- // 错误提示已经在 request 拦截器中自动处理
- }
+ const apiCall = async () => {
+ if (formType.value === 'add') {
+ await request.post('/Admin/AccessRule', form);
+ } else {
+ await request.put('/Admin/AccessRule', form);
}
- });
+ };
+
+ const onSuccess = () => {
+ dialogVisible.value = false;
+ loadData();
+ };
+
+ await handleFormSubmit(formRef.value, apiCall, onSuccess);
};
// 初始化加载数据
diff --git a/apps/cube-admin/src/pages/admin/department/index.vue b/apps/cube-admin/src/pages/admin/department/index.vue
index b488e55..9bc2c94 100644
--- a/apps/cube-admin/src/pages/admin/department/index.vue
+++ b/apps/cube-admin/src/pages/admin/department/index.vue
@@ -11,7 +11,7 @@
<CubeListToolbarSearch
:on-search="SearchData"
:on-reset="ResetData"
- :on-callback="loadData"
+ :on-callback="callback"
/>
<el-alert
@@ -149,15 +149,14 @@
<script setup lang="ts">
import { ref, reactive, onMounted } from 'vue';
-import { ElMessageBox } from 'element-plus';
import type { FormInstance, FormRules } from 'element-plus';
import { request } from '@core/utils/request';
-import { processListResponse } from '@core/utils/api-helpers';
+import { apiDataToList, handleDeleteOperation, handleFormSubmit } from '@core/utils/api-helpers';
import CubeListToolbarSearch from '@core/components/CubeListToolbarSearch.vue';
+import type { BaseEntity } from '@core/types/common';
// 定义部门类型接口
-interface Department {
- id: number;
+interface Department extends BaseEntity {
tenantId: number;
code: string;
name: string;
@@ -174,15 +173,10 @@ interface Department {
ex4: string | null;
ex5: string | null;
ex6: string | null;
- createUser: string;
createUserID: number;
createIP: string;
- createTime: string;
- updateUser: string;
updateUserID: number;
updateIP: string;
- updateTime: string;
- remark: string | null;
tenantName: string | null;
managerName: string | null;
parentName: string | null;
@@ -198,8 +192,12 @@ const loading = ref(false);
const total = ref(0);
const departmentOptions = ref<Department[]>([]);
-// 查询表单数据 - 用于存储搜索条件
-const searchForm = reactive({ p: '' });
+// 页面请求参数
+const queryParams = reactive({
+ q: '',// 搜索关键字
+ pageIndex: 1,
+ pageSize: 10000, // 获取全部数据用于构建树
+});
// 表单相关
const dialogVisible = ref(false);
@@ -231,7 +229,7 @@ const form = reactive<Department>({
updateUserID: 0,
updateIP: '',
updateTime: '',
- remark: null,
+ remark: '',
tenantName: null,
managerName: null,
parentName: null,
@@ -327,27 +325,38 @@ const buildTreeData = (data: Department[]): Department[] => {
return roots;
};
-// 加载数据
-const loadData = async (searchData?: { p: string }) => {
- // 如果传入了搜索数据,则更新本地搜索条件
- if (searchData !== undefined) {
- searchForm.p = searchData.p;
- }
+// 组件回调函数
+const callback = (e?: Record<string, unknown>) => {
+ console.log(e?.type, e?.params);
+ const query = Object.assign(queryParams, e?.params || {});
+ console.log('queryParams:', query);
+ loadData();
+};
+
+// 搜索数据处理
+const SearchData = (e?: Record<string, unknown>) => {
+ Object.assign(queryParams, e || {});
+ console.log('SearchData:', queryParams);
+};
+
+// 重置数据处理
+const ResetData = (e?: Record<string, unknown>) => {
+ Object.assign(queryParams, e || {});
+ console.log('ResetData:', queryParams);
+};
+// 加载数据
+const loadData = async () => {
loading.value = true;
try {
const response = await request.get('/Admin/Department', {
- params: {
- pageIndex: 1,
- pageSize: 10000, // 获取全部数据用于构建树
- q: searchForm.p
- }
+ params: queryParams
});
let dataList: Department[] = [];
// 处理API响应数据
- const { list } = processListResponse<Department>(response);
+ const { list } = apiDataToList<Department>(response);
dataList = preprocessDepartmentData(list);
// 构建树结构并排序
@@ -366,16 +375,6 @@ const loadData = async (searchData?: { p: string }) => {
}
};
-// 搜索数据处理
-const SearchData = () => {
- // 空函数,实际搜索通过onCallback处理
-};
-
-// 重置数据处理
-const ResetData = () => {
- // 空函数,实际重置通过onCallback处理
-};
-
// 新增
const handleAdd = () => {
formType.value = 'add';
@@ -426,43 +425,29 @@ const handleEdit = (row: Department) => {
// 删除
const handleDelete = (row: Department) => {
- ElMessageBox.confirm('确认删除该部门吗?', '提示', {
- confirmButtonText: '确定',
- cancelButtonText: '取消',
- type: 'warning'
- })
- .then(async () => {
- try {
- await request.delete('/Admin/Department', {
- params: { id: row.id }
- });
- loadData();
- } catch {
- // 错误提示已经在 request 拦截器中自动处理
- }
- })
- .catch(() => { });
+ handleDeleteOperation(
+ () => request.delete('/Admin/Department', { params: { id: row.id } }),
+ loadData,
+ '确认删除该部门吗?'
+ );
};
// 提交表单
const submitForm = async () => {
- if (!formRef.value) return;
-
- formRef.value.validate(async (valid: boolean) => {
- if (valid) {
- try {
- if (formType.value === 'add') {
- await request.post('/Admin/Department', form);
- } else {
- await request.put('/Admin/Department', form);
- }
- dialogVisible.value = false;
- loadData();
- } catch {
- // 错误提示已经在 request 拦截器中自动处理
- }
+ const apiCall = async () => {
+ if (formType.value === 'add') {
+ await request.post('/Admin/Department', form);
+ } else {
+ await request.put('/Admin/Department', form);
}
- });
+ };
+
+ const onSuccess = () => {
+ dialogVisible.value = false;
+ loadData();
+ };
+
+ await handleFormSubmit(formRef.value, apiCall, onSuccess);
};
// 初始化加载数据
diff --git a/apps/cube-admin/src/pages/admin/log/index.vue b/apps/cube-admin/src/pages/admin/log/index.vue
index 2e1a53b..747c354 100644
--- a/apps/cube-admin/src/pages/admin/log/index.vue
+++ b/apps/cube-admin/src/pages/admin/log/index.vue
@@ -10,7 +10,7 @@
<CubeListToolbarSearch
:on-search="SearchData"
:on-reset="ResetData"
- :on-callback="loadData"
+ :on-callback="callback"
/>
<el-table :data="tableData" border style="width: 100%" v-loading="loading">
@@ -30,12 +30,12 @@
</el-table>
<CubeListPager
- :total="total"
- :current-page="currentPage"
- :page-size="pageSize"
+ :total="queryParams.total"
+ :current-page="queryParams.pageIndex"
+ :page-size="queryParams.pageSize"
:on-current-change="CurrentPageChange"
:on-size-change="PageSizeChange"
- :on-callback="loadData"
+ :on-callback="callback"
/>
</el-card>
@@ -62,15 +62,17 @@
</template>
<script setup lang="ts">
+
import { ref, reactive, onMounted } from 'vue';
import { ElMessage } from 'element-plus';
import { request } from '@core/utils/request';
import CubeListToolbarSearch from '@core/components/CubeListToolbarSearch.vue';
import CubeListPager from '@core/components/CubeListPager.vue';
+import { pageInfoDefault } from '@core/types/common';
+import type { BaseEntity } from '@core/types/common';
-// 定义日志类型接口
-interface Log {
- id: number;
+// 定义日志类型接口,继承 BaseEntity
+interface Log extends BaseEntity {
category: string;
action: string;
linkID: number;
@@ -85,12 +87,12 @@ interface Log {
// 表格数据
const tableData = ref<Log[]>([]);
const loading = ref(false);
-const total = ref(0);
-const currentPage = ref(1);
-const pageSize = ref(20);
-// 查询表单数据 - 用于存储搜索条件
-const searchForm = reactive({ p: '' });
+// 分页与搜索参数
+const queryParams = reactive({
+ q: '',
+ ...pageInfoDefault
+});
// 详情对话框
const detailVisible = ref(false);
@@ -107,48 +109,38 @@ const currentLog = reactive<Log>({
remark: '',
});
-// 加载数据
-const loadData = async (searchData?: { p: string }) => {
- // 如果传入了搜索数据,则更新本地搜索条件
- if (searchData !== undefined) {
- searchForm.p = searchData.p;
- }
+// 组件回调函数
+const callback = (e?: Record<string, unknown>) => {
+ Object.assign(queryParams, e?.params || {});
+ loadData();
+};
+// 加载数据
+const loadData = async () => {
loading.value = true;
try {
- const params: Record<string, string | number> = {
- pageIndex: currentPage.value,
- pageSize: pageSize.value,
- };
-
- // 添加搜索条件
- if (searchForm.p) {
- params.q = searchForm.p;
- }
-
- const response = await request.get('/Admin/Log', { params });
-
+ const response = await request.get('/Admin/Log', { params: queryParams });
// 处理不同的响应格式
if (response && typeof response === 'object' && 'list' in response && 'total' in response) {
tableData.value = Array.isArray(response.list) ? response.list : [];
- total.value = typeof response.total === 'number' ? response.total : 0;
+ queryParams.total = typeof response.total === 'number' ? response.total : 0;
} else if (response && response.data && Array.isArray(response.data.data)) {
tableData.value = response.data.data;
// 处理分页信息
if (response.data.page) {
const pageInfo = response.data.page;
const count = pageInfo.longTotalCount || pageInfo.totalCount;
- total.value = count ? Number(count) : 0;
- currentPage.value = pageInfo.pageIndex || 1;
+ queryParams.total = count ? Number(count) : 0;
+ queryParams.pageIndex = pageInfo.pageIndex || 1;
} else {
- total.value = response.data.data.length || 0;
+ queryParams.total = response.data.data.length || 0;
}
} else if (response && Array.isArray(response.data)) {
tableData.value = response.data;
- total.value = response.data.length;
+ queryParams.total = response.data.length;
} else {
tableData.value = [];
- total.value = 0;
+ queryParams.total = 0;
}
} catch (error) {
ElMessage.error('加载数据失败');
@@ -158,25 +150,25 @@ const loadData = async (searchData?: { p: string }) => {
}
};
-// 搜索数据处理
-const SearchData = () => {
- currentPage.value = 1;
+// 搜索按钮点击事件
+const SearchData = (e?: Record<string, unknown>) => {
+ Object.assign(queryParams, { pageIndex: 1 }, e || {});
};
-// 重置数据处理
-const ResetData = () => {
- currentPage.value = 1;
+// 重置按钮点击事件
+const ResetData = (e?: Record<string, unknown>) => {
+ Object.assign(queryParams, { pageIndex: 1 }, e || {});
};
// 页码变更处理
const CurrentPageChange = (page: number) => {
- currentPage.value = page;
+ queryParams.pageIndex = page;
};
// 每页显示条数变更处理
const PageSizeChange = (size: number) => {
- pageSize.value = size;
- currentPage.value = 1;
+ queryParams.pageSize = size;
+ queryParams.pageIndex = 1;
};
// 查看详情
diff --git a/apps/cube-admin/src/pages/admin/menu/index.vue b/apps/cube-admin/src/pages/admin/menu/index.vue
index 1ba5c4f..d59dd30 100644
--- a/apps/cube-admin/src/pages/admin/menu/index.vue
+++ b/apps/cube-admin/src/pages/admin/menu/index.vue
@@ -29,11 +29,11 @@
<CubeListToolbarSearch
:on-search="SearchData"
:on-reset="ResetData"
- :on-callback="loadData"
+ :on-callback="callback"
/>
<el-alert
- :title="`共找到 ${total} 个菜单项,其中根菜单 ${tableData.length} 个。请选择一行进行上移/下移操作。`"
+ :title="`共找到 ${total} 个菜单项,其中根菜单 ${tableData.length} 个。`"
type="info"
:closable="false"
show-icon
@@ -167,14 +167,14 @@
<script setup lang="ts">
import { ref, reactive, onMounted } from 'vue';
-import { ElMessageBox } from 'element-plus';
import type { FormInstance, FormRules } from 'element-plus';
import { request } from '@core/utils/request';
+import { handleDeleteOperation, handleFormSubmit } from '@core/utils/api-helpers';
import CubeListToolbarSearch from '@core/components/CubeListToolbarSearch.vue';
+import type { BaseEntity } from '@core/types/common';
// 定义菜单类型接口
-interface Menu {
- id: number;
+interface Menu extends BaseEntity {
name: string;
displayName: string;
fullName: string;
@@ -192,15 +192,10 @@ interface Menu {
ex4: string;
ex5: string;
ex6: string;
- createUser: string;
createUserID: number;
createIP: string;
- createTime: string;
- updateUser: string;
updateUserID: number;
updateIP: string;
- updateTime: string;
- remark: string;
children?: Menu[];
hasChildren?: boolean;
}
@@ -212,8 +207,12 @@ const total = ref(0);
const menuOptions = ref<Menu[]>([]);
const selectedRows = ref<Menu[]>([]);
-// 查询表单数据 - 用于存储搜索条件
-const searchForm = reactive({ p: '' });
+// 页面请求参数
+const queryParams = reactive({
+ q: '',// 搜索关键字
+ pageIndex: 1,
+ pageSize: 10000, // 获取全部数据用于构建树
+});
// 表单相关
const dialogVisible = ref(false);
@@ -323,26 +322,37 @@ const buildTreeData = (data: Menu[]): Menu[] => {
return roots;
};
+// 组件回调函数
+const callback = (e?: Record<string, unknown>) => {
+ console.log(e?.type, e?.params);
+ const query = Object.assign(queryParams, e?.params || {});
+ console.log('queryParams:', query);
+ loadData();
+};
+
+// 搜索数据处理
+const SearchData = (e?: Record<string, unknown>) => {
+ Object.assign(queryParams, e || {});
+ console.log('SearchData:', queryParams);
+};
+
+// 重置数据处理
+const ResetData = (e?: Record<string, unknown>) => {
+ Object.assign(queryParams, e || {});
+ console.log('ResetData:', queryParams);
+};
+
// 选择变化处理
const handleSelectionChange = (selection: Menu[]) => {
selectedRows.value = selection;
};
// 加载数据
-const loadData = async (searchData?: { p: string }) => {
- // 如果传入了搜索数据,则更新本地搜索条件
- if (searchData !== undefined) {
- searchForm.p = searchData.p;
- }
-
+const loadData = async () => {
loading.value = true;
try {
const response = await request.get('/Admin/Menu', {
- params: {
- pageIndex: 1,
- pageSize: 10000, // 获取全部数据用于构建树
- q: searchForm.p,
- },
+ params: queryParams,
});
let dataList: Menu[] = [];
@@ -377,16 +387,6 @@ const loadData = async (searchData?: { p: string }) => {
}
};
-// 搜索数据处理
-const SearchData = () => {
- // 不需要重置页码,因为菜单是树状结构,不需要分页
-};
-
-// 重置数据处理
-const ResetData = () => {
- // 不需要重置页码,因为菜单是树状结构,不需要分页
-};
-
// 新增
const handleAdd = () => {
formType.value = 'add';
@@ -409,14 +409,10 @@ const handleAdd = () => {
ex4: '',
ex5: '',
ex6: '',
- createUser: '',
createUserID: 0,
createIP: '',
- createTime: '',
- updateUser: '',
updateUserID: 0,
updateIP: '',
- updateTime: '',
remark: '',
});
dialogVisible.value = true;
@@ -433,43 +429,29 @@ const handleEdit = (row: Menu) => {
// 删除
const handleDelete = (row: Menu) => {
- ElMessageBox.confirm('确认删除该菜单吗?', '提示', {
- confirmButtonText: '确定',
- cancelButtonText: '取消',
- type: 'warning',
- })
- .then(async () => {
- try {
- await request.delete('/Admin/Menu', {
- params: { id: row.id },
- });
- loadData();
- } catch {
- // 错误提示已经在 request 拦截器中自动处理
- }
- })
- .catch(() => {});
+ handleDeleteOperation(
+ () => request.delete('/Admin/Menu', { params: { id: row.id } }),
+ loadData,
+ '确认删除该菜单吗?'
+ );
};
// 提交表单
const submitForm = async () => {
- if (!formRef.value) return;
-
- formRef.value.validate(async (valid: boolean) => {
- if (valid) {
- try {
- if (formType.value === 'add') {
- await request.post('/Admin/Menu', form);
- } else {
- await request.put('/Admin/Menu', form);
- }
- dialogVisible.value = false;
- loadData();
- } catch {
- // 错误提示已经在 request 拦截器中自动处理
- }
+ const apiCall = async () => {
+ if (formType.value === 'add') {
+ await request.post('/Admin/Menu', form);
+ } else {
+ await request.put('/Admin/Menu', form);
}
- });
+ };
+
+ const onSuccess = () => {
+ dialogVisible.value = false;
+ loadData();
+ };
+
+ await handleFormSubmit(formRef.value, apiCall, onSuccess);
};
// 初始化加载数据
diff --git a/apps/cube-admin/src/pages/admin/oauth-config/index.vue b/apps/cube-admin/src/pages/admin/oauth-config/index.vue
index bde27ab..d2e0d0b 100644
--- a/apps/cube-admin/src/pages/admin/oauth-config/index.vue
+++ b/apps/cube-admin/src/pages/admin/oauth-config/index.vue
@@ -11,7 +11,7 @@
<CubeListToolbarSearch
:on-search="SearchData"
:on-reset="ResetData"
- :on-callback="loadData"
+ :on-callback="callback"
/>
<el-table :data="tableData" border style="width: 100%" v-loading="loading">
@@ -58,12 +58,12 @@
</el-table>
<CubeListPager
- :total="total"
- :current-page="currentPage"
- :page-size="pageSize"
+ :total="queryParams.total"
+ :current-page="queryParams.pageIndex"
+ :page-size="queryParams.pageSize"
:on-current-change="CurrentPageChange"
:on-size-change="PageSizeChange"
- :on-callback="loadData"
+ :on-callback="callback"
/>
</el-card>
@@ -170,16 +170,17 @@
</template>
<script setup lang="ts">
+
import { ref, reactive, onMounted } from 'vue';
-import { ElMessageBox } from 'element-plus';
import type { FormInstance, FormRules } from 'element-plus';
import { request } from '@core/utils/request';
import CubeListToolbarSearch from '@core/components/CubeListToolbarSearch.vue';
import CubeListPager from '@core/components/CubeListPager.vue';
+import { pageInfoDefault } from '@core/types/common';
+import type { BaseEntity } from '@core/types/common';
-// 定义OAuth配置类型接口
-interface OAuthConfig {
- id: number;
+// 定义OAuth配置类型接口,继承 BaseEntity
+interface OAuthConfig extends BaseEntity {
name: string;
nickName: string;
logo: string;
@@ -215,12 +216,12 @@ interface OAuthConfig {
// 表格数据
const tableData = ref<OAuthConfig[]>([]);
const loading = ref(false);
-const total = ref(0);
-const currentPage = ref(1);
-const pageSize = ref(10);
-// 查询表单数据 - 用于存储搜索条件
-const searchForm = reactive({ p: '' });
+// 分页与搜索参数
+const queryParams = reactive({
+ q: '',
+ ...pageInfoDefault
+});
// 表单相关
const dialogVisible = ref(false);
@@ -274,63 +275,59 @@ const formRules = reactive<FormRules>({
]
});
-// 加载数据
-const loadData = async (searchData?: { p: string }) => {
- // 如果传入了搜索数据,则更新本地搜索条件
- if (searchData !== undefined) {
- searchForm.p = searchData.p;
- }
+// 组件回调函数
+const callback = (e?: Record<string, unknown>) => {
+ Object.assign(queryParams, e?.params || {});
+ loadData();
+};
+// 加载数据
+const loadData = async () => {
loading.value = true;
try {
const data = await request.get('/Admin/OAuthConfig', {
- params: {
- pageIndex: currentPage.value,
- pageSize: pageSize.value,
- q: searchForm.p
- }
+ params: queryParams
});
-
// 处理不同的响应格式
if (data && typeof data === 'object' && 'data' in data && 'page' in data) {
// 包含分页信息的响应
tableData.value = Array.isArray(data.data) ? data.data : [];
- total.value = data.page?.totalCount || tableData.value.length;
+ queryParams.total = data.page?.totalCount || tableData.value.length;
} else if (Array.isArray(data)) {
// 直接返回数组的响应(无分页信息)
tableData.value = data;
- total.value = data.length;
+ queryParams.total = data.length;
} else {
tableData.value = [];
- total.value = 0;
+ queryParams.total = 0;
}
} catch {
tableData.value = [];
- total.value = 0;
+ queryParams.total = 0;
} finally {
loading.value = false;
}
};
-// 搜索数据处理
-const SearchData = () => {
- currentPage.value = 1;
+// 搜索按钮点击事件
+const SearchData = (e?: Record<string, unknown>) => {
+ Object.assign(queryParams, { pageIndex: 1 }, e || {});
};
-// 重置数据处理
-const ResetData = () => {
- currentPage.value = 1;
+// 重置按钮点击事件
+const ResetData = (e?: Record<string, unknown>) => {
+ Object.assign(queryParams, { pageIndex: 1 }, e || {});
};
// 页码变更处理
const CurrentPageChange = (page: number) => {
- currentPage.value = page;
+ queryParams.pageIndex = page;
};
// 每页显示条数变更处理
const PageSizeChange = (size: number) => {
- pageSize.value = size;
- currentPage.value = 1;
+ queryParams.pageSize = size;
+ queryParams.pageIndex = 1;
};
// 新增
diff --git a/apps/cube-admin/src/pages/admin/oauth-log/index.vue b/apps/cube-admin/src/pages/admin/oauth-log/index.vue
index 85f9198..fda215b 100644
--- a/apps/cube-admin/src/pages/admin/oauth-log/index.vue
+++ b/apps/cube-admin/src/pages/admin/oauth-log/index.vue
@@ -15,7 +15,7 @@
<CubeListToolbarSearch
:on-search="SearchData"
:on-reset="ResetData"
- :on-callback="getOAuthLogList"
+ :on-callback="callback"
/>
<!-- 数据表格 -->
@@ -59,12 +59,12 @@
</div>
<CubeListPager
- :total="pagination.total"
- :current-page="pagination.page"
- :page-size="pagination.size"
+ :total="queryParams.total"
+ :current-page="queryParams.pageIndex"
+ :page-size="queryParams.pageSize"
:on-current-change="CurrentPageChange"
:on-size-change="PageSizeChange"
- :on-callback="getOAuthLogList"
+ :on-callback="callback"
/>
</el-card>
@@ -110,14 +110,16 @@
</template>
<script setup lang="ts">
+
import { ref, reactive, onMounted } from 'vue'
import { request } from '@core/utils/request'
import CubeListPager from '@core/components/CubeListPager.vue'
import CubeListToolbarSearch from '@core/components/CubeListToolbarSearch.vue'
+import { pageInfoDefault } from '@core/types/common';
+import type { BaseEntity } from '@core/types/common';
-// OAuth日志接口
-interface OAuthLog {
- id: number
+// OAuth日志接口,继承 BaseEntity
+interface OAuthLog extends BaseEntity {
provider: string
connectId: number
userId: number
@@ -138,11 +140,6 @@ interface OAuthLog {
updateTime: string
}
-// 搜索表单
-const searchForm = reactive({
- p: '', // 统一搜索关键词
-})
-
// 表格数据
const tableData = ref<OAuthLog[]>([])
const selectedRows = ref<OAuthLog[]>([])
@@ -151,12 +148,11 @@ const selectedRows = ref<OAuthLog[]>([])
const detailData = ref<Partial<OAuthLog>>({})
const showDetailDialog = ref(false)
-// 分页
-const pagination = reactive({
- page: 1,
- size: 20,
- total: 0
-})
+// 分页与搜索参数
+const queryParams = reactive({
+ q: '',
+ ...pageInfoDefault
+});
// 加载状态
const loading = reactive({
@@ -164,42 +160,37 @@ const loading = reactive({
detail: false
})
+// 组件回调函数
+const callback = (e?: Record<string, unknown>) => {
+ Object.assign(queryParams, e?.params || {});
+ getOAuthLogList();
+};
+
// 获取OAuth日志列表
-const getOAuthLogList = async (searchData?: { p: string }) => {
+const getOAuthLogList = async () => {
try {
loading.list = true
-
- // 如果传入了搜索数据,则更新本地搜索条件
- if (searchData !== undefined) {
- searchForm.p = searchData.p;
- }
-
const data = await request.get('/Admin/OAuthLog', {
- params: {
- pageIndex: pagination.page,
- pageSize: pagination.size,
- q: searchForm.p || undefined
- }
+ params: queryParams
})
-
// 处理不同的响应格式
if (data && typeof data === 'object' && 'list' in data && 'total' in data) {
tableData.value = Array.isArray(data.list) ? data.list : [];
- pagination.total = Number(data.total) || 0;
+ queryParams.total = Number(data.total) || 0;
} else if (data && typeof data === 'object' && 'data' in data && 'page' in data) {
// 使用processListResponse格式
tableData.value = Array.isArray(data.data) ? data.data : [];
- pagination.total = Number((data as { page?: { totalCount?: number } })?.page?.totalCount) || 0;
+ queryParams.total = Number((data as { page?: { totalCount?: number } })?.page?.totalCount) || 0;
} else if (Array.isArray(data)) {
tableData.value = data;
- pagination.total = data.length;
+ queryParams.total = data.length;
} else {
tableData.value = [];
- pagination.total = 0;
+ queryParams.total = 0;
}
} catch {
tableData.value = [];
- pagination.total = 0;
+ queryParams.total = 0;
} finally {
loading.list = false
}
@@ -224,26 +215,26 @@ const getOAuthLogDetail = async (id: number) => {
}
}
-// 搜索数据处理
-const SearchData = () => {
- pagination.page = 1
-}
+// 搜索按钮点击事件
+const SearchData = (e?: Record<string, unknown>) => {
+ Object.assign(queryParams, { pageIndex: 1 }, e || {});
+};
-// 重置数据处理
-const ResetData = () => {
- pagination.page = 1
-}
+// 重置按钮点击事件
+const ResetData = (e?: Record<string, unknown>) => {
+ Object.assign(queryParams, { pageIndex: 1 }, e || {});
+};
// 页码变更处理
const CurrentPageChange = (page: number) => {
- pagination.page = page
-}
+ queryParams.pageIndex = page;
+};
// 每页显示条数变更处理
const PageSizeChange = (size: number) => {
- pagination.size = size
- pagination.page = 1
-}
+ queryParams.pageSize = size;
+ queryParams.pageIndex = 1;
+};
// 查看详情
const handleDetail = async (row: OAuthLog) => {
@@ -265,8 +256,8 @@ const formatDate = (dateStr?: string) => {
// 组件挂载时获取数据
onMounted(() => {
- getOAuthLogList()
-})
+ getOAuthLogList();
+});
</script>
<style scoped>
diff --git a/apps/cube-admin/src/pages/admin/parameter/index.vue b/apps/cube-admin/src/pages/admin/parameter/index.vue
index c8b9836..e571310 100644
--- a/apps/cube-admin/src/pages/admin/parameter/index.vue
+++ b/apps/cube-admin/src/pages/admin/parameter/index.vue
@@ -11,7 +11,7 @@
<CubeListToolbarSearch
:on-search="SearchData"
:on-reset="ResetData"
- :on-callback="loadData"
+ :on-callback="callback"
/>
<el-table :data="tableData" border style="width: 100%" v-loading="loading">
@@ -49,12 +49,12 @@
</el-table>
<CubeListPager
- :total="total"
- :current-page="currentPage"
- :page-size="pageSize"
+ :total="queryParams.total"
+ :current-page="queryParams.pageIndex"
+ :page-size="queryParams.pageSize"
:on-current-change="CurrentPageChange"
:on-size-change="PageSizeChange"
- :on-callback="loadData"
+ :on-callback="callback"
/>
</el-card>
@@ -96,16 +96,18 @@
</template>
<script setup lang="ts">
+
import { ref, reactive, onMounted } from 'vue';
-import { ElMessageBox } from 'element-plus';
import type { FormInstance, FormRules } from 'element-plus';
import { request } from '@core/utils/request';
+// ...existing code...
import CubeListToolbarSearch from '@core/components/CubeListToolbarSearch.vue';
import CubeListPager from '@core/components/CubeListPager.vue';
+import { pageInfoDefault } from '@core/types/common';
+import type { BaseEntity } from '@core/types/common';
-// 定义参数类型接口
-interface Parameter {
- id: number;
+// 定义参数类型接口,继承 BaseEntity
+interface Parameter extends BaseEntity {
tenantId: number;
category: string;
name: string;
@@ -138,12 +140,12 @@ interface Parameter {
// 表格数据
const tableData = ref<Parameter[]>([]);
const loading = ref(false);
-const total = ref(0);
-const currentPage = ref(1);
-const pageSize = ref(10);
-// 查询表单数据 - 用于存储搜索条件
-const searchForm = reactive({ p: '' });
+// 分页与搜索参数
+const queryParams = reactive({
+ q: '',
+ ...pageInfoDefault
+});
// 表单相关
const dialogVisible = ref(false);
@@ -210,63 +212,59 @@ const getKindType = (kind: number) => {
return map[kind] || '';
};
-// 加载数据
-const loadData = async (searchData?: { p: string }) => {
- // 如果传入了搜索数据,则更新本地搜索条件
- if (searchData !== undefined) {
- searchForm.p = searchData.p;
- }
+// 组件回调函数
+const callback = (e?: Record<string, unknown>) => {
+ Object.assign(queryParams, e?.params || {});
+ loadData();
+};
+// 加载数据
+const loadData = async () => {
loading.value = true;
try {
const data = await request.get('/Admin/Parameter', {
- params: {
- pageIndex: currentPage.value,
- pageSize: pageSize.value,
- q: searchForm.p
- }
+ params: queryParams
});
-
// 处理不同的响应格式
if (data && typeof data === 'object' && 'data' in data && 'page' in data) {
// 包含分页信息的响应
tableData.value = Array.isArray(data.data) ? data.data : [];
- total.value = data.page?.totalCount || tableData.value.length;
+ queryParams.total = data.page?.totalCount || tableData.value.length;
} else if (Array.isArray(data)) {
// 直接返回数组的响应(无分页信息)
tableData.value = data;
- total.value = data.length;
+ queryParams.total = data.length;
} else {
tableData.value = [];
- total.value = 0;
+ queryParams.total = 0;
}
} catch {
tableData.value = [];
- total.value = 0;
+ queryParams.total = 0;
} finally {
loading.value = false;
}
};
-// 搜索数据处理
-const SearchData = () => {
- currentPage.value = 1;
+// 搜索按钮点击事件
+const SearchData = (e?: Record<string, unknown>) => {
+ Object.assign(queryParams, { pageIndex: 1 }, e || {});
};
-// 重置数据处理
-const ResetData = () => {
- currentPage.value = 1;
+// 重置按钮点击事件
+const ResetData = (e?: Record<string, unknown>) => {
+ Object.assign(queryParams, { pageIndex: 1 }, e || {});
};
// 页码变更处理
const CurrentPageChange = (page: number) => {
- currentPage.value = page;
+ queryParams.pageIndex = page;
};
// 每页显示条数变更处理
const PageSizeChange = (size: number) => {
- pageSize.value = size;
- currentPage.value = 1;
+ queryParams.pageSize = size;
+ queryParams.pageIndex = 1;
};
// 新增
diff --git a/apps/cube-admin/src/pages/admin/role/index.vue b/apps/cube-admin/src/pages/admin/role/index.vue
index 0aee1ee..453b839 100644
--- a/apps/cube-admin/src/pages/admin/role/index.vue
+++ b/apps/cube-admin/src/pages/admin/role/index.vue
@@ -11,7 +11,7 @@
<CubeListToolbarSearch
:on-search="SearchData"
:on-reset="ResetData"
- :on-callback="loadData"
+ :on-callback="callback"
/>
<el-table :data="tableData" border style="width: 100%" v-loading="loading">
@@ -48,12 +48,12 @@
</el-table>
<CubeListPager
- :total="total"
- :current-page="currentPage"
- :page-size="pageSize"
+ :total="queryParams.total"
+ :current-page="queryParams.pageIndex"
+ :page-size="queryParams.pageSize"
:on-current-change="CurrentPageChange"
:on-size-change="PageSizeChange"
- :on-callback="loadData"
+ :on-callback="callback"
/>
</el-card>
@@ -93,11 +93,12 @@
<script setup lang="ts">
import { ref, reactive, onMounted } from 'vue';
-import { ElMessageBox } from 'element-plus';
import type { FormInstance, FormRules } from 'element-plus';
import { request } from '@core/utils/request';
+import { apiDataToList, handleDeleteOperation, handleFormSubmit } from '@core/utils/api-helpers';
import CubeListToolbarSearch from '@core/components/CubeListToolbarSearch.vue';
import CubeListPager from '@core/components/CubeListPager.vue';
+import { pageInfoDefault } from '@core/types/common';
// 定义角色类型接口
interface Role {
@@ -129,13 +130,11 @@ interface Role {
// 表格数据
const tableData = ref<Role[]>([]);
const loading = ref(false);
-const total = ref(0);
-const currentPage = ref(1);
-const pageSize = ref(10);
-// 查询表单
-const searchForm = reactive({
- q: '',
+// 页面请求参数
+const queryParams = reactive({
+ q: '',// 搜索关键字
+ ...pageInfoDefault,// 分页参数
});
// 表单相关
@@ -175,39 +174,28 @@ const formRules = reactive<FormRules>({
]
});
-// 加载数据
-const loadData = async (searchData?: { p: string }) => {
+// 组件回调函数
+const callback = (e?: Record<string, unknown>) => {
+ console.log(e?.type, e?.params);
+ const query = Object.assign(queryParams, e?.params || {});
+ console.log('queryParams:', query);
+ loadData();
+};
+
+// 查询请求
+const loadData = async () => {
loading.value = true;
try {
- // 如果传入了搜索数据,则更新本地搜索条件
- if (searchData !== undefined) {
- searchForm.q = searchData.p;
- }
-
const data = await request.get('/Admin/Role', {
- params: {
- pageIndex: currentPage.value,
- pageSize: pageSize.value,
- q: searchForm.q
- }
+ params: queryParams
});
- // 处理不同的响应格式
- if (data && typeof data === 'object' && 'data' in data && 'page' in data) {
- // 包含分页信息的响应
- tableData.value = Array.isArray(data.data) ? data.data : [];
- total.value = data.page?.totalCount || tableData.value.length;
- } else if (Array.isArray(data)) {
- // 直接返回数组的响应(无分页信息)
- tableData.value = data;
- total.value = data.length;
- } else {
- tableData.value = [];
- total.value = 0;
- }
+ const { list, page } = apiDataToList<Role>(data);
+ tableData.value = list;
+ queryParams.total = page?.totalCount; // 更新总数
} catch {
tableData.value = [];
- total.value = 0;
+ queryParams.total = 0;
} finally {
loading.value = false;
}
@@ -215,23 +203,25 @@ const loadData = async (searchData?: { p: string }) => {
// 页码变更处理
const CurrentPageChange = (page: number) => {
- currentPage.value = page;
+ queryParams.pageIndex = page;
};
// 每页显示条数变更处理
const PageSizeChange = (size: number) => {
- pageSize.value = size;
- currentPage.value = 1;
+ queryParams.pageSize = size;
+ queryParams.pageIndex = 1;
};
// 搜索数据处理
-const SearchData = () => {
- currentPage.value = 1;
+const SearchData = (e?: Record<string, unknown>) => {
+ Object.assign(queryParams, { pageIndex: 1 }, e || {});
+ console.log('SearchData:', queryParams);
};
// 重置数据处理
-const ResetData = () => {
- currentPage.value = 1;
+const ResetData = (e?: Record<string, unknown>) => {
+ Object.assign(queryParams, { pageIndex: 1 }, e || {});
+ console.log('ResetData:', queryParams);
};
// 新增
@@ -278,43 +268,29 @@ const handleDelete = (row: Role) => {
return;
}
- ElMessageBox.confirm('确认删除该角色吗?', '提示', {
- confirmButtonText: '确定',
- cancelButtonText: '取消',
- type: 'warning'
- })
- .then(async () => {
- try {
- await request.delete('/Admin/Role', {
- params: { id: row.id }
- });
- loadData();
- } catch {
- // 错误提示已经在 request 拦截器中自动处理
- }
- })
- .catch(() => { });
+ handleDeleteOperation(
+ () => request.delete('/Admin/Role', { params: { id: row.id } }),
+ loadData,
+ '确认删除该角色吗?'
+ );
};
// 提交表单
const submitForm = async () => {
- if (!formRef.value) return;
-
- formRef.value.validate(async (valid: boolean) => {
- if (valid) {
- try {
- if (formType.value === 'add') {
- await request.post('/Admin/Role', form);
- } else {
- await request.put('/Admin/Role', form);
- }
- dialogVisible.value = false;
- loadData();
- } catch {
- // 错误提示已经在 request 拦截器中自动处理
- }
+ const apiCall = async () => {
+ if (formType.value === 'add') {
+ await request.post('/Admin/Role', form);
+ } else {
+ await request.put('/Admin/Role', form);
}
- });
+ };
+
+ const onSuccess = () => {
+ dialogVisible.value = false;
+ loadData();
+ };
+
+ await handleFormSubmit(formRef.value, apiCall, onSuccess);
};
// 初始化加载数据
diff --git a/apps/cube-admin/src/pages/admin/tenant-user/index.vue b/apps/cube-admin/src/pages/admin/tenant-user/index.vue
index 807d8fa..f6d6bc6 100644
--- a/apps/cube-admin/src/pages/admin/tenant-user/index.vue
+++ b/apps/cube-admin/src/pages/admin/tenant-user/index.vue
@@ -25,7 +25,7 @@
<CubeListToolbarSearch
:on-search="SearchData"
:on-reset="ResetData"
- :on-callback="getTenantUserList"
+ :on-callback="callback"
/>
<!-- 数据表格 -->
@@ -79,12 +79,12 @@
</div>
<CubeListPager
- :total="pagination.total"
- :current-page="pagination.page"
- :page-size="pagination.size"
+ :total="queryParams.total"
+ :current-page="queryParams.pageIndex"
+ :page-size="queryParams.pageSize"
:on-current-change="CurrentPageChange"
:on-size-change="PageSizeChange"
- :on-callback="getTenantUserList"
+ :on-callback="callback"
/>
</el-card>
@@ -181,10 +181,11 @@ import { Plus, Refresh } from '@element-plus/icons-vue'
import { request } from '@core/utils/request'
import CubeListToolbarSearch from '@core/components/CubeListToolbarSearch.vue'
import CubeListPager from '@core/components/CubeListPager.vue'
+import { pageInfoDefault } from '@core/types/common';
+import type { BaseEntity } from '@core/types/common';
-// 租户用户接口
-interface TenantUser {
- id: number
+// 租户用户接口,继承 BaseEntity
+interface TenantUser extends BaseEntity {
tenantId: number
tenantName: string
userId: number
@@ -203,9 +204,6 @@ interface TenantUser {
remark: string
}
-// 查询表单数据 - 用于存储搜索条件
-const searchForm = reactive({ p: '' })
-
// 表格数据
const tableData = ref<TenantUser[]>([])
const selectedRows = ref<TenantUser[]>([])
@@ -232,11 +230,10 @@ const formRules = {
]
}
-// 分页
-const pagination = reactive({
- page: 1,
- size: 20,
- total: 0
+// 分页与搜索参数
+const queryParams = reactive({
+ q: '',
+ ...pageInfoDefault
})
// 加载状态
@@ -247,38 +244,35 @@ const loading = reactive({
detail: false
})
-// 获取租户用户列表
-const getTenantUserList = async (searchData?: { p: string }) => {
- // 如果传入了搜索数据,则更新本地搜索条件
- if (searchData !== undefined) {
- searchForm.p = searchData.p;
- }
+// 组件回调函数
+const callback = (e?: Record<string, unknown>) => {
+ Object.assign(queryParams, e?.params || {});
+ getTenantUserList();
+};
+// 获取租户用户列表
+const getTenantUserList = async () => {
try {
loading.list = true
-
const data = await request.get('/Admin/TenantUser', {
- params: {
- page: pagination.page,
- size: pagination.size,
- q: searchForm.p
- }
+ params: queryParams
})
-
- // 处理不同的响应格式
- if (data && typeof data === 'object' && 'list' in data && 'total' in data) {
+ if (data && typeof data === 'object' && 'list' in data && 'page' in data) {
tableData.value = Array.isArray(data.list) ? data.list : [];
- pagination.total = data.total || 0;
+ queryParams.total = data.page?.totalCount || 0;
+ } else if (data && typeof data === 'object' && 'list' in data && 'total' in data) {
+ tableData.value = Array.isArray(data.list) ? data.list : [];
+ queryParams.total = data.total || 0;
} else if (Array.isArray(data)) {
tableData.value = data;
- pagination.total = data.length;
+ queryParams.total = data.length;
} else {
tableData.value = [];
- pagination.total = 0;
+ queryParams.total = 0;
}
} catch {
tableData.value = [];
- pagination.total = 0;
+ queryParams.total = 0;
} finally {
loading.list = false
}
@@ -347,14 +341,14 @@ const deleteTenantUser = async (id: number) => {
}
}
-// 搜索数据处理
-const SearchData = () => {
- pagination.page = 1;
+// 搜索按钮点击事件
+const SearchData = (e?: Record<string, unknown>) => {
+ Object.assign(queryParams, { pageIndex: 1 }, e || {});
};
-// 重置数据处理
-const ResetData = () => {
- pagination.page = 1;
+// 重置按钮点击事件
+const ResetData = (e?: Record<string, unknown>) => {
+ Object.assign(queryParams, { pageIndex: 1 }, e || {});
};
// 刷新列表
@@ -428,14 +422,14 @@ const handleSelectionChange = (selection: TenantUser[]) => {
// 页码变更处理
const CurrentPageChange = (page: number) => {
- pagination.page = page
-}
+ queryParams.pageIndex = page;
+};
// 每页显示条数变更处理
const PageSizeChange = (size: number) => {
- pagination.size = size
- pagination.page = 1
-}
+ queryParams.pageSize = size;
+ queryParams.pageIndex = 1;
+};
// 格式化日期
const formatDate = (dateStr: string) => {
@@ -446,8 +440,8 @@ const formatDate = (dateStr: string) => {
// 组件挂载时获取数据
onMounted(() => {
- getTenantUserList()
-})
+ getTenantUserList();
+});
</script>
<style scoped>
diff --git a/apps/cube-admin/src/pages/admin/tenant/index.vue b/apps/cube-admin/src/pages/admin/tenant/index.vue
index 190f847..b754d12 100644
--- a/apps/cube-admin/src/pages/admin/tenant/index.vue
+++ b/apps/cube-admin/src/pages/admin/tenant/index.vue
@@ -11,7 +11,7 @@
<CubeListToolbarSearch
:on-search="SearchData"
:on-reset="ResetData"
- :on-callback="loadData"
+ :on-callback="callback"
/>
<el-table :data="tableData" border style="width: 100%" v-loading="loading">
@@ -48,12 +48,12 @@
</el-table>
<CubeListPager
- :total="total"
- :current-page="currentPage"
- :page-size="pageSize"
+ :total="queryParams.total"
+ :current-page="queryParams.pageIndex"
+ :page-size="queryParams.pageSize"
:on-current-change="CurrentPageChange"
:on-size-change="PageSizeChange"
- :on-callback="loadData"
+ :on-callback="callback"
/>
</el-card>
@@ -92,11 +92,12 @@
<script setup lang="ts">
import { ref, reactive, onMounted } from 'vue';
-import { ElMessageBox } from 'element-plus';
import type { FormInstance, FormRules } from 'element-plus';
import { request } from '@core/utils/request';
+import { apiDataToList, handleDeleteOperation, handleFormSubmit } from '@core/utils/api-helpers';
import CubeListToolbarSearch from '@core/components/CubeListToolbarSearch.vue';
import CubeListPager from '@core/components/CubeListPager.vue';
+import { pageInfoDefault } from '@core/types/common';
// 定义租户类型接口
interface Tenant {
@@ -129,12 +130,12 @@ interface Tenant {
// 表格数据
const tableData = ref<Tenant[]>([]);
const loading = ref(false);
-const total = ref(0);
-const currentPage = ref(1);
-const pageSize = ref(10);
-// 查询表单数据 - 用于存储搜索条件
-const searchForm = reactive({ p: '' });
+// 页面请求参数
+const queryParams = reactive({
+ q: '',// 搜索关键字
+ ...pageInfoDefault,// 分页参数
+});
// 表单相关
const dialogVisible = ref(false);
@@ -187,71 +188,62 @@ const getKindText = (kind: number) => {
};
// 获取类型标签类型
-const getKindType = (kind: number) => {
- const map: Record<number, string> = {
- 0: '',
+const getKindType = (kind: number): 'warning' | undefined => {
+ const map: Record<number, 'warning' | undefined> = {
+ 0: undefined,
1: 'warning'
};
- return map[kind] || '';
+ return map[kind] || undefined;
};
-// 加载数据
-const loadData = async (searchData?: { p: string }) => {
- // 如果传入了搜索数据,则更新本地搜索条件
- if (searchData !== undefined) {
- searchForm.p = searchData.p;
- }
+// 组件回调函数
+const callback = (e?: Record<string, unknown>) => {
+ console.log(e?.type, e?.params);
+ const query = Object.assign(queryParams, e?.params || {});
+ console.log('queryParams:', query);
+ loadData();
+};
+// 查询请求
+const loadData = async () => {
loading.value = true;
try {
const data = await request.get('/Admin/Tenant', {
- params: {
- pageIndex: currentPage.value,
- pageSize: pageSize.value,
- q: searchForm.p
- }
+ params: queryParams
});
- // 处理不同的响应格式
- if (data && typeof data === 'object' && 'data' in data && 'page' in data) {
- // 包含分页信息的响应
- tableData.value = Array.isArray(data.data) ? data.data : [];
- total.value = data.page?.totalCount || tableData.value.length;
- } else if (Array.isArray(data)) {
- // 直接返回数组的响应(无分页信息)
- tableData.value = data;
- total.value = data.length;
- } else {
- tableData.value = [];
- total.value = 0;
- }
+ const { list, page } = apiDataToList<Tenant>(data);
+ tableData.value = list;
+ queryParams.total = page?.totalCount; // 更新总数
} catch {
tableData.value = [];
- total.value = 0;
+ queryParams.total = 0;
} finally {
loading.value = false;
}
};
// 搜索数据处理
-const SearchData = () => {
- currentPage.value = 1;
+const SearchData = (e?: Record<string, unknown>) => {
+ Object.assign(queryParams, { pageIndex: 1 }, e || {});
+ console.log('SearchData:', queryParams);
};
// 重置数据处理
-const ResetData = () => {
- currentPage.value = 1;
+const ResetData = (e?: Record<string, unknown>) => {
+ Object.assign(queryParams, { pageIndex: 1 }, e || {});
+ console.log('ResetData:', queryParams);
};
// 页码变更处理
const CurrentPageChange = (page: number) => {
- currentPage.value = page;
+ queryParams.pageIndex = page;
};
// 每页显示条数变更处理
const PageSizeChange = (size: number) => {
- pageSize.value = size;
- currentPage.value = 1;
+ queryParams.pageSize = size;
+ queryParams.pageIndex = 1;
};
// 新增
@@ -295,43 +287,29 @@ const handleEdit = (row: Tenant) => {
// 删除
const handleDelete = (row: Tenant) => {
- ElMessageBox.confirm('确认删除该租户吗?', '提示', {
- confirmButtonText: '确定',
- cancelButtonText: '取消',
- type: 'warning'
- })
- .then(async () => {
- try {
- await request.delete('/Admin/Tenant', {
- params: { id: row.id }
- });
- loadData();
- } catch {
- // 错误提示已经在 request 拦截器中自动处理
- }
- })
- .catch(() => { });
+ handleDeleteOperation(
+ () => request.delete('/Admin/Tenant', { params: { id: row.id } }),
+ loadData,
+ '确认删除该租户吗?'
+ );
};
// 提交表单
const submitForm = async () => {
- if (!formRef.value) return;
-
- formRef.value.validate(async (valid: boolean) => {
- if (valid) {
- try {
- if (formType.value === 'add') {
- await request.post('/Admin/Tenant', form);
- } else {
- await request.put('/Admin/Tenant', form);
- }
- dialogVisible.value = false;
- loadData();
- } catch {
- // 错误提示已经在 request 拦截器中自动处理
- }
+ const apiCall = async () => {
+ if (formType.value === 'add') {
+ await request.post('/Admin/Tenant', form);
+ } else {
+ await request.put('/Admin/Tenant', form);
}
- });
+ };
+
+ const onSuccess = () => {
+ dialogVisible.value = false;
+ loadData();
+ };
+
+ await handleFormSubmit(formRef.value, apiCall, onSuccess);
};
// 初始化加载数据
diff --git a/apps/cube-admin/src/pages/admin/user-connect/index.vue b/apps/cube-admin/src/pages/admin/user-connect/index.vue
index e356cba..7287978 100644
--- a/apps/cube-admin/src/pages/admin/user-connect/index.vue
+++ b/apps/cube-admin/src/pages/admin/user-connect/index.vue
@@ -7,11 +7,7 @@
</div>
</template>
- <CubeListToolbarSearch
- :on-search="SearchData"
- :on-reset="ResetData"
- :on-callback="loadData"
- />
+ <CubeListToolbarSearch :on-search="SearchData" :on-reset="ResetData" :on-callback="callback" />
<el-table :data="tableData" border style="width: 100%" v-loading="loading">
<el-table-column prop="id" label="编号" width="80" />
@@ -47,28 +43,23 @@
</el-table-column>
</el-table>
- <CubeListPager
- :total="total"
- :current-page="currentPage"
- :page-size="pageSize"
- :on-current-change="CurrentPageChange"
- :on-size-change="PageSizeChange"
- :on-callback="loadData"
- />
+ <CubeListPager :total="queryParams.total" :current-page="queryParams.pageIndex" :page-size="queryParams.pageSize"
+ :on-current-change="CurrentPageChange" :on-size-change="PageSizeChange" :on-callback="callback" />
</el-card>
</div>
</template>
<script setup lang="ts">
import { ref, reactive, onMounted } from 'vue';
-import { ElMessageBox } from 'element-plus';
import { request } from '@core/utils/request';
+import { apiDataToList, handleDeleteOperation } from '@core/utils/api-helpers';
import CubeListToolbarSearch from '@core/components/CubeListToolbarSearch.vue';
import CubeListPager from '@core/components/CubeListPager.vue';
+import { pageInfoDefault } from '@core/types/common';
+import type { BaseEntity } from '@core/types/common';
-// 定义用户连接类型接口
-interface UserConnect {
- id: number;
+// 定义用户连接类型接口,继承 BaseEntity
+interface UserConnect extends BaseEntity {
provider: string;
openID: string;
userName: string;
@@ -77,96 +68,70 @@ interface UserConnect {
refreshToken: string;
expire: string;
enable: boolean;
- updateTime: string;
+ remark?: string;
}
+
// 表格数据
const tableData = ref<UserConnect[]>([]);
const loading = ref(false);
-const total = ref(0);
-const currentPage = ref(1);
-const pageSize = ref(10);
-
-// 查询表单数据 - 用于存储搜索条件
-const searchForm = reactive({ p: '' });
-
-// 加载数据
-const loadData = async (searchData?: { p: string }) => {
- // 如果传入了搜索数据,则更新本地搜索条件
- if (searchData !== undefined) {
- searchForm.p = searchData.p;
- }
+// 页面请求参数
+const queryParams = reactive({
+ q: '', // 搜索关键字
+ ...pageInfoDefault,
+});
+
+// 组件回调函数
+const callback = (e?: Record<string, unknown>) => {
+ Object.assign(queryParams, e?.params || {});
+ loadData();
+};
+
+// 查询请求
+const loadData = async () => {
loading.value = true;
try {
- const data = await request.get('/Admin/UserConnect', {
- params: {
- pageIndex: currentPage.value,
- pageSize: pageSize.value,
- q: searchForm.p
- }
- });
-
- // 处理不同的响应格式
- if (data && typeof data === 'object' && 'data' in data && 'page' in data) {
- // 包含分页信息的响应
- tableData.value = Array.isArray(data.data) ? data.data : [];
- total.value = data.page?.totalCount || tableData.value.length;
- } else if (Array.isArray(data)) {
- // 直接返回数组的响应(无分页信息)
- tableData.value = data;
- total.value = data.length;
- } else {
- tableData.value = [];
- total.value = 0;
- }
+ const data = await request.get('/Admin/UserConnect', { params: queryParams });
+ const { list, page } = apiDataToList<UserConnect>(data);
+ tableData.value = list;
+ queryParams.total = page?.totalCount;
} catch {
tableData.value = [];
- total.value = 0;
+ queryParams.total = 0;
} finally {
loading.value = false;
}
};
-// 搜索数据处理
-const SearchData = () => {
- currentPage.value = 1;
+// 搜索按钮点击事件
+const SearchData = (e?: Record<string, unknown>) => {
+ Object.assign(queryParams, { pageIndex: 1 }, e || {});
};
-// 重置数据处理
-const ResetData = () => {
- currentPage.value = 1;
+// 重置按钮点击事件
+const ResetData = (e?: Record<string, unknown>) => {
+ Object.assign(queryParams, { pageIndex: 1 }, e || {});
};
// 页码变更处理
const CurrentPageChange = (page: number) => {
- currentPage.value = page;
+ queryParams.pageIndex = page;
};
// 每页显示条数变更处理
const PageSizeChange = (size: number) => {
- pageSize.value = size;
- currentPage.value = 1;
+ queryParams.pageSize = size;
+ queryParams.pageIndex = 1;
};
// 删除
const handleDelete = (row: UserConnect) => {
- ElMessageBox.confirm('确认删除该用户连接吗?', '提示', {
- confirmButtonText: '确定',
- cancelButtonText: '取消',
- type: 'warning'
- })
- .then(async () => {
- try {
- await request.delete('/Admin/UserConnect', {
- params: { id: row.id }
- });
- loadData();
- } catch {
- // 错误提示已经在 request 拦截器中自动处理
- }
- })
- .catch(() => { });
+ handleDeleteOperation(
+ () => request.delete('/Admin/UserConnect', { params: { id: row.id } }),
+ loadData,
+ '确认删除该用户连接吗?'
+ );
};
// 初始化加载数据
diff --git a/apps/cube-admin/src/pages/admin/user-online/index.vue b/apps/cube-admin/src/pages/admin/user-online/index.vue
index 933faf2..8ff2111 100644
--- a/apps/cube-admin/src/pages/admin/user-online/index.vue
+++ b/apps/cube-admin/src/pages/admin/user-online/index.vue
@@ -7,7 +7,7 @@
</div>
</template>
- <CubeListToolbarSearch :on-search="SearchData" :on-reset="ResetData" :on-callback="loadUserOnlineData" />
+ <CubeListToolbarSearch :on-search="SearchData" :on-reset="ResetData" :on-callback="callback" />
<el-table :data="tableData" style="width: 100%" v-loading="loading" border>
<el-table-column type="selection" width="55" />
@@ -48,12 +48,12 @@
</el-table>
<CubeListPager
- :total="total"
- :current-page="currentPage"
- :page-size="pageSize"
+ :total="queryParams.total"
+ :current-page="queryParams.pageIndex"
+ :page-size="queryParams.pageSize"
:on-current-change="CurrentPageChange"
:on-size-change="PageSizeChange"
- :on-callback="loadUserOnlineData"
+ :on-callback="callback"
/>
</el-card>
@@ -84,15 +84,17 @@
</template>
<script setup lang="ts">
+
import { ref, reactive, onMounted } from 'vue'
import { request } from '@core/utils/request'
-import { processListResponse, handleDeleteOperation } from '@core/utils/api-helpers'
+import { apiDataToList, handleDeleteOperation } from '@core/utils/api-helpers'
import CubeListToolbarSearch from '@core/components/CubeListToolbarSearch.vue'
import CubeListPager from '@core/components/CubeListPager.vue'
+import { pageInfoDefault } from '@core/types/common';
+import type { BaseEntity } from '@core/types/common';
-// 在线用户接口
-interface UserOnline {
- id: number
+// 在线用户接口,继承 BaseEntity
+interface UserOnline extends BaseEntity {
userID: number
name: string
sessionID: string
@@ -100,7 +102,7 @@ interface UserOnline {
times: number
page: string
platform: string
- oS: string // 注意这里是 oS 不是 os
+ oS: string
device: string
brower: string
netType: string
@@ -120,40 +122,36 @@ interface UserOnline {
// 表格数据
const tableData = ref<UserOnline[]>([])
const loading = ref(false)
-const total = ref(0)
-const currentPage = ref(1)
-const pageSize = ref(10)
-// 查询表单数据 - 用于存储搜索条件
-const searchForm = reactive({ p: '' })
+// 分页与搜索参数
+const queryParams = reactive({
+ q: '',
+ ...pageInfoDefault
+});
// 详情数据
const detailData = ref<Partial<UserOnline>>({})
const showDetailDialog = ref(false)
+// 组件回调函数
+const callback = (e?: Record<string, unknown>) => {
+ Object.assign(queryParams, e?.params || {});
+ loadUserOnlineData();
+};
+
// 加载在线用户数据
-const loadUserOnlineData = async (searchData?: { p: string }) => {
+const loadUserOnlineData = async () => {
loading.value = true
try {
- // 如果传入了搜索数据,则更新本地搜索条件
- if (searchData !== undefined) {
- searchForm.p = searchData.p
- }
-
const data = await request.get('/Admin/UserOnline', {
- params: {
- q: searchForm.p,
- pageIndex: currentPage.value,
- pageSize: pageSize.value,
- }
+ params: queryParams
})
-
- const { list, total: totalCount } = processListResponse<UserOnline>(data)
+ const { list, page } = apiDataToList<UserOnline>(data)
tableData.value = list
- total.value = totalCount
+ queryParams.total = page?.totalCount || list.length
} catch {
tableData.value = []
- total.value = 0
+ queryParams.total = 0
} finally {
loading.value = false
}
@@ -161,24 +159,24 @@ const loadUserOnlineData = async (searchData?: { p: string }) => {
// 页码变更处理
const CurrentPageChange = (page: number) => {
- currentPage.value = page
-}
+ queryParams.pageIndex = page;
+};
// 每页显示条数变更处理
const PageSizeChange = (size: number) => {
- pageSize.value = size
- currentPage.value = 1
-}
+ queryParams.pageSize = size;
+ queryParams.pageIndex = 1;
+};
-// 搜索数据处理
-const SearchData = () => {
- currentPage.value = 1
-}
+// 搜索按钮点击事件
+const SearchData = (e?: Record<string, unknown>) => {
+ Object.assign(queryParams, { pageIndex: 1 }, e || {});
+};
-// 重置数据处理
-const ResetData = () => {
- currentPage.value = 1
-}
+// 重置按钮点击事件
+const ResetData = (e?: Record<string, unknown>) => {
+ Object.assign(queryParams, { pageIndex: 1 }, e || {});
+};
// 获取在线用户详情
const getUserOnlineDetail = async (id: number) => {
@@ -234,8 +232,8 @@ const formatDate = (dateStr?: string) => {
// 组件挂载时获取数据
onMounted(() => {
- loadUserOnlineData()
-})
+ loadUserOnlineData();
+});
</script>
<style scoped>
diff --git a/apps/cube-admin/src/pages/admin/user-stat/index.vue b/apps/cube-admin/src/pages/admin/user-stat/index.vue
index f6b40ef..2dfd5e9 100644
--- a/apps/cube-admin/src/pages/admin/user-stat/index.vue
+++ b/apps/cube-admin/src/pages/admin/user-stat/index.vue
@@ -15,7 +15,7 @@
<CubeListToolbarSearch
:on-search="SearchData"
:on-reset="ResetData"
- :on-callback="loadUserStatData"
+ :on-callback="callback"
/>
<!-- 数据表格 -->
@@ -59,12 +59,12 @@
<!-- 分页 -->
<CubeListPager
- :total="total"
- :current-page="currentPage"
- :page-size="pageSize"
+ :total="queryParams.total"
+ :current-page="queryParams.pageIndex"
+ :page-size="queryParams.pageSize"
:on-current-change="CurrentPageChange"
:on-size-change="PageSizeChange"
- :on-callback="loadUserStatData"
+ :on-callback="callback"
/>
</el-card>
@@ -99,69 +99,65 @@
</template>
<script setup lang="ts">
+
import { ref, reactive, onMounted } from 'vue'
import { request } from '@core/utils/request'
-import { processListResponse } from '@core/utils/api-helpers'
+import { apiDataToList } from '@core/utils/api-helpers'
import CubeListToolbarSearch from '@core/components/CubeListToolbarSearch.vue'
import CubeListPager from '@core/components/CubeListPager.vue'
-
-// 用户统计接口
-interface UserStat {
- id: number
- date: string // 统计日期
- total: number // 总数
- logins: number // 登录数
- oAuths: number // OAuth登录
- maxOnline: number // 最大在线
- actives: number // 活跃
- activesT7: number // 7天活跃
- activesT30: number // 30天活跃
- news: number // 新用户
- newsT7: number // 7天注册
- newsT30: number // 30天注册
- onlineTime: number // 在线时间(秒)
- createTime: string
- updateTime: string
+import { pageInfoDefault } from '@core/types/common';
+import type { BaseEntity } from '@core/types/common';
+
+// 用户统计接口,继承 BaseEntity
+interface UserStat extends BaseEntity {
+ date: string
+ total: number
+ logins: number
+ oAuths: number
+ maxOnline: number
+ actives: number
+ activesT7: number
+ activesT30: number
+ news: number
+ newsT7: number
+ newsT30: number
+ onlineTime: number
remark?: string
}
-// 查询表单数据 - 用于存储搜索条件
-const searchForm = reactive({ p: '' })
-
// 表格数据
const tableData = ref<UserStat[]>([])
const loading = ref(false)
-const total = ref(0)
-const currentPage = ref(1)
-const pageSize = ref(10)
+
+// 分页与搜索参数
+const queryParams = reactive({
+ q: '',
+ ...pageInfoDefault
+});
// 详情数据
const detailData = ref<Partial<UserStat>>({})
const showDetailDialog = ref(false)
+// 组件回调函数
+const callback = (e?: Record<string, unknown>) => {
+ Object.assign(queryParams, e?.params || {});
+ loadUserStatData();
+};
+
// 加载用户统计数据
-const loadUserStatData = async (searchData?: { p: string }) => {
+const loadUserStatData = async () => {
loading.value = true
try {
- // 如果传入了搜索数据,则更新本地搜索条件
- if (searchData !== undefined) {
- searchForm.p = searchData.p
- }
-
const data = await request.get('/Admin/UserStat', {
- params: {
- q: searchForm.p,
- pageIndex: currentPage.value,
- pageSize: pageSize.value,
- }
+ params: queryParams
})
-
- const { list, total: totalCount } = processListResponse<UserStat>(data)
+ const { list, page } = apiDataToList<UserStat>(data)
tableData.value = list
- total.value = totalCount
+ queryParams.total = page?.totalCount || list.length
} catch {
tableData.value = []
- total.value = 0
+ queryParams.total = 0
} finally {
loading.value = false
}
@@ -169,35 +165,32 @@ const loadUserStatData = async (searchData?: { p: string }) => {
// 页码变更处理
const CurrentPageChange = (page: number) => {
- currentPage.value = page
-}
+ queryParams.pageIndex = page;
+};
// 每页显示条数变更处理
const PageSizeChange = (size: number) => {
- pageSize.value = size
- currentPage.value = 1
-}
+ queryParams.pageSize = size;
+ queryParams.pageIndex = 1;
+};
-// 搜索数据处理
-const SearchData = () => {
- currentPage.value = 1
-}
+// 搜索按钮点击事件
+const SearchData = (e?: Record<string, unknown>) => {
+ Object.assign(queryParams, { pageIndex: 1 }, e || {});
+};
-// 重置数据处理
-const ResetData = () => {
- currentPage.value = 1
-}
+// 重置按钮点击事件
+const ResetData = (e?: Record<string, unknown>) => {
+ Object.assign(queryParams, { pageIndex: 1 }, e || {});
+};
// 获取用户统计详情
const getUserStatDetail = async (id: number) => {
try {
loading.value = true
-
const response = await request.get(`/Admin/UserStat/Detail`, {
params: { id }
})
-
- // 处理响应数据
if (response && typeof response === 'object') {
if ('data' in response && response.data) {
detailData.value = response.data as UserStat
@@ -237,10 +230,9 @@ const formatOnlineTime = (seconds?: number) => {
return `${hours}:${minutes.toString().padStart(2, '0')}:${secs.toString().padStart(2, '0')}`
}
-// 组件挂载时获取数据
onMounted(() => {
- loadUserStatData()
-})
+ loadUserStatData();
+});
</script>
<style scoped>
diff --git a/apps/cube-admin/src/pages/admin/user-token/index.vue b/apps/cube-admin/src/pages/admin/user-token/index.vue
index 893cd4f..c608f09 100644
--- a/apps/cube-admin/src/pages/admin/user-token/index.vue
+++ b/apps/cube-admin/src/pages/admin/user-token/index.vue
@@ -19,7 +19,7 @@
<CubeListToolbarSearch
:on-search="SearchData"
:on-reset="ResetData"
- :on-callback="loadUserTokenData"
+ :on-callback="callback"
/>
<!-- 数据表格 -->
@@ -76,12 +76,12 @@
<!-- 分页 -->
<CubeListPager
- :total="total"
- :current-page="currentPage"
- :page-size="pageSize"
+ :total="queryParams.total"
+ :current-page="queryParams.pageIndex"
+ :page-size="queryParams.pageSize"
:on-current-change="CurrentPageChange"
:on-size-change="PageSizeChange"
- :on-callback="loadUserTokenData"
+ :on-callback="callback"
/>
</el-card>
@@ -193,18 +193,20 @@
</template>
<script setup lang="ts">
+
import { ref, reactive, onMounted } from 'vue'
import { Plus } from '@element-plus/icons-vue'
import type { FormInstance, FormRules } from 'element-plus'
import { ElMessage } from 'element-plus'
import { request } from '@core/utils/request';
-import { processListResponse, handleDeleteOperation, handleFormSubmit } from '@core/utils/api-helpers';
+import { apiDataToList, handleDeleteOperation, handleFormSubmit } from '@core/utils/api-helpers';
import CubeListToolbarSearch from '@core/components/CubeListToolbarSearch.vue';
import CubeListPager from '@core/components/CubeListPager.vue';
+import { pageInfoDefault } from '@core/types/common';
+import type { BaseEntity } from '@core/types/common';
-// 定义用户令牌类型接口
-interface UserToken {
- id: number;
+// 用户令牌类型接口,继承 BaseEntity
+interface UserToken extends BaseEntity {
userId: number;
userName: string;
tokenType: string;
@@ -212,14 +214,12 @@ interface UserToken {
refreshToken: string;
enable: boolean;
expire: string;
- createTime: string;
- updateTime: string;
createIP: string;
updateIP: string;
remark: string;
}
-// 定义初始令牌表单数据
+// 初始令牌表单数据
const initialTokenForm: Partial<UserToken> = {
id: 0,
userId: 0,
@@ -233,12 +233,12 @@ const initialTokenForm: Partial<UserToken> = {
// 表格数据
const tableData = ref<UserToken[]>([]);
const loading = ref(false);
-const total = ref(0);
-const currentPage = ref(1);
-const pageSize = ref(10);
-// 查询表单数据 - 用于存储搜索条件
-const searchForm = reactive({ p: '' });
+// 分页与搜索参数
+const queryParams = reactive({
+ q: '',
+ ...pageInfoDefault
+});
// 详情相关
const detailVisible = ref(false);
@@ -271,29 +271,25 @@ const formRules: FormRules = {
]
};
+// 组件回调函数
+const callback = (e?: Record<string, unknown>) => {
+ Object.assign(queryParams, e?.params || {});
+ loadUserTokenData();
+};
+
// 加载用户令牌数据
-const loadUserTokenData = async (searchData?: { p: string }) => {
+const loadUserTokenData = async () => {
loading.value = true;
try {
- // 如果传入了搜索数据,则更新本地搜索条件
- if (searchData !== undefined) {
- searchForm.p = searchData.p;
- }
-
const data = await request.get('/Admin/UserToken', {
- params: {
- q: searchForm.p,
- pageIndex: currentPage.value,
- pageSize: pageSize.value,
- }
+ params: queryParams
});
-
- const { list, total: totalCount } = processListResponse<UserToken>(data);
+ const { list, page } = apiDataToList<UserToken>(data);
tableData.value = list;
- total.value = totalCount;
+ queryParams.total = page?.totalCount || list.length;
} catch {
tableData.value = [];
- total.value = 0;
+ queryParams.total = 0;
} finally {
loading.value = false;
}
@@ -301,23 +297,23 @@ const loadUserTokenData = async (searchData?: { p: string }) => {
// 页码变更处理
const CurrentPageChange = (page: number) => {
- currentPage.value = page;
+ queryParams.pageIndex = page;
};
// 每页显示条数变更处理
const PageSizeChange = (size: number) => {
- pageSize.value = size;
- currentPage.value = 1;
+ queryParams.pageSize = size;
+ queryParams.pageIndex = 1;
};
-// 搜索数据处理
-const SearchData = () => {
- currentPage.value = 1;
+// 搜索按钮点击事件
+const SearchData = (e?: Record<string, unknown>) => {
+ Object.assign(queryParams, { pageIndex: 1 }, e || {});
};
-// 重置数据处理
-const ResetData = () => {
- currentPage.value = 1;
+// 重置按钮点击事件
+const ResetData = (e?: Record<string, unknown>) => {
+ Object.assign(queryParams, { pageIndex: 1 }, e || {});
};
// 查看详情
@@ -389,10 +385,9 @@ const formatDate = (dateStr?: string) => {
return date.toLocaleString('zh-CN')
}
-// 初始化加载数据
onMounted(() => {
loadUserTokenData();
-})
+});
</script>
<style scoped>
diff --git a/apps/cube-admin/src/pages/admin/xcode/index.vue b/apps/cube-admin/src/pages/admin/xcode/index.vue
index fa32dcf..c89e8d4 100644
--- a/apps/cube-admin/src/pages/admin/xcode/index.vue
+++ b/apps/cube-admin/src/pages/admin/xcode/index.vue
@@ -81,17 +81,17 @@
</template>
<script setup lang="ts">
+
import { ref, reactive, onMounted } from 'vue';
-import type { FormRules } from 'element-plus';
+import type { FormInstance, FormRules } from 'element-plus';
import { request } from '@core/utils/request';
-import type { XCodeSetting } from '@/types/admin';
// 表单相关
const formRef = ref<FormInstance | null>(null);
const loading = ref(false);
// 表单数据
-const form = reactive<XCodeSetting>({
+const form = reactive({
isNew: false,
debug: false,
showSQL: true,
@@ -110,27 +110,37 @@ const form = reactive<XCodeSetting>({
});
// 表单验证规则
-const formRules = reactive<FormRules>({
+const formRules: FormRules = {
traceSQLTime: [
- { required: true, message: '请输入SQL执行时间阀值', trigger: 'blur' }
+ { required: true, message: '请输入SQL执行时间阀值', trigger: 'blur' },
+ { type: 'number', min: 0, message: '值不能小于0', trigger: 'blur' }
],
sqlMaxLength: [
- { required: true, message: '请输入SQL最大长度', trigger: 'blur' }
+ { required: true, message: '请输入SQL最大长度', trigger: 'blur' },
+ { type: 'number', min: 0, message: '值不能小于0', trigger: 'blur' }
],
batchSize: [
- { required: true, message: '请输入批大小', trigger: 'blur' }
+ { required: true, message: '请输入批大小', trigger: 'blur' },
+ { type: 'number', min: 1, message: '值不能小于1', trigger: 'blur' }
],
batchInterval: [
- { required: true, message: '请输入批操作间隙', trigger: 'blur' }
+ { required: true, message: '请输入批操作间隙', trigger: 'blur' },
+ { type: 'number', min: 0, message: '值不能小于0', trigger: 'blur' }
],
-});
+ commandTimeout: [
+ { type: 'number', min: 0, message: '值不能小于0', trigger: 'blur' }
+ ],
+ retryOnFailure: [
+ { type: 'number', min: 0, message: '值不能小于0', trigger: 'blur' }
+ ]
+};
// 接口调用函数
const api = {
getSettings: async () => {
return await request.get('/Admin/XCode');
},
- updateSettings: async (data: XCodeSetting) => {
+ updateSettings: async (data: typeof form) => {
return await request.put('/Admin/XCode', data);
}
};
diff --git a/apps/cube-cube/src/pages/cube/app-log/index.vue b/apps/cube-cube/src/pages/cube/app-log/index.vue
index 16f29db..297b16a 100644
--- a/apps/cube-cube/src/pages/cube/app-log/index.vue
+++ b/apps/cube-cube/src/pages/cube/app-log/index.vue
@@ -10,6 +10,7 @@
<CubeListToolbarSearch
:on-search="SearchData"
:on-reset="ResetData"
+ :on-callback="callback"
/>
<el-table
@@ -33,98 +34,92 @@
</el-table>
<CubeListPager
- :total="total"
- :current-page="currentPage"
- :page-size="pageSize"
+ :total="queryParams.total"
+ :current-page="queryParams.pageIndex"
+ :page-size="queryParams.pageSize"
:on-current-change="CurrentPageChange"
:on-size-change="PageSizeChange"
+ :on-callback="callback"
/>
</el-card>
</div>
</template>
<script setup lang="ts">
+
import { ref, reactive, onMounted } from 'vue';
import { ElMessage } from 'element-plus';
import { request } from '@core/utils/request';
-import { processListResponse } from '@core/utils/api-helpers';
+import { apiDataToList } from '@core/utils/api-helpers';
import CubeListToolbarSearch from '@core/components/CubeListToolbarSearch.vue';
import CubeListPager from '@core/components/CubeListPager.vue';
+import { pageInfoDefault } from '@core/types/common';
+import type { BaseEntity } from '@core/types/common';
-// 定义日志类型接口
-interface AppLog {
- id: number;
+// 日志类型接口,继承 BaseEntity
+interface AppLog extends BaseEntity {
appId: number;
appName: string;
action: string;
success: boolean;
remark: string;
- createTime: string;
createUser: string;
createIP: string;
}
// 响应式数据
const loading = ref(false);
-const total = ref(0);
const tableData = ref<AppLog[]>([]);
-// 分页相关
-const currentPage = ref(1);
-const pageSize = ref(10);
+// 分页与搜索参数
+const queryParams = reactive({
+ q: '',
+ ...pageInfoDefault
+});
-// 查询表单数据 - 用于存储搜索条件
-const searchForm = reactive({ p: '' });
+// 组件回调函数
+const callback = (e?: Record<string, unknown>) => {
+ Object.assign(queryParams, e?.params || {});
+ fetchData();
+};
// 加载数据
-const fetchData = async (searchData?: { p: string }) => {
- // 如果传入了搜索数据,则更新本地搜索条件
- if (searchData !== undefined) {
- searchForm.p = searchData.p;
- }
-
+const fetchData = async () => {
loading.value = true;
try {
- const params: Record<string, unknown> = {
- q: searchForm.p,
- pageSize: pageSize.value,
- pageIndex: currentPage.value,
- };
-
- const response = await request.get('/Cube/AppLog', { params });
- const { list, total: totalCount } = processListResponse<AppLog>(response);
-
+ const response = await request.get('/Cube/AppLog', { params: queryParams });
+ const { list, page } = apiDataToList<AppLog>(response);
tableData.value = list;
- total.value = totalCount;
+ queryParams.total = page?.totalCount || list.length;
} catch (error) {
ElMessage.error('加载数据失败');
console.error('加载数据失败:', error);
tableData.value = [];
- total.value = 0;
+ queryParams.total = 0;
} finally {
loading.value = false;
}
};
-// 搜索数据处理
-const SearchData = () => {
- currentPage.value = 1;
+// 搜索按钮点击事件
+const SearchData = (e?: Record<string, unknown>) => {
+ Object.assign(queryParams, { pageIndex: 1 }, e || {});
};
-// 重置数据处理
-const ResetData = () => {
- currentPage.value = 1;
+// 重置按钮点击事件
+const ResetData = (e?: Record<string, unknown>) => {
+ Object.assign(queryParams, { pageIndex: 1 }, e || {});
};
// 页码变更处理
const CurrentPageChange = (page: number) => {
- currentPage.value = page;
+ queryParams.pageIndex = page;
};
// 每页显示条数变更处理
const PageSizeChange = (size: number) => {
- pageSize.value = size;
- currentPage.value = 1;
+ queryParams.pageSize = size;
+ queryParams.pageIndex = 1;
};
// 初始化
diff --git a/apps/cube-cube/src/pages/cube/app/index.vue b/apps/cube-cube/src/pages/cube/app/index.vue
index 7262664..59ea759 100644
--- a/apps/cube-cube/src/pages/cube/app/index.vue
+++ b/apps/cube-cube/src/pages/cube/app/index.vue
@@ -11,6 +11,7 @@
<CubeListToolbarSearch
:on-search="SearchData"
:on-reset="ResetData"
+ :on-callback="callback"
/>
<el-table
@@ -52,11 +53,12 @@
</el-table>
<CubeListPager
- :total="total"
- :current-page="currentPage"
- :page-size="pageSize"
+ :total="queryParams.total"
+ :current-page="queryParams.pageIndex"
+ :page-size="queryParams.pageSize"
:on-current-change="CurrentPageChange"
:on-size-change="PageSizeChange"
+ :on-callback="callback"
/>
</el-card>
@@ -110,17 +112,19 @@
</template>
<script setup lang="ts">
+
import { ref, reactive, onMounted } from 'vue';
import { ElMessage, ElMessageBox } from 'element-plus';
import type { FormInstance, FormRules } from 'element-plus';
import { request } from '@core/utils/request';
-import { processListResponse } from '@core/utils/api-helpers';
+import { apiDataToList } from '@core/utils/api-helpers';
import CubeListToolbarSearch from '@core/components/CubeListToolbarSearch.vue';
import CubeListPager from '@core/components/CubeListPager.vue';
+import { pageInfoDefault } from '@core/types/common';
+import type { BaseEntity } from '@core/types/common';
-// 定义应用类型接口
-interface App {
- id: number;
+// 应用类型接口,继承 BaseEntity
+interface App extends BaseEntity {
name: string;
displayName: string;
category: string;
@@ -132,8 +136,6 @@ interface App {
autoStart: boolean;
enable: boolean;
description: string;
- createTime: string;
- updateTime: string;
}
// 响应式数据
@@ -141,15 +143,13 @@ const loading = ref(false);
const dialogVisible = ref(false);
const formType = ref<'add' | 'edit'>('add');
const formRef = ref<FormInstance | null>(null);
-const total = ref(0);
const tableData = ref<App[]>([]);
-// 分页相关
-const currentPage = ref(1);
-const pageSize = ref(10);
-
-// 查询表单数据 - 用于存储搜索条件
-const searchForm = reactive({ p: '' });
+// 分页与搜索参数
+const queryParams = reactive({
+ q: '',
+ ...pageInfoDefault
+});
// 应用表单
const form = reactive<Partial<App>>({
@@ -176,58 +176,49 @@ const formRules = reactive<FormRules>({
]
});
-// 加载数据
-const fetchData = async (searchData?: { p: string }) => {
- // 如果传入了搜索数据,则更新本地搜索条件
- if (searchData !== undefined) {
- searchForm.p = searchData.p;
- }
+// 组件回调函数
+const callback = (e?: Record<string, unknown>) => {
+ Object.assign(queryParams, e?.params || {});
+ fetchData();
+};
+// 加载数据
+const fetchData = async () => {
loading.value = true;
try {
- const params = {
- q: searchForm.p,
- pageSize: pageSize.value,
- pageIndex: currentPage.value,
- };
-
- const response = await request.get('/Cube/App', { params });
- const { list, total: totalCount } = processListResponse<App>(response);
-
+ const response = await request.get('/Cube/App', { params: queryParams });
+ const { list, page } = apiDataToList<App>(response);
tableData.value = list;
- total.value = totalCount;
-
- console.log('加载的数据:', tableData.value);
- console.log('总数:', total.value);
+ queryParams.total = page?.totalCount || list.length;
} catch (error) {
ElMessage.error('加载数据失败');
console.error('加载数据失败:', error);
tableData.value = [];
- total.value = 0;
+ queryParams.total = 0;
} finally {
loading.value = false;
}
};
-// 搜索数据处理
-const SearchData = () => {
- currentPage.value = 1;
+// 搜索按钮点击事件
+const SearchData = (e?: Record<string, unknown>) => {
+ Object.assign(queryParams, { pageIndex: 1 }, e || {});
};
-// 重置数据处理
-const ResetData = () => {
- currentPage.value = 1;
+// 重置按钮点击事件
+const ResetData = (e?: Record<string, unknown>) => {
+ Object.assign(queryParams, { pageIndex: 1 }, e || {});
};
// 页码变更处理
const CurrentPageChange = (page: number) => {
- currentPage.value = page;
+ queryParams.pageIndex = page;
};
// 每页显示条数变更处理
const PageSizeChange = (size: number) => {
- pageSize.value = size;
- currentPage.value = 1;
+ queryParams.pageSize = size;
+ queryParams.pageIndex = 1;
};
// 新增
diff --git a/apps/cube-cube/src/pages/cube/area/index.vue b/apps/cube-cube/src/pages/cube/area/index.vue
index e5821af..8817bb9 100644
--- a/apps/cube-cube/src/pages/cube/area/index.vue
+++ b/apps/cube-cube/src/pages/cube/area/index.vue
@@ -8,23 +8,11 @@
</div>
</template>
- <el-form :inline="true" :model="searchForm" class="search-form">
- <el-form-item label="地区名称">
- <el-input v-model="searchForm.q" placeholder="请输入地区名称" clearable />
- </el-form-item>
- <el-form-item label="地区级别">
- <el-select v-model="searchForm.level" placeholder="请选择地区级别" clearable>
- <el-option label="省份" :value="1" />
- <el-option label="城市" :value="2" />
- <el-option label="区县" :value="3" />
- <el-option label="乡镇" :value="4" />
- </el-select>
- </el-form-item>
- <el-form-item>
- <el-button type="primary" @click="handleSearch">查询</el-button>
- <el-button @click="resetSearch">重置</el-button>
- </el-form-item>
- </el-form>
+ <CubeListToolbarSearch
+ :on-search="SearchData"
+ :on-reset="ResetData"
+ :on-callback="callback"
+ />
<el-table
:data="tableData"
@@ -64,11 +52,14 @@
</el-table-column>
</el-table>
- <div class="pagination">
- <el-pagination v-model:current-page="currentPage" v-model:page-size="pageSize" :page-sizes="[10, 20, 50, 100]"
- :total="total" layout="total, sizes, prev, pager, next, jumper" @size-change="handleSizeChange"
- @current-change="handleCurrentChange" />
- </div>
+ <CubeListPager
+ :total="queryParams.total"
+ :current-page="queryParams.pageIndex"
+ :page-size="queryParams.pageSize"
+ :on-current-change="CurrentPageChange"
+ :on-size-change="PageSizeChange"
+ :on-callback="callback"
+ />
</el-card>
<!-- 地区表单对话框 -->
@@ -131,15 +122,19 @@
</template>
<script setup lang="ts">
+
import { ref, reactive, onMounted } from 'vue';
import { ElMessage, ElMessageBox } from 'element-plus';
import type { FormInstance, FormRules } from 'element-plus';
import { request } from '@core/utils/request';
-import { processListResponse } from '@core/utils/api-helpers';
-
-// 定义地区类型接口
-interface Area {
- id: number;
+import { apiDataToList } from '@core/utils/api-helpers';
+import CubeListToolbarSearch from '@core/components/CubeListToolbarSearch.vue';
+import CubeListPager from '@core/components/CubeListPager.vue';
+import { pageInfoDefault } from '@core/types/common';
+import type { BaseEntity } from '@core/types/common';
+
+// 地区类型接口,继承 BaseEntity
+interface Area extends BaseEntity {
name: string;
fullName: string;
code: string;
@@ -150,8 +145,6 @@ interface Area {
longitude: number;
latitude: number;
enable: boolean;
- createTime: string;
- updateTime: string;
children?: Area[];
}
@@ -160,18 +153,14 @@ const loading = ref(false);
const dialogVisible = ref(false);
const formType = ref<'add' | 'edit'>('add');
const formRef = ref<FormInstance | null>(null);
-const total = ref(0);
const tableData = ref<Area[]>([]);
const areaOptions = ref<Area[]>([]);
-// 分页相关
-const currentPage = ref(1);
-const pageSize = ref(10);
-
-// 搜索表单
-const searchForm = reactive({
+// 分页与搜索参数
+const queryParams = reactive({
q: '',
level: undefined as number | undefined,
+ ...pageInfoDefault
});
// 地区表单
@@ -229,7 +218,7 @@ const loadAreaOptions = async () => {
console.log('地区选项响应:', response);
if (response && response.data) {
- const { list } = processListResponse<Area>(response);
+ const { list } = apiDataToList<Area>(response);
areaOptions.value = list;
console.log('地区选项数据:', areaOptions.value);
}
@@ -238,50 +227,39 @@ const loadAreaOptions = async () => {
}
};
+
+// 组件回调函数
+const callback = (e?: Record<string, unknown>) => {
+ Object.assign(queryParams, e?.params || {});
+ loadData();
+};
+
// 加载表格数据(用于搜索、分页等操作)
const loadData = async () => {
loading.value = true;
try {
- const params = {
- ...searchForm,
- pageSize: pageSize.value,
- pageIndex: currentPage.value, // 使用cube-admin的方式,不减1
- };
-
- console.log('表格数据请求参数:', params);
-
- const response = await request.get('/Cube/Area', { params });
- console.log('表格数据响应:', response);
-
- const { list, total: totalCount } = processListResponse<Area>(response);
-
+ const response = await request.get('/Cube/Area', { params: queryParams });
+ const { list, page } = apiDataToList<Area>(response);
tableData.value = list;
- total.value = totalCount;
-
- console.log('表格数据:', tableData.value);
- console.log('总数:', total.value);
+ queryParams.total = page?.totalCount || list.length;
} catch (error) {
ElMessage.error('加载数据失败');
console.error('加载数据失败:', error);
tableData.value = [];
- total.value = 0;
+ queryParams.total = 0;
} finally {
loading.value = false;
}
};
-// 搜索
-const handleSearch = () => {
- currentPage.value = 1;
- loadData();
+// 搜索按钮点击事件
+const SearchData = (e?: Record<string, unknown>) => {
+ Object.assign(queryParams, { pageIndex: 1 }, e || {});
};
-// 重置搜索
-const resetSearch = () => {
- searchForm.q = '';
- searchForm.level = undefined;
- currentPage.value = 1;
- loadData();
+// 重置按钮点击事件
+const ResetData = (e?: Record<string, unknown>) => {
+ Object.assign(queryParams, { q: '', level: undefined, pageIndex: 1 }, e || {});
};
// 新增
@@ -307,16 +285,14 @@ const handleEdit = (row: Area) => {
};
// 页码变更处理
-const handleCurrentChange = (page: number) => {
- currentPage.value = page;
- loadData();
+const CurrentPageChange = (page: number) => {
+ queryParams.pageIndex = page;
};
// 每页显示条数变更处理
-const handleSizeChange = (size: number) => {
- pageSize.value = size;
- currentPage.value = 1;
- loadData();
+const PageSizeChange = (size: number) => {
+ queryParams.pageSize = size;
+ queryParams.pageIndex = 1;
};
// 删除
@@ -385,8 +361,8 @@ const submitForm = () => {
// 初始化
onMounted(() => {
- loadAreaOptions(); // 加载地区选项
- loadData(); // 加载表格数据
+ loadAreaOptions();
+ loadData();
});
</script>
diff --git a/apps/cube-cube/src/pages/cube/attachment/index.vue b/apps/cube-cube/src/pages/cube/attachment/index.vue
index 417cf9d..a42f87f 100644
--- a/apps/cube-cube/src/pages/cube/attachment/index.vue
+++ b/apps/cube-cube/src/pages/cube/attachment/index.vue
@@ -8,18 +8,11 @@
</div>
</template>
- <el-form :inline="true" :model="searchForm" class="search-form">
- <el-form-item label="文件名">
- <el-input v-model="searchForm.q" placeholder="请输入文件名" clearable />
- </el-form-item>
- <el-form-item label="分类">
- <el-input v-model="searchForm.category" placeholder="请输入分类" clearable />
- </el-form-item>
- <el-form-item>
- <el-button type="primary" @click="handleSearch">查询</el-button>
- <el-button @click="resetSearch">重置</el-button>
- </el-form-item>
- </el-form>
+ <CubeListToolbarSearch
+ :on-search="SearchData"
+ :on-reset="ResetData"
+ :on-callback="callback"
+ />
<el-table
:data="tableData"
@@ -54,11 +47,14 @@
</el-table-column>
</el-table>
- <div class="pagination">
- <el-pagination v-model:current-page="currentPage" v-model:page-size="pageSize" :page-sizes="[10, 20, 50, 100]"
- :total="total" layout="total, sizes, prev, pager, next, jumper" @size-change="handleSizeChange"
- @current-change="handleCurrentChange" />
- </div>
+ <CubeListPager
+ :total="queryParams.total"
+ :current-page="queryParams.pageIndex"
+ :page-size="queryParams.pageSize"
+ :on-current-change="CurrentPageChange"
+ :on-size-change="PageSizeChange"
+ :on-callback="callback"
+ />
</el-card>
<!-- 附件表单对话框 -->
@@ -118,15 +114,19 @@
<script setup lang="ts">
import { ref, reactive, onMounted } from 'vue';
+
import { ElMessage, ElMessageBox } from 'element-plus';
import { UploadFilled } from '@element-plus/icons-vue';
import type { FormInstance, FormRules, UploadProps, UploadFile } from 'element-plus';
import { request } from '@core/utils/request';
-import { processListResponse } from '@core/utils/api-helpers';
-
-// 定义附件类型接口
-interface Attachment {
- id: number;
+import { apiDataToList } from '@core/utils/api-helpers';
+import CubeListToolbarSearch from '@core/components/CubeListToolbarSearch.vue';
+import CubeListPager from '@core/components/CubeListPager.vue';
+import { pageInfoDefault } from '@core/types/common';
+import type { BaseEntity } from '@core/types/common';
+
+// 附件类型接口,继承 BaseEntity
+interface Attachment extends BaseEntity {
fileName: string;
displayName: string;
category: string;
@@ -136,9 +136,7 @@ interface Attachment {
downloads: number;
enable: boolean;
description: string;
- createTime: string;
createUser: string;
- updateTime: string;
}
// 响应式数据
@@ -148,19 +146,15 @@ const dialogVisible = ref(false);
const formType = ref<'add' | 'edit'>('add');
const formRef = ref<FormInstance | null>(null);
const uploadRef = ref();
-const total = ref(0);
const tableData = ref<Attachment[]>([]);
const selectedFile = ref<File | null>(null);
-// 分页相关
-const currentPage = ref(1);
-const pageSize = ref(10);
-
-// 搜索表单
-const searchForm = reactive({
+// 分页与搜索参数
+const queryParams = reactive({
q: '',
category: '',
dateRange: null as [string, string] | null,
+ ...pageInfoDefault
});
// 附件表单
@@ -188,73 +182,55 @@ const formatFileSize = (bytes: number) => {
return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i];
};
+
+// 组件回调函数
+const callback = (e?: Record<string, unknown>) => {
+ Object.assign(queryParams, e?.params || {});
+ loadData();
+};
+
// 加载数据
const loadData = async () => {
loading.value = true;
try {
- interface QueryParams {
- q?: string;
- category?: string;
- pageSize: number;
- pageIndex: number;
- startTime?: string;
- endTime?: string;
- }
-
- const params: QueryParams = {
- q: searchForm.q,
- category: searchForm.category,
- pageSize: pageSize.value,
- pageIndex: currentPage.value,
- };
-
- // 处理日期范围
- if (searchForm.dateRange) {
- params.startTime = searchForm.dateRange[0];
- params.endTime = searchForm.dateRange[1];
+ const params: Record<string, unknown> = { ...queryParams };
+ if (queryParams.dateRange) {
+ params.startTime = queryParams.dateRange[0];
+ params.endTime = queryParams.dateRange[1];
}
-
const response = await request.get('/Cube/Attachment', { params });
- const { list, total: totalCount } = processListResponse<Attachment>(response);
-
+ const { list, page } = apiDataToList<Attachment>(response);
tableData.value = list;
- total.value = totalCount;
+ queryParams.total = page?.totalCount || list.length;
} catch (error) {
ElMessage.error('加载数据失败');
console.error('加载数据失败:', error);
tableData.value = [];
- total.value = 0;
+ queryParams.total = 0;
} finally {
loading.value = false;
}
};
-// 搜索
-const handleSearch = () => {
- currentPage.value = 1;
- loadData();
+// 搜索按钮点击事件
+const SearchData = (e?: Record<string, unknown>) => {
+ Object.assign(queryParams, { pageIndex: 1 }, e || {});
};
-// 重置搜索
-const resetSearch = () => {
- searchForm.q = '';
- searchForm.category = '';
- searchForm.dateRange = null;
- currentPage.value = 1;
- loadData();
+// 重置按钮点击事件
+const ResetData = (e?: Record<string, unknown>) => {
+ Object.assign(queryParams, { q: '', category: '', dateRange: null, pageIndex: 1 }, e || {});
};
// 页码变更处理
-const handleCurrentChange = (page: number) => {
- currentPage.value = page;
- loadData();
+const CurrentPageChange = (page: number) => {
+ queryParams.pageIndex = page;
};
// 每页显示条数变更处理
-const handleSizeChange = (size: number) => {
- pageSize.value = size;
- currentPage.value = 1;
- loadData();
+const PageSizeChange = (size: number) => {
+ queryParams.pageSize = size;
+ queryParams.pageIndex = 1;
};
// 文件选择变化
diff --git a/apps/cube-cube/src/pages/cube/cron-job/index.vue b/apps/cube-cube/src/pages/cube/cron-job/index.vue
index 8ba62ec..2233fb3 100644
--- a/apps/cube-cube/src/pages/cube/cron-job/index.vue
+++ b/apps/cube-cube/src/pages/cube/cron-job/index.vue
@@ -11,7 +11,7 @@
<CubeListToolbarSearch
:on-search="SearchData"
:on-reset="ResetData"
- :on-callback="fetchData"
+ :on-callback="callback"
/>
<el-table
@@ -47,12 +47,12 @@
</el-table>
<CubeListPager
- :total="total"
- :current-page="currentPage"
- :page-size="pageSize"
+ :total="queryParams.total"
+ :current-page="queryParams.pageIndex"
+ :page-size="queryParams.pageSize"
:on-current-change="CurrentPageChange"
:on-size-change="PageSizeChange"
- :on-callback="fetchData"
+ :on-callback="callback"
/>
</el-card>
@@ -128,17 +128,19 @@
</template>
<script setup lang="ts">
+
import { ref, reactive, onMounted } from 'vue';
import { ElMessage, ElMessageBox } from 'element-plus';
import type { FormInstance, FormRules } from 'element-plus';
import { request } from '@core/utils/request';
-import { processListResponse } from '@core/utils/api-helpers';
+import { apiDataToList } from '@core/utils/api-helpers';
import CubeListToolbarSearch from '@core/components/CubeListToolbarSearch.vue';
import CubeListPager from '@core/components/CubeListPager.vue';
+import { pageInfoDefault } from '@core/types/common';
+import type { BaseEntity } from '@core/types/common';
-// 定义任务类型接口
-interface CronJob {
- id: number;
+// 任务类型接口,继承 BaseEntity
+interface CronJob extends BaseEntity {
name: string;
displayName: string;
cron: string;
@@ -156,8 +158,6 @@ interface CronJob {
lastTime: string;
nextTime: string;
description: string;
- createTime: string;
- updateTime: string;
}
// 响应式数据
@@ -165,16 +165,12 @@ const loading = ref(false);
const dialogVisible = ref(false);
const formType = ref<'add' | 'edit'>('add');
const formRef = ref<FormInstance | null>(null);
-const total = ref(0);
const tableData = ref<CronJob[]>([]);
-// 分页变量
-const currentPage = ref(1);
-const pageSize = ref(10);
-
-// 搜索表单
-const searchForm = reactive({
- p: '',
+// 分页与搜索参数
+const queryParams = reactive({
+ q: '',
+ ...pageInfoDefault
});
// 任务表单
@@ -210,51 +206,48 @@ const formRules = reactive<FormRules>({
]
});
+// 组件回调函数
+const callback = (e?: Record<string, unknown>) => {
+ Object.assign(queryParams, e?.params || {});
+ fetchData();
+};
+
// 加载数据
-const fetchData = async (searchData?: { p: string }) => {
+const fetchData = async () => {
loading.value = true;
try {
- const params: { pageSize: number; pageIndex: number; q?: string } = {
- pageSize: pageSize.value,
- pageIndex: currentPage.value,
- };
-
- // 如果有搜索参数,添加到请求中
- if (searchData?.p) {
- params.q = searchData.p;
- }
-
- const response = await request.get('/Cube/CronJob', { params });
- const { list, total: totalCount } = processListResponse<CronJob>(response);
-
+ const response = await request.get('/Cube/CronJob', { params: queryParams });
+ const { list, page } = apiDataToList<CronJob>(response);
tableData.value = list;
- total.value = totalCount;
+ queryParams.total = page?.totalCount || list.length;
} catch (error) {
ElMessage.error('加载数据失败');
console.error('加载数据失败:', error);
+ tableData.value = [];
+ queryParams.total = 0;
} finally {
loading.value = false;
}
};
-// 搜索回调
-const SearchData = () => {
- currentPage.value = 1;
+// 搜索按钮点击事件
+const SearchData = (e?: Record<string, unknown>) => {
+ Object.assign(queryParams, { pageIndex: 1 }, e || {});
};
-// 重置回调
-const ResetData = () => {
- currentPage.value = 1;
+// 重置按钮点击事件
+const ResetData = (e?: Record<string, unknown>) => {
+ Object.assign(queryParams, { pageIndex: 1 }, e || {});
};
// 分页回调
const CurrentPageChange = (page: number) => {
- currentPage.value = page;
+ queryParams.pageIndex = page;
};
const PageSizeChange = (size: number) => {
- pageSize.value = size;
- currentPage.value = 1;
+ queryParams.pageSize = size;
+ queryParams.pageIndex = 1;
};
// 立即执行
@@ -262,7 +255,7 @@ const handleExecute = async (row: CronJob) => {
try {
await request.post(`/Cube/CronJob/ExecuteNow?id=${row.id}`);
ElMessage.success('任务已提交执行');
- fetchData(searchForm);
+ fetchData();
} catch (error) {
ElMessage.error('执行失败');
console.error('执行失败:', error);
@@ -297,7 +290,7 @@ const handleDelete = (row: CronJob) => {
try {
await request.delete(`/Cube/CronJob?id=${row.id}`);
ElMessage.success('删除成功');
- fetchData(searchForm);
+ fetchData();
} catch (error) {
ElMessage.error('删除失败');
console.error('删除失败:', error);
@@ -338,7 +331,7 @@ const submitForm = () => {
ElMessage.success('更新成功');
}
dialogVisible.value = false;
- fetchData(searchForm);
+ fetchData();
} catch (error) {
ElMessage.error(`${formType.value === 'add' ? '新增' : '更新'}失败`);
console.error('操作失败:', error);
@@ -347,7 +340,6 @@ const submitForm = () => {
});
};
-// 初始化
onMounted(() => {
fetchData();
});
diff --git a/apps/cube-cube/src/pages/cube/order-manager/index.vue b/apps/cube-cube/src/pages/cube/order-manager/index.vue
index da370bf..f9fe8b4 100644
--- a/apps/cube-cube/src/pages/cube/order-manager/index.vue
+++ b/apps/cube-cube/src/pages/cube/order-manager/index.vue
@@ -11,34 +11,11 @@
</div>
</template>
- <el-form :inline="true" :model="searchForm" class="search-form">
- <el-form-item label="订单编号">
- <el-input v-model="searchForm.q" placeholder="请输入订单编号" clearable />
- </el-form-item>
- <el-form-item label="状态">
- <el-select v-model="searchForm.status" placeholder="请选择状态" clearable>
- <el-option label="待处理" :value="0" />
- <el-option label="处理中" :value="1" />
- <el-option label="已完成" :value="2" />
- <el-option label="已取消" :value="3" />
- </el-select>
- </el-form-item>
- <el-form-item label="日期范围">
- <el-date-picker
- v-model="searchForm.dateRange"
- type="datetimerange"
- range-separator="至"
- start-placeholder="开始日期"
- end-placeholder="结束日期"
- format="YYYY-MM-DD HH:mm:ss"
- value-format="YYYY-MM-DDTHH:mm:ss"
- />
- </el-form-item>
- <el-form-item>
- <el-button type="primary" @click="handleSearch">查询</el-button>
- <el-button @click="resetSearch">重置</el-button>
- </el-form-item>
- </el-form>
+ <CubeListToolbarSearch
+ :on-search="SearchData"
+ :on-reset="ResetData"
+ :on-callback="callback"
+ />
<el-table
:data="tableData"
@@ -71,17 +48,14 @@
</el-table-column>
</el-table>
- <div class="pagination">
- <el-pagination
- v-model:current-page="currentPage"
- v-model:page-size="pageSize"
- :page-sizes="[10, 20, 50, 100]"
- :total="total"
- layout="total, sizes, prev, pager, next, jumper"
- @size-change="handleSizeChange"
- @current-change="handleCurrentChange"
- />
- </div>
+ <CubeListPager
+ :total="queryParams.total"
+ :current-page="queryParams.pageIndex"
+ :page-size="queryParams.pageSize"
+ :on-current-change="CurrentPageChange"
+ :on-size-change="PageSizeChange"
+ :on-callback="callback"
+ />
</el-card>
<!-- 订单表单对话框 -->
@@ -147,15 +121,19 @@
</template>
<script setup lang="ts">
+
import { ref, reactive, onMounted } from 'vue';
import { ElMessage, ElMessageBox } from 'element-plus';
import type { FormInstance, FormRules } from 'element-plus';
import { request } from '@core/utils/request';
-import { processListResponse } from '@core/utils/api-helpers';
-
-// 定义订单类型接口
-interface OrderManager {
- id: number;
+import { apiDataToList } from '@core/utils/api-helpers';
+import CubeListToolbarSearch from '@core/components/CubeListToolbarSearch.vue';
+import CubeListPager from '@core/components/CubeListPager.vue';
+import { pageInfoDefault } from '@core/types/common';
+import type { BaseEntity } from '@core/types/common';
+
+// 订单类型接口,继承 BaseEntity
+interface OrderManager extends BaseEntity {
code: string;
name: string;
amount: number;
@@ -164,8 +142,6 @@ interface OrderManager {
customerPhone: string;
customerAddress: string;
remark: string;
- createTime: string;
- updateTime: string;
createUser: string;
updateUser: string;
}
@@ -176,18 +152,14 @@ const dialogVisible = ref(false);
const infoDialogVisible = ref(false);
const formType = ref<'add' | 'edit'>('add');
const formRef = ref<FormInstance | null>(null);
-const total = ref(0);
const tableData = ref<OrderManager[]>([]);
-// 分页变量
-const currentPage = ref(1);
-const pageSize = ref(10);
-
-// 搜索表单
-const searchForm = reactive({
+// 分页与搜索参数
+const queryParams = reactive({
q: '',
status: undefined as number | undefined,
dateRange: [] as [string, string] | [],
+ ...pageInfoDefault
});
// 订单表单
@@ -240,68 +212,55 @@ const getStatusText = (status: number) => {
return texts[status] || '未知';
};
+
+// 组件回调函数
+const callback = (e?: Record<string, unknown>) => {
+ Object.assign(queryParams, e?.params || {});
+ loadData();
+};
+
// 加载数据
const loadData = async () => {
loading.value = true;
try {
- interface QueryParams {
- q?: string;
- pageSize: number;
- pageIndex: number;
- startTime?: string;
- endTime?: string;
- }
-
- const params: QueryParams = {
- q: searchForm.q,
- pageSize: pageSize.value,
- pageIndex: currentPage.value,
- };
-
- // 处理日期范围
- if (searchForm.dateRange && searchForm.dateRange.length === 2) {
- params.startTime = searchForm.dateRange[0];
- params.endTime = searchForm.dateRange[1];
+ const params: Record<string, unknown> = { ...queryParams };
+ if (queryParams.dateRange && queryParams.dateRange.length === 2) {
+ params.startTime = queryParams.dateRange[0];
+ params.endTime = queryParams.dateRange[1];
}
-
const response = await request.get('/Cube/OrderManager', { params });
- const { list, total: totalCount } = processListResponse<OrderManager>(response);
-
+ const { list, page } = apiDataToList<OrderManager>(response);
tableData.value = list;
- total.value = totalCount;
+ queryParams.total = page?.totalCount || list.length;
} catch (error) {
ElMessage.error('加载数据失败');
console.error('加载数据失败:', error);
tableData.value = [];
- total.value = 0;
+ queryParams.total = 0;
} finally {
loading.value = false;
}
};
-// 搜索
-const handleSearch = () => {
- currentPage.value = 1;
- loadData();
+// 搜索按钮点击事件
+const SearchData = (e?: Record<string, unknown>) => {
+ Object.assign(queryParams, { pageIndex: 1 }, e || {});
};
-// 重置搜索
-const resetSearch = () => {
- searchForm.q = '';
- searchForm.status = undefined;
- searchForm.dateRange = [];
- currentPage.value = 1;
- loadData();
+// 重置按钮点击事件
+const ResetData = (e?: Record<string, unknown>) => {
+ Object.assign(queryParams, { q: '', status: undefined, dateRange: [], pageIndex: 1 }, e || {});
};
-// 分页处理
-const handleCurrentChange = () => {
- loadData();
+// 页码变更处理
+const CurrentPageChange = (page: number) => {
+ queryParams.pageIndex = page;
};
-const handleSizeChange = () => {
- currentPage.value = 1;
- loadData();
+// 每页显示条数变更处理
+const PageSizeChange = (size: number) => {
+ queryParams.pageSize = size;
+ queryParams.pageIndex = 1;
};
// 查询订单信息
diff --git a/apps/cube-cube/src/pages/cube/principal-agent/index.vue b/apps/cube-cube/src/pages/cube/principal-agent/index.vue
index 2a12311..a66aeaf 100644
--- a/apps/cube-cube/src/pages/cube/principal-agent/index.vue
+++ b/apps/cube-cube/src/pages/cube/principal-agent/index.vue
@@ -11,7 +11,7 @@
<CubeListToolbarSearch
:on-search="SearchData"
:on-reset="ResetData"
- :on-callback="fetchData"
+ :on-callback="callback"
/>
<el-table
@@ -42,12 +42,12 @@
</el-table>
<CubeListPager
- :total="total"
- :current-page="currentPage"
- :page-size="pageSize"
+ :total="queryParams.total"
+ :current-page="queryParams.pageIndex"
+ :page-size="queryParams.pageSize"
:on-current-change="CurrentPageChange"
:on-size-change="PageSizeChange"
- :on-callback="fetchData"
+ :on-callback="callback"
/>
</el-card>
@@ -102,17 +102,14 @@
</template>
<script setup lang="ts">
-import { ref, reactive, onMounted } from 'vue';
-import { ElMessage, ElMessageBox } from 'element-plus';
-import type { FormInstance, FormRules } from 'element-plus';
+
+import { pageInfoDefault, type BaseEntity } from '@core/types/common';
+import { handleDeleteOperation, handleFormSubmit, apiDataToList } from '@core/utils/api-helpers';
import { request } from '@core/utils/request';
-import { processListResponse } from '@core/utils/api-helpers';
-import CubeListToolbarSearch from '@core/components/CubeListToolbarSearch.vue';
-import CubeListPager from '@core/components/CubeListPager.vue';
+import type { FormInstance, FormRules } from 'element-plus';
-// 定义主体代理类型接口
-interface PrincipalAgent {
- id: number;
+// 定义主体代理类型接口,继承 BaseEntity
+interface PrincipalAgent extends BaseEntity {
name: string;
displayName: string;
type: string;
@@ -122,28 +119,20 @@ interface PrincipalAgent {
contactEmail: string;
address: string;
enable: boolean;
- remark: string;
- createTime: string;
- updateTime: string;
- createUser: string;
- updateUser: string;
}
+
// 响应式数据
const loading = ref(false);
const dialogVisible = ref(false);
const formType = ref<'add' | 'edit'>('add');
const formRef = ref<FormInstance | null>(null);
-const total = ref(0);
const tableData = ref<PrincipalAgent[]>([]);
-// 分页变量
-const currentPage = ref(1);
-const pageSize = ref(10);
-
-// 搜索表单
-const searchForm = reactive({
- p: '',
+// 分页与搜索参数
+const queryParams = reactive({
+ q: '',
+ ...pageInfoDefault
});
// 代理表单
@@ -180,56 +169,51 @@ const formRules = reactive<FormRules>({
]
});
+// 统一回调
+const callback = (e?: Record<string, unknown>) => {
+ Object.assign(queryParams, e?.params || {});
+ loadData();
+};
+
// 加载数据
-const fetchData = async (searchData?: { p: string }) => {
+const loadData = async () => {
loading.value = true;
try {
- // 如果传入了搜索数据,则更新本地搜索条件
- if (searchData !== undefined) {
- searchForm.p = searchData.p;
- }
-
const response = await request.get('/Cube/PrincipalAgent', {
- params: {
- q: searchForm.p,
- pageIndex: currentPage.value,
- pageSize: pageSize.value,
- }
+ params: queryParams
});
-
- const { list, total: totalCount } = processListResponse<PrincipalAgent>(response);
+ const { list, page } = apiDataToList<PrincipalAgent>(response);
tableData.value = list;
- total.value = totalCount;
- } catch (error) {
- ElMessage.error('加载数据失败');
- console.error('加载数据失败:', error);
+ queryParams.total = page?.totalCount || list.length;
+ } catch {
tableData.value = [];
- total.value = 0;
+ queryParams.total = 0;
} finally {
loading.value = false;
}
};
-// 搜索回调
-const SearchData = () => {
- currentPage.value = 1;
+// 搜索按钮点击事件
+const SearchData = (e?: Record<string, unknown>) => {
+ Object.assign(queryParams, { pageIndex: 1 }, e || {});
};
-// 重置回调
-const ResetData = () => {
- currentPage.value = 1;
+// 重置按钮点击事件
+const ResetData = (e?: Record<string, unknown>) => {
+ Object.assign(queryParams, { pageIndex: 1 }, e || {});
};
// 分页回调
const CurrentPageChange = (page: number) => {
- currentPage.value = page;
+ queryParams.pageIndex = page;
};
const PageSizeChange = (size: number) => {
- pageSize.value = size;
- currentPage.value = 1;
+ queryParams.pageSize = size;
+ queryParams.pageIndex = 1;
};
+
// 新增
const handleAdd = () => {
formType.value = 'add';
@@ -246,26 +230,14 @@ const handleEdit = (row: PrincipalAgent) => {
// 删除
const handleDelete = (row: PrincipalAgent) => {
- ElMessageBox.confirm(
- `确定要删除代理"${row.displayName || row.name}"吗?`,
- '确认删除',
- {
- confirmButtonText: '确定',
- cancelButtonText: '取消',
- type: 'warning',
- }
- ).then(async () => {
- try {
- await request.delete(`/Cube/PrincipalAgent?id=${row.id}`);
- ElMessage.success('删除成功');
- fetchData();
- } catch (error) {
- ElMessage.error('删除失败');
- console.error('删除失败:', error);
- }
- });
+ handleDeleteOperation(
+ () => request.delete(`/Cube/PrincipalAgent?id=${row.id}`),
+ () => callback(),
+ `确定要删除代理"${row.displayName || row.name}"吗?`
+ );
};
+
// 重置表单
const resetForm = () => {
Object.assign(form, {
@@ -284,33 +256,24 @@ const resetForm = () => {
formRef.value?.clearValidate();
};
+
// 提交表单
const submitForm = () => {
- if (!formRef.value) return;
-
- formRef.value.validate(async (valid: boolean) => {
- if (valid) {
- try {
- if (formType.value === 'add') {
- await request.post('/Cube/PrincipalAgent', form);
- ElMessage.success('新增成功');
- } else {
- await request.put('/Cube/PrincipalAgent', form);
- ElMessage.success('更新成功');
- }
- dialogVisible.value = false;
- fetchData();
- } catch (error) {
- ElMessage.error(`${formType.value === 'add' ? '新增' : '更新'}失败`);
- console.error('操作失败:', error);
- }
+ handleFormSubmit(
+ formRef.value,
+ () => formType.value === 'add'
+ ? request.post('/Cube/PrincipalAgent', form)
+ : request.put('/Cube/PrincipalAgent', form),
+ () => {
+ dialogVisible.value = false;
+ callback();
}
- });
+ );
};
// 初始化
onMounted(() => {
- fetchData();
+ loadData();
});
</script>
diff --git a/auto-imports.d.ts b/auto-imports.d.ts
index 03983a3..6a26f7c 100644
--- a/auto-imports.d.ts
+++ b/auto-imports.d.ts
@@ -7,6 +7,7 @@
export {}
declare global {
const EffectScope: typeof import('vue')['EffectScope']
+ const ElMessageBox: typeof import('element-plus/es')['ElMessageBox']
const computed: typeof import('vue')['computed']
const createApp: typeof import('vue')['createApp']
const customRef: typeof import('vue')['customRef']
diff --git a/core/components/CubeListPager.vue b/core/components/CubeListPager.vue
index a263efc..fbf5aaf 100644
--- a/core/components/CubeListPager.vue
+++ b/core/components/CubeListPager.vue
@@ -22,7 +22,7 @@ defineOptions({
// 定义组件 props
interface Props {
- total: number;
+ total?: number;
currentPage?: number;
pageSize?: number;
pageSizes?: number[];