feat: 增加 QQBot 登录密码配置
This commit is contained in:
parent
c8729cb096
commit
176e139017
@ -72,7 +72,7 @@ function arrayBufferToBase64(buffer: ArrayBuffer) {
|
|||||||
return window.btoa(binary);
|
return window.btoa(binary);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function encryptPassword(password: string) {
|
export async function encryptPassword(password: string) {
|
||||||
const { hash, publicKey } = await getPasswordPublicKeyApi();
|
const { hash, publicKey } = await getPasswordPublicKeyApi();
|
||||||
const cryptoKey = await window.crypto.subtle.importKey(
|
const cryptoKey = await window.crypto.subtle.importKey(
|
||||||
'spki',
|
'spki',
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
import type { Recordable } from '@vben/types';
|
import type { Recordable } from '@vben/types';
|
||||||
|
|
||||||
|
import { encryptPassword } from '#/api/core/auth';
|
||||||
import { requestClient } from '#/api/request';
|
import { requestClient } from '#/api/request';
|
||||||
|
|
||||||
export namespace QqbotApi {
|
export namespace QqbotApi {
|
||||||
@ -64,7 +65,9 @@ export namespace QqbotApi {
|
|||||||
accessToken?: string;
|
accessToken?: string;
|
||||||
connectionMode?: 'reverse-ws';
|
connectionMode?: 'reverse-ws';
|
||||||
enabled?: boolean;
|
enabled?: boolean;
|
||||||
|
encryptedLoginPassword?: string;
|
||||||
id?: string;
|
id?: string;
|
||||||
|
loginPassword?: string;
|
||||||
name?: string;
|
name?: string;
|
||||||
remark?: string;
|
remark?: string;
|
||||||
selfId: string;
|
selfId: string;
|
||||||
@ -292,12 +295,30 @@ export function getQqbotEnabledAccounts() {
|
|||||||
return requestClient.get<QqbotApi.Account[]>('/qqbot/account/enabled');
|
return requestClient.get<QqbotApi.Account[]>('/qqbot/account/enabled');
|
||||||
}
|
}
|
||||||
|
|
||||||
export function createQqbotAccount(data: QqbotApi.AccountBody) {
|
export async function createQqbotAccount(data: QqbotApi.AccountBody) {
|
||||||
return requestClient.post<string>('/qqbot/account/save', data);
|
return requestClient.post<string>(
|
||||||
|
'/qqbot/account/save',
|
||||||
|
await buildAccountRequest(data),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function updateQqbotAccount(data: QqbotApi.AccountBody) {
|
export async function updateQqbotAccount(data: QqbotApi.AccountBody) {
|
||||||
return requestClient.post<boolean>('/qqbot/account/update', data);
|
return requestClient.post<boolean>(
|
||||||
|
'/qqbot/account/update',
|
||||||
|
await buildAccountRequest(data),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function buildAccountRequest(data: QqbotApi.AccountBody) {
|
||||||
|
const { loginPassword, ...payload } = data;
|
||||||
|
const password =
|
||||||
|
loginPassword === undefined || loginPassword === null
|
||||||
|
? ''
|
||||||
|
: `${loginPassword}`;
|
||||||
|
if (password.trim()) {
|
||||||
|
payload.encryptedLoginPassword = await encryptPassword(password);
|
||||||
|
}
|
||||||
|
return payload;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function deleteQqbotAccount(id: string) {
|
export function deleteQqbotAccount(id: string) {
|
||||||
|
|||||||
@ -101,6 +101,21 @@ export default defineComponent({
|
|||||||
const scanProgressCurrent = computed(() =>
|
const scanProgressCurrent = computed(() =>
|
||||||
Math.max(scanProgressItems.value.length - 1, 0),
|
Math.max(scanProgressItems.value.length - 1, 0),
|
||||||
);
|
);
|
||||||
|
const scanQrcodePlaceholderText = computed(() => {
|
||||||
|
if (
|
||||||
|
scanState.mode === 'refresh' &&
|
||||||
|
scanState.errorMessage?.includes('正在尝试快速登录')
|
||||||
|
) {
|
||||||
|
return '正在尝试快速登录';
|
||||||
|
}
|
||||||
|
if (
|
||||||
|
scanState.mode === 'refresh' &&
|
||||||
|
scanState.errorMessage?.includes('正在尝试密码登录')
|
||||||
|
) {
|
||||||
|
return '正在尝试密码登录';
|
||||||
|
}
|
||||||
|
return '二维码生成中';
|
||||||
|
});
|
||||||
let scanTimer: number | undefined;
|
let scanTimer: number | undefined;
|
||||||
let scanEventSessionId = '';
|
let scanEventSessionId = '';
|
||||||
let scanEventSource: EventSource | undefined;
|
let scanEventSource: EventSource | undefined;
|
||||||
@ -138,6 +153,16 @@ export default defineComponent({
|
|||||||
fieldName: 'accessToken',
|
fieldName: 'accessToken',
|
||||||
label: 'Token',
|
label: 'Token',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
component: 'InputPassword',
|
||||||
|
componentProps: () => ({
|
||||||
|
placeholder: editingId.value
|
||||||
|
? '留空表示不修改 QQ 登录密码'
|
||||||
|
: '可选,用于 NapCat 密码登录',
|
||||||
|
}),
|
||||||
|
fieldName: 'loginPassword',
|
||||||
|
label: '登录密码',
|
||||||
|
},
|
||||||
{
|
{
|
||||||
component: 'Switch',
|
component: 'Switch',
|
||||||
fieldName: 'enabled',
|
fieldName: 'enabled',
|
||||||
@ -729,6 +754,7 @@ export default defineComponent({
|
|||||||
accessToken: '',
|
accessToken: '',
|
||||||
connectionMode: 'reverse-ws',
|
connectionMode: 'reverse-ws',
|
||||||
enabled: true,
|
enabled: true,
|
||||||
|
loginPassword: '',
|
||||||
name: '',
|
name: '',
|
||||||
remark: '',
|
remark: '',
|
||||||
selfId: '',
|
selfId: '',
|
||||||
@ -764,6 +790,7 @@ export default defineComponent({
|
|||||||
connectionMode: row.connectionMode,
|
connectionMode: row.connectionMode,
|
||||||
enabled: row.enabled,
|
enabled: row.enabled,
|
||||||
id: row.id,
|
id: row.id,
|
||||||
|
loginPassword: '',
|
||||||
name: row.name,
|
name: row.name,
|
||||||
remark: row.remark || '',
|
remark: row.remark || '',
|
||||||
selfId: row.selfId,
|
selfId: row.selfId,
|
||||||
@ -791,6 +818,7 @@ export default defineComponent({
|
|||||||
selfId,
|
selfId,
|
||||||
};
|
};
|
||||||
if (!payload.accessToken) delete payload.accessToken;
|
if (!payload.accessToken) delete payload.accessToken;
|
||||||
|
if (!payload.loginPassword) delete payload.loginPassword;
|
||||||
await (editingId.value
|
await (editingId.value
|
||||||
? updateQqbotAccount(payload)
|
? updateQqbotAccount(payload)
|
||||||
: createQqbotAccount(payload));
|
: createQqbotAccount(payload));
|
||||||
@ -907,7 +935,7 @@ export default defineComponent({
|
|||||||
width: '240px',
|
width: '240px',
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
二维码生成中
|
{scanQrcodePlaceholderText.value}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user