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