From bdc0227c086d5efbf2d15c12b2d5612ed20341fd Mon Sep 17 00:00:00 2001 From: xiaojunnuo Date: Sun, 22 Sep 2024 02:06:34 +0800 Subject: [PATCH] chore: account --- .../libs/lib-iframe/src/lib/iframe.client.ts | 71 ++++++++++---- packages/ui/certd-client/package.json | 1 + .../src/components/vip-button/index.vue | 2 +- .../src/layout/layout-outside.vue | 5 +- .../src/router/source/modules/sys.ts | 10 ++ .../src/store/modules/settings.ts | 1 + .../src/views/certd/account/index.vue | 8 -- .../src/views/framework/login/index.vue | 93 ++++++++++--------- .../src/views/sys/account/index.vue | 45 +++++++++ 9 files changed, 163 insertions(+), 73 deletions(-) delete mode 100644 packages/ui/certd-client/src/views/certd/account/index.vue create mode 100644 packages/ui/certd-client/src/views/sys/account/index.vue diff --git a/packages/libs/lib-iframe/src/lib/iframe.client.ts b/packages/libs/lib-iframe/src/lib/iframe.client.ts index 2be6f8a0b..8f2d8a199 100644 --- a/packages/libs/lib-iframe/src/lib/iframe.client.ts +++ b/packages/libs/lib-iframe/src/lib/iframe.client.ts @@ -1,51 +1,90 @@ import { nanoid } from 'nanoid'; -export type IframeMessageData = { +export type IframeMessageData = { action: string; id: string; - data: any; + data?: T; replyId?: string; + errorCode?: number; //0为成功 + message?: string; }; -export type IframeMessageReq = { - req: IframeMessageData; - onReply: (data: IframeMessageData) => void; +export type IframeMessageReq = { + req: IframeMessageData; + onReply: (data: IframeMessageData) => void; }; +export class IframeException extends Error { + code?: number = 0; + constructor(data: IframeMessageData) { + super(data.message); + this.code = data.errorCode; + } +} + export class IframeClient { - messageBucket: Record = {}; + requestQueue: Record = {}; //当前客户端是否是父级页面 iframe?: HTMLIFrameElement; + + handlers: Record) => Promise> = {}; constructor(iframe?: HTMLIFrameElement) { this.iframe = iframe; - window.addEventListener('message', (event: MessageEvent) => { + window.addEventListener('message', async (event: MessageEvent>) => { const data = event.data; - if (data.replyId) { - const req = this.messageBucket[data.replyId]; - if (req) { - req.onReply(data); - delete this.messageBucket[data.replyId]; + if (data.action) { + console.log('收到消息', data); + try { + const handler = this.handlers[data.action]; + if (handler) { + const res = await handler(data); + if (data.id && data.action !== 'reply') { + await this.send('reply', res, data.id); + } + } else { + throw new Error(`action:${data.action} 未注册处理器`); + } + } catch (e: any) { + await this.send('reply', {}, data.id, 500, e.message); } } }); + + this.register('reply', async data => { + const req = this.requestQueue[data.replyId!]; + if (req) { + req.onReply(data); + delete this.requestQueue[data.replyId!]; + } + }); } isInFrame() { return window.self !== window.top; } - async send(action: string, data?: any, replyId?: string) { - const reqMessageData: IframeMessageData = { + register(action: string, handler: (data: IframeMessageData) => Promise) { + this.handlers[action] = handler; + } + + async send(action: string, data?: T, replyId?: string, errorCode?: number, message?: string): Promise> { + const reqMessageData: IframeMessageData = { id: nanoid(), action, data, replyId, + errorCode, + message, }; return new Promise((resolve, reject) => { - const onReply = async (reply: IframeMessageData) => { + const onReply = async (reply: IframeMessageData) => { + if (reply.errorCode && reply.errorCode > 0) { + reject(new IframeException(reply)); + return; + } resolve(reply); }; - this.messageBucket[reqMessageData.id] = { + this.requestQueue[reqMessageData.id] = { req: reqMessageData, onReply, }; diff --git a/packages/ui/certd-client/package.json b/packages/ui/certd-client/package.json index 4bc6adad0..be79a05fc 100644 --- a/packages/ui/certd-client/package.json +++ b/packages/ui/certd-client/package.json @@ -58,6 +58,7 @@ "vuedraggable": "^4.1.0" }, "devDependencies": { + "@certd/lib-iframe": "^1.24.4", "@certd/pipeline": "^1.24.4", "@rollup/plugin-commonjs": "^25.0.7", "@rollup/plugin-node-resolve": "^15.2.3", diff --git a/packages/ui/certd-client/src/components/vip-button/index.vue b/packages/ui/certd-client/src/components/vip-button/index.vue index 8d44ee5e4..762b9fb46 100644 --- a/packages/ui/certd-client/src/components/vip-button/index.vue +++ b/packages/ui/certd-client/src/components/vip-button/index.vue @@ -143,8 +143,8 @@ function openUpgrade() {
站点ID: -
注意保存好数据库,暂不支持换绑(默认数据库路径/data/certd/db.sqlite)
+
注意保存好数据库,暂不支持换绑(默认数据库路径/data/certd/db.sqlite)
diff --git a/packages/ui/certd-client/src/layout/layout-outside.vue b/packages/ui/certd-client/src/layout/layout-outside.vue index 0dc736fa9..52492168f 100644 --- a/packages/ui/certd-client/src/layout/layout-outside.vue +++ b/packages/ui/certd-client/src/layout/layout-outside.vue @@ -57,7 +57,7 @@ export default { .container { .main { max-width: 368px; - width: 98%; + width: 96%; } } } @@ -137,8 +137,6 @@ export default { .main { min-width: 260px; - width: 368px; - margin: 0 auto; } .footer { @@ -163,6 +161,7 @@ export default { color: rgba(0, 0, 0, 0.45); font-size: 14px; display: flex; + flex-wrap: wrap; justify-content: center; align-items: center; span { diff --git a/packages/ui/certd-client/src/router/source/modules/sys.ts b/packages/ui/certd-client/src/router/source/modules/sys.ts index 29261481f..a2da21b94 100644 --- a/packages/ui/certd-client/src/router/source/modules/sys.ts +++ b/packages/ui/certd-client/src/router/source/modules/sys.ts @@ -65,6 +65,16 @@ export const sysResources = [ }, path: "/sys/settings", component: "/sys/settings/index.vue" + }, + { + title: "账号绑定", + name: "account", + meta: { + icon: "ion:settings-outline", + permission: "sys:settings:view" + }, + path: "/sys/account", + component: "/sys/account/index.vue" } ] } diff --git a/packages/ui/certd-client/src/store/modules/settings.ts b/packages/ui/certd-client/src/store/modules/settings.ts index 397b25603..6e4240d78 100644 --- a/packages/ui/certd-client/src/store/modules/settings.ts +++ b/packages/ui/certd-client/src/store/modules/settings.ts @@ -23,6 +23,7 @@ export interface SettingState { sysPublic?: SysPublicSetting; installInfo?: { siteId: string; + installTime?: number; }; } diff --git a/packages/ui/certd-client/src/views/certd/account/index.vue b/packages/ui/certd-client/src/views/certd/account/index.vue deleted file mode 100644 index 98adeef09..000000000 --- a/packages/ui/certd-client/src/views/certd/account/index.vue +++ /dev/null @@ -1,8 +0,0 @@ - diff --git a/packages/ui/certd-client/src/views/framework/login/index.vue b/packages/ui/certd-client/src/views/framework/login/index.vue index 238b672b8..959a0e622 100644 --- a/packages/ui/certd-client/src/views/framework/login/index.vue +++ b/packages/ui/certd-client/src/views/framework/login/index.vue @@ -1,5 +1,5 @@