fix(layout): add OptStore
This commit is contained in:
@@ -18,6 +18,7 @@ import { Notifications } from "@mantine/notifications"
|
|||||||
import { Suspense } from "react"
|
import { Suspense } from "react"
|
||||||
import "./globals.css"
|
import "./globals.css"
|
||||||
import { theme } from "./theme"
|
import { theme } from "./theme"
|
||||||
|
import { OptStore } from "@/components/label/OptStore"
|
||||||
|
|
||||||
export default function RootLayout({
|
export default function RootLayout({
|
||||||
children,
|
children,
|
||||||
@@ -56,6 +57,7 @@ export default function RootLayout({
|
|||||||
<MantineProvider defaultColorScheme="auto" theme={theme}>
|
<MantineProvider defaultColorScheme="auto" theme={theme}>
|
||||||
<Notifications />
|
<Notifications />
|
||||||
<InfoCheck />
|
<InfoCheck />
|
||||||
|
<OptStore />
|
||||||
<ModalsProvider>
|
<ModalsProvider>
|
||||||
<Suspense fallback={<></>}>{children}</Suspense>
|
<Suspense fallback={<></>}>{children}</Suspense>
|
||||||
</ModalsProvider>
|
</ModalsProvider>
|
||||||
|
|||||||
@@ -20,7 +20,8 @@ export default function AdminUserModal(props: {
|
|||||||
if (!opened) return
|
if (!opened) return
|
||||||
form.setValues({ users: value.map(String) })
|
form.setValues({ users: value.map(String) })
|
||||||
form.resetDirty()
|
form.resetDirty()
|
||||||
}, [opened, value, form])
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
|
}, [opened, value])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Modal
|
<Modal
|
||||||
|
|||||||
@@ -21,7 +21,8 @@ export default function StageUserModal(props: {
|
|||||||
if (!opened) return
|
if (!opened) return
|
||||||
form.setValues({ users: value.map(String) })
|
form.setValues({ users: value.map(String) })
|
||||||
form.resetDirty()
|
form.resetDirty()
|
||||||
}, [opened, value, form])
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
|
}, [opened, value])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Modal
|
<Modal
|
||||||
|
|||||||
116
components/label/OptStore.tsx
Normal file
116
components/label/OptStore.tsx
Normal file
@@ -0,0 +1,116 @@
|
|||||||
|
"use client"
|
||||||
|
import { getName } from "@tauri-apps/api/app"
|
||||||
|
import { getCurrentWindow } from "@tauri-apps/api/window"
|
||||||
|
import { useEffect } from "react"
|
||||||
|
import {
|
||||||
|
useAllTaskStore,
|
||||||
|
useAllUserStore,
|
||||||
|
useOwnTaskStore,
|
||||||
|
usePermissionStore,
|
||||||
|
} from "./store/auth"
|
||||||
|
import { getUserAll, getUserGroupTree } from "./api/user"
|
||||||
|
import { usePathname } from "next/navigation"
|
||||||
|
import { getProjectAdminList } from "./api/project"
|
||||||
|
|
||||||
|
export function OptStore() {
|
||||||
|
const detectEnvironment = async () => {
|
||||||
|
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 <></>
|
||||||
|
}
|
||||||
32
components/label/api/user/index.ts
Normal file
32
components/label/api/user/index.ts
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
import httpFetch from "@/api/fetch"
|
||||||
|
import { BASE_LABEL_API } from "../const"
|
||||||
|
import { Organization } from "./typing"
|
||||||
|
|
||||||
|
// 获取用户组织树
|
||||||
|
export const getUserGroupTree = () => {
|
||||||
|
return httpFetch<Organization.Response[]>({
|
||||||
|
url: "/api/v1/label_server/user/group/tree",
|
||||||
|
method: "GET",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ****************************** Options ****************************** */
|
||||||
|
interface Option {
|
||||||
|
label: string
|
||||||
|
value: string
|
||||||
|
}
|
||||||
|
// 获取所有用户组
|
||||||
|
export const getUserGroupAll = () => {
|
||||||
|
return httpFetch<Array<Option>>({
|
||||||
|
url: BASE_LABEL_API + `/api/v1/label_server/user/group/all`,
|
||||||
|
method: "GET",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取所有用户
|
||||||
|
export const getUserAll = () => {
|
||||||
|
return httpFetch<Array<Option>>({
|
||||||
|
url: BASE_LABEL_API + "/api/v1/label_server/user/all",
|
||||||
|
method: "GET",
|
||||||
|
})
|
||||||
|
}
|
||||||
21
components/label/api/user/typing.ts
Normal file
21
components/label/api/user/typing.ts
Normal file
@@ -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
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user