fix(daily): opt
This commit is contained in:
112
components/label/OptStore.tsx
Normal file
112
components/label/OptStore.tsx
Normal file
@@ -0,0 +1,112 @@
|
||||
"use client"
|
||||
import { usePathname } from "next/navigation"
|
||||
import { useEffect } from "react"
|
||||
import { getProjectAdminList } from "./api/project"
|
||||
import { getUserAll, getUserGroupTree } from "./api/user"
|
||||
import {
|
||||
useAllTaskStore,
|
||||
useAllUserStore,
|
||||
usePermissionStore,
|
||||
} from "./store/auth"
|
||||
|
||||
export function OptStore() {
|
||||
// const detectEnvironment = async () => {
|
||||
// try {
|
||||
// const result = await getName()
|
||||
// console.log("Running in Tauri environment", result)
|
||||
// return true
|
||||
// } catch {
|
||||
// console.log("Not running in Tauri environment")
|
||||
// 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()
|
||||
}
|
||||
}, [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 <></>
|
||||
}
|
||||
98
components/label/api/user/index.ts
Normal file
98
components/label/api/user/index.ts
Normal file
@@ -0,0 +1,98 @@
|
||||
import httpFetch from "@/api/fetch"
|
||||
import { BASE_LABEL_API } from "../const"
|
||||
import { Organization, User } from "./typing"
|
||||
|
||||
// 获取用户列表
|
||||
export const getUserList = (data: User.ListRequest) => {
|
||||
return httpFetch<User.ListResponse>({
|
||||
url: BASE_LABEL_API + "/api/v1/label_server/user/list",
|
||||
method: "POST",
|
||||
body: JSON.stringify({ ...data, tenant: "cowarobot" }),
|
||||
})
|
||||
}
|
||||
|
||||
// 新增用户
|
||||
export const userAdd = (data: User.CreateProps) => {
|
||||
return httpFetch({
|
||||
url: BASE_LABEL_API + "/api/v1/label_server/user/add",
|
||||
method: "POST",
|
||||
body: JSON.stringify(data),
|
||||
})
|
||||
}
|
||||
|
||||
// 批量导入用户
|
||||
export const userImport = (data: { user_infos: any[] }) => {
|
||||
return httpFetch<string[]>({
|
||||
url: BASE_LABEL_API + "/api/v1/label_server/user/batch_add",
|
||||
method: "POST",
|
||||
body: JSON.stringify(data),
|
||||
})
|
||||
}
|
||||
|
||||
// 编辑用户
|
||||
export const userEditById = (data: User.EditProps, id: number) => {
|
||||
return httpFetch({
|
||||
url: BASE_LABEL_API + `/api/v1/label_server/user/edit/${id}`,
|
||||
method: "PUT",
|
||||
body: JSON.stringify(data),
|
||||
})
|
||||
}
|
||||
|
||||
// 编辑用户组织
|
||||
export const userUpdateGroup = (data: User.UpdateGroupProps) => {
|
||||
return httpFetch({
|
||||
url: BASE_LABEL_API + `/api/v1/label_server/user/update/group`,
|
||||
method: "POST",
|
||||
body: JSON.stringify(data),
|
||||
})
|
||||
}
|
||||
|
||||
// 获取用户组织树
|
||||
export const getUserGroupTree = () => {
|
||||
return httpFetch<Organization.Response[]>({
|
||||
url: BASE_LABEL_API + "/api/v1/label_server/user/group/tree",
|
||||
method: "GET",
|
||||
})
|
||||
}
|
||||
|
||||
// 新增用户组
|
||||
export const userGroupAdd = (data: Organization.CreateProps) => {
|
||||
return httpFetch({
|
||||
url: BASE_LABEL_API + "/api/v1/label_server/user/group/add",
|
||||
method: "POST",
|
||||
body: JSON.stringify(data),
|
||||
})
|
||||
}
|
||||
|
||||
// 修改用户密码
|
||||
export const modifyUserPassword = (data: {
|
||||
old_password: string
|
||||
new_password: string
|
||||
}) => {
|
||||
return httpFetch({
|
||||
url: BASE_LABEL_API + "/api/v1/label_server/user/modify_password",
|
||||
method: "PUT",
|
||||
body: JSON.stringify(data),
|
||||
})
|
||||
}
|
||||
|
||||
/* ****************************** 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",
|
||||
})
|
||||
}
|
||||
76
components/label/api/user/typing.ts
Normal file
76
components/label/api/user/typing.ts
Normal file
@@ -0,0 +1,76 @@
|
||||
export namespace User {
|
||||
export interface UserInfo {
|
||||
uid: number
|
||||
name: string
|
||||
all_projects: { [x: number]: number[] }
|
||||
collect_projects: number[]
|
||||
group_name: string
|
||||
group_uuid: string
|
||||
work_status: number
|
||||
base_city: string
|
||||
}
|
||||
|
||||
export interface LoginInfo extends UserInfo {
|
||||
token: string
|
||||
refresh_token: string
|
||||
}
|
||||
|
||||
export interface ListRequest {
|
||||
name?: string
|
||||
page_number?: number
|
||||
page_size?: number
|
||||
}
|
||||
|
||||
export interface ListResponse {
|
||||
user_list: UserInfo[]
|
||||
total_pages: number
|
||||
total_items: number
|
||||
}
|
||||
|
||||
export interface CreateProps {
|
||||
user_name: string
|
||||
group_uuid: string
|
||||
base_city: string
|
||||
}
|
||||
|
||||
export interface EditProps {
|
||||
user_name?: string
|
||||
password?: string
|
||||
group_uuid?: string
|
||||
base_city?: string
|
||||
work_status?: number
|
||||
}
|
||||
|
||||
export interface UpdateGroupProps {
|
||||
user_id: number
|
||||
group_uuid: string
|
||||
}
|
||||
}
|
||||
|
||||
export namespace Organization {
|
||||
export interface CreateProps {
|
||||
group_name: string
|
||||
leader_uid: number
|
||||
parent_group_uuid: string
|
||||
}
|
||||
|
||||
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