perf: 支持绑定两个url地址

This commit is contained in:
xiaojunnuo
2026-02-02 16:36:43 +08:00
parent 0902349130
commit a2e9a41a7e
6 changed files with 80 additions and 25 deletions
@@ -54,9 +54,9 @@ export class PlusService {
await plusRequestService.verify({ license: licenseInfo.license }); await plusRequestService.verify({ license: licenseInfo.license });
} }
async bindUrl(url: string) { async bindUrl(url: string, url2?:string) {
const plusRequestService = await this.getPlusRequestService(); const plusRequestService = await this.getPlusRequestService();
const res = await plusRequestService.bindUrl(url); const res = await plusRequestService.bindUrl(url,url2);
this.plusRequestService = null; this.plusRequestService = null;
return res; return res;
} }
+5 -1
View File
@@ -8,19 +8,23 @@
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import { computed, provide, ref } from "vue"; import { computed, provide, Ref, ref } from "vue";
import { preferences, usePreferences } from "/@/vben/preferences"; import { preferences, usePreferences } from "/@/vben/preferences";
import { useAntdDesignTokens } from "/@/vben/hooks"; import { useAntdDesignTokens } from "/@/vben/hooks";
import { Modal, theme } from "ant-design-vue"; import { Modal, theme } from "ant-design-vue";
import AConfigProvider from "ant-design-vue/es/config-provider"; import AConfigProvider from "ant-design-vue/es/config-provider";
import { antdvLocale } from "./locales/antdv"; import { antdvLocale } from "./locales/antdv";
import { setI18nLanguage } from "/@/locales"; import { setI18nLanguage } from "/@/locales";
import { mitter } from "./utils/util.mitt";
defineOptions({ defineOptions({
name: "App", name: "App",
}); });
const [modal, contextHolder] = Modal.useModal(); const [modal, contextHolder] = Modal.useModal();
provide("modal", modal); provide("modal", modal);
mitter.on("getModal", (event: any) => {
event.ModalRef = modal;
});
const locale = preferences.app.locale; const locale = preferences.app.locale;
setI18nLanguage(locale); setI18nLanguage(locale);
@@ -107,6 +107,8 @@ export type SysPrivateSetting = {
}; };
export type SysInstallInfo = { export type SysInstallInfo = {
siteId: string; siteId: string;
bindUrl?: string;
bindUrl2?: string;
}; };
export type MenuItem = { export type MenuItem = {
id: string; id: string;
@@ -1,5 +1,5 @@
import { defineStore } from "pinia"; import { defineStore } from "pinia";
import { Modal, notification } from "ant-design-vue"; import { notification } from "ant-design-vue";
import * as basicApi from "./api.basic"; import * as basicApi from "./api.basic";
import { AppInfo, HeaderMenus, PlusInfo, SiteEnv, SiteInfo, SuiteSetting, SysInstallInfo, SysPublicSetting } from "./api.basic"; import { AppInfo, HeaderMenus, PlusInfo, SiteEnv, SiteInfo, SuiteSetting, SysInstallInfo, SysPublicSetting } from "./api.basic";
import { useUserStore } from "../user"; import { useUserStore } from "../user";
@@ -20,6 +20,7 @@ export interface SettingState {
installTime?: number; installTime?: number;
bindUserId?: number; bindUserId?: number;
bindUrl?: string; bindUrl?: string;
bindUrl2?: string;
accountServerBaseUrl?: string; accountServerBaseUrl?: string;
appKey?: string; appKey?: string;
}; };
@@ -153,9 +154,11 @@ export const useSettingStore = defineStore({
if (this.plusInfo?.expireTime === -1) { if (this.plusInfo?.expireTime === -1) {
return "永久"; return "永久";
} }
//@ts-ignore
return dayjs(this.plusInfo?.expireTime).format("YYYY-MM-DD"); return dayjs(this.plusInfo?.expireTime).format("YYYY-MM-DD");
}, },
isForever() { isForever() {
//@ts-ignore
return this.isPlus && this.plusInfo?.expireTime === -1; return this.isPlus && this.plusInfo?.expireTime === -1;
}, },
vipLabel(): string { vipLabel(): string {
@@ -251,9 +254,17 @@ export const useSettingStore = defineStore({
url = url.split("#")[0]; url = url.split("#")[0];
return url; return url;
}, },
async doBindUrl() { async doBindUrl(key: string = "url") {
const url = this.getBaseUrl(); const url = this.installInfo.bindUrl;
await basicApi.bindUrl({ url }); const url2 = this.installInfo.bindUrl2;
const thisUrl = this.getBaseUrl();
const form = {
url,
url2,
[key]: thisUrl,
};
await basicApi.bindUrl(form);
await this.loadSysSettings(); await this.loadSysSettings();
}, },
async checkUrlBound() { async checkUrlBound() {
@@ -262,24 +273,64 @@ export const useSettingStore = defineStore({
if (!userStore.isAdmin) { if (!userStore.isAdmin) {
return; return;
} }
const event: any = { ModalRef: null };
mitter.emit("getModal", event);
const Modal = event.ModalRef;
let modalRef: any = null;
const bindUrl = this.installInfo.bindUrl; const bindUrl = this.installInfo.bindUrl;
const bindUrl2 = this.installInfo.bindUrl2;
const doBindRequest = async (key: string) => {
await this.doBindUrl(key);
if (modalRef) {
modalRef.destroy();
}
};
if (!bindUrl) { if (!bindUrl) {
//绑定url //绑定url
await this.doBindUrl(); await this.doBindUrl("url");
} else { } else {
//检查当前url 是否与绑定的url一致 //检查当前url 是否与绑定的url一致
const url = window.location.href; const url = window.location.href;
if (!url.startsWith(bindUrl)) { if (!url.startsWith(bindUrl) && !url.startsWith(bindUrl2)) {
Modal.confirm({ modalRef = Modal.warning({
title: "URL地址有变化", title: "URL地址未绑定,是否绑定此地址?",
content: "以后都用这个新地址访问本系统吗?", width: 500,
onOk: async () => { keyboard: false,
await this.doBindUrl(); content: () => {
return (
<div class="p-4">
<div class="flex items-center justify-between">
<span>
1
<a-tag color="green">{bindUrl || "未占用"}</a-tag>
</span>
<a-button type="primary" onClick={() => doBindRequest("url")}>
1
</a-button>
</div>
<div class="flex items-center justify-between mt-3">
<span>
2
<a-tag color="green">{bindUrl2 || "未占用"}</a-tag>
</span>
<a-button type="primary" onClick={() => doBindRequest("url2")}>
2
</a-button>
</div>
</div>
);
}, },
okText: "是的,继续", onOk: async () => {
cancelText: "不是,回到原来的地址", // await this.doBindUrl();
window.location.href = bindUrl;
},
okButtonProps: {
danger: true,
},
okText: "不,回到原来的地址",
cancelText: "不,回到原来的地址",
onCancel: () => { onCancel: () => {
window.location.href = bindUrl; window.location.href = bindUrl;
}, },
@@ -22,14 +22,13 @@ export class SysPlusController extends BaseController {
return this.ok(true); return this.ok(true);
} }
@Post('/bindUrl', { summary: 'sys:settings:edit' }) @Post('/bindUrl', { summary: 'sys:settings:edit' })
async bindUrl(@Body(ALL) body: { url: string }) { async bindUrl(@Body(ALL) body: { url: string ,url2?:string }) {
const { url } = body; const { url,url2 } = body;
await this.plusService.register(); await this.plusService.register();
const installInfo: SysInstallInfo = await this.sysSettingsService.getSetting(SysInstallInfo); const installInfo: SysInstallInfo = await this.sysSettingsService.getSetting(SysInstallInfo);
await this.plusService.bindUrl(url); await this.plusService.bindUrl(url,url2);
installInfo.bindUrl = url; installInfo.bindUrl = url;
installInfo.bindUrl2 = url2;
await this.sysSettingsService.saveSetting(installInfo); await this.sysSettingsService.saveSetting(installInfo);
//重新验证vip //重新验证vip
@@ -1,9 +1,8 @@
import { CommonException, SysSettingsService } from "@certd/lib-server";
import { Autoload, Config, Init, Inject, Provide, Scope, ScopeEnum } from '@midwayjs/core'; import { Autoload, Config, Init, Inject, Provide, Scope, ScopeEnum } from '@midwayjs/core';
import { IMidwayKoaContext, IWebMiddleware, NextFunction } from '@midwayjs/koa'; import { IMidwayKoaContext, IWebMiddleware, NextFunction } from '@midwayjs/koa';
import { CommonException, SysSettingsService } from "@certd/lib-server"; import { UserSettingsService } from "../../modules/mine/service/user-settings-service.js";
import { UserService } from '../../modules/sys/authority/service/user-service.js'; import { UserService } from '../../modules/sys/authority/service/user-service.js';
import { logger } from '@certd/basic';
import {UserSettingsService} from "../../modules/mine/service/user-settings-service.js";
/** /**
* 重置密码模式 * 重置密码模式