mirror of
https://github.com/usual2970/certimate.git
synced 2025-06-07 21:19:51 +00:00
refactor: clean code
This commit is contained in:
parent
2374bb56fa
commit
d693d26323
@ -46,7 +46,7 @@ import AccessEditFormTencentCloudConfig from "./AccessEditFormTencentCloudConfig
|
||||
import AccessEditFormVolcEngineConfig from "./AccessEditFormVolcEngineConfig";
|
||||
import AccessEditFormWebhookConfig from "./AccessEditFormWebhookConfig";
|
||||
|
||||
type AccessEditFormModelType = Partial<Omit<AccessModel, "id" | "created" | "updated" | "deleted">>;
|
||||
type AccessEditFormModelType = Partial<MaybeModelRecord<AccessModel>>;
|
||||
|
||||
export type AccessEditFormProps = {
|
||||
className?: string;
|
||||
@ -79,9 +79,9 @@ const AccessEditForm = forwardRef<AccessEditFormInstance, AccessEditFormProps>((
|
||||
const formRule = createSchemaFieldRule(formSchema);
|
||||
const [form] = Form.useForm<z.infer<typeof formSchema>>();
|
||||
|
||||
const [initialValues, setInitialValues] = useState<Partial<z.infer<typeof formSchema>>>(model ?? {});
|
||||
const [initialValues, setInitialValues] = useState<Partial<z.infer<typeof formSchema>>>(model as Partial<z.infer<typeof formSchema>>);
|
||||
useEffect(() => {
|
||||
setInitialValues(model ?? {});
|
||||
setInitialValues(model as Partial<z.infer<typeof formSchema>>);
|
||||
}, [model]);
|
||||
|
||||
const [configType, setConfigType] = useState(model?.configType);
|
||||
|
@ -9,7 +9,7 @@ import { getErrMsg } from "@/utils/error";
|
||||
import AccessEditForm, { type AccessEditFormInstance } from "./AccessEditForm";
|
||||
|
||||
export type AccessEditModalProps = {
|
||||
data?: Partial<AccessModel>;
|
||||
data?: Partial<MaybeModelRecord<AccessModel>>;
|
||||
loading?: boolean;
|
||||
mode: "add" | "edit" | "copy";
|
||||
open?: boolean;
|
||||
|
4
ui/src/declarations.d.ts
vendored
4
ui/src/declarations.d.ts
vendored
@ -1,4 +0,0 @@
|
||||
declare module "antd/locale/zh_CN" {
|
||||
import zhCN from "antd/locale/zh_CN";
|
||||
export default zhCN;
|
||||
}
|
@ -1,5 +1,3 @@
|
||||
import { type BaseModel } from "pocketbase";
|
||||
|
||||
/*
|
||||
注意:如果追加新的常量值,请保持以 ASCII 排序。
|
||||
NOTICE: If you add new constant, please keep ASCII order.
|
||||
|
@ -1,8 +1,6 @@
|
||||
import { type BaseModel } from "pocketbase";
|
||||
import { type WorkflowModel } from "./workflow";
|
||||
|
||||
import { WorkflowModel } from "./workflow";
|
||||
|
||||
export interface CertificateModel extends Omit<BaseModel, "created" | "updated"> {
|
||||
export interface CertificateModel extends BaseModel {
|
||||
san: string;
|
||||
certificate: string;
|
||||
privateKey: string;
|
||||
|
@ -1,6 +1,4 @@
|
||||
import { type BaseModel } from "pocketbase";
|
||||
|
||||
export interface SettingsModel<T> extends Omit<BaseModel, "created" | "updated"> {
|
||||
export interface SettingsModel<T> extends BaseModel {
|
||||
name: string;
|
||||
content: T;
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
import { produce } from "immer";
|
||||
import { nanoid } from "nanoid";
|
||||
import { type BaseModel } from "pocketbase";
|
||||
|
||||
import i18n from "@/i18n";
|
||||
import { deployTargets, KVType } from "./domain";
|
||||
@ -28,7 +27,7 @@ export type WorkflowOutput = {
|
||||
error: string;
|
||||
};
|
||||
|
||||
export interface WorkflowModel extends Omit<BaseModel, "created" | "updated"> {
|
||||
export interface WorkflowModel extends BaseModel {
|
||||
name: string;
|
||||
description?: string;
|
||||
type: string;
|
||||
@ -152,6 +151,8 @@ export const initWorkflow = (): WorkflowModel => {
|
||||
crontab: "0 0 * * *",
|
||||
enabled: false,
|
||||
draft: rs,
|
||||
created: new Date().toUTCString(),
|
||||
updated: new Date().toUTCString(),
|
||||
};
|
||||
};
|
||||
|
||||
|
@ -24,11 +24,6 @@
|
||||
--input: 20 5.9% 90%;
|
||||
--ring: 24.6 95% 53.1%;
|
||||
--radius: 0.5rem;
|
||||
--chart-1: 12 76% 61%;
|
||||
--chart-2: 173 58% 39%;
|
||||
--chart-3: 197 37% 24%;
|
||||
--chart-4: 43 74% 66%;
|
||||
--chart-5: 27 87% 67%;
|
||||
}
|
||||
|
||||
.dark {
|
||||
@ -51,10 +46,5 @@
|
||||
--border: 12 6.5% 15.1%;
|
||||
--input: 12 6.5% 15.1%;
|
||||
--ring: 20.5 90.2% 48.2%;
|
||||
--chart-1: 220 70% 50%;
|
||||
--chart-2: 160 60% 45%;
|
||||
--chart-3: 30 80% 55%;
|
||||
--chart-4: 280 65% 60%;
|
||||
--chart-5: 340 75% 55%;
|
||||
}
|
||||
}
|
||||
|
13
ui/src/global.d.ts
vendored
Normal file
13
ui/src/global.d.ts
vendored
Normal file
@ -0,0 +1,13 @@
|
||||
import { type BaseModel as PbBaseModel } from "pocketbase";
|
||||
|
||||
declare global {
|
||||
declare interface BaseModel extends PbBaseModel {
|
||||
deleted?: string;
|
||||
}
|
||||
|
||||
declare type MaybeModelRecord<T extends BaseModel = BaseModel> = T | Omit<T, "id" | "created" | "updated" | "deleted">;
|
||||
|
||||
declare type MaybeModelRecordWithId<T extends BaseModel = BaseModel> = T | Pick<T, "id">;
|
||||
}
|
||||
|
||||
export {};
|
@ -12,7 +12,7 @@ export const list = async () => {
|
||||
});
|
||||
};
|
||||
|
||||
export const save = async (record: AccessModel | Omit<AccessModel, "id" | "created" | "updated" | "deleted">) => {
|
||||
export const save = async (record: MaybeModelRecord<AccessModel>) => {
|
||||
if (record.id) {
|
||||
return await getPocketBase().collection(COLLECTION_NAME).update<AccessModel>(record.id, record);
|
||||
}
|
||||
@ -20,7 +20,7 @@ export const save = async (record: AccessModel | Omit<AccessModel, "id" | "creat
|
||||
return await getPocketBase().collection(COLLECTION_NAME).create<AccessModel>(record);
|
||||
};
|
||||
|
||||
export const remove = async (record: AccessModel) => {
|
||||
export const remove = async (record: MaybeModelRecordWithId<AccessModel>) => {
|
||||
record = { ...record, deleted: dayjs.utc().format("YYYY-MM-DD HH:mm:ss") };
|
||||
await getPocketBase().collection(COLLECTION_NAME).update<AccessModel>(record.id!, record);
|
||||
};
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { SettingsModel } from "@/domain/settings";
|
||||
import { type SettingsModel } from "@/domain/settings";
|
||||
import { getPocketBase } from "./pocketbase";
|
||||
|
||||
export const get = async <T>(name: string) => {
|
||||
@ -13,7 +13,7 @@ export const get = async <T>(name: string) => {
|
||||
}
|
||||
};
|
||||
|
||||
export const save = async <T>(record: SettingsModel<T>) => {
|
||||
export const save = async <T>(record: MaybeModelRecordWithId<SettingsModel<T>>) => {
|
||||
if (record.id) {
|
||||
return await getPocketBase().collection("settings").update<SettingsModel<T>>(record.id, record);
|
||||
}
|
||||
|
@ -39,7 +39,7 @@ export const save = async (record: Record<string, string | boolean | WorkflowNod
|
||||
return await getPocketBase().collection(COLLECTION_NAME).create<WorkflowModel>(record);
|
||||
};
|
||||
|
||||
export const remove = async (record: WorkflowModel) => {
|
||||
export const remove = async (record: MaybeModelRecordWithId<WorkflowModel>) => {
|
||||
return await getPocketBase().collection(COLLECTION_NAME).delete(record.id);
|
||||
};
|
||||
|
||||
|
@ -6,9 +6,9 @@ import { list as listAccess, save as saveAccess, remove as removeAccess } from "
|
||||
|
||||
export interface AccessState {
|
||||
accesses: AccessModel[];
|
||||
createAccess: (access: Omit<AccessModel, "id" | "created" | "udpated" | "deleted">) => void;
|
||||
updateAccess: (access: AccessModel) => void;
|
||||
deleteAccess: (access: AccessModel) => void;
|
||||
createAccess: (access: MaybeModelRecord<AccessModel>) => void;
|
||||
updateAccess: (access: MaybeModelRecordWithId<AccessModel>) => void;
|
||||
deleteAccess: (access: MaybeModelRecordWithId<AccessModel>) => void;
|
||||
fetchAccesses: () => Promise<void>;
|
||||
}
|
||||
|
||||
|
@ -36,14 +36,14 @@ export const useWorkflowStore = create<WorkflowState>((set, get) => ({
|
||||
id: "",
|
||||
name: "placeholder",
|
||||
type: WorkflowNodeType.Start,
|
||||
},
|
||||
} as WorkflowModel,
|
||||
initialized: false,
|
||||
init: async (id?: string) => {
|
||||
let data: WorkflowModel = {
|
||||
let data = {
|
||||
id: "",
|
||||
name: "placeholder",
|
||||
type: "auto",
|
||||
};
|
||||
} as WorkflowModel;
|
||||
|
||||
if (!id) {
|
||||
data = initWorkflow();
|
||||
|
@ -4,12 +4,18 @@
|
||||
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo",
|
||||
"target": "ES2020",
|
||||
"useDefineForClassFields": true,
|
||||
"lib": ["ES2020", "DOM", "DOM.Iterable"],
|
||||
"lib": [
|
||||
"ES2020",
|
||||
"DOM",
|
||||
"DOM.Iterable"
|
||||
],
|
||||
"module": "ESNext",
|
||||
"skipLibCheck": true,
|
||||
"baseUrl": ".",
|
||||
"paths": {
|
||||
"@/*": ["./src/*"]
|
||||
"@/*": [
|
||||
"./src/*"
|
||||
]
|
||||
},
|
||||
/* Bundler mode */
|
||||
"moduleResolution": "bundler",
|
||||
@ -25,5 +31,7 @@
|
||||
"noUnusedParameters": true,
|
||||
"noFallthroughCasesInSwitch": true
|
||||
},
|
||||
"include": ["src", "src/declarations.d.ts"]
|
||||
"include": [
|
||||
"src"
|
||||
]
|
||||
}
|
||||
|
@ -11,8 +11,9 @@
|
||||
"compilerOptions": {
|
||||
"baseUrl": ".",
|
||||
"paths": {
|
||||
"@/*": ["./src/*"]
|
||||
"@/*": [
|
||||
"./src/*"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -9,5 +9,7 @@
|
||||
"strict": true,
|
||||
"noEmit": true
|
||||
},
|
||||
"include": ["vite.config.ts"]
|
||||
"include": [
|
||||
"vite.config.ts"
|
||||
]
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user