mirror of
https://github.com/jxxghp/MoviePilot-Frontend.git
synced 2026-09-04 23:18:44 +08:00
修复配置向导中的用户信息保存逻辑
This commit is contained in:
@@ -4,6 +4,7 @@ import { useRouter } from 'vue-router'
|
|||||||
import { useI18n } from 'vue-i18n'
|
import { useI18n } from 'vue-i18n'
|
||||||
import api from '@/api'
|
import api from '@/api'
|
||||||
import { copyToClipboard } from '@/@core/utils/navigator'
|
import { copyToClipboard } from '@/@core/utils/navigator'
|
||||||
|
import { User } from '@/api/types'
|
||||||
|
|
||||||
export interface WizardData {
|
export interface WizardData {
|
||||||
basic: {
|
basic: {
|
||||||
@@ -823,21 +824,13 @@ export function useSetupWizard() {
|
|||||||
// 完成向导
|
// 完成向导
|
||||||
async function completeWizard() {
|
async function completeWizard() {
|
||||||
try {
|
try {
|
||||||
// 如果输入了密码,验证密码一致性
|
// 先处理下一步
|
||||||
if (wizardData.value.basic.password) {
|
await nextStep()
|
||||||
if (wizardData.value.basic.password !== wizardData.value.basic.confirmPassword) {
|
// 保存设置向导完成状态
|
||||||
$toast.error(t('dialog.userAddEdit.passwordMismatch'))
|
await saveSetupWizardState()
|
||||||
return
|
|
||||||
}
|
|
||||||
// 更新用户密码
|
|
||||||
await updateUserPassword()
|
|
||||||
}
|
|
||||||
|
|
||||||
// 保存最后一步的设置(资源偏好)
|
|
||||||
await savePreferenceSettings()
|
|
||||||
|
|
||||||
$toast.success(t('setupWizard.completed'))
|
$toast.success(t('setupWizard.completed'))
|
||||||
router.push('/setting')
|
router.push('/')
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Setup wizard failed:', error)
|
console.error('Setup wizard failed:', error)
|
||||||
$toast.error(t('setupWizard.failed'))
|
$toast.error(t('setupWizard.failed'))
|
||||||
@@ -849,9 +842,7 @@ export function useSetupWizard() {
|
|||||||
if (wizardData.value.basic.username && wizardData.value.basic.password) {
|
if (wizardData.value.basic.username && wizardData.value.basic.password) {
|
||||||
try {
|
try {
|
||||||
// 获取当前用户信息
|
// 获取当前用户信息
|
||||||
const response = await api.get('user/')
|
const currentUser: User = await api.get('user/current')
|
||||||
const existingUsers = response.data || []
|
|
||||||
const currentUser = existingUsers.find((user: any) => user.name === wizardData.value.basic.username)
|
|
||||||
|
|
||||||
if (currentUser) {
|
if (currentUser) {
|
||||||
// 更新现有用户的密码
|
// 更新现有用户的密码
|
||||||
@@ -894,9 +885,22 @@ export function useSetupWizard() {
|
|||||||
GITHUB_TOKEN: wizardData.value.basic.githubToken,
|
GITHUB_TOKEN: wizardData.value.basic.githubToken,
|
||||||
}
|
}
|
||||||
|
|
||||||
const response = await api.post('system/env', basicSettings)
|
// 保存基础设置
|
||||||
if (response.data?.success) {
|
const response: { [key: string]: any } = await api.post('system/env', basicSettings)
|
||||||
|
if (response.success) {
|
||||||
$toast.success(t('setupWizard.basicSettingsSaved'))
|
$toast.success(t('setupWizard.basicSettingsSaved'))
|
||||||
|
} else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 如果输入了密码,验证密码一致性
|
||||||
|
if (wizardData.value.basic.password) {
|
||||||
|
if (wizardData.value.basic.password !== wizardData.value.basic.confirmPassword) {
|
||||||
|
$toast.error(t('dialog.userAddEdit.passwordMismatch'))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// 更新用户密码
|
||||||
|
await updateUserPassword()
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Save basic settings failed:', error)
|
console.error('Save basic settings failed:', error)
|
||||||
@@ -937,8 +941,8 @@ export function useSetupWizard() {
|
|||||||
library_category_folder: true,
|
library_category_folder: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
const response = await api.post('system/setting/Directories', [directory])
|
const response: { [key: string]: any } = await api.post('system/setting/Directories', [directory])
|
||||||
if (response.data?.success) {
|
if (response.success) {
|
||||||
$toast.success(t('setupWizard.storageSettingsSaved'))
|
$toast.success(t('setupWizard.storageSettingsSaved'))
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -959,8 +963,8 @@ export function useSetupWizard() {
|
|||||||
config: wizardData.value.downloader.config,
|
config: wizardData.value.downloader.config,
|
||||||
}
|
}
|
||||||
|
|
||||||
const response = await api.post('system/setting/Downloaders', [downloader])
|
const response: { [key: string]: any } = await api.post('system/setting/Downloaders', [downloader])
|
||||||
if (response.data?.success) {
|
if (response.success) {
|
||||||
$toast.success(t('setupWizard.downloaderSettingsSaved'))
|
$toast.success(t('setupWizard.downloaderSettingsSaved'))
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -984,8 +988,8 @@ export function useSetupWizard() {
|
|||||||
config: wizardData.value.mediaServer.config,
|
config: wizardData.value.mediaServer.config,
|
||||||
}
|
}
|
||||||
|
|
||||||
const response = await api.post('system/setting/MediaServers', [mediaServer])
|
const response: { [key: string]: any } = await api.post('system/setting/MediaServers', [mediaServer])
|
||||||
if (response.data?.success) {
|
if (response.success) {
|
||||||
$toast.success(t('setupWizard.mediaServerSettingsSaved'))
|
$toast.success(t('setupWizard.mediaServerSettingsSaved'))
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -1009,8 +1013,8 @@ export function useSetupWizard() {
|
|||||||
config: wizardData.value.notification.config,
|
config: wizardData.value.notification.config,
|
||||||
}
|
}
|
||||||
|
|
||||||
const response = await api.post('system/setting/Notifications', [notification])
|
const response: { [key: string]: any } = await api.post('system/setting/Notifications', [notification])
|
||||||
if (response.data?.success) {
|
if (response.success) {
|
||||||
$toast.success(t('setupWizard.notificationSettingsSaved'))
|
$toast.success(t('setupWizard.notificationSettingsSaved'))
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -1034,8 +1038,8 @@ export function useSetupWizard() {
|
|||||||
RESOLUTION_PREFERENCE: wizardData.value.preferences.resolution,
|
RESOLUTION_PREFERENCE: wizardData.value.preferences.resolution,
|
||||||
}
|
}
|
||||||
|
|
||||||
const response = await api.post('system/env', preferenceSettings)
|
const response: { [key: string]: any } = await api.post('system/env', preferenceSettings)
|
||||||
if (response.data?.success) {
|
if (response.success) {
|
||||||
$toast.success(t('setupWizard.preferenceSettingsSaved'))
|
$toast.success(t('setupWizard.preferenceSettingsSaved'))
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -1044,6 +1048,19 @@ export function useSetupWizard() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 保存设置向导完成状态
|
||||||
|
async function saveSetupWizardState() {
|
||||||
|
try {
|
||||||
|
const response: { [key: string]: any } = await api.post('system/setting/SetupWizardState', '1')
|
||||||
|
if (response.success) {
|
||||||
|
console.log('Setup wizard state saved successfully')
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Save setup wizard state failed:', error)
|
||||||
|
// 这里不显示错误提示,因为向导状态保存失败不应该阻止用户完成向导
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 加载系统设置
|
// 加载系统设置
|
||||||
async function loadSystemSettings() {
|
async function loadSystemSettings() {
|
||||||
try {
|
try {
|
||||||
@@ -1065,6 +1082,11 @@ export function useSetupWizard() {
|
|||||||
if (result.data.SUPERUSER) {
|
if (result.data.SUPERUSER) {
|
||||||
wizardData.value.basic.username = result.data.SUPERUSER
|
wizardData.value.basic.username = result.data.SUPERUSER
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 如果没有API Token,则创建一个随机的
|
||||||
|
if (!wizardData.value.basic.apiToken) {
|
||||||
|
createRandomString()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log('Load system settings failed:', error)
|
console.log('Load system settings failed:', error)
|
||||||
@@ -1163,11 +1185,6 @@ export function useSetupWizard() {
|
|||||||
await loadMediaServerSettings()
|
await loadMediaServerSettings()
|
||||||
await loadNotificationSettings()
|
await loadNotificationSettings()
|
||||||
await loadPreferenceSettings()
|
await loadPreferenceSettings()
|
||||||
|
|
||||||
// 如果没有API Token,则创建一个随机的
|
|
||||||
if (!wizardData.value.basic.apiToken) {
|
|
||||||
createRandomString()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
+1
-1
@@ -170,7 +170,7 @@ function login() {
|
|||||||
avatar: response.avatar,
|
avatar: response.avatar,
|
||||||
level: response.level,
|
level: response.level,
|
||||||
permissions: response.permissions,
|
permissions: response.permissions,
|
||||||
wizard: response.wizard,
|
wizard: response.widzard,
|
||||||
}
|
}
|
||||||
|
|
||||||
// 在保存用户信息之前检查权限
|
// 在保存用户信息之前检查权限
|
||||||
|
|||||||
Reference in New Issue
Block a user