diff --git a/src/api/modules/config.js b/src/api/modules/config.js
index 81e423636e3934d9a0db698d14fae262c4972a02..46d14512414fd39951d1c288b11bd4f918187098 100644
--- a/src/api/modules/config.js
+++ b/src/api/modules/config.js
@@ -36,6 +36,19 @@ export const updateAccountConfig = (username, data) => {
})
}
+/**
+ * 创建账号配置信息
+ * @param {object} data - 账号配置数据 { username, secret, token }
+ * @returns {Promise}
+ */
+export const createAccountConfig = (data) => {
+ return request({
+ url: '/conf/accounts',
+ method: 'post',
+ data: data
+ })
+}
+
/**
* 获取数据源信息
@@ -67,6 +80,7 @@ const configApi = {
accountNames,
confAccounts,
updateAccountConfig,
+ createAccountConfig,
getdbSource,
putdbSource
}
diff --git a/src/pages/config/account/index.vue b/src/pages/config/account/index.vue
index ecf644204e9b4d313e50eef037e268dec3153c99..a3498c21a6f49ad13f08efd1923abb3e4b26c6ba 100644
--- a/src/pages/config/account/index.vue
+++ b/src/pages/config/account/index.vue
@@ -7,14 +7,22 @@
账号配置
-
+
+
+
+
@@ -138,6 +146,79 @@
+
+
+
@@ -156,6 +237,14 @@ const editingAccountKey = ref(null) // 当前编辑的账号 key
const editingAccountData = ref(null) // 当前编辑的账号数据
const saving = ref(false)
+// 新建账号弹窗状态
+const createDialogVisible = ref(false)
+const createFormData = ref({
+ username: '',
+ secret: '',
+ token: ''
+})
+
// 计算属性:判断是否有账号数据
const hasAccounts = computed(() => {
return Object.keys(accountsList.value).length > 0
@@ -186,6 +275,105 @@ const shouldShowUuToken = (accountData) => {
return platforms.includes('uu')
}
+// 打开新建账号弹窗
+const openCreateDialog = () => {
+ createFormData.value = {
+ username: '',
+ secret: '',
+ token: ''
+ }
+ createDialogVisible.value = true
+}
+
+// 创建账号
+const handleCreate = async () => {
+ // 验证必填字段
+ if (!createFormData.value.username?.trim()) {
+ toast.add({
+ severity: 'warn',
+ summary: '提示',
+ detail: '请输入用户名',
+ life: 3000
+ })
+ return
+ }
+
+ // 验证用户名长度
+ const usernameLen = createFormData.value.username.trim().length
+ if (usernameLen < 2 || usernameLen > 50) {
+ toast.add({
+ severity: 'warn',
+ summary: '提示',
+ detail: '用户名长度需为2-50个字符',
+ life: 3000
+ })
+ return
+ }
+
+ // 验证密钥长度(如果填写了)
+ if (createFormData.value.secret) {
+ const secretLen = createFormData.value.secret.trim().length
+ if (secretLen < 2 || secretLen > 50) {
+ toast.add({
+ severity: 'warn',
+ summary: '提示',
+ detail: '密钥长度需为2-50个字符',
+ life: 3000
+ })
+ return
+ }
+ }
+
+ // 验证Token长度(如果填写了)
+ if (createFormData.value.token) {
+ const tokenLen = createFormData.value.token.trim().length
+ if (tokenLen < 2 || tokenLen > 50) {
+ toast.add({
+ severity: 'warn',
+ summary: '提示',
+ detail: 'Token长度需为2-50个字符',
+ life: 3000
+ })
+ return
+ }
+ }
+
+ saving.value = true
+ try {
+ const processValue = (value) => {
+ if (!value) return ''
+ return value.trim()
+ }
+
+ const createData = {
+ username: processValue(createFormData.value.username),
+ secret: processValue(createFormData.value.secret),
+ token: processValue(createFormData.value.token)
+ }
+
+ await configApi.createAccountConfig(createData)
+
+ toast.add({
+ severity: 'success',
+ summary: '成功',
+ detail: '账号创建成功',
+ life: 3000
+ })
+
+ createDialogVisible.value = false
+ await loadAccounts()
+ } catch (error) {
+ toast.add({
+ severity: 'error',
+ summary: '错误',
+ detail: error.message || '创建失败,请稍后重试',
+ life: 5000
+ })
+ } finally {
+ saving.value = false
+ }
+}
+
// 处理卡片点击
const handleCardClick = (accountKey, accountData) => {
// 如果不可编辑,不打开弹窗