Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 内置客户端支持自定义签名地址 #215

Merged
merged 10 commits into from
Jul 10, 2024
102 changes: 98 additions & 4 deletions src/components/PageConnectInfoItems.vue
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,13 @@
<el-form-item label="接入方式">
<div>内置客户端</div>
</el-form-item>
<el-form-item label="签名地址">
<el-tooltip class="item" effect="dark" :content="i.enable ? '禁用账号后方可修改签名服务地址' : '单击修改签名服务地址'"
placement="bottom">
<el-button :icon="Edit" size="small" circle :disabled="i.enable" style="margin-left: 0.5rem"
@click="showSetSignServerDialog(i)" />
</el-tooltip>
</el-form-item>
</template>

<template v-if="i.platform === 'QQ' && i.protocolType === 'red'">
Expand Down Expand Up @@ -475,7 +482,26 @@
</span>
</template>
</el-dialog>

<el-dialog v-model="dialogSetSignServerVisible" title="签名地址修改" :close-on-click-modal="false"
:close-on-press-escape="false" :show-close="false" class="the-dialog">
<el-form-item label="签名地址" :label-width="formLabelWidth" required>
<el-radio-group v-model="form.signServerType">
<el-radio :value="0">海豹</el-radio>
<el-radio :value="1">Lagrange</el-radio>
<el-radio :value="2">自定义地址</el-radio>
</el-radio-group>
</el-form-item>
<el-form-item v-if="form.signServerType === 2" label="自定义签名地址" :label-width="formLabelWidth" required>
<el-input v-model="form.signServerUrl" type="text" autocomplete="off"></el-input>
</el-form-item>
<template #footer>
<span class="dialog-footer">
<el-button @click="dialogSetSignServerVisible = false">取消</el-button>
<el-button type="primary" @click="doSetSignServer"
:disabled="form.signServerType === 2 && form.signServerUrl === ''">确定</el-button>
</span>
</template>
</el-dialog>
<el-dialog v-model="dialogFormVisible" title="帐号登录" :close-on-click-modal="false" :close-on-press-escape="false"
:show-close="false" class="the-dialog">
<el-button style="float: right; margin-top: -4rem;" @click="openSocks">辅助工具-13325端口</el-button>
Expand Down Expand Up @@ -555,7 +581,22 @@
</el-select>
</el-form-item> -->

<el-form-item v-if="form.accountType === 0 || form.accountType === 15" label="账号" :label-width="formLabelWidth" required>
<el-form-item v-if="form.accountType === 15" label="账号" :label-width="formLabelWidth" required>
<el-input v-model="form.account" type="number" autocomplete="off"></el-input>
</el-form-item>
<el-form-item v-if="form.accountType === 15" label="签名服务" :label-width="formLabelWidth" required>
<el-radio-group v-model="form.signServerType">
<el-radio :value="0">海豹</el-radio>
<el-radio :value="1">Lagrange</el-radio>
<el-radio :value="2">自定义地址</el-radio>
</el-radio-group>
</el-form-item>
<el-form-item v-if="form.accountType === 15 && form.signServerType === 2" label="自定义签名地址"
:label-width="formLabelWidth" required>
<el-input v-model="form.signServerUrl" type="text" autocomplete="off"></el-input>
</el-form-item>

<el-form-item v-if="form.accountType === 0" label="账号" :label-width="formLabelWidth" required>
<el-input v-model="form.account" type="number" autocomplete="off"></el-input>
</el-form-item>

Expand Down Expand Up @@ -1091,7 +1132,7 @@
form.accountType === 9 && (form.botToken === '' || form.appToken === '') ||
form.accountType === 11 && (form.account === '' || form.reverseAddr === '') ||
form.accountType === 13 && (form.token === '' || form.url === '') ||
form.accountType === 15 && form.account === ''">
form.accountType === 15 && (form.account === '' || form.signServerType === 2 && form.signServerUrl === '')">
下一步</el-button>
</template>
<template v-if="form.isEnd">
Expand Down Expand Up @@ -1172,6 +1213,7 @@ const isRecentLogin = ref(false)
const duringRelogin = ref(false)
const dialogFormVisible = ref(false)
const dialogSetDataFormVisible = ref(false)
const dialogSetSignServerVisible = ref(false)
const dialogSlideVisible = ref(false)
const formLabelWidth = '120px'
const isTestMode = ref(false)
Expand Down Expand Up @@ -1302,6 +1344,17 @@ const goStepTwo = async () => {
setRecentLogin()
duringRelogin.value = false;

if (form.accountType === 15) {
switch (form.signServerType) {
case 0:
form.signServerUrl = "sealdice";
break;
case 1:
form.signServerUrl = "lagrange";
break;
}
}

store.addImConnection(form as any).then((conn) => {
if ((conn as any).testMode) {
isTestMode.value = true
Expand All @@ -1316,6 +1369,7 @@ const goStepTwo = async () => {
if (form.accountType > 0) {
dialogFormVisible.value = false
form.step = 1
form.signServerUrl=""
return
}
activities.value = []
Expand Down Expand Up @@ -1405,7 +1459,47 @@ const doSetData = async () => {
ElMessage.success('修改完成,请手动重新登录');
dialogSetDataFormVisible.value = false;
}
const showSetSignServerDialog = async (i: DiceConnection) => {
form.endpoint = i;
const ret = await store.getImConnectionsSetSignServerUrl(form.endpoint, "",false);
if (ret.result) {
form.signServerUrl = ret.signServerUrl
switch (form.signServerUrl) {
case "sealdice":
form.signServerType = 0;
form.signServerUrl = "";
break;
case "lagrange":
form.signServerType = 1;
form.signServerUrl = "";
break;
default:
form.signServerType = 2;
break;
}
dialogSetSignServerVisible.value = true;
} else {
ElMessage.error(ret.err)
}
}

const doSetSignServer = async() =>{
switch (form.signServerType) {
case 0:
form.signServerUrl = "sealdice";
break;
case 1:
form.signServerUrl = "lagrange";
break;
}
const ret = await store.getImConnectionsSetSignServerUrl(form.endpoint, form.signServerUrl,true);
if (ret.result) {
ElMessage.success('修改完成,请手动启用账号以生效');
} else {
ElMessage.error(ret.err)
}
dialogSetSignServerVisible.value = false;
}

const askSetEnable = async (i: DiceConnection, val: boolean) => {
ElMessageBox.confirm(
Expand Down Expand Up @@ -1478,7 +1572,6 @@ const gocqhttpReLogin = async (i: DiceConnection) => {
form.step = 4
}
}

const signConfigType: Ref<'none' | 'simple' | 'advanced'> = ref('none')
const signConfigTypeChange = (value: any) => {
switch (value) {
Expand Down Expand Up @@ -1579,6 +1672,7 @@ const form = reactive({
autoRefreshToken: false,
refreshInterval: 40
},
signServerType: 0,
signServerUrl: '',
signServerKey: '',

Expand Down
8 changes: 7 additions & 1 deletion src/store/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ export const useStore = defineStore('main', {
accessToken,
useSignServer,
signServerConfig,
signServerUrl,
reverseAddr,
onlyQQGuild,
platform } = form
Expand Down Expand Up @@ -338,7 +339,7 @@ export const useStore = defineStore('main', {
info = await backend.post(urlPrefix + '/im_connections/addSatori', { platform, host, port, token }, { timeout: 65000 })
break
case 15:
info = await backend.post(urlPrefix + '/im_connections/addLagrange', { account, protocol }, { timeout: 65000 })
info = await backend.post(urlPrefix + '/im_connections/addLagrange', { account, signServerUrl }, { timeout: 65000 })
break
}
return info as any as DiceConnection
Expand Down Expand Up @@ -375,6 +376,11 @@ export const useStore = defineStore('main', {
return info as any as DiceConnection
},

async getImConnectionsSetSignServerUrl(i: DiceConnection, signServerUrl: string, w: boolean) {
const info: { result: false, err: string } | { result: true ,signServerUrl:string} = await backend.post(urlPrefix + '/im_connections/set_sign_server', { id: i.id, signServerUrl, w })
return info
},

async logFetchAndClear() {
const info = await backend.get(urlPrefix + '/log/fetchAndClear')
this.curDice.logs = info as any;
Expand Down
Loading