From e54dd44edbb66f81fdbaa29e5f052905573f6aae Mon Sep 17 00:00:00 2001 From: jxxghp Date: Fri, 7 Jul 2023 10:26:15 +0800 Subject: [PATCH] =?UTF-8?q?add=20=E7=AB=99=E7=82=B9=E7=BC=96=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/types.ts | 2 + src/components/cards/SiteCard.vue | 217 ++++++++++++++++++++++++++---- 2 files changed, 195 insertions(+), 24 deletions(-) diff --git a/src/api/types.ts b/src/api/types.ts index 2b490fdd..d08bebfa 100644 --- a/src/api/types.ts +++ b/src/api/types.ts @@ -173,6 +173,8 @@ export interface Site { filter?: string // 是否演染 render?: number + // 是否公开站点 + public?: number // 备注 note?: string // 流控单位周期 diff --git a/src/components/cards/SiteCard.vue b/src/components/cards/SiteCard.vue index a88940ca..52e698c2 100644 --- a/src/components/cards/SiteCard.vue +++ b/src/components/cards/SiteCard.vue @@ -32,6 +32,9 @@ const updateButtonDisable = ref(false); // 更新站点Cookie UA弹窗 const siteCookieDialog = ref(false); +// 站点编辑弹窗 +const siteInfoDialog = ref(false); + // 用户名密码表单 const userPwForm = ref({ username: "", @@ -70,6 +73,11 @@ const handleSiteUpdate = async () => { siteCookieDialog.value = true; }; +// 打开站点编辑弹窗 +const handleSiteInfo = async () => { + siteInfoDialog.value = true; +}; + // 调用API,更新站点Cookie UA const updateSiteCookie = async () => { try { @@ -88,7 +96,7 @@ const updateSiteCookie = async () => { params: { username: userPwForm.value.username, password: userPwForm.value.password, - } + }, } ); if (result.success) { @@ -103,6 +111,68 @@ const updateSiteCookie = async () => { } }; +// 调用API更新站点信息 +const updateSiteInfo = async () => { + try { + // 更新按钮状态 + siteInfoDialog.value = false; + + const result: { [key: string]: any } = await api.put("site", siteForm); + if (result.success) { + $toast.success(`${props.site?.name} 更新成功!`); + } else { + $toast.error(`${props.site?.name} 更新失败:${result.message}`); + } + } catch (error) { + $toast.error(`${props.site?.name} 更新失败!`); + console.error(error); + } +}; + +// 站点编辑表单数据 +const siteForm = reactive({ + // ID + id: props.site?.id, + // 站点名称 + name: props.site?.name, + // 站点主域名Key + domain: props.site?.domain, + // 站点地址 + url: props.site?.url, + // 站点优先级 + pri: props.site?.pri, + // RSS地址 + rss: props.site?.rss, + // Cookie + cookie: props.site?.cookie, + // User-Agent + ua: props.site?.ua, + // 是否使用代理 + proxy: props.site?.proxy ? true : false, + // 过滤规则 + filter: props.site?.filter, + // 是否演染 + render: props.site?.render ? true : false, + // 是否公开站点 + public: props.site?.public, + // 备注 + note: props.site?.note, + // 流控单位周期 + limit_interval: props.site?.limit_interval, + // 流控次数 + limit_count: props.site?.limit_count, + // 流控间隔 + limit_seconds: props.site?.limit_seconds, + // 是否启用 + is_active: props.site?.is_active, +}); + +// 状态下拉项 +const statusItems = [ + { title: "启用", value: true }, + { title: "停用", value: false }, +]; + // 装载时查询站点图标 onMounted(() => { getSiteIcon(); @@ -110,7 +180,12 @@ onMounted(() => {