feat(user): 同步飞书用户功能
Some checks failed
Lint Code / Lint Code (push) Failing after 14m14s

- 新增 syncFeishuUsers API 用于同步飞书用户数据
- 用户列表页面添加“同步飞书用户”按钮及加载状态
- useUser hook 中实现同步飞书用户逻辑,支持按钮触发同步
- 分页处理逻辑调整,保证切换页码和页面大小均触发查询
- usePermission hook 中替换旧接口 getPermissionTree 为分页查询的 getPermissionList
- 权限列表分页数据更新,更准确处理总数、当前页和页面大小
This commit is contained in:
2026-03-28 11:46:29 +08:00
parent b8cb28589d
commit 39fa3a6370
4 changed files with 58 additions and 14 deletions

View File

@@ -51,3 +51,12 @@ export const getFeishuUserInfo = () => {
message: string; message: string;
}>("get", "/api/v1/auth/feishu/user/info"); }>("get", "/api/v1/auth/feishu/user/info");
}; };
/** 同步飞书用户 */
export const syncFeishuUsers = () => {
return http.request<{
code: number;
data: Record<string, any>;
message: string;
}>("post", "/api/v1/feishu/sync/users");
};

View File

@@ -4,7 +4,7 @@ import { addDialog } from "@/components/ReDialog";
import type { PaginationProps } from "@pureadmin/table"; import type { PaginationProps } from "@pureadmin/table";
import type { FormItemProps } from "./types"; import type { FormItemProps } from "./types";
import editForm from "../form/index.vue"; import editForm from "../form/index.vue";
import { getPermissionTree } from "@/api/system"; import { getPermissionList } from "@/api/system";
import { type Ref, h, ref, computed, reactive, onMounted } from "vue"; import { type Ref, h, ref, computed, reactive, onMounted } from "vue";
import { getKeyList, deviceDetection } from "@pureadmin/utils"; import { getKeyList, deviceDetection } from "@pureadmin/utils";
import { ElMessageBox } from "element-plus"; import { ElMessageBox } from "element-plus";
@@ -161,11 +161,13 @@ export function usePermission(tableRef: Ref) {
} }
function handleSizeChange(val: number) { function handleSizeChange(val: number) {
console.log(`${val} items per page`); pagination.pageSize = val;
onSearch();
} }
function handleCurrentChange(val: number) { function handleCurrentChange(val: number) {
console.log(`current page: ${val}`); pagination.currentPage = val;
onSearch();
} }
function handleSelectionChange(val) { function handleSelectionChange(val) {
@@ -190,10 +192,16 @@ export function usePermission(tableRef: Ref) {
async function onSearch() { async function onSearch() {
loading.value = true; loading.value = true;
try { try {
const { code, data } = await getPermissionTree(); const { code, data } = await getPermissionList({
pageNum: pagination.currentPage,
pageSize: pagination.pageSize,
keyword: form.permissionName || form.permissionCode || undefined
});
if (code === 200) { if (code === 200) {
dataList.value = data || []; dataList.value = data?.records || [];
pagination.total = data?.length || 0; pagination.total = data?.total || 0;
pagination.pageSize = data?.size || 10;
pagination.currentPage = data?.current || 1;
} }
} catch (error) { } catch (error) {
console.error(error); console.error(error);

View File

@@ -11,7 +11,7 @@ import More from "~icons/ep/more-filled";
import Delete from "~icons/ep/delete"; import Delete from "~icons/ep/delete";
import EditPen from "~icons/ep/edit-pen"; import EditPen from "~icons/ep/edit-pen";
import Refresh from "~icons/ep/refresh"; import Refresh from "~icons/ep/refresh";
import AddFill from "~icons/ri/add-circle-line"; import Sync from "~icons/ri/refresh-line";
defineOptions({ defineOptions({
name: "SystemUser" name: "SystemUser"
@@ -41,7 +41,9 @@ const {
handleSizeChange, handleSizeChange,
onSelectionCancel, onSelectionCancel,
handleCurrentChange, handleCurrentChange,
handleSelectionChange handleSelectionChange,
syncLoading,
handleSyncFeishuUsers
} = useUser(tableRef); } = useUser(tableRef);
</script> </script>
@@ -103,10 +105,11 @@ const {
<template #buttons> <template #buttons>
<el-button <el-button
type="primary" type="primary"
:icon="useRenderIcon(AddFill)" :icon="useRenderIcon(Sync)"
@click="openDialog()" :loading="syncLoading"
@click="handleSyncFeishuUsers"
> >
新增用户 同步飞书用户
</el-button> </el-button>
</template> </template>
<template v-slot="{ size, dynamicColumns }"> <template v-slot="{ size, dynamicColumns }">

View File

@@ -17,6 +17,7 @@ import {
deviceDetection deviceDetection
} from "@pureadmin/utils"; } from "@pureadmin/utils";
import { getUserRoleIds, getUserList, getAllRoleList } from "@/api/system"; import { getUserRoleIds, getUserList, getAllRoleList } from "@/api/system";
import { syncFeishuUsers } from "@/api/feishu";
import { import {
ElForm, ElForm,
ElInput, ElInput,
@@ -213,11 +214,13 @@ export function useUser(tableRef: Ref) {
} }
function handleSizeChange(val: number) { function handleSizeChange(val: number) {
console.log(`${val} items per page`); pagination.pageSize = val;
onSearch();
} }
function handleCurrentChange(val: number) { function handleCurrentChange(val: number) {
console.log(`current page: ${val}`); pagination.currentPage = val;
onSearch();
} }
/** 当CheckBox选择项发生变化时会触发该事件 */ /** 当CheckBox选择项发生变化时会触发该事件 */
@@ -453,6 +456,25 @@ export function useUser(tableRef: Ref) {
}); });
} }
/** 同步飞书用户 */
const syncLoading = ref(false);
async function handleSyncFeishuUsers() {
syncLoading.value = true;
try {
const { code, message: msg } = await syncFeishuUsers();
if (code === 200) {
message("同步飞书用户成功", { type: "success" });
onSearch();
} else {
message(msg || "同步失败", { type: "error" });
}
} catch {
message("同步飞书用户失败", { type: "error" });
} finally {
syncLoading.value = false;
}
}
onMounted(async () => { onMounted(async () => {
onSearch(); onSearch();
// 角色列表 // 角色列表
@@ -480,6 +502,8 @@ export function useUser(tableRef: Ref) {
handleSizeChange, handleSizeChange,
onSelectionCancel, onSelectionCancel,
handleCurrentChange, handleCurrentChange,
handleSelectionChange handleSelectionChange,
syncLoading,
handleSyncFeishuUsers
}; };
} }