mirror of https://github.com/certd/certd
feat: 支持vip转移
parent
e85b4da2e3
commit
361e8fe7ae
|
@ -26,10 +26,12 @@ export class IframeClient {
|
||||||
requestQueue: Record<string, IframeMessageReq> = {};
|
requestQueue: Record<string, IframeMessageReq> = {};
|
||||||
//当前客户端是否是父级页面
|
//当前客户端是否是父级页面
|
||||||
iframe?: HTMLIFrameElement;
|
iframe?: HTMLIFrameElement;
|
||||||
|
onError?: any;
|
||||||
|
|
||||||
handlers: Record<string, (data: IframeMessageData<any>) => Promise<void>> = {};
|
handlers: Record<string, (data: IframeMessageData<any>) => Promise<void>> = {};
|
||||||
constructor(iframe?: HTMLIFrameElement) {
|
constructor(iframe?: HTMLIFrameElement, onError?: (e: any) => void) {
|
||||||
this.iframe = iframe;
|
this.iframe = iframe;
|
||||||
|
this.onError = onError;
|
||||||
window.addEventListener('message', async (event: MessageEvent<IframeMessageData<any>>) => {
|
window.addEventListener('message', async (event: MessageEvent<IframeMessageData<any>>) => {
|
||||||
const data = event.data;
|
const data = event.data;
|
||||||
if (data.action) {
|
if (data.action) {
|
||||||
|
@ -37,13 +39,12 @@ export class IframeClient {
|
||||||
try {
|
try {
|
||||||
const handler = this.handlers[data.action];
|
const handler = this.handlers[data.action];
|
||||||
if (handler) {
|
if (handler) {
|
||||||
debugger;
|
|
||||||
const res = await handler(data);
|
const res = await handler(data);
|
||||||
if (data.id && data.action !== 'reply') {
|
if (data.id && data.action !== 'reply') {
|
||||||
await this.send('reply', res, data.id);
|
await this.send('reply', res, data.id);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
throw new Error(`action:${data.action} 未注册处理器`);
|
throw new Error(`action:${data.action} 未注册处理器,可能版本过低`);
|
||||||
}
|
}
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
|
@ -69,6 +70,17 @@ export class IframeClient {
|
||||||
}
|
}
|
||||||
|
|
||||||
async send<R = any, T = any>(action: string, data?: T, replyId?: string, errorCode?: number, message?: string): Promise<IframeMessageData<R>> {
|
async send<R = any, T = any>(action: string, data?: T, replyId?: string, errorCode?: number, message?: string): Promise<IframeMessageData<R>> {
|
||||||
|
try {
|
||||||
|
return await this.doSend<R, T>(action, data, replyId, errorCode, message);
|
||||||
|
} catch (e) {
|
||||||
|
if (this.onError) {
|
||||||
|
this.onError(e);
|
||||||
|
}
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async doSend<R = any, T = any>(action: string, data?: T, replyId?: string, errorCode?: number, message?: string): Promise<IframeMessageData<R>> {
|
||||||
const reqMessageData: IframeMessageData<T> = {
|
const reqMessageData: IframeMessageData<T> = {
|
||||||
id: nanoid(),
|
id: nanoid(),
|
||||||
action,
|
action,
|
||||||
|
|
|
@ -136,14 +136,15 @@ export default {
|
||||||
}
|
}
|
||||||
|
|
||||||
.main {
|
.main {
|
||||||
min-width: 260px;
|
min-width: 300px;
|
||||||
|
width: 94%;
|
||||||
}
|
}
|
||||||
|
|
||||||
.footer {
|
.footer {
|
||||||
// position: absolute;
|
// position: absolute;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
bottom: 0;
|
bottom: 0;
|
||||||
margin: 48px 0 24px;
|
margin: 24px 0 24px;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
|
|
||||||
.links {
|
.links {
|
||||||
|
|
|
@ -2,7 +2,7 @@ import { request } from "/src/api/service";
|
||||||
|
|
||||||
const apiPrefix = "/pi/history";
|
const apiPrefix = "/pi/history";
|
||||||
|
|
||||||
export function GetList(query: any) {
|
export async function GetList(query: any) {
|
||||||
return await request({
|
return await request({
|
||||||
url: apiPrefix + "/page",
|
url: apiPrefix + "/page",
|
||||||
method: "post",
|
method: "post",
|
||||||
|
@ -10,7 +10,7 @@ export function GetList(query: any) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function AddObj(obj: any) {
|
export async function AddObj(obj: any) {
|
||||||
return await request({
|
return await request({
|
||||||
url: apiPrefix + "/add",
|
url: apiPrefix + "/add",
|
||||||
method: "post",
|
method: "post",
|
||||||
|
@ -18,7 +18,7 @@ export function AddObj(obj: any) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function UpdateObj(obj: any) {
|
export async function UpdateObj(obj: any) {
|
||||||
return await request({
|
return await request({
|
||||||
url: apiPrefix + "/update",
|
url: apiPrefix + "/update",
|
||||||
method: "post",
|
method: "post",
|
||||||
|
@ -26,7 +26,7 @@ export function UpdateObj(obj: any) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function DelObj(id: any) {
|
export async function DelObj(id: any) {
|
||||||
return await request({
|
return await request({
|
||||||
url: apiPrefix + "/delete",
|
url: apiPrefix + "/delete",
|
||||||
method: "post",
|
method: "post",
|
||||||
|
@ -34,7 +34,7 @@ export function DelObj(id: any) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function GetObj(id: any) {
|
export async function GetObj(id: any) {
|
||||||
return await request({
|
return await request({
|
||||||
url: apiPrefix + "/info",
|
url: apiPrefix + "/info",
|
||||||
method: "post",
|
method: "post",
|
||||||
|
@ -42,7 +42,7 @@ export function GetObj(id: any) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function GetDetail(id: any) {
|
export async function GetDetail(id: any) {
|
||||||
return await request({
|
return await request({
|
||||||
url: apiPrefix + "/detail",
|
url: apiPrefix + "/detail",
|
||||||
method: "post",
|
method: "post",
|
||||||
|
@ -50,7 +50,7 @@ export function GetDetail(id: any) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function DeleteBatch(ids: any[]) {
|
export async function DeleteBatch(ids: any[]) {
|
||||||
return await request({
|
return await request({
|
||||||
url: apiPrefix + "/deleteByIds",
|
url: apiPrefix + "/deleteByIds",
|
||||||
method: "post",
|
method: "post",
|
||||||
|
|
|
@ -3,7 +3,7 @@ import { request } from "/src/api/service";
|
||||||
const apiPrefix = "/pi/pipeline";
|
const apiPrefix = "/pi/pipeline";
|
||||||
const historyApiPrefix = "/pi/history";
|
const historyApiPrefix = "/pi/history";
|
||||||
|
|
||||||
export function GetList(query: any) {
|
export async function GetList(query: any) {
|
||||||
return await request({
|
return await request({
|
||||||
url: apiPrefix + "/page",
|
url: apiPrefix + "/page",
|
||||||
method: "post",
|
method: "post",
|
||||||
|
@ -11,7 +11,7 @@ export function GetList(query: any) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function AddObj(obj: any) {
|
export async function AddObj(obj: any) {
|
||||||
return await request({
|
return await request({
|
||||||
url: apiPrefix + "/add",
|
url: apiPrefix + "/add",
|
||||||
method: "post",
|
method: "post",
|
||||||
|
@ -19,7 +19,7 @@ export function AddObj(obj: any) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function UpdateObj(obj: any) {
|
export async function UpdateObj(obj: any) {
|
||||||
return await request({
|
return await request({
|
||||||
url: apiPrefix + "/update",
|
url: apiPrefix + "/update",
|
||||||
method: "post",
|
method: "post",
|
||||||
|
@ -27,7 +27,7 @@ export function UpdateObj(obj: any) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function DelObj(id: any) {
|
export async function DelObj(id: any) {
|
||||||
return await request({
|
return await request({
|
||||||
url: apiPrefix + "/delete",
|
url: apiPrefix + "/delete",
|
||||||
method: "post",
|
method: "post",
|
||||||
|
@ -35,7 +35,7 @@ export function DelObj(id: any) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function GetObj(id: any) {
|
export async function GetObj(id: any) {
|
||||||
return await request({
|
return await request({
|
||||||
url: apiPrefix + "/info",
|
url: apiPrefix + "/info",
|
||||||
method: "post",
|
method: "post",
|
||||||
|
@ -43,7 +43,7 @@ export function GetObj(id: any) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function GetDetail(id: any) {
|
export async function GetDetail(id: any) {
|
||||||
return await request({
|
return await request({
|
||||||
url: apiPrefix + "/detail",
|
url: apiPrefix + "/detail",
|
||||||
method: "post",
|
method: "post",
|
||||||
|
@ -51,7 +51,7 @@ export function GetDetail(id: any) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function Save(pipelineEntity: any) {
|
export async function Save(pipelineEntity: any) {
|
||||||
return await request({
|
return await request({
|
||||||
url: apiPrefix + "/save",
|
url: apiPrefix + "/save",
|
||||||
method: "post",
|
method: "post",
|
||||||
|
@ -59,7 +59,7 @@ export function Save(pipelineEntity: any) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function Trigger(id: any, stepId?: string) {
|
export async function Trigger(id: any, stepId?: string) {
|
||||||
return await request({
|
return await request({
|
||||||
url: apiPrefix + "/trigger",
|
url: apiPrefix + "/trigger",
|
||||||
method: "post",
|
method: "post",
|
||||||
|
@ -67,7 +67,7 @@ export function Trigger(id: any, stepId?: string) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function Cancel(historyId: any) {
|
export async function Cancel(historyId: any) {
|
||||||
return await request({
|
return await request({
|
||||||
url: apiPrefix + "/cancel",
|
url: apiPrefix + "/cancel",
|
||||||
method: "post",
|
method: "post",
|
||||||
|
|
|
@ -208,7 +208,8 @@ export default defineComponent({
|
||||||
<style lang="less">
|
<style lang="less">
|
||||||
@import "../../../style/theme/index.less";
|
@import "../../../style/theme/index.less";
|
||||||
.login-page.main {
|
.login-page.main {
|
||||||
margin: 20px !important;
|
//margin: 20px !important;
|
||||||
|
margin-bottom: 100px;
|
||||||
.user-layout-login {
|
.user-layout-login {
|
||||||
label {
|
label {
|
||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
|
|
|
@ -23,3 +23,11 @@ export async function UnbindUser(userId: number) {
|
||||||
data: { userId }
|
data: { userId }
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function UpdateLicense(data: any) {
|
||||||
|
await request({
|
||||||
|
url: "/sys/account/updateLicense",
|
||||||
|
method: "post",
|
||||||
|
data
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
|
@ -10,6 +10,7 @@ import { onMounted, ref } from "vue";
|
||||||
import { useUserStore } from "/@/store/modules/user";
|
import { useUserStore } from "/@/store/modules/user";
|
||||||
import { useSettingStore } from "/@/store/modules/settings";
|
import { useSettingStore } from "/@/store/modules/settings";
|
||||||
import * as api from "./api";
|
import * as api from "./api";
|
||||||
|
import { notification } from "ant-design-vue";
|
||||||
const iframeRef = ref();
|
const iframeRef = ref();
|
||||||
|
|
||||||
const userStore = useUserStore();
|
const userStore = useUserStore();
|
||||||
|
@ -21,7 +22,12 @@ type SubjectInfo = {
|
||||||
expiresTime?: number;
|
expiresTime?: number;
|
||||||
};
|
};
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
const iframeClient = new IframeClient(iframeRef.value);
|
const iframeClient = new IframeClient(iframeRef.value, (e: any) => {
|
||||||
|
notification.error({
|
||||||
|
message: " error",
|
||||||
|
description: e.message
|
||||||
|
});
|
||||||
|
});
|
||||||
iframeClient.register("getSubjectInfo", async (req) => {
|
iframeClient.register("getSubjectInfo", async (req) => {
|
||||||
const subjectInfo: SubjectInfo = {
|
const subjectInfo: SubjectInfo = {
|
||||||
subjectId: settingStore.installInfo.siteId,
|
subjectId: settingStore.installInfo.siteId,
|
||||||
|
@ -47,6 +53,15 @@ onMounted(() => {
|
||||||
const userId = req.data.userId;
|
const userId = req.data.userId;
|
||||||
await api.UnbindUser(userId);
|
await api.UnbindUser(userId);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
iframeClient.register("updateLicense", async (req) => {
|
||||||
|
await api.UpdateLicense(req.data);
|
||||||
|
await userStore.reInit();
|
||||||
|
notification.success({
|
||||||
|
message: "更新成功",
|
||||||
|
description: "专业版已激活"
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
|
@ -46,7 +46,7 @@ export async function GetObj(id: any) {
|
||||||
* @returns {*}
|
* @returns {*}
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
export function getPermissionIds(roleId: any) {
|
export async function getPermissionIds(roleId: any) {
|
||||||
return await request({
|
return await request({
|
||||||
url: apiPrefix + "/getPermissionIds",
|
url: apiPrefix + "/getPermissionIds",
|
||||||
method: "post",
|
method: "post",
|
||||||
|
@ -61,7 +61,7 @@ export function getPermissionIds(roleId: any) {
|
||||||
* @returns {*}
|
* @returns {*}
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
export function DoAuthz(roleId: any, permissionIds: any) {
|
export async function DoAuthz(roleId: any, permissionIds: any) {
|
||||||
return await request({
|
return await request({
|
||||||
url: apiPrefix + "/authz",
|
url: apiPrefix + "/authz",
|
||||||
method: "post",
|
method: "post",
|
||||||
|
|
|
@ -1,10 +1,8 @@
|
||||||
koa:
|
|
||||||
port: 7001
|
|
||||||
# key: ./data/ssl/cert.key
|
# key: ./data/ssl/cert.key
|
||||||
# cert: ./data/ssl/cert.crt
|
# cert: ./data/ssl/cert.crt
|
||||||
#plus:
|
|
||||||
# server:
|
|
||||||
# baseUrl: 'http://127.0.0.1:11007'
|
|
||||||
plus:
|
plus:
|
||||||
server:
|
server:
|
||||||
baseUrl: 'https://api.ai.handsfree.work'
|
baseUrl: 'http://127.0.0.1:11007'
|
||||||
|
#plus:
|
||||||
|
# server:
|
||||||
|
# baseUrl: 'https://api.ai.handsfree.work'
|
||||||
|
|
|
@ -26,8 +26,9 @@ export class BasicController extends BaseController {
|
||||||
public async preBindUser(@Body(ALL) body: PreBindUserReq) {
|
public async preBindUser(@Body(ALL) body: PreBindUserReq) {
|
||||||
const installInfo: SysInstallInfo = await this.sysSettingsService.getSetting(SysInstallInfo);
|
const installInfo: SysInstallInfo = await this.sysSettingsService.getSetting(SysInstallInfo);
|
||||||
// 设置缓存内容
|
// 设置缓存内容
|
||||||
await this.plusService.request({
|
await this.plusService.requestWithoutSign({
|
||||||
url: '/activation/subject/preBind',
|
url: '/activation/subject/preBind',
|
||||||
|
method: 'POST',
|
||||||
data: {
|
data: {
|
||||||
userId: body.userId,
|
userId: body.userId,
|
||||||
appKey: AppKey,
|
appKey: AppKey,
|
||||||
|
@ -53,4 +54,11 @@ export class BasicController extends BaseController {
|
||||||
await this.sysSettingsService.saveSetting(installInfo);
|
await this.sysSettingsService.saveSetting(installInfo);
|
||||||
return this.ok({});
|
return this.ok({});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Post('/updateLicense', { summary: 'sys:settings:edit' })
|
||||||
|
public async updateLicense(@Body(ALL) body: { license: string }) {
|
||||||
|
const installInfo: SysInstallInfo = await this.sysSettingsService.getSetting(SysInstallInfo);
|
||||||
|
await this.plusService.updateLicense(installInfo.siteId, body.license);
|
||||||
|
return this.ok(true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import { Config, Inject, Provide, Scope, ScopeEnum } from '@midwayjs/core';
|
import { Config, Inject, Provide, Scope, ScopeEnum } from '@midwayjs/core';
|
||||||
import { SysSettingsService } from '../../system/service/sys-settings-service.js';
|
import { SysSettingsService } from '../../system/service/sys-settings-service.js';
|
||||||
import { SysInstallInfo } from '../../system/service/models.js';
|
import { SysInstallInfo, SysLicenseInfo } from '../../system/service/models.js';
|
||||||
import { AppKey, getPlusInfo, isPlus } from '@certd/pipeline';
|
import { AppKey, getPlusInfo, isPlus, verify } from '@certd/pipeline';
|
||||||
import * as crypto from 'crypto';
|
import * as crypto from 'crypto';
|
||||||
import { request } from '../../../utils/http.js';
|
import { request } from '../../../utils/http.js';
|
||||||
import { logger } from '../../../utils/logger.js';
|
import { logger } from '../../../utils/logger.js';
|
||||||
|
@ -16,6 +16,7 @@ export class PlusService {
|
||||||
|
|
||||||
async requestWithoutSign(config: any): Promise<any> {
|
async requestWithoutSign(config: any): Promise<any> {
|
||||||
config.baseURL = this.plusServerBaseUrl;
|
config.baseURL = this.plusServerBaseUrl;
|
||||||
|
config.method = config.method || 'POST';
|
||||||
return await request(config);
|
return await request(config);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -76,4 +77,24 @@ export class PlusService {
|
||||||
data: formData,
|
data: formData,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async updateLicense(siteId: string, license: string) {
|
||||||
|
let licenseInfo: SysLicenseInfo = await this.sysSettingsService.getSetting(SysLicenseInfo);
|
||||||
|
if (!licenseInfo) {
|
||||||
|
licenseInfo = new SysLicenseInfo();
|
||||||
|
}
|
||||||
|
licenseInfo.license = license;
|
||||||
|
await this.sysSettingsService.saveSetting(licenseInfo);
|
||||||
|
|
||||||
|
const verifyRes = await verify({
|
||||||
|
subjectId: siteId,
|
||||||
|
license,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!verifyRes.isPlus) {
|
||||||
|
const message = verifyRes.message || '授权码校验失败';
|
||||||
|
logger.error(message);
|
||||||
|
throw new Error(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
import { ALL, Body, Controller, Inject, Post, Provide } from '@midwayjs/core';
|
import { ALL, Body, Controller, Inject, Post, Provide } from '@midwayjs/core';
|
||||||
import { SysSettingsService } from '../service/sys-settings-service.js';
|
import { SysSettingsService } from '../service/sys-settings-service.js';
|
||||||
import { BaseController } from '../../../basic/base-controller.js';
|
import { BaseController } from '../../../basic/base-controller.js';
|
||||||
import { AppKey, verify } from '@certd/pipeline';
|
import { AppKey } from '@certd/pipeline';
|
||||||
import { SysInstallInfo, SysLicenseInfo } from '../service/models.js';
|
import { SysInstallInfo } from '../service/models.js';
|
||||||
import { logger } from '../../../utils/logger.js';
|
import { logger } from '../../../utils/logger.js';
|
||||||
import { PlusService } from '../../basic/service/plus-service.js';
|
import { PlusService } from '../../basic/service/plus-service.js';
|
||||||
|
|
||||||
|
@ -21,10 +21,11 @@ export class SysPlusController extends BaseController {
|
||||||
async active(@Body(ALL) body) {
|
async active(@Body(ALL) body) {
|
||||||
const { code } = body;
|
const { code } = body;
|
||||||
const installInfo: SysInstallInfo = await this.sysSettingsService.getSetting(SysInstallInfo);
|
const installInfo: SysInstallInfo = await this.sysSettingsService.getSetting(SysInstallInfo);
|
||||||
|
const siteId = installInfo.siteId;
|
||||||
const formData = {
|
const formData = {
|
||||||
appKey: AppKey,
|
appKey: AppKey,
|
||||||
code,
|
code,
|
||||||
subjectId: installInfo.siteId,
|
subjectId: siteId,
|
||||||
};
|
};
|
||||||
|
|
||||||
const res: any = await this.plusService.active(formData);
|
const res: any = await this.plusService.active(formData);
|
||||||
|
@ -33,26 +34,10 @@ export class SysPlusController extends BaseController {
|
||||||
logger.error('激活失败', res.message);
|
logger.error('激活失败', res.message);
|
||||||
return this.fail(res.message, 1);
|
return this.fail(res.message, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
const license = res.data.license;
|
const license = res.data.license;
|
||||||
|
|
||||||
let licenseInfo: SysLicenseInfo = await this.sysSettingsService.getSetting(SysLicenseInfo);
|
await this.plusService.updateLicense(siteId, license);
|
||||||
if (!licenseInfo) {
|
|
||||||
licenseInfo = new SysLicenseInfo();
|
|
||||||
}
|
|
||||||
licenseInfo.license = license;
|
|
||||||
await this.sysSettingsService.saveSetting(licenseInfo);
|
|
||||||
|
|
||||||
const verifyRes = await verify({
|
return this.ok(true);
|
||||||
subjectId: installInfo.siteId,
|
|
||||||
license,
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!verifyRes.isPlus) {
|
|
||||||
const message = verifyRes.message || '授权码校验失败';
|
|
||||||
logger.error(message);
|
|
||||||
return this.fail(message, 1);
|
|
||||||
}
|
|
||||||
return this.ok(res.data);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue