diff --git a/src/shared/api/account.ts b/src/shared/api/account.ts new file mode 100644 index 0000000..64db653 --- /dev/null +++ b/src/shared/api/account.ts @@ -0,0 +1,259 @@ +import axios from 'axios' +import { get_session_api_headers } from './auth' + +// 创建或重新生成 API Secret +export const createApiSecret = async (): Promise<{ success: boolean; data?: { api_key: string; api_secret: string }; message?: string }> => { + try { + const response = await axios.post( + `/api/action/jcloud.api.account.create_api_secret`, + {}, + { + headers: get_session_api_headers(), + withCredentials: true + } + ) + + const result = response.data + if (result?.message) { + return { success: true, data: result.message } + } + return { success: true, data: result } + } catch (error: any) { + return { + success: false, + message: error.response?.data?.detail || error.response?.data?.message || error.message || '创建 API Secret 失败' + } + } +} + +// 更新个人资料 +export interface UpdateProfileParams { + first_name?: string + last_name?: string + username?: string + mobile_no?: string + email?: string +} + +export const updateProfile = async (params: UpdateProfileParams): Promise<{ success: boolean; message?: string }> => { + try { + const response = await axios.post( + `/api/action/jcloud.api.account.update_profile`, + params, + { + headers: get_session_api_headers(), + withCredentials: true + } + ) + + return { success: true, message: response.data?.message || '更新成功' } + } catch (error: any) { + return { + success: false, + message: error.response?.data?.detail || error.response?.data?.message || error.message || '更新个人资料失败' + } + } +} + +// 获取邮箱列表 +export const getEmails = async (): Promise<{ success: boolean; data?: Array<{ type: string; value: string }>; message?: string }> => { + try { + const response = await axios.get( + `/api/action/jcloud.api.account.get_emails`, + { + headers: get_session_api_headers(), + withCredentials: true + } + ) + + const result = response.data + return { success: true, data: result?.message || result } + } catch (error: any) { + return { + success: false, + message: error.response?.data?.detail || error.response?.data?.message || error.message || '获取邮箱列表失败' + } + } +} + +// 更新邮箱 +export const updateEmails = async (data: Array<{ type: string; value: string }>): Promise<{ success: boolean; message?: string }> => { + try { + const response = await axios.post( + `/api/action/jcloud.api.account.update_emails`, + { data: JSON.stringify(data) }, + { + headers: get_session_api_headers(), + withCredentials: true + } + ) + + return { success: true, message: response.data?.message || '更新成功' } + } catch (error: any) { + return { + success: false, + message: error.response?.data?.detail || error.response?.data?.message || error.message || '更新邮箱失败' + } + } +} + +// 获取用户 SSH 密钥列表 +export const getUserSSHKeys = async (): Promise<{ success: boolean; data?: Array; message?: string }> => { + try { + const response = await axios.get( + `/api/action/jcloud.api.account.get_user_ssh_keys`, + { + headers: get_session_api_headers(), + withCredentials: true + } + ) + + const result = response.data + return { success: true, data: result?.message || result || [] } + } catch (error: any) { + return { + success: false, + message: error.response?.data?.detail || error.response?.data?.message || error.message || '获取 SSH 密钥列表失败' + } + } +} + +// 添加 SSH 密钥 +export const addSSHKey = async (sshPublicKey: string): Promise<{ success: boolean; message?: string }> => { + try { + const response = await axios.post( + `/api/action/jcloud.api.client.insert`, + { + pg: { + pagetype: 'User SSH Key', + ssh_public_key: sshPublicKey, + user: '' // 后端会自动获取当前用户 + } + }, + { + headers: get_session_api_headers(), + withCredentials: true + } + ) + + return { success: true, message: response.data?.message || '添加成功' } + } catch (error: any) { + return { + success: false, + message: error.response?.data?.detail || error.response?.data?.message || error.message || '添加 SSH 密钥失败' + } + } +} + +// 设置 SSH 密钥为默认 +export const markKeyAsDefault = async (keyName: string): Promise<{ success: boolean; message?: string }> => { + try { + const response = await axios.post( + `/api/action/jcloud.api.account.mark_key_as_default`, + { key_name: keyName }, + { + headers: get_session_api_headers(), + withCredentials: true + } + ) + + return { success: true, message: response.data?.message || '设置成功' } + } catch (error: any) { + return { + success: false, + message: error.response?.data?.detail || error.response?.data?.message || error.message || '设置默认密钥失败' + } + } +} + +// 删除 SSH 密钥 +export const deleteSSHKey = async (keyName: string): Promise<{ success: boolean; message?: string }> => { + try { + const response = await axios.post( + `/api/action/jcloud.api.client.delete`, + { + pagetype: 'User SSH Key', + name: keyName + }, + { + headers: get_session_api_headers(), + withCredentials: true + } + ) + + return { success: true, message: response.data?.message || '删除成功' } + } catch (error: any) { + return { + success: false, + message: error.response?.data?.detail || error.response?.data?.message || error.message || '删除 SSH 密钥失败' + } + } +} + +// 获取功能标志 +export const getFeatureFlags = async (): Promise<{ success: boolean; data?: Record; message?: string }> => { + try { + // 这里需要根据实际 API 调整 + const response = await axios.get( + `/api/action/jcloud.api.account.get_feature_flags`, + { + headers: get_session_api_headers(), + withCredentials: true + } + ) + + const result = response.data + return { success: true, data: result?.message || result } + } catch (error: any) { + // 如果 API 不存在,返回空对象 + return { success: false, data: {}, message: '功能标志 API 不可用' } + } +} + +// 更新功能标志 +export const updateFeatureFlags = async (values: Record): Promise<{ success: boolean; message?: string }> => { + try { + const response = await axios.post( + `/api/action/jcloud.api.account.update_feature_flags`, + { values }, + { + headers: get_session_api_headers(), + withCredentials: true + } + ) + + return { success: true, message: response.data?.message || '更新成功' } + } catch (error: any) { + return { + success: false, + message: error.response?.data?.detail || error.response?.data?.message || error.message || '更新功能标志失败' + } + } +} + +// 获取用户信息(包含 API Key) +// 使用 jcloud.api.account.get API 获取账户信息 +export const getUserAccountInfo = async (): Promise<{ success: boolean; data?: any; message?: string }> => { + try { + const response = await axios.get( + `/api/action/jcloud.api.account.get`, + { + headers: get_session_api_headers(), + withCredentials: true + } + ) + + const result = response.data?.message || response.data + + if (result?.user) { + return { success: true, data: result.user } + } + + return { success: false, message: 'API 返回的数据中未找到用户信息' } + } catch (error: any) { + return { + success: false, + message: error.response?.data?.detail || error.response?.data?.message || error.message || '获取用户信息失败' + } + } +} diff --git a/src/shared/components/ClickToCopyField.vue b/src/shared/components/ClickToCopyField.vue new file mode 100644 index 0000000..849f623 --- /dev/null +++ b/src/shared/components/ClickToCopyField.vue @@ -0,0 +1,78 @@ + + + + + diff --git a/src/views/settings/Settings.vue b/src/views/settings/Settings.vue index 2ffaa40..dede9cf 100644 --- a/src/views/settings/Settings.vue +++ b/src/views/settings/Settings.vue @@ -4,193 +4,460 @@

{{ t('Settings') }}

- - - - - - - - - - + + + + + +
+ + {{ userAccountInfo?.first_name?.[0] || authStore.user?.user?.[0] || 'U' }} + +
+

+ {{ userAccountInfo?.first_name || '' }} {{ userAccountInfo?.last_name || '' }} + + {{ authStore.user?.user || '' }} + +

+
+
+ {{ t('Username') }}: + {{ userAccountInfo?.username || '-' }} +
+
+ {{ t('Phone') }}: + {{ userAccountInfo?.mobile_no || '-' }} +
+
+ {{ t('Email') }}: + {{ userAccountInfo?.email || '-' }} +
+
+
+
+ + + {{ t('Edit') }} + +
+
+
+ + + + + + + + + + + + + + +
+
+ + + + + + + +
+ {{ t('API key and API secret can be used to access') }} + {{ t('Jingrow API') }} +
+
+ + {{ apiKeyButtonLabel }} + +
+
+ +
+
+ {{ t("You don't have an API key yet. Click the button above to create one.") }} +
+
+
+ + + + +
+ + + {{ t('Add SSH Key') }} + +
+ -
- - - - - - {{ timezoneError }} + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + {{ timezoneError }} + + + + + + + + + + + + + {{ t('Only system administrators can view and edit environment configuration') }} - - - - - - + + + + + + + + + + + + + - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+

+ {{ t('API key and API secret pairs can be used to access the') }} + {{ t('Jingrow API') }}. +

+
+
- {{ t('Only system administrators can view and edit environment configuration') }} + {{ t('Please copy the API secret now. You won\'t be able to see it again!') }} - + + + + + +
+
+ +
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + +

{{ t('Add a new SSH key to your account') }}

+ + + + +
+ +