rht
This commit is contained in:
parent
5ab23e4a42
commit
853303a726
|
@ -1,14 +1,16 @@
|
|||
import { z } from "zod";
|
||||
import { z, ZodType } from "zod";
|
||||
import { ShareCodeService } from "./share-code.service";
|
||||
import { TrpcService } from "@server/trpc/trpc.service";
|
||||
import { Injectable } from "@nestjs/common";
|
||||
import { Prisma } from "@nice/common";
|
||||
const ShareCodeWhereInputSchema: ZodType<Prisma.ShareCodeWhereInput> = z.any();
|
||||
@Injectable()
|
||||
export class ShareCodeRouter {
|
||||
constructor(
|
||||
private readonly shareCodeService: ShareCodeService,
|
||||
private readonly trpc: TrpcService
|
||||
) {}
|
||||
|
||||
) { }
|
||||
|
||||
router = this.trpc.router({
|
||||
generateShareCode: this.trpc.procedure
|
||||
.input(z.object({ fileId: z.string(), expiresAt: z.date(), canUseTimes: z.number() }))
|
||||
|
@ -45,5 +47,26 @@ export class ShareCodeRouter {
|
|||
.mutation(async ({ input }) => {
|
||||
return this.shareCodeService.generateShareCodeByFileId(input.fileId, input.expiresAt, input.canUseTimes);
|
||||
}),
|
||||
getShareCodesWithResources: this.trpc.procedure
|
||||
.input(z.object({ page: z.number(), pageSize: z.number(), where: ShareCodeWhereInputSchema.optional() }))
|
||||
.query(async ({ input }) => {
|
||||
return this.shareCodeService.getShareCodesWithResources(input);
|
||||
}),
|
||||
softDeleteShareCodes: this.trpc.procedure
|
||||
.input(z.object({ ids: z.array(z.string()) }))
|
||||
.mutation(async ({ input }) => {
|
||||
return this.shareCodeService.softDeleteShareCodes(input.ids);
|
||||
}),
|
||||
updateShareCode: this.trpc.procedure
|
||||
.input(z.object({
|
||||
id: z.string(),
|
||||
data: z.object({
|
||||
expiresAt: z.date().optional(),
|
||||
canUseTimes: z.number().optional(),
|
||||
})
|
||||
}))
|
||||
.mutation(async ({ input }) => {
|
||||
return this.shareCodeService.updateShareCode(input.id, input.data);
|
||||
}),
|
||||
});
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
import { Injectable, Logger, NotFoundException } from '@nestjs/common';
|
||||
import { customAlphabet } from 'nanoid-cjs';
|
||||
import { db } from '@nice/common';
|
||||
import { db, ObjectType, Prisma, Resource } from '@nice/common';
|
||||
import { Cron, CronExpression } from '@nestjs/schedule';
|
||||
import { ResourceService } from '@server/models/resource/resource.service';
|
||||
import * as fs from 'fs'
|
||||
|
@ -8,6 +8,7 @@ import * as path from 'path'
|
|||
import dayjs from 'dayjs';
|
||||
import utc from 'dayjs/plugin/utc';
|
||||
import timezone from 'dayjs/plugin/timezone';
|
||||
import { BaseService } from '../base/base.service';
|
||||
dayjs.extend(utc);
|
||||
dayjs.extend(timezone);
|
||||
export interface ShareCode {
|
||||
|
@ -33,7 +34,7 @@ interface ResourceMeta {
|
|||
}
|
||||
|
||||
@Injectable()
|
||||
export class ShareCodeService {
|
||||
export class ShareCodeService extends BaseService<Prisma.ShareCodeDelegate> {
|
||||
private readonly logger = new Logger(ShareCodeService.name);
|
||||
// 生成8位分享码,使用易读的字符
|
||||
private readonly generateCode = customAlphabet(
|
||||
|
@ -41,7 +42,9 @@ export class ShareCodeService {
|
|||
8,
|
||||
);
|
||||
|
||||
constructor(private readonly resourceService: ResourceService) { }
|
||||
constructor(private readonly resourceService: ResourceService) {
|
||||
super(db, ObjectType.SHARE_CODE, false);
|
||||
}
|
||||
|
||||
async generateShareCode(
|
||||
fileId: string,
|
||||
|
@ -54,42 +57,40 @@ export class ShareCodeService {
|
|||
const resource = await this.resourceService.findUnique({
|
||||
where: { fileId },
|
||||
});
|
||||
this.logger.log('完整 fileId:', fileId); // 确保与前端一致
|
||||
|
||||
this.logger.log('完整 resource:', resource);
|
||||
if (!resource) {
|
||||
throw new NotFoundException('文件不存在');
|
||||
}
|
||||
|
||||
const { filename } = resource.meta as any as ResourceMeta
|
||||
// 生成分享码
|
||||
const code = this.generateCode();
|
||||
// 查找是否已有分享码记录
|
||||
const existingShareCode = await db.shareCode.findUnique({
|
||||
const existingShareCode = await super.findUnique({
|
||||
where: { fileId },
|
||||
});
|
||||
|
||||
if (existingShareCode) {
|
||||
// 更新现有记录,但保留原有文件名
|
||||
await db.shareCode.update({
|
||||
await super.update({
|
||||
where: { fileId },
|
||||
data: {
|
||||
code,
|
||||
expiresAt,
|
||||
canUseTimes,
|
||||
isUsed: false,
|
||||
// 只在没有现有文件名且提供了新文件名时才更新文件名
|
||||
...(fileName && !existingShareCode.fileName ? { fileName } : {}),
|
||||
fileName: filename|| "downloaded_file",
|
||||
},
|
||||
});
|
||||
} else {
|
||||
// 创建新记录
|
||||
await db.shareCode.create({
|
||||
await super.create({
|
||||
data: {
|
||||
code,
|
||||
fileId,
|
||||
expiresAt,
|
||||
canUseTimes,
|
||||
isUsed: false,
|
||||
fileName: fileName || null,
|
||||
fileName: filename || "downloaded_file",
|
||||
},
|
||||
});
|
||||
}
|
||||
|
@ -304,6 +305,68 @@ export class ShareCodeService {
|
|||
this.logger.error('生成分享码错误:', error);
|
||||
return error
|
||||
}
|
||||
}
|
||||
|
||||
async getShareCodesWithResources(args: {
|
||||
page?: number;
|
||||
pageSize?: number;
|
||||
where?: Prisma.ShareCodeWhereInput;
|
||||
}): Promise<{
|
||||
items: Array<ShareCode & { resource?: Resource }>;
|
||||
totalPages: number;
|
||||
}> {
|
||||
try {
|
||||
console.log('args:', args.where.OR);
|
||||
// 使用include直接关联查询Resource
|
||||
const { items, totalPages } = await super.findManyWithPagination({
|
||||
...args,
|
||||
select:{
|
||||
id: true,
|
||||
code: true,
|
||||
fileId: true,
|
||||
expiresAt: true,
|
||||
fileName: true,
|
||||
canUseTimes: true,
|
||||
resource: {
|
||||
select: {
|
||||
id: true,
|
||||
type: true,
|
||||
url: true,
|
||||
meta: true,
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
this.logger.log('search result:', items);
|
||||
return {
|
||||
items,
|
||||
totalPages
|
||||
};
|
||||
} catch (error) {
|
||||
this.logger.error('Failed to get share codes with resources', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
async softDeleteShareCodes(ids: string[]): Promise<any> {
|
||||
try {
|
||||
this.logger.log(`尝试软删除分享码,IDs: ${ids.join(', ')}`);
|
||||
const result = await super.softDeleteByIds(ids);
|
||||
this.logger.log(`软删除分享码成功,数量: ${result.length}`);
|
||||
return result;
|
||||
} catch (error) {
|
||||
this.logger.error('软删除分享码失败', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
async updateShareCode(id: string, data: Partial<ShareCode>): Promise<any> {
|
||||
try {
|
||||
this.logger.log(`尝试更新分享码,ID: ${id},数据:`, data);
|
||||
const result = await super.updateById(id, data);
|
||||
this.logger.log(`更新分享码成功:`, result);
|
||||
return result;
|
||||
} catch (error) {
|
||||
this.logger.error('更新分享码失败', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,126 @@
|
|||
import { Form, FormInstance, message } from "antd";
|
||||
import { api } from "@nice/client";
|
||||
import { createContext, useContext, useState } from "react";
|
||||
import { useQueryClient } from "@tanstack/react-query";
|
||||
import { getQueryKey } from "@trpc/react-query";
|
||||
|
||||
interface CodeManageContextType {
|
||||
editForm: FormInstance<any>;
|
||||
isLoading: boolean;
|
||||
currentShareCodes: ShareCodeWithResource;
|
||||
currentPage: number;
|
||||
setCurrentPage: (page: number) => void;
|
||||
pageSize: number;
|
||||
deletShareCode: (id: string) => void;
|
||||
updateCode: (expiresAt: Date, canUseTimes: number) => void
|
||||
setCurrentCodeId: (id: string) => void,
|
||||
currentCodeId: string | null,
|
||||
searchRefetch: () => void,
|
||||
setSearchKeyword: (keyword: string) => void,
|
||||
currentCode: string | null,
|
||||
setCurrentCode: (code: string) => void
|
||||
}
|
||||
|
||||
interface ShareCodeWithResource {
|
||||
items: {
|
||||
id: string;
|
||||
code: string;
|
||||
fileName: string;
|
||||
fileSize: number;
|
||||
expiresAt: string;
|
||||
createdAt: string;
|
||||
canUseTimes: number;
|
||||
resource: {
|
||||
id: string;
|
||||
type: string;
|
||||
url: string;
|
||||
meta: any;
|
||||
}
|
||||
}[],
|
||||
totalPages: number
|
||||
}
|
||||
|
||||
export const CodeManageContext = createContext<CodeManageContextType | null>(null);
|
||||
|
||||
export const CodeManageProvider = ({ children }: { children: React.ReactNode }) => {
|
||||
const [editForm] = Form.useForm();
|
||||
const [currentPage, setCurrentPage] = useState(1);
|
||||
const [currentCodeId, setCurrentCodeId] = useState<string | null>()
|
||||
const [currentCode, setCurrentCode] = useState<string | null>()
|
||||
const queryClient = useQueryClient();
|
||||
const pageSize = 8;
|
||||
// 在组件顶部添加
|
||||
const [searchKeyword, setSearchKeyword] = useState('');
|
||||
// 构建查询条件
|
||||
const whereCondition = {
|
||||
deletedAt: null,
|
||||
...(searchKeyword ? {
|
||||
OR: [
|
||||
{ fileName: { contains: searchKeyword } },
|
||||
{ code: { contains: searchKeyword } }
|
||||
]
|
||||
} : {})
|
||||
};
|
||||
const { data: currentShareCodes, refetch: searchRefetch }: { data: ShareCodeWithResource, refetch: () => void } = api.shareCode.getShareCodesWithResources.useQuery(
|
||||
{
|
||||
page: currentPage,
|
||||
pageSize: pageSize,
|
||||
where: whereCondition,
|
||||
},
|
||||
{
|
||||
enabled: true,
|
||||
refetchOnWindowFocus: false,
|
||||
}
|
||||
)
|
||||
const { mutate: softDeleteShareCode } = api.shareCode.softDeleteShareCodes.useMutation({
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: getQueryKey(api.shareCode) });
|
||||
},
|
||||
onError: () => {
|
||||
message.error('删除失败')
|
||||
}
|
||||
})
|
||||
const { mutate: updateShareCode } = api.shareCode.updateShareCode.useMutation({
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: getQueryKey(api.shareCode) });
|
||||
},
|
||||
onError: () => {
|
||||
message.error('更新失败')
|
||||
}
|
||||
})
|
||||
const deletShareCode = (id: string) => {
|
||||
softDeleteShareCode({ ids: [id] })
|
||||
}
|
||||
const updateCode = (expiresAt: Date, canUseTimes: number) => {
|
||||
if (currentCodeId) updateShareCode({ id: currentCodeId, data: { expiresAt, canUseTimes } })
|
||||
}
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
return <>
|
||||
<CodeManageContext.Provider value={{
|
||||
editForm,
|
||||
isLoading,
|
||||
currentShareCodes,
|
||||
currentPage,
|
||||
setCurrentPage,
|
||||
pageSize,
|
||||
deletShareCode,
|
||||
updateCode,
|
||||
currentCodeId,
|
||||
setCurrentCodeId,
|
||||
searchRefetch,
|
||||
setSearchKeyword,
|
||||
currentCode,
|
||||
setCurrentCode
|
||||
}}>
|
||||
{children}
|
||||
</CodeManageContext.Provider>
|
||||
</>
|
||||
};
|
||||
|
||||
export const useCodeManageContext = () => {
|
||||
const context = useContext(CodeManageContext);
|
||||
if (!context) {
|
||||
throw new Error("useCodeManageContext must be used within a CodeManageProvider");
|
||||
}
|
||||
return context;
|
||||
};
|
|
@ -0,0 +1,72 @@
|
|||
import { useCodeManageContext } from "./CodeManageContext";
|
||||
import { Form, DatePicker, Input, Button } from "antd";
|
||||
import dayjs from "dayjs";
|
||||
import { useState } from "react";
|
||||
|
||||
export default function CodeManageEdit() {
|
||||
const { editForm } = useCodeManageContext();
|
||||
// 验证数字输入只能是大于等于0的整数
|
||||
const validatePositiveInteger = (_: any, value: string) => {
|
||||
const num = parseInt(value, 10);
|
||||
if (isNaN(num) || num < 0 || num !== parseFloat(value)) {
|
||||
return Promise.reject("请输入大于等于0的整数");
|
||||
}
|
||||
return Promise.resolve();
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="w-full max-w-md mx-auto bg-white p-6 rounded-lg">
|
||||
<Form
|
||||
form={editForm}
|
||||
layout="vertical"
|
||||
className="space-y-4"
|
||||
>
|
||||
<Form.Item
|
||||
label={<span className="text-gray-700 font-medium">分享码有效期</span>}
|
||||
name="expiresAt"
|
||||
rules={[{ required: true, message: "请选择有效期" }]}
|
||||
className="mb-5"
|
||||
>
|
||||
<DatePicker
|
||||
className="w-full"
|
||||
showTime
|
||||
placeholder="选择日期和时间"
|
||||
disabledDate={(current) => current && current < dayjs().startOf('day')}
|
||||
disabledTime={(current) => {
|
||||
if (current && current.isSame(dayjs(), 'day')) {
|
||||
return {
|
||||
disabledHours: () => [...Array(dayjs().hour()).keys()],
|
||||
disabledMinutes: (selectedHour) => {
|
||||
if (selectedHour === dayjs().hour()) {
|
||||
return [...Array(dayjs().minute()).keys()];
|
||||
}
|
||||
return [];
|
||||
}
|
||||
};
|
||||
}
|
||||
return {};
|
||||
}}
|
||||
/>
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item
|
||||
label={<span className="text-gray-700 font-medium">使用次数</span>}
|
||||
name="canUseTimes"
|
||||
rules={[
|
||||
{ required: true, message: "请输入使用次数" },
|
||||
{ validator: validatePositiveInteger }
|
||||
]}
|
||||
className="mb-5"
|
||||
>
|
||||
<Input
|
||||
type="number"
|
||||
min={0}
|
||||
step={1}
|
||||
placeholder="请输入使用次数"
|
||||
className="w-full"
|
||||
/>
|
||||
</Form.Item>
|
||||
</Form>
|
||||
</div>
|
||||
);
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
import CodeManageSearchBase from "./CodeManageSearchBase";
|
||||
import CodeManageDisplay from "./CodeMangeDisplay";
|
||||
export default function CodeManageLayout() {
|
||||
return (
|
||||
<div className="max-w-[1100px] mx-auto h-[100vh]">
|
||||
<CodeManageSearchBase></CodeManageSearchBase>
|
||||
<CodeManageDisplay></CodeManageDisplay>
|
||||
</div>
|
||||
)
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
import { Button, Form, Input } from 'antd';
|
||||
import { useCodeManageContext } from './CodeManageContext';
|
||||
import { ChangeEvent, useRef } from 'react';
|
||||
|
||||
export default function CodeManageSearchBase() {
|
||||
const { setCurrentPage, searchRefetch, setSearchKeyword } = useCodeManageContext();
|
||||
const debounceTimer = useRef<NodeJS.Timeout | null>(null);
|
||||
const onSearch = (value: string) => {
|
||||
console.log(value);
|
||||
setSearchKeyword(value);
|
||||
setCurrentPage(1)
|
||||
searchRefetch()
|
||||
};
|
||||
const onChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||
// 设置表单值
|
||||
setSearchKeyword(e.target.value);
|
||||
// 设置页码为1,确保从第一页开始显示搜索结果
|
||||
setCurrentPage(1);
|
||||
// 使用防抖处理,避免频繁发送请求
|
||||
if (debounceTimer.current) {
|
||||
clearTimeout(debounceTimer.current);
|
||||
}
|
||||
debounceTimer.current = setTimeout(() => {
|
||||
// 触发查询
|
||||
searchRefetch();
|
||||
}, 300); // 300毫秒的防抖延迟
|
||||
};
|
||||
return <>
|
||||
<div className="py-4 mt-10 w-2/3 mx-auto">
|
||||
<Form>
|
||||
<Form.Item name="search" label="关键字搜索">
|
||||
<Input.Search
|
||||
placeholder="输入分享码或文件名"
|
||||
enterButton
|
||||
onSearch={onSearch}
|
||||
onChange={onChange}
|
||||
/>
|
||||
</Form.Item>
|
||||
</Form>
|
||||
</div>
|
||||
</>
|
||||
}
|
|
@ -0,0 +1,87 @@
|
|||
import { message, Modal, Pagination } from "antd";
|
||||
import ShareCodeList from "./ShareCodeList";
|
||||
import { useCodeManageContext } from "./CodeManageContext";
|
||||
import { useEffect, useState } from "react";
|
||||
import { ExclamationCircleFilled } from "@ant-design/icons";
|
||||
import CodeManageEdit from "./CodeManageEdit";
|
||||
import dayjs from "dayjs";
|
||||
export default function CodeMangeDisplay() {
|
||||
const { isLoading, currentShareCodes, pageSize, currentPage,
|
||||
setCurrentPage, deletShareCode, editForm,
|
||||
updateCode, setCurrentCodeId, setCurrentCode, currentCode
|
||||
} = useCodeManageContext();
|
||||
const [modalOpen, setModalOpen] = useState(false);
|
||||
const [formLoading, setFormLoading] = useState(false);
|
||||
const { confirm } = Modal;
|
||||
const handleEdit = (id: string, expiresAt: Date, canUseTimes: number, code: string) => {
|
||||
console.log('编辑分享码:', id);
|
||||
setCurrentCodeId(id)
|
||||
setModalOpen(true);
|
||||
setCurrentCode(code)
|
||||
editForm.setFieldsValue({
|
||||
expiresAt: dayjs(expiresAt),
|
||||
canUseTimes: canUseTimes
|
||||
});
|
||||
};
|
||||
const handleEditOk = () => {
|
||||
const expiresAt = editForm.getFieldsValue().expiresAt.tz('Asia/Shanghai').toDate()
|
||||
const canUseTimes = Number(editForm.getFieldsValue().canUseTimes)
|
||||
updateCode(expiresAt, canUseTimes)
|
||||
message.success('分享码已更新')
|
||||
setModalOpen(false)
|
||||
}
|
||||
const handleDelete = (id: string) => {
|
||||
console.log('删除分享码:', id);
|
||||
confirm({
|
||||
title: '确定删除该分享码吗',
|
||||
icon: <ExclamationCircleFilled />,
|
||||
content: '',
|
||||
okText: '删除',
|
||||
okType: 'danger',
|
||||
cancelText: '取消',
|
||||
async onOk() {
|
||||
deletShareCode(id)
|
||||
message.success('分享码已删除')
|
||||
},
|
||||
onCancel() {
|
||||
},
|
||||
});
|
||||
};
|
||||
useEffect(() => {
|
||||
console.log('currentShareCodes:', currentShareCodes);
|
||||
}, [currentShareCodes]);
|
||||
return <>
|
||||
<div className="w-full min-h-[550px] mx-auto">
|
||||
<ShareCodeList
|
||||
data={currentShareCodes?.items}
|
||||
loading={isLoading}
|
||||
onEdit={handleEdit}
|
||||
onDelete={handleDelete}
|
||||
/>
|
||||
</div>
|
||||
<div className="py-4 mt-10 w-2/3 mx-auto flex justify-center">
|
||||
<Pagination
|
||||
defaultCurrent={currentPage}
|
||||
total={currentShareCodes?.totalPages * pageSize}
|
||||
pageSize={pageSize}
|
||||
onChange={(page, pageSize) => {
|
||||
setCurrentPage(page);
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
<Modal
|
||||
width={550}
|
||||
onOk={() => {
|
||||
handleEditOk()
|
||||
}}
|
||||
centered
|
||||
open={modalOpen}
|
||||
confirmLoading={formLoading}
|
||||
onCancel={() => {
|
||||
setModalOpen(false);
|
||||
}}
|
||||
title={`编辑分享码:${currentCode}`}>
|
||||
<CodeManageEdit></CodeManageEdit>
|
||||
</Modal>
|
||||
</>
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
import React from 'react';
|
||||
import { List,} from 'antd';
|
||||
import dayjs from 'dayjs';
|
||||
import utc from 'dayjs/plugin/utc';
|
||||
import timezone from 'dayjs/plugin/timezone';
|
||||
import ShareCodeListCard from './ShareCodeListCard';
|
||||
|
||||
dayjs.extend(utc);
|
||||
dayjs.extend(timezone);
|
||||
|
||||
export interface ShareCodeItem {
|
||||
id: string;
|
||||
code: string;
|
||||
expiresAt: string;
|
||||
fileName: string;
|
||||
canUseTimes: number;
|
||||
resource: {
|
||||
id: string;
|
||||
type: string;
|
||||
url: string;
|
||||
meta: {
|
||||
size: number;
|
||||
filename: string;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
interface ShareCodeListProps {
|
||||
data: ShareCodeItem[];
|
||||
loading?: boolean;
|
||||
onEdit?: (id: string,expiresAt:Date,canUseTimes:number,code:string) => void;
|
||||
onDelete?: (id: string) => void;
|
||||
}
|
||||
|
||||
const ShareCodeList: React.FC<ShareCodeListProps> = ({
|
||||
data,
|
||||
loading,
|
||||
onEdit,
|
||||
onDelete
|
||||
}) => {
|
||||
|
||||
return (
|
||||
<List
|
||||
grid={{ gutter: 16, xs: 1, sm: 2, md: 4, lg: 4 }}
|
||||
dataSource={data}
|
||||
loading={loading}
|
||||
renderItem={(item) => (
|
||||
<List.Item>
|
||||
<ShareCodeListCard item={item} onEdit={onEdit} onDelete={onDelete} />
|
||||
</List.Item>
|
||||
)}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
export default ShareCodeList;
|
|
@ -0,0 +1,54 @@
|
|||
import { DeleteOutlined, EditOutlined } from "@ant-design/icons";
|
||||
import { Button, Card, Typography } from "antd";
|
||||
import dayjs from "dayjs";
|
||||
import { ShareCodeItem } from "./ShareCodeList";
|
||||
import { useEffect } from "react";
|
||||
|
||||
export default function ShareCodeListCard({ item, onEdit, onDelete }: { item: ShareCodeItem, onEdit: (id: string,expiresAt:Date,canUseTimes:number,code:string) => void, onDelete: (id: string) => void }) {
|
||||
useEffect(() => {
|
||||
console.log('item:', item);
|
||||
}, [item]);
|
||||
return <div>
|
||||
<Card
|
||||
className="shadow-md hover:shadow-lg transition-shadow duration-300 space-x-4"
|
||||
title={
|
||||
<Typography.Text
|
||||
strong
|
||||
className="text-lg font-semibold text-blue-600"
|
||||
>
|
||||
{item.code}
|
||||
</Typography.Text>
|
||||
}
|
||||
hoverable
|
||||
actions={[
|
||||
<Button
|
||||
type="text"
|
||||
icon={<EditOutlined />}
|
||||
onClick={() => onEdit?.(item.id,dayjs(item.expiresAt).toDate(),item.canUseTimes,item.code)}
|
||||
className="text-blue-500 hover:text-blue-700"
|
||||
/>,
|
||||
<Button
|
||||
type="text"
|
||||
icon={<DeleteOutlined />}
|
||||
onClick={() => onDelete?.(item.id)}
|
||||
className="text-red-500 hover:text-red-700"
|
||||
/>
|
||||
]}
|
||||
>
|
||||
<div className="space-y-2">
|
||||
<p className="text-gray-700">
|
||||
<span className="font-medium">文件名:</span> {item.fileName}
|
||||
</p>
|
||||
<p className="text-gray-700">
|
||||
<span className="font-medium">文件大小:</span> {Math.max(0.01, (item?.resource?.meta?.size / 1024 / 1024)).toFixed(2)} MB
|
||||
</p>
|
||||
<p className="text-gray-700">
|
||||
<span className="font-medium">过期时间:</span> {dayjs(item.expiresAt).format('YYYY-MM-DD HH:mm:ss')}
|
||||
</p>
|
||||
<p className="text-gray-700">
|
||||
<span className="font-medium">剩余使用次数:</span> {item.canUseTimes}
|
||||
</p>
|
||||
</div>
|
||||
</Card>
|
||||
</div>
|
||||
}
|
|
@ -56,13 +56,13 @@ const LoginPage: React.FC = () => {
|
|||
}>
|
||||
<div
|
||||
className="flex items-center transition-all hover:bg-white overflow-hidden border-2 border-white bg-gray-50 shadow-elegant rounded-xl "
|
||||
style={{ width: 800, height: 600 }}>
|
||||
style={{ width: 900, height: 600 }}>
|
||||
<div
|
||||
className={`transition-all h-full flex-1 text-white p-10 flex items-center justify-center bg-primary`}>
|
||||
{showLogin ? (
|
||||
<div className="flex flex-col">
|
||||
<SineWave width={300} height={200} />
|
||||
<div className="text-2xl my-4">没有账号?</div>
|
||||
<SineWave width={350} height={400} />
|
||||
{/* <div className="text-2xl my-4">没有账号?</div>
|
||||
<div className="my-4 font-thin text-sm">
|
||||
点击注册一个属于你自己的账号吧!
|
||||
</div>
|
||||
|
@ -70,7 +70,7 @@ const LoginPage: React.FC = () => {
|
|||
onClick={() => setShowLogin(false)}
|
||||
className="hover:translate-y-1 my-8 p-2 text-center rounded-xl border-white border hover:bg-white hover:text-primary hover:shadow-xl hover:cursor-pointer transition-all">
|
||||
注册
|
||||
</div>
|
||||
</div> */}
|
||||
</div>
|
||||
) : (
|
||||
<div className="flex flex-col">
|
||||
|
@ -122,8 +122,8 @@ const LoginPage: React.FC = () => {
|
|||
]}>
|
||||
<Input.Password />
|
||||
</Form.Item>
|
||||
<div className="flex items-center justify-center">
|
||||
<Button type="primary" htmlType="submit">
|
||||
<div className="flex items-center justify-center mt-4">
|
||||
<Button type="primary" className="w-full" htmlType="submit">
|
||||
登录
|
||||
</Button>
|
||||
</div>
|
||||
|
|
|
@ -7,6 +7,10 @@ import {
|
|||
} from "react-router-dom";
|
||||
import ErrorPage from "../app/error";
|
||||
import DeptSettingPage from "../app/admin/deptsettingpage/page";
|
||||
import LoginPage from "../app/login";
|
||||
import WithAuth from "../components/utils/with-auth";
|
||||
import { CodeManageProvider } from "../app/admin/code-manage/CodeManageContext";
|
||||
import CodeManageLayout from "../app/admin/code-manage/CodeManageLayout";
|
||||
interface CustomIndexRouteObject extends IndexRouteObject {
|
||||
name?: string;
|
||||
breadcrumb?: string;
|
||||
|
@ -33,6 +37,21 @@ export const routes: CustomRouteObject[] = [
|
|||
element: <DeptSettingPage></DeptSettingPage>,
|
||||
errorElement: <ErrorPage />,
|
||||
},
|
||||
{
|
||||
path: "/login",
|
||||
breadcrumb: "登录",
|
||||
element: <LoginPage></LoginPage>,
|
||||
},
|
||||
{
|
||||
path: "/code-manage",
|
||||
element: <>
|
||||
<WithAuth>
|
||||
<CodeManageProvider>
|
||||
<CodeManageLayout></CodeManageLayout>
|
||||
</CodeManageProvider>
|
||||
</WithAuth>
|
||||
</>
|
||||
},
|
||||
];
|
||||
|
||||
export const router = createBrowserRouter(routes);
|
||||
|
|
|
@ -360,6 +360,7 @@ model Resource {
|
|||
ownerId String? @map("owner_id")
|
||||
post Post? @relation(fields: [postId], references: [id])
|
||||
postId String? @map("post_id")
|
||||
shareCode ShareCode?
|
||||
|
||||
// 索引
|
||||
@@index([type])
|
||||
|
@ -431,7 +432,10 @@ model ShareCode {
|
|||
isUsed Boolean? @default(false)
|
||||
fileName String? @map("file_name")
|
||||
canUseTimes Int?
|
||||
resource Resource? @relation(fields: [fileId], references: [fileId])
|
||||
deletedAt DateTime? @map("deleted_at")
|
||||
@@index([code])
|
||||
@@index([fileId])
|
||||
@@index([expiresAt])
|
||||
}
|
||||
@@map("share_code")
|
||||
}
|
|
@ -59,6 +59,7 @@ export enum ObjectType {
|
|||
LECTURE = "lecture",
|
||||
ENROLLMENT = "enrollment",
|
||||
RESOURCE = "resource",
|
||||
SHARE_CODE = "shareCode",
|
||||
}
|
||||
export enum RolePerms {
|
||||
// Create Permissions 创建权限
|
||||
|
|
Loading…
Reference in New Issue