perf: 站点监控支持批量导入域名和ip

This commit is contained in:
xiaojunnuo
2025-06-05 23:31:36 +08:00
parent 6467edb843
commit 2d7729dbe9
12 changed files with 358 additions and 98 deletions
@@ -56,6 +56,14 @@ export const siteInfoApi = {
});
},
async Import(form: any) {
return await request({
url: apiPrefix + "/import",
method: "post",
data: form,
});
},
async DisabledChange(id: number, disabled: boolean) {
return await request({
url: apiPrefix + "/disabledChange",
@@ -8,6 +8,7 @@ import { useSettingStore } from "/@/store/settings";
import { mySuiteApi } from "/@/views/certd/suite/mine/api";
import { mitter } from "/@/utils/util.mitt";
import { useSiteIpMonitor } from "./ip/use";
import { useSiteImport } from "/@/views/certd/monitor/site/use";
export default function ({ crudExpose, context }: CreateCrudOptionsProps): CreateCrudOptionsRet {
const { t } = useI18n();
@@ -44,6 +45,7 @@ export default function ({ crudExpose, context }: CreateCrudOptionsProps): Creat
});
const { openSiteIpMonitorDialog } = useSiteIpMonitor();
const { openSiteImportDialog } = useSiteImport();
return {
crudOptions: {
request: {
@@ -97,6 +99,19 @@ export default function ({ crudExpose, context }: CreateCrudOptionsProps): Creat
await crudExpose.openAdd({});
},
},
//导入按钮
import: {
show: true,
text: "批量导入",
type: "primary",
async click() {
openSiteImportDialog({
afterSubmit() {
crudExpose.doRefresh();
},
});
},
},
},
},
rowHandle: {
@@ -235,7 +250,7 @@ export default function ({ crudExpose, context }: CreateCrudOptionsProps): Creat
},
};
return (
<a-popover placement="left" v-slots={slots} overlayStyle={{ maxWidth: "30%" }}>
<a-popover placement={"left"} v-slots={slots} overlayStyle={{ maxWidth: "30%" }}>
{row.certDomains}
</a-popover>
);
@@ -68,4 +68,11 @@ export const siteIpApi = {
},
});
},
async Import(form: any) {
return await request({
url: apiPrefix + "/import",
method: "post",
data: form,
});
},
};
@@ -4,13 +4,11 @@ import { AddReq, CreateCrudOptionsProps, CreateCrudOptionsRet, DelReq, dict, Edi
import { siteIpApi } from "./api";
import dayjs from "dayjs";
import { Modal, notification } from "ant-design-vue";
import { useSettingStore } from "/@/store/settings";
import { useSiteIpMonitor } from "/@/views/certd/monitor/site/ip/use";
export default function ({ crudExpose, context }: CreateCrudOptionsProps): CreateCrudOptionsRet {
const { t } = useI18n();
const api = siteIpApi;
const { crudBinding } = crudExpose;
const pageRequest = async (query: UserPageQuery): Promise<UserPageRes> => {
if (!query.query) {
query.query = {};
@@ -36,8 +34,6 @@ export default function ({ crudExpose, context }: CreateCrudOptionsProps): Creat
return res;
};
const settingsStore = useSettingStore();
const checkStatusDict = dict({
data: [
{ label: "成功", value: "ok", color: "green" },
@@ -45,6 +41,7 @@ export default function ({ crudExpose, context }: CreateCrudOptionsProps): Creat
{ label: "异常", value: "error", color: "red" },
],
});
const { openSiteIpImportDialog } = useSiteIpMonitor();
return {
crudOptions: {
request: {
@@ -75,6 +72,19 @@ export default function ({ crudExpose, context }: CreateCrudOptionsProps): Creat
await crudExpose.openAdd({});
},
},
import: {
show: true,
text: "批量导入",
type: "primary",
async click() {
openSiteIpImportDialog({
siteId: context.props.siteId,
afterSubmit() {
crudExpose.doRefresh();
},
});
},
},
load: {
text: "同步IP",
type: "primary",
@@ -295,6 +305,7 @@ export default function ({ crudExpose, context }: CreateCrudOptionsProps): Creat
data: [
{ label: "同步", value: "sync", color: "green" },
{ label: "手动", value: "manual", color: "blue" },
{ label: "导入", value: "import", color: "blue" },
],
}),
form: {
@@ -1,11 +1,10 @@
import { useFormWrapper } from "@fast-crud/fast-crud";
import { useRouter } from "vue-router";
import SiteIpCertMonitor from "./index.vue";
import { siteIpApi } from "/@/views/certd/monitor/site/ip/api";
export function useSiteIpMonitor() {
const { openDialog } = useFormWrapper();
const router = useRouter();
const { openDialog, openCrudFormDialog } = useFormWrapper();
async function openSiteIpMonitorDialog(opts: { siteId: number }) {
await openDialog({
@@ -34,7 +33,42 @@ export function useSiteIpMonitor() {
});
}
async function openSiteIpImportDialog(opts: { afterSubmit: any; siteId: any }) {
const { afterSubmit } = opts;
await openCrudFormDialog<any>({
crudOptions: {
columns: {
text: {
type: "textarea",
title: "IP列表",
form: {
helper: "IP或者CNAME域名,一行一个",
rules: [{ required: true, message: "请输入要导入的IP或域名" }],
component: {
placeholder: "192.168.1.2\ncname.foo.com",
rows: 8,
},
col: {
span: 24,
},
},
},
},
form: {
async doSubmit({ form }) {
return siteIpApi.Import({
...form,
siteId: opts.siteId,
});
},
afterSubmit,
},
},
});
}
return {
openSiteIpMonitorDialog,
openSiteIpImportDialog,
};
}
@@ -0,0 +1,41 @@
import { useFormWrapper } from "@fast-crud/fast-crud";
import { siteInfoApi } from "./api";
export function useSiteImport() {
const { openCrudFormDialog } = useFormWrapper();
async function openSiteImportDialog(opts: { afterSubmit: any }) {
const { afterSubmit } = opts;
await openCrudFormDialog<any>({
crudOptions: {
columns: {
text: {
type: "textarea",
title: "域名列表",
form: {
helper: "格式【域名:端口:名称】,一行一个,其中端口、名称可以省略\n比如:\nwww.baidu.com:443:百度\nwww.taobao.com::淘宝\nwww.google.com",
rules: [{ required: true, message: "请输入要导入的域名" }],
component: {
placeholder: "www.baidu.com:443:百度\nwww.taobao.com::淘宝\nwww.google.com\n",
rows: 8,
},
col: {
span: 24,
},
},
},
},
form: {
async doSubmit({ form }) {
return siteInfoApi.Import(form);
},
afterSubmit,
},
},
});
}
return {
openSiteImportDialog,
};
}