86 行
3.8 KiB
TypeScript
86 行
3.8 KiB
TypeScript
import { useMutation, useQuery } from "@tanstack/react-query";
|
|
import { useSearchParams } from "react-router-dom";
|
|
import { fetchWecomConfig, startWecomBind, unbindWecom } from "../api/auth";
|
|
import { PageHeader } from "../components/common/PageHeader";
|
|
import { useAuth } from "../auth/AuthContext";
|
|
import { Button } from "../components/ui/button";
|
|
|
|
export function ProfilePage() {
|
|
const { me, permissions } = useAuth();
|
|
const [searchParams] = useSearchParams();
|
|
const wecomConfigQuery = useQuery({ queryKey: ["auth", "wecom-config"], queryFn: () => fetchWecomConfig(), staleTime: 60_000 });
|
|
const bindMutation = useMutation({
|
|
mutationFn: async () => startWecomBind("/settings/profile"),
|
|
onSuccess: (payload) => { window.location.assign(payload.loginUrl); },
|
|
});
|
|
const unbindMutation = useMutation({
|
|
mutationFn: () => unbindWecom(),
|
|
onSuccess: () => { window.location.reload(); },
|
|
});
|
|
|
|
return (
|
|
<div>
|
|
<PageHeader title="个人设置" subtitle="展示当前登录人的基础信息与权限摘要。" />
|
|
|
|
<section className="card-std">
|
|
<h3 className="card-title">个人信息</h3>
|
|
<dl className="grid gap-3 text-sm text-zinc-700 md:grid-cols-2">
|
|
<div>
|
|
<dt className="text-secondary">姓名</dt>
|
|
<dd className="font-medium text-zinc-900">{me?.name ?? "-"}</dd>
|
|
</div>
|
|
<div>
|
|
<dt className="text-secondary">员工号</dt>
|
|
<dd className="font-medium text-zinc-900">{me?.employeeNo ?? "-"}</dd>
|
|
</div>
|
|
<div>
|
|
<dt className="text-secondary">邮箱</dt>
|
|
<dd className="font-medium text-zinc-900">{me?.email ?? "-"}</dd>
|
|
</div>
|
|
<div>
|
|
<dt className="text-secondary">手机号</dt>
|
|
<dd className="font-medium text-zinc-900">{me?.phone ?? "-"}</dd>
|
|
</div>
|
|
<div>
|
|
<dt className="text-secondary">部门ID</dt>
|
|
<dd className="font-medium text-zinc-900">{me?.departmentId ?? "-"}</dd>
|
|
</div>
|
|
<div>
|
|
<dt className="text-secondary">直属上级ID</dt>
|
|
<dd className="font-medium text-zinc-900">{me?.directManagerId ?? "-"}</dd>
|
|
</div>
|
|
</dl>
|
|
</section>
|
|
|
|
<section className="card-std mt-4">
|
|
<h3 className="card-title">企业微信绑定</h3>
|
|
<div className="space-y-3 text-sm text-zinc-700">
|
|
<div>接入状态:<span className="font-medium text-zinc-900">{wecomConfigQuery.data?.enabled ? "已启用" : "未启用"}</span></div>
|
|
<div>绑定状态:<span className="font-medium text-zinc-900">{me?.wecomBinding?.externalUserId ?? "未绑定"}</span></div>
|
|
{searchParams.get("wecomBind") ? (
|
|
<div className="rounded-lg border border-zinc-200 bg-zinc-50 px-3 py-2">绑定结果:{searchParams.get("wecomBind")}</div>
|
|
) : null}
|
|
<div className="flex flex-wrap gap-2">
|
|
<Button type="button" variant="secondary" disabled={!wecomConfigQuery.data?.enabled || bindMutation.isPending} onClick={() => bindMutation.mutate()}>绑定企业微信</Button>
|
|
<Button type="button" variant="secondary" disabled={!me?.wecomBinding || unbindMutation.isPending} onClick={() => unbindMutation.mutate()}>解绑企业微信</Button>
|
|
</div>
|
|
</div>
|
|
</section>
|
|
|
|
<section className="card-std mt-4">
|
|
<h3 className="card-title">权限列表</h3>
|
|
<div className="flex flex-wrap gap-2">
|
|
{permissions.map((permission) => (
|
|
<span
|
|
className="rounded-full bg-primary-50 px-2.5 py-1 text-xs font-medium text-primary"
|
|
key={permission}
|
|
>
|
|
{permission}
|
|
</span>
|
|
))}
|
|
</div>
|
|
</section>
|
|
</div>
|
|
);
|
|
}
|