add
This commit is contained in:
parent
d411935430
commit
483058090d
|
@ -1,9 +1,6 @@
|
||||||
import { Injectable } from '@nestjs/common';
|
import { Injectable } from '@nestjs/common';
|
||||||
import { TrpcService } from '@server/trpc/trpc.service';
|
import { TrpcService } from '@server/trpc/trpc.service';
|
||||||
import {
|
import { ObjectType, RoleMapMethodSchema } from '@nice/common';
|
||||||
ObjectType,
|
|
||||||
RoleMapMethodSchema,
|
|
||||||
} from '@nice/common';
|
|
||||||
import { RoleMapService } from './rolemap.service';
|
import { RoleMapService } from './rolemap.service';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
|
@ -67,5 +64,10 @@ export class RoleMapRouter {
|
||||||
.query(async ({ input }) => {
|
.query(async ({ input }) => {
|
||||||
return this.roleMapService.getStaffsNotMap(input);
|
return this.roleMapService.getStaffsNotMap(input);
|
||||||
}),
|
}),
|
||||||
|
getStaffIdsByRoleNames: this.trpc.procedure
|
||||||
|
.input(RoleMapMethodSchema.getStaffIdsByRoleNames)
|
||||||
|
.query(async ({ input }) => {
|
||||||
|
return this.roleMapService.getStaffIdsByRoleNames(input);
|
||||||
|
}),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,7 +44,7 @@ export class RoleMapService extends RowModelService {
|
||||||
) {
|
) {
|
||||||
const { roleId, domainId } = request;
|
const { roleId, domainId } = request;
|
||||||
// Base conditions
|
// Base conditions
|
||||||
let condition = super.createGetRowsFilters(request, staff);
|
const condition = super.createGetRowsFilters(request, staff);
|
||||||
if (isFieldCondition(condition)) return;
|
if (isFieldCondition(condition)) return;
|
||||||
// Adding conditions based on parameters existence
|
// Adding conditions based on parameters existence
|
||||||
if (roleId) {
|
if (roleId) {
|
||||||
|
@ -64,10 +64,7 @@ export class RoleMapService extends RowModelService {
|
||||||
return condition;
|
return condition;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected async getRowDto(
|
protected async getRowDto(row: any, staff?: UserProfile): Promise<any> {
|
||||||
row: any,
|
|
||||||
staff?: UserProfile,
|
|
||||||
): Promise<any> {
|
|
||||||
if (!row.id) return row;
|
if (!row.id) return row;
|
||||||
return row;
|
return row;
|
||||||
}
|
}
|
||||||
|
@ -126,15 +123,17 @@ export class RoleMapService extends RowModelService {
|
||||||
data: roleMaps,
|
data: roleMaps,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
const wrapResult = Promise.all(result.map(async item => {
|
const wrapResult = Promise.all(
|
||||||
|
result.map(async (item) => {
|
||||||
const staff = await db.staff.findMany({
|
const staff = await db.staff.findMany({
|
||||||
include: { department: true },
|
include: { department: true },
|
||||||
where: {
|
where: {
|
||||||
id: item.objectId
|
id: item.objectId,
|
||||||
}
|
},
|
||||||
})
|
});
|
||||||
return { ...item, staff }
|
return { ...item, staff };
|
||||||
}))
|
}),
|
||||||
|
);
|
||||||
return wrapResult;
|
return wrapResult;
|
||||||
}
|
}
|
||||||
async addRoleForObjects(
|
async addRoleForObjects(
|
||||||
|
@ -260,7 +259,9 @@ export class RoleMapService extends RowModelService {
|
||||||
// const processedItems = await Promise.all(items.map(item => this.genRoleMapDto(item)));
|
// const processedItems = await Promise.all(items.map(item => this.genRoleMapDto(item)));
|
||||||
return { items, totalCount };
|
return { items, totalCount };
|
||||||
}
|
}
|
||||||
async getStaffsNotMap(data: z.infer<typeof RoleMapMethodSchema.getStaffsNotMap>) {
|
async getStaffsNotMap(
|
||||||
|
data: z.infer<typeof RoleMapMethodSchema.getStaffsNotMap>,
|
||||||
|
) {
|
||||||
const { domainId, roleId } = data;
|
const { domainId, roleId } = data;
|
||||||
let staffs = await db.staff.findMany({
|
let staffs = await db.staff.findMany({
|
||||||
where: {
|
where: {
|
||||||
|
@ -280,6 +281,35 @@ export class RoleMapService extends RowModelService {
|
||||||
);
|
);
|
||||||
return staffs;
|
return staffs;
|
||||||
}
|
}
|
||||||
|
async getStaffIdsByRoleNames(
|
||||||
|
data: z.infer<typeof RoleMapMethodSchema.getStaffIdsByRoleNames>,
|
||||||
|
) {
|
||||||
|
const { roleNames } = data;
|
||||||
|
const roles = await db.role.findMany({
|
||||||
|
where: {
|
||||||
|
name: {
|
||||||
|
in: roleNames,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
const roleMaps = await db.roleMap.findMany({
|
||||||
|
where: {
|
||||||
|
roleId: {
|
||||||
|
in: roles.map((role) => role.id),
|
||||||
|
},
|
||||||
|
objectType: ObjectType.STAFF,
|
||||||
|
},
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
objectId: true,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
const staffIds = roleMaps.map((roleMap) => roleMap.objectId);
|
||||||
|
return staffIds;
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* 更新角色映射
|
* 更新角色映射
|
||||||
* @param data 包含更新信息的数据
|
* @param data 包含更新信息的数据
|
||||||
|
@ -300,7 +330,9 @@ export class RoleMapService extends RowModelService {
|
||||||
* @param data 包含角色ID和域ID的数据
|
* @param data 包含角色ID和域ID的数据
|
||||||
* @returns 角色映射详情,包含部门ID和员工ID列表
|
* @returns 角色映射详情,包含部门ID和员工ID列表
|
||||||
*/
|
*/
|
||||||
async getRoleMapDetail(data: z.infer<typeof RoleMapMethodSchema.getRoleMapDetail>) {
|
async getRoleMapDetail(
|
||||||
|
data: z.infer<typeof RoleMapMethodSchema.getRoleMapDetail>,
|
||||||
|
) {
|
||||||
const { roleId, domainId } = data;
|
const { roleId, domainId } = data;
|
||||||
const res = await db.roleMap.findMany({ where: { roleId, domainId } });
|
const res = await db.roleMap.findMany({ where: { roleId, domainId } });
|
||||||
|
|
||||||
|
|
|
@ -3,13 +3,17 @@ import { TrpcService } from '@server/trpc/trpc.service';
|
||||||
import { Prisma, UpdateOrderSchema } from '@nice/common';
|
import { Prisma, UpdateOrderSchema } from '@nice/common';
|
||||||
import { ResourceService } from './resource.service';
|
import { ResourceService } from './resource.service';
|
||||||
import { z, ZodType } from 'zod';
|
import { z, ZodType } from 'zod';
|
||||||
const ResourceCreateArgsSchema: ZodType<Prisma.ResourceCreateArgs> = z.any()
|
const ResourceCreateArgsSchema: ZodType<Prisma.ResourceCreateArgs> = z.any();
|
||||||
const ResourceCreateManyInputSchema: ZodType<Prisma.ResourceCreateManyInput> = z.any()
|
const ResourceCreateManyInputSchema: ZodType<Prisma.ResourceCreateManyInput> =
|
||||||
const ResourceDeleteManyArgsSchema: ZodType<Prisma.ResourceDeleteManyArgs> = z.any()
|
z.any();
|
||||||
const ResourceFindManyArgsSchema: ZodType<Prisma.ResourceFindManyArgs> = z.any()
|
const ResourceDeleteManyArgsSchema: ZodType<Prisma.ResourceDeleteManyArgs> =
|
||||||
const ResourceFindFirstArgsSchema: ZodType<Prisma.ResourceFindFirstArgs> = z.any()
|
z.any();
|
||||||
const ResourceWhereInputSchema: ZodType<Prisma.ResourceWhereInput> = z.any()
|
const ResourceFindManyArgsSchema: ZodType<Prisma.ResourceFindManyArgs> =
|
||||||
const ResourceSelectSchema: ZodType<Prisma.ResourceSelect> = z.any()
|
z.any();
|
||||||
|
const ResourceFindFirstArgsSchema: ZodType<Prisma.ResourceFindFirstArgs> =
|
||||||
|
z.any();
|
||||||
|
const ResourceWhereInputSchema: ZodType<Prisma.ResourceWhereInput> = z.any();
|
||||||
|
const ResourceSelectSchema: ZodType<Prisma.ResourceSelect> = z.any();
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class ResourceRouter {
|
export class ResourceRouter {
|
||||||
|
@ -24,7 +28,8 @@ export class ResourceRouter {
|
||||||
const { staff } = ctx;
|
const { staff } = ctx;
|
||||||
return await this.resourceService.create(input, { staff });
|
return await this.resourceService.create(input, { staff });
|
||||||
}),
|
}),
|
||||||
createMany: this.trpc.protectProcedure.input(z.array(ResourceCreateManyInputSchema))
|
createMany: this.trpc.protectProcedure
|
||||||
|
.input(z.array(ResourceCreateManyInputSchema))
|
||||||
.mutation(async ({ ctx, input }) => {
|
.mutation(async ({ ctx, input }) => {
|
||||||
const { staff } = ctx;
|
const { staff } = ctx;
|
||||||
|
|
||||||
|
@ -56,12 +61,14 @@ export class ResourceRouter {
|
||||||
return await this.resourceService.findMany(input);
|
return await this.resourceService.findMany(input);
|
||||||
}),
|
}),
|
||||||
findManyWithCursor: this.trpc.protectProcedure
|
findManyWithCursor: this.trpc.protectProcedure
|
||||||
.input(z.object({
|
.input(
|
||||||
|
z.object({
|
||||||
cursor: z.any().nullish(),
|
cursor: z.any().nullish(),
|
||||||
take: z.number().nullish(),
|
take: z.number().nullish(),
|
||||||
where: ResourceWhereInputSchema.nullish(),
|
where: ResourceWhereInputSchema.nullish(),
|
||||||
select: ResourceSelectSchema.nullish()
|
select: ResourceSelectSchema.nullish(),
|
||||||
}))
|
}),
|
||||||
|
)
|
||||||
.query(async ({ ctx, input }) => {
|
.query(async ({ ctx, input }) => {
|
||||||
const { staff } = ctx;
|
const { staff } = ctx;
|
||||||
return await this.resourceService.findManyWithCursor(input);
|
return await this.resourceService.findManyWithCursor(input);
|
||||||
|
|
|
@ -15,6 +15,8 @@ import { WebSocketModule } from '@server/socket/websocket.module';
|
||||||
import { RoleMapModule } from '@server/models/rbac/rbac.module';
|
import { RoleMapModule } from '@server/models/rbac/rbac.module';
|
||||||
import { TransformModule } from '@server/models/transform/transform.module';
|
import { TransformModule } from '@server/models/transform/transform.module';
|
||||||
|
|
||||||
|
import { ResourceModule } from '@server/models/resource/resource.module';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [
|
imports: [
|
||||||
AuthModule,
|
AuthModule,
|
||||||
|
@ -30,6 +32,7 @@ import { TransformModule } from '@server/models/transform/transform.module';
|
||||||
PostModule,
|
PostModule,
|
||||||
VisitModule,
|
VisitModule,
|
||||||
WebSocketModule,
|
WebSocketModule,
|
||||||
|
ResourceModule,
|
||||||
],
|
],
|
||||||
controllers: [],
|
controllers: [],
|
||||||
providers: [TrpcService, TrpcRouter, Logger],
|
providers: [TrpcService, TrpcRouter, Logger],
|
||||||
|
|
|
@ -13,10 +13,10 @@ import { VisitRouter } from '@server/models/visit/visit.router';
|
||||||
import { RoleMapRouter } from '@server/models/rbac/rolemap.router';
|
import { RoleMapRouter } from '@server/models/rbac/rolemap.router';
|
||||||
import { TransformRouter } from '@server/models/transform/transform.router';
|
import { TransformRouter } from '@server/models/transform/transform.router';
|
||||||
import { RoleRouter } from '@server/models/rbac/role.router';
|
import { RoleRouter } from '@server/models/rbac/role.router';
|
||||||
|
import { ResourceRouter } from '../models/resource/resource.router';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class TrpcRouter {
|
export class TrpcRouter {
|
||||||
|
|
||||||
logger = new Logger(TrpcRouter.name);
|
logger = new Logger(TrpcRouter.name);
|
||||||
constructor(
|
constructor(
|
||||||
private readonly trpc: TrpcService,
|
private readonly trpc: TrpcService,
|
||||||
|
@ -31,10 +31,10 @@ export class TrpcRouter {
|
||||||
private readonly app_config: AppConfigRouter,
|
private readonly app_config: AppConfigRouter,
|
||||||
private readonly message: MessageRouter,
|
private readonly message: MessageRouter,
|
||||||
private readonly visitor: VisitRouter,
|
private readonly visitor: VisitRouter,
|
||||||
|
private readonly resource: ResourceRouter,
|
||||||
) {}
|
) {}
|
||||||
getRouter() {
|
getRouter() {
|
||||||
return
|
return;
|
||||||
}
|
}
|
||||||
appRouter = this.trpc.router({
|
appRouter = this.trpc.router({
|
||||||
transform: this.transform.router,
|
transform: this.transform.router,
|
||||||
|
@ -48,6 +48,7 @@ export class TrpcRouter {
|
||||||
message: this.message.router,
|
message: this.message.router,
|
||||||
app_config: this.app_config.router,
|
app_config: this.app_config.router,
|
||||||
visitor: this.visitor.router,
|
visitor: this.visitor.router,
|
||||||
|
resource: this.resource.router,
|
||||||
});
|
});
|
||||||
wss: WebSocketServer = undefined;
|
wss: WebSocketServer = undefined;
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
import { TrpcRouter } from "./trpc.router";
|
import { TrpcRouter } from './trpc.router';
|
||||||
|
|
||||||
export type AppRouter = TrpcRouter[`appRouter`];
|
export type AppRouter = TrpcRouter[`appRouter`];
|
||||||
|
|
|
@ -9,7 +9,7 @@ export default function LetterEditorPage() {
|
||||||
const termId = searchParams.get("termId");
|
const termId = searchParams.get("termId");
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="min-h-screen rounded-xl shadow-elegant border-2 border-white bg-gradient-to-b from-slate-100 to-slate-50 ">
|
<div className="shadow-elegant border-2 border-white rounded-xl bg-slate-200">
|
||||||
<WriteHeader></WriteHeader>
|
<WriteHeader></WriteHeader>
|
||||||
<LetterFormProvider receiverId={receiverId} termId={termId}>
|
<LetterFormProvider receiverId={receiverId} termId={termId}>
|
||||||
<LetterBasicForm />
|
<LetterBasicForm />
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { useState, useCallback, useEffect } from "react";
|
import { useState, useCallback, useEffect, useMemo } from "react";
|
||||||
import { motion, AnimatePresence } from "framer-motion";
|
import { motion, AnimatePresence } from "framer-motion";
|
||||||
import { useSearchParams } from "react-router-dom";
|
import { useSearchParams } from "react-router-dom";
|
||||||
|
|
||||||
|
@ -9,6 +9,7 @@ import DepartmentSelect from "@web/src/components/models/department/department-s
|
||||||
import debounce from "lodash/debounce";
|
import debounce from "lodash/debounce";
|
||||||
import { SearchOutlined } from "@ant-design/icons";
|
import { SearchOutlined } from "@ant-design/icons";
|
||||||
import WriteHeader from "./WriteHeader";
|
import WriteHeader from "./WriteHeader";
|
||||||
|
import { ObjectType, RoleName } from "@nice/common";
|
||||||
|
|
||||||
export default function WriteLetterPage() {
|
export default function WriteLetterPage() {
|
||||||
const [searchParams] = useSearchParams();
|
const [searchParams] = useSearchParams();
|
||||||
|
@ -18,12 +19,23 @@ export default function WriteLetterPage() {
|
||||||
const [currentPage, setCurrentPage] = useState(1);
|
const [currentPage, setCurrentPage] = useState(1);
|
||||||
const pageSize = 10;
|
const pageSize = 10;
|
||||||
const { getTerm } = useTerm();
|
const { getTerm } = useTerm();
|
||||||
|
const { data: enabledStaffIds, isLoading: roleMapIsLoading } =
|
||||||
|
api.rolemap.getStaffIdsByRoleNames.useQuery({
|
||||||
|
roleNames: [RoleName.Leader, RoleName.Organization],
|
||||||
|
});
|
||||||
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
|
|
||||||
const { data, isLoading, error } =
|
const { data, isLoading, error } =
|
||||||
api.staff.findManyWithPagination.useQuery({
|
api.staff.findManyWithPagination.useQuery(
|
||||||
|
{
|
||||||
page: currentPage,
|
page: currentPage,
|
||||||
pageSize,
|
pageSize,
|
||||||
where: {
|
where: {
|
||||||
|
id: enabledStaffIds
|
||||||
|
? {
|
||||||
|
in: enabledStaffIds,
|
||||||
|
}
|
||||||
|
: undefined,
|
||||||
deptId: selectedDept,
|
deptId: selectedDept,
|
||||||
OR: [
|
OR: [
|
||||||
{
|
{
|
||||||
|
@ -36,13 +48,22 @@ export default function WriteLetterPage() {
|
||||||
contains: searchQuery,
|
contains: searchQuery,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
meta: {
|
||||||
|
path: ["rank"], // 指定 JSON 字段的路径
|
||||||
|
string_contains: searchQuery, // 对 rank 字段进行模糊搜索
|
||||||
|
},
|
||||||
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
orderBy: {
|
orderBy: {
|
||||||
order: "desc",
|
order: "asc",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
enabled: !roleMapIsLoading,
|
||||||
}
|
}
|
||||||
});
|
);
|
||||||
|
|
||||||
const resetPage = useCallback(() => {
|
const resetPage = useCallback(() => {
|
||||||
setCurrentPage(1);
|
setCurrentPage(1);
|
||||||
|
|
|
@ -2,6 +2,7 @@ import { env } from "@web/src/env";
|
||||||
import { message, Progress, Spin, theme } from "antd";
|
import { message, Progress, Spin, theme } from "antd";
|
||||||
import React, { useState, useEffect, useRef } from "react";
|
import React, { useState, useEffect, useRef } from "react";
|
||||||
import { useTusUpload } from "@web/src/hooks/useTusUpload";
|
import { useTusUpload } from "@web/src/hooks/useTusUpload";
|
||||||
|
import { Avatar } from "antd/lib";
|
||||||
|
|
||||||
export interface AvatarUploaderProps {
|
export interface AvatarUploaderProps {
|
||||||
value?: string;
|
value?: string;
|
||||||
|
@ -69,7 +70,6 @@ const AvatarUploader: React.FC<AvatarUploaderProps> = ({
|
||||||
file?.fileKey
|
file?.fileKey
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
setPreviewUrl(`http://${env.SERVER_IP}/uploads/${fileId}`);
|
|
||||||
onChange?.(fileId);
|
onChange?.(fileId);
|
||||||
message.success("头像上传成功");
|
message.success("头像上传成功");
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
@ -94,7 +94,6 @@ const AvatarUploader: React.FC<AvatarUploaderProps> = ({
|
||||||
background: token.colorBgContainer,
|
background: token.colorBgContainer,
|
||||||
...style, // 应用外部传入的样式
|
...style, // 应用外部传入的样式
|
||||||
}}>
|
}}>
|
||||||
<div>{previewUrl}</div>
|
|
||||||
<input
|
<input
|
||||||
type="file"
|
type="file"
|
||||||
ref={inputRef}
|
ref={inputRef}
|
||||||
|
@ -103,9 +102,9 @@ const AvatarUploader: React.FC<AvatarUploaderProps> = ({
|
||||||
style={{ display: "none" }}
|
style={{ display: "none" }}
|
||||||
/>
|
/>
|
||||||
{previewUrl ? (
|
{previewUrl ? (
|
||||||
<img
|
<Avatar
|
||||||
src={previewUrl}
|
src={previewUrl}
|
||||||
alt="Avatar"
|
shape="square"
|
||||||
className="w-full h-full object-cover"
|
className="w-full h-full object-cover"
|
||||||
/>
|
/>
|
||||||
) : (
|
) : (
|
||||||
|
|
|
@ -130,9 +130,8 @@ export const TusUploader = ({ value = [], onChange }: TusUploaderProps) => {
|
||||||
<div className="space-y-1">
|
<div className="space-y-1">
|
||||||
<Upload.Dragger
|
<Upload.Dragger
|
||||||
name="files"
|
name="files"
|
||||||
multiple
|
|
||||||
showUploadList={false}
|
showUploadList={false}
|
||||||
style={{ background: "white", borderStyle: "solid" }}
|
style={{ background: "transparent", borderStyle: "none" }}
|
||||||
beforeUpload={handleChange}>
|
beforeUpload={handleChange}>
|
||||||
<p className="ant-upload-drag-icon">
|
<p className="ant-upload-drag-icon">
|
||||||
<UploadOutlined />
|
<UploadOutlined />
|
||||||
|
@ -143,7 +142,7 @@ export const TusUploader = ({ value = [], onChange }: TusUploaderProps) => {
|
||||||
<p className="ant-upload-hint">支持单个或批量上传文件</p>
|
<p className="ant-upload-hint">支持单个或批量上传文件</p>
|
||||||
{/* 正在上传的文件 */}
|
{/* 正在上传的文件 */}
|
||||||
{(uploadingFiles.length > 0 || completedFiles.length > 0) && (
|
{(uploadingFiles.length > 0 || completedFiles.length > 0) && (
|
||||||
<div className=" px-2 py-0 border rounded bg-white mt-1 ">
|
<div className=" px-2 py-0 rounded mt-1 ">
|
||||||
{uploadingFiles.map((file) => (
|
{uploadingFiles.map((file) => (
|
||||||
<div
|
<div
|
||||||
key={file.fileKey}
|
key={file.fileKey}
|
||||||
|
|
|
@ -1,22 +1,52 @@
|
||||||
import { Link, NavLink, useNavigate } from "react-router-dom";
|
import { Link, NavLink, useNavigate } from "react-router-dom";
|
||||||
import { memo } from "react";
|
import { memo, useMemo } from "react";
|
||||||
import { SearchBar } from "./SearchBar";
|
import { SearchBar } from "./SearchBar";
|
||||||
import Navigation from "./navigation";
|
import Navigation from "./navigation";
|
||||||
import { useAuth } from "@web/src/providers/auth-provider";
|
import { useAuth } from "@web/src/providers/auth-provider";
|
||||||
import { UserOutlined } from "@ant-design/icons";
|
import { UserOutlined } from "@ant-design/icons";
|
||||||
import { UserMenu } from "../element/usermenu/usermenu";
|
import { UserMenu } from "../element/usermenu/usermenu";
|
||||||
|
import { api, useAppConfig } from "@nice/client";
|
||||||
|
import { env } from "@web/src/env";
|
||||||
|
|
||||||
export const Header = memo(function Header() {
|
export const Header = memo(function Header() {
|
||||||
const { isAuthenticated } = useAuth();
|
const { isAuthenticated } = useAuth();
|
||||||
|
const { logo } = useAppConfig();
|
||||||
|
const { data: logoRes, isLoading } = api.resource.findFirst.useQuery(
|
||||||
|
{
|
||||||
|
where: {
|
||||||
|
fileId: logo,
|
||||||
|
},
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
url: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
enabled: !!logo,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
const logoUrl: string = useMemo(() => {
|
||||||
|
return `http://${env.SERVER_IP}/uploads/${logoRes?.url}`;
|
||||||
|
}, [logoRes]);
|
||||||
return (
|
return (
|
||||||
<header className="sticky top-0 z-50 bg-gradient-to-br from-primary-500 to-primary-800 text-white shadow-lg">
|
<header className="sticky top-0 z-50 bg-gradient-to-br from-primary-500 to-primary-800 text-white shadow-lg">
|
||||||
<div className=" mx-auto px-4">
|
<div className=" mx-auto px-4">
|
||||||
<div className="py-4">
|
<div className="py-2">
|
||||||
<div className="flex items-center justify-between gap-4">
|
<div className="flex items-center justify-between gap-4">
|
||||||
<div className="">
|
<div className="">
|
||||||
<span className="text-xl font-bold">首长机关信箱</span>
|
{/** 在这里放置logo */}
|
||||||
<p className=" text-sm text-secondary-50">聆怀若水,应语如风;纾难化困,践诺成春</p>
|
{isLoading ? (
|
||||||
|
<div className="w-48 h-24 bg-gray-300 animate-pulse"></div>
|
||||||
|
) : (
|
||||||
|
logoUrl && (
|
||||||
|
<img
|
||||||
|
src={logoUrl}
|
||||||
|
alt="Logo"
|
||||||
|
style={{ width: 192, height: 72 }}
|
||||||
|
className=" w-full h-full"
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
<div className="flex-grow max-w-2xl">
|
<div className="flex-grow max-w-2xl">
|
||||||
<SearchBar />
|
<SearchBar />
|
||||||
|
@ -34,7 +64,6 @@ focus:outline-none focus:ring-2
|
||||||
focus:ring-[#8EADD4] focus:ring-offset-2
|
focus:ring-[#8EADD4] focus:ring-offset-2
|
||||||
focus:ring-offset-[#13294B]"
|
focus:ring-offset-[#13294B]"
|
||||||
aria-label="Login">
|
aria-label="Login">
|
||||||
|
|
||||||
<UserOutlined
|
<UserOutlined
|
||||||
className="h-5 w-5 transition-transform
|
className="h-5 w-5 transition-transform
|
||||||
group-hover:scale-110 group-hover:rotate-12"></UserOutlined>
|
group-hover:scale-110 group-hover:rotate-12"></UserOutlined>
|
||||||
|
|
|
@ -28,7 +28,7 @@ export default function Navigation({ className }: NavigationProps) {
|
||||||
return (
|
return (
|
||||||
<nav
|
<nav
|
||||||
className={twMerge(
|
className={twMerge(
|
||||||
"mt-4 rounded-xl bg-gradient-to-r from-primary-500 to-primary-600 shadow-lg",
|
"mt-4 rounded-t-xl bg-gradient-to-r from-primary-500 to-primary-600 shadow-lg",
|
||||||
className
|
className
|
||||||
)}>
|
)}>
|
||||||
<div className="flex flex-col md:flex-row items-stretch">
|
<div className="flex flex-col md:flex-row items-stretch">
|
||||||
|
|
|
@ -16,6 +16,7 @@ import PostLikeButton from "./PostHeader/PostLikeButton";
|
||||||
import { CustomAvatar } from "@web/src/components/presentation/CustomAvatar";
|
import { CustomAvatar } from "@web/src/components/presentation/CustomAvatar";
|
||||||
import PostResources from "./PostResources";
|
import PostResources from "./PostResources";
|
||||||
import PostHateButton from "./PostHeader/PostHateButton";
|
import PostHateButton from "./PostHeader/PostHateButton";
|
||||||
|
import PostSendButton from "./PostHeader/PostSendButton";
|
||||||
|
|
||||||
export default function PostCommentCard({
|
export default function PostCommentCard({
|
||||||
post,
|
post,
|
||||||
|
@ -60,11 +61,15 @@ export default function PostCommentCard({
|
||||||
{/* 添加有帮助按钮 */}
|
{/* 添加有帮助按钮 */}
|
||||||
<div>
|
<div>
|
||||||
<div className="flex justify-center items-center gap-2">
|
<div className="flex justify-center items-center gap-2">
|
||||||
<span className=" text-sm text-slate-500">{`#${index + 1}`}</span>
|
{isReceiverComment && (
|
||||||
|
<PostSendButton
|
||||||
|
post={post}></PostSendButton>
|
||||||
|
)}
|
||||||
<PostLikeButton
|
<PostLikeButton
|
||||||
post={post}></PostLikeButton>
|
post={post}></PostLikeButton>
|
||||||
<PostHateButton
|
<PostHateButton
|
||||||
post={post}></PostHateButton>
|
post={post}></PostHateButton>
|
||||||
|
<span className=" text-sm text-slate-500">{`#${index + 1}`}</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -60,11 +60,9 @@ export default function PostCommentEditor() {
|
||||||
<QuillEditor
|
<QuillEditor
|
||||||
value={content}
|
value={content}
|
||||||
onChange={setContent}
|
onChange={setContent}
|
||||||
|
|
||||||
className="bg-transparent"
|
className="bg-transparent"
|
||||||
theme="snow"
|
theme="snow"
|
||||||
minRows={6}
|
minRows={6}
|
||||||
|
|
||||||
modules={{
|
modules={{
|
||||||
toolbar: [
|
toolbar: [
|
||||||
["bold", "italic", "strike"],
|
["bold", "italic", "strike"],
|
||||||
|
@ -77,16 +75,17 @@ export default function PostCommentEditor() {
|
||||||
["clean"],
|
["clean"],
|
||||||
],
|
],
|
||||||
}}
|
}}
|
||||||
|
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</TabPane>
|
</TabPane>
|
||||||
<TabPane tab="附件" key="2">
|
<TabPane tab="附件" key="2">
|
||||||
|
<div className="relative rounded-xl border border-white hover:ring-1 ring-white transition-all duration-300 ease-in-out bg-slate-100">
|
||||||
<TusUploader
|
<TusUploader
|
||||||
onChange={(value) => {
|
onChange={(value) => {
|
||||||
setFileIds(value);
|
setFileIds(value);
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
</div>
|
||||||
</TabPane>
|
</TabPane>
|
||||||
</Tabs>
|
</Tabs>
|
||||||
|
|
||||||
|
|
|
@ -36,8 +36,9 @@ export default function PostHateButton({ post }: { post: PostDto }) {
|
||||||
type={post?.hated ? "primary" : "default"}
|
type={post?.hated ? "primary" : "default"}
|
||||||
style={{
|
style={{
|
||||||
backgroundColor: post?.hated ? "#ff4d4f" : "#fff",
|
backgroundColor: post?.hated ? "#ff4d4f" : "#fff",
|
||||||
borderColor: "#ff4d4f",
|
borderColor: post?.hated ? "transparent" : "#ff4d4f",
|
||||||
color: post?.hated ? "#fff" : "#ff4d4f",
|
color: post?.hated ? "#fff" : "#ff4d4f",
|
||||||
|
boxShadow: "none", // 去除阴影
|
||||||
}}
|
}}
|
||||||
shape="round"
|
shape="round"
|
||||||
icon={post?.hated ? <DislikeFilled /> : <DislikeOutlined />}
|
icon={post?.hated ? <DislikeFilled /> : <DislikeOutlined />}
|
||||||
|
|
|
@ -0,0 +1,32 @@
|
||||||
|
import { PostDto, VisitType } from "@nice/common";
|
||||||
|
import { useVisitor } from "@nice/client";
|
||||||
|
import { Button, Tooltip } from "antd";
|
||||||
|
import {
|
||||||
|
DislikeFilled,
|
||||||
|
DislikeOutlined,
|
||||||
|
SendOutlined,
|
||||||
|
} from "@ant-design/icons";
|
||||||
|
import { useAuth } from "@web/src/providers/auth-provider";
|
||||||
|
|
||||||
|
export default function PostSendButton({ post }: { post: PostDto }) {
|
||||||
|
const { user } = useAuth();
|
||||||
|
const { hate, unHate } = useVisitor();
|
||||||
|
function sendPost() {
|
||||||
|
if (post?.authorId) {
|
||||||
|
window.open(`/editor?receiverId=${post?.authorId}`, "_blank");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return (
|
||||||
|
<Button
|
||||||
|
title="给他写信"
|
||||||
|
type="default"
|
||||||
|
shape="round"
|
||||||
|
onClick={(e) => {
|
||||||
|
e.stopPropagation();
|
||||||
|
sendPost();
|
||||||
|
}}
|
||||||
|
icon={<SendOutlined />}>
|
||||||
|
<span className="mr-1">给他写信</span>
|
||||||
|
</Button>
|
||||||
|
);
|
||||||
|
}
|
|
@ -4,7 +4,7 @@ import { DownloadOutlined } from "@ant-design/icons";
|
||||||
import { PostDto } from "@nice/common";
|
import { PostDto } from "@nice/common";
|
||||||
import { env } from "@web/src/env";
|
import { env } from "@web/src/env";
|
||||||
import { getFileIcon } from "./utils";
|
import { getFileIcon } from "./utils";
|
||||||
import { formatFileSize } from '@nice/utils';
|
import { formatFileSize } from "@nice/utils";
|
||||||
export default function PostResources({ post }: { post: PostDto }) {
|
export default function PostResources({ post }: { post: PostDto }) {
|
||||||
const { resources } = useMemo(() => {
|
const { resources } = useMemo(() => {
|
||||||
if (!post?.resources) return { resources: [] };
|
if (!post?.resources) return { resources: [] };
|
||||||
|
@ -99,7 +99,9 @@ export default function PostResources({ post }: { post: PostDto }) {
|
||||||
</span>
|
</span>
|
||||||
<span className="text-xs text-gray-400">
|
<span className="text-xs text-gray-400">
|
||||||
{resource.meta.size &&
|
{resource.meta.size &&
|
||||||
formatFileSize(resource.meta.size)}
|
formatFileSize(
|
||||||
|
resource.meta.size
|
||||||
|
)}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -65,7 +65,7 @@ export function LetterBasicForm() {
|
||||||
name="content"
|
name="content"
|
||||||
rules={[{ required: true, message: "请输入内容" }]}
|
rules={[{ required: true, message: "请输入内容" }]}
|
||||||
required={false}>
|
required={false}>
|
||||||
<div className="rounded-lg border border-gray-200 bg-white shadow-sm">
|
<div className="rounded-xl border border-white hover:ring-1 ring-white transition-all duration-300 ease-in-out bg-slate-100">
|
||||||
<QuillEditor
|
<QuillEditor
|
||||||
maxLength={10000}
|
maxLength={10000}
|
||||||
placeholder="请输入内容"
|
placeholder="请输入内容"
|
||||||
|
@ -79,7 +79,8 @@ export function LetterBasicForm() {
|
||||||
</TabPane>
|
</TabPane>
|
||||||
<TabPane tab="附件" key="2">
|
<TabPane tab="附件" key="2">
|
||||||
<Form.Item name="resources" required={false}>
|
<Form.Item name="resources" required={false}>
|
||||||
<div className="rounded-lg border border-gray-200 bg-white shadow-sm">
|
<div className="rounded-xl border border-white hover:ring-1 ring-white transition-all duration-300 ease-in-out bg-slate-100">
|
||||||
|
|
||||||
<TusUploader
|
<TusUploader
|
||||||
onChange={(resources) =>
|
onChange={(resources) =>
|
||||||
form.setFieldValue(
|
form.setFieldValue(
|
||||||
|
@ -88,12 +89,13 @@ export function LetterBasicForm() {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
</TabPane>
|
</TabPane>
|
||||||
</Tabs>
|
</Tabs>
|
||||||
{/* Footer Actions */}
|
{/* Footer Actions */}
|
||||||
<div className="flex flex-col-reverse sm:flex-row items-center justify-between gap-4 mt-6">
|
<div className="flex flex-col-reverse sm:flex-row items-center justify-between gap-4 ">
|
||||||
<Form.Item name="isPublic" valuePropName="checked">
|
<Form.Item name="isPublic" valuePropName="checked">
|
||||||
<Checkbox className="text-gray-600 hover:text-gray-900 transition-colors text-sm">
|
<Checkbox className="text-gray-600 hover:text-gray-900 transition-colors text-sm">
|
||||||
是否公开
|
是否公开
|
||||||
|
|
|
@ -4,14 +4,11 @@ import { RoleEditorContext } from "./role-editor";
|
||||||
import RoleForm from "./role-form";
|
import RoleForm from "./role-form";
|
||||||
|
|
||||||
export default function RoleModal() {
|
export default function RoleModal() {
|
||||||
const {
|
const { roleForm, editRoleId, roleModalOpen, setRoleModalOpen } =
|
||||||
roleForm,
|
useContext(RoleEditorContext);
|
||||||
editRoleId,
|
|
||||||
roleModalOpen, setRoleModalOpen
|
|
||||||
} = useContext(RoleEditorContext);
|
|
||||||
|
|
||||||
const handleOk = async () => {
|
const handleOk = async () => {
|
||||||
roleForm.submit()
|
roleForm.submit();
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleCancel = () => setRoleModalOpen(false);
|
const handleCancel = () => setRoleModalOpen(false);
|
||||||
|
@ -23,8 +20,7 @@ export default function RoleModal() {
|
||||||
open={roleModalOpen}
|
open={roleModalOpen}
|
||||||
onOk={handleOk}
|
onOk={handleOk}
|
||||||
// confirmLoading={loading}
|
// confirmLoading={loading}
|
||||||
onCancel={handleCancel}
|
onCancel={handleCancel}>
|
||||||
>
|
|
||||||
<RoleForm></RoleForm>
|
<RoleForm></RoleForm>
|
||||||
</Modal>
|
</Modal>
|
||||||
);
|
);
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import * as tus from "tus-js-client";
|
import * as tus from "tus-js-client";
|
||||||
|
import { env } from "../env";
|
||||||
|
|
||||||
// useTusUpload.ts
|
// useTusUpload.ts
|
||||||
interface UploadProgress {
|
interface UploadProgress {
|
||||||
|
@ -27,7 +28,16 @@ export function useTusUpload() {
|
||||||
}
|
}
|
||||||
return parts.slice(uploadIndex + 1, uploadIndex + 5).join("/");
|
return parts.slice(uploadIndex + 1, uploadIndex + 5).join("/");
|
||||||
};
|
};
|
||||||
|
const getResourceUrl = (url: string) => {
|
||||||
|
const parts = url.split("/");
|
||||||
|
const uploadIndex = parts.findIndex((part) => part === "upload");
|
||||||
|
if (uploadIndex === -1 || uploadIndex + 4 >= parts.length) {
|
||||||
|
throw new Error("Invalid upload URL format");
|
||||||
|
}
|
||||||
|
const resUrl = `http://${env.SERVER_IP}/uploads/${parts.slice(uploadIndex + 1, uploadIndex + 6).join("/")}`;
|
||||||
|
console.log(resUrl);
|
||||||
|
return resUrl;
|
||||||
|
};
|
||||||
const handleFileUpload = async (
|
const handleFileUpload = async (
|
||||||
file: File,
|
file: File,
|
||||||
onSuccess: (result: UploadResult) => void,
|
onSuccess: (result: UploadResult) => void,
|
||||||
|
@ -52,7 +62,7 @@ export function useTusUpload() {
|
||||||
metadata: {
|
metadata: {
|
||||||
filename: file.name,
|
filename: file.name,
|
||||||
filetype: file.type,
|
filetype: file.type,
|
||||||
size: file.size as any
|
size: file.size as any,
|
||||||
},
|
},
|
||||||
onProgress: (bytesUploaded, bytesTotal) => {
|
onProgress: (bytesUploaded, bytesTotal) => {
|
||||||
const progress = Number(
|
const progress = Number(
|
||||||
|
@ -67,13 +77,14 @@ export function useTusUpload() {
|
||||||
try {
|
try {
|
||||||
if (upload.url) {
|
if (upload.url) {
|
||||||
const fileId = getFileId(upload.url);
|
const fileId = getFileId(upload.url);
|
||||||
|
const url = getResourceUrl(upload.url);
|
||||||
setIsUploading(false);
|
setIsUploading(false);
|
||||||
setUploadProgress((prev) => ({
|
setUploadProgress((prev) => ({
|
||||||
...prev,
|
...prev,
|
||||||
[fileKey]: 100,
|
[fileKey]: 100,
|
||||||
}));
|
}));
|
||||||
onSuccess({
|
onSuccess({
|
||||||
url: upload.url,
|
url,
|
||||||
fileId,
|
fileId,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@ export function useVisitor() {
|
||||||
const create = api.visitor.create.useMutation({
|
const create = api.visitor.create.useMutation({
|
||||||
onSuccess() {
|
onSuccess() {
|
||||||
utils.visitor.invalidate();
|
utils.visitor.invalidate();
|
||||||
|
|
||||||
// utils.post.invalidate();
|
// utils.post.invalidate();
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
|
@ -201,3 +201,10 @@ export const PostStateLabels = {
|
||||||
[PostState.PROCESSING]: "处理中",
|
[PostState.PROCESSING]: "处理中",
|
||||||
[PostState.RESOLVED]: "已完成",
|
[PostState.RESOLVED]: "已完成",
|
||||||
};
|
};
|
||||||
|
export enum RoleName {
|
||||||
|
Basic = "基层", // 基层
|
||||||
|
Organization = "机关", // 机关
|
||||||
|
Leader = "领导", // 领导
|
||||||
|
DomainAdmin = "域管理员", // 域管理员
|
||||||
|
RootAdmin = "根管理员", // 根管理员
|
||||||
|
}
|
||||||
|
|
|
@ -320,6 +320,9 @@ export const RoleMapMethodSchema = {
|
||||||
domainId: z.string().nullish(),
|
domainId: z.string().nullish(),
|
||||||
roleId: z.string().nullish(),
|
roleId: z.string().nullish(),
|
||||||
}),
|
}),
|
||||||
|
getStaffIdsByRoleNames: z.object({
|
||||||
|
roleNames: z.array(z.string()),
|
||||||
|
}),
|
||||||
};
|
};
|
||||||
export const RoleMethodSchema = {
|
export const RoleMethodSchema = {
|
||||||
create: z.object({
|
create: z.object({
|
||||||
|
|
Loading…
Reference in New Issue