diff --git a/app/layout.tsx b/app/layout.tsx index d415e34..89ec239 100644 --- a/app/layout.tsx +++ b/app/layout.tsx @@ -18,6 +18,7 @@ import { Notifications } from "@mantine/notifications" import { Suspense } from "react" import "./globals.css" import { theme } from "./theme" +import { OptStore } from "@/components/label/OptStore" export default function RootLayout({ children, @@ -56,6 +57,7 @@ export default function RootLayout({ + }>{children} diff --git a/app/management/person/collection/detail/components/AdminUserModal.tsx b/app/management/person/collection/detail/components/AdminUserModal.tsx index f18eee0..6c39f0d 100644 --- a/app/management/person/collection/detail/components/AdminUserModal.tsx +++ b/app/management/person/collection/detail/components/AdminUserModal.tsx @@ -20,7 +20,8 @@ export default function AdminUserModal(props: { if (!opened) return form.setValues({ users: value.map(String) }) form.resetDirty() - }, [opened, value, form]) + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [opened, value]) return ( { + try { + const result = await getName() + console.log("Running in Tauri environment", result) + return true + } catch (error) { + console.log("Not running in Tauri environment", error) + return false + } + } + const user_id = usePermissionStore.getState().user_id + const { needUpdate, setUserOpts, setTreeData, setAdminOpts, setFlag } = + useAllUserStore() + const pathname = usePathname() + + useEffect(() => { + if (user_id) { + const getData = async () => { + const res = await getUserAll() + setUserOpts(res) + const gRes = await getUserGroupTree() + const getTreeData = (data: any, parentHasDisabledChild = false) => { + let hasDisabledChild = parentHasDisabledChild + + const newData: any = { + title: data.name, + value: data.id, + key: data.id, + children: [], + disabled: false, + } + + if (data.members && data.members.length) { + data.members.forEach((member: any) => { + newData.children.push({ + title: member.name, + value: member.id, + key: member.id, + }) + }) + } + + if (data.children && data.children.length) { + data.children.forEach((child: any) => { + const childData = getTreeData(child, hasDisabledChild) + newData.children.push(childData) + if (childData.disabled) { + hasDisabledChild = true + } + }) + } + if ( + data.id.includes("-") && + (!data.members || !data.members.length) && + (!data.children || !data.children.length || hasDisabledChild) + ) { + newData.disabled = true + } + + return newData + } + let arr: any[] = [] + gRes.forEach((g: any) => { + arr.push(getTreeData(g)) + }) + const aRes = await getProjectAdminList() + setAdminOpts(aRes) + setTreeData(arr) + setFlag(false) + } + if (needUpdate) getData() + } + }, [user_id, setTreeData, setUserOpts, needUpdate, setFlag, setAdminOpts]) + + // 全局监听 重置项目详情中任务列表搜索缓存 + useEffect(() => { + if (pathname !== "/project/info/detail" && pathname !== "/label") { + useAllTaskStore.getState().resetParams() + useOwnTaskStore.getState().resetParams() + } + }, [pathname]) + + // tauri://close-requested + useEffect(() => { + ;(async () => { + if (await detectEnvironment()) { + const window = getCurrentWindow() + const unlisten = await window.onCloseRequested(async (_event) => { + usePermissionStore.getState().logout() + // event.preventDefault(); + }) + + return () => { + unlisten() + } + } + })() + }, []) + + return <> +} diff --git a/components/label/api/user/index.ts b/components/label/api/user/index.ts new file mode 100644 index 0000000..f1a1467 --- /dev/null +++ b/components/label/api/user/index.ts @@ -0,0 +1,32 @@ +import httpFetch from "@/api/fetch" +import { BASE_LABEL_API } from "../const" +import { Organization } from "./typing" + +// 获取用户组织树 +export const getUserGroupTree = () => { + return httpFetch({ + url: "/api/v1/label_server/user/group/tree", + method: "GET", + }) +} + +/* ****************************** Options ****************************** */ +interface Option { + label: string + value: string +} +// 获取所有用户组 +export const getUserGroupAll = () => { + return httpFetch>({ + url: BASE_LABEL_API + `/api/v1/label_server/user/group/all`, + method: "GET", + }) +} + +// 获取所有用户 +export const getUserAll = () => { + return httpFetch>({ + url: BASE_LABEL_API + "/api/v1/label_server/user/all", + method: "GET", + }) +} diff --git a/components/label/api/user/typing.ts b/components/label/api/user/typing.ts new file mode 100644 index 0000000..23ca1c3 --- /dev/null +++ b/components/label/api/user/typing.ts @@ -0,0 +1,21 @@ +export namespace Organization { + interface Member { + base_city: string + id: number + name: string + work_status: number + } + + export interface Response { + children?: Response[] + create_at?: string + create_user?: string + group_uuid: string + leader_uid?: number + leader_name?: string + members?: Member[] + name: string + parent_group_uuid: string + [key: string]: boolean | string | number | Response[] | Member[] | undefined + } +}