feat: 网盘设置加「默认账号」列, 同类型最多2个主账号
- 数据库 migration: cloud_configs 加 is_primary 字段 - 后端: togglePrimary API (PUT /admin/cloud-configs/:id/primary) - 后端: getAndValidateCredential 优先选 is_primary 账号 - 前端: CloudConfig.vue 转存启用后加「默认账号」开关列 - 前端: api/index.ts 加 setPrimary 方法
This commit is contained in:
@@ -267,6 +267,14 @@ export async function deleteCloudConfig(
|
||||
await api.delete(`/admin/cloud-configs/${id}`)
|
||||
}
|
||||
|
||||
export async function setPrimary(
|
||||
id: number,
|
||||
primary: boolean
|
||||
): Promise<any> {
|
||||
const { data } = await api.put(`/admin/cloud-configs/${id}/primary`, { primary })
|
||||
return data
|
||||
}
|
||||
|
||||
export async function getStats(days?: number): Promise<StatsData> {
|
||||
const params: Record<string, number> = {}
|
||||
if (days) params.days = days
|
||||
|
||||
@@ -99,6 +99,16 @@
|
||||
/>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="默认账号" width="100" align="center">
|
||||
<template #default="{ row }">
|
||||
<el-switch
|
||||
:model-value="row.is_primary === 1"
|
||||
:disabled="!row.is_transfer_enabled"
|
||||
size="small"
|
||||
@change="(val: boolean) => handleTogglePrimary(row, val)"
|
||||
/>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="操作" width="390" align="center">
|
||||
<template #default="{ row }">
|
||||
<el-button text type="primary" @click="openDialog(row)">编辑</el-button>
|
||||
@@ -171,7 +181,7 @@ import { Loading } from '@element-plus/icons-vue'
|
||||
import { CLOUD_LABELS } from '../../types'
|
||||
import type { CloudType, CloudConfig } from '../../types'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { getCloudConfigs, saveCloudConfig, updateCloudConfig, deleteCloudConfig, testCloudConnection, getCloudTypes, toggleCloudType } from '../../api'
|
||||
import { getCloudConfigs, saveCloudConfig, updateCloudConfig, deleteCloudConfig, testCloudConnection, getCloudTypes, toggleCloudType, setPrimary } from '../../api'
|
||||
import CloudBadge from '../../components/CloudBadge.vue'
|
||||
import type { ElForm } from 'element-plus'
|
||||
|
||||
@@ -351,6 +361,16 @@ async function handleToggleTransfer(row: CloudConfig, enabled: boolean) {
|
||||
}
|
||||
}
|
||||
|
||||
async function handleTogglePrimary(row: CloudConfig, enabled: boolean) {
|
||||
try {
|
||||
await setPrimary(row.id!, enabled)
|
||||
row.is_primary = enabled ? 1 : 0
|
||||
ElMessage.success(enabled ? `已将「${row.nickname || row.cloud_type}」设为默认账号` : '已取消默认账号')
|
||||
} catch (e: any) {
|
||||
ElMessage.error(e.response?.data?.error || e.message || '操作失败')
|
||||
}
|
||||
}
|
||||
|
||||
async function autoVerifyAll() {
|
||||
for (const cfg of configs.value) {
|
||||
if (cfg.cookie_preview || cfg.nickname) {
|
||||
|
||||
Reference in New Issue
Block a user