From a1d7e81859f554f3a53680cc35f0f49bf1f77098 Mon Sep 17 00:00:00 2001
From: wwf <1971391498@qq.com>
Date: 星期四, 14 五月 2026 14:37:02 +0800
Subject: [PATCH] 导入项目
---
src/views/Profile/components/BasicInfo.vue | 121 ++++++++++++++++++++++++++++++++++++++++
1 files changed, 121 insertions(+), 0 deletions(-)
diff --git a/src/views/Profile/components/BasicInfo.vue b/src/views/Profile/components/BasicInfo.vue
new file mode 100644
index 0000000..094df40
--- /dev/null
+++ b/src/views/Profile/components/BasicInfo.vue
@@ -0,0 +1,121 @@
+<template>
+ <Form ref="formRef" :labelWidth="200" :rules="rules" :schema="schema">
+ <template #sex="form">
+ <el-radio-group v-model="form['sex']">
+ <el-radio :value="1">{{ t('profile.user.man') }}</el-radio>
+ <el-radio :value="2">{{ t('profile.user.woman') }}</el-radio>
+ </el-radio-group>
+ </template>
+ </Form>
+ <div style="text-align: center">
+ <XButton :title="t('common.save')" type="primary" @click="submit()" />
+ <XButton :title="t('common.reset')" type="danger" @click="init()" />
+ </div>
+</template>
+<script lang="ts" setup>
+import type { FormRules } from 'element-plus'
+import { FormSchema } from '@/types/form'
+import type { FormExpose } from '@/components/Form'
+import {
+ getUserProfile,
+ updateUserProfile,
+ UserProfileUpdateReqVO
+} from '@/api/system/user/profile'
+import { useUserStore } from '@/store/modules/user'
+
+defineOptions({ name: 'BasicInfo' })
+
+const { t } = useI18n()
+const message = useMessage() // 娑堟伅寮圭獥
+const userStore = useUserStore()
+
+// 瀹氫箟浜嬩欢
+const emit = defineEmits<{
+ (e: 'success'): void
+}>()
+
+// 琛ㄥ崟鏍¢獙
+const rules = reactive<FormRules>({
+ nickname: [{ required: true, message: t('profile.rules.nickname'), trigger: 'blur' }],
+ email: [
+ { required: true, message: t('profile.rules.mail'), trigger: 'blur' },
+ {
+ type: 'email',
+ message: t('profile.rules.truemail'),
+ trigger: ['blur', 'change']
+ }
+ ],
+ mobile: [
+ { required: true, message: t('profile.rules.phone'), trigger: 'blur' },
+ {
+ pattern: /^1[3-9]\d{9}$/,
+ message: t('profile.rules.truephone'),
+ trigger: 'blur'
+ }
+ ]
+})
+const schema = reactive<FormSchema[]>([
+ {
+ field: 'nickname',
+ label: t('profile.user.nickname'),
+ component: 'Input'
+ },
+ {
+ field: 'mobile',
+ label: t('profile.user.mobile'),
+ component: 'Input'
+ },
+ {
+ field: 'email',
+ label: t('profile.user.email'),
+ component: 'Input'
+ },
+ {
+ field: 'sex',
+ label: t('profile.user.sex'),
+ component: 'InputNumber',
+ value: 0
+ }
+])
+const formRef = ref<FormExpose>() // 琛ㄥ崟 Ref
+
+// 鐩戝惉 userStore 涓ご鍍忕殑鍙樺寲锛屽悓姝ユ洿鏂拌〃鍗曟暟鎹�
+watch(
+ () => userStore.getUser.avatar,
+ (newAvatar) => {
+ if (newAvatar && formRef.value) {
+ // 鐩存帴鏇存柊琛ㄥ崟妯″瀷涓殑澶村儚瀛楁
+ const formModel = formRef.value.formModel
+ if (formModel) {
+ formModel.avatar = newAvatar
+ }
+ }
+ }
+)
+
+const submit = () => {
+ const elForm = unref(formRef)?.getElFormRef()
+ if (!elForm) return
+ elForm.validate(async (valid) => {
+ if (valid) {
+ const data = unref(formRef)?.formModel as UserProfileUpdateReqVO
+ await updateUserProfile(data)
+ message.success(t('common.updateSuccess'))
+ const profile = await init()
+ await userStore.setUserNicknameAction(profile.nickname)
+ // 鍙戦�佹垚鍔熶簨浠�
+ emit('success')
+ }
+ })
+}
+
+const init = async () => {
+ const res = await getUserProfile()
+ unref(formRef)?.setValues(res)
+ return res
+}
+
+onMounted(async () => {
+ await init()
+})
+</script>
--
Gitblit v1.8.0