|
|
@@ -10,29 +10,31 @@
|
|
|
>
|
|
|
<!-- 头像 -->
|
|
|
<view class="avatar-section">
|
|
|
- <view class="avatar-container" @click="handleAvatarClick">
|
|
|
- <image
|
|
|
- :src="formModel.avatar || DefaultAvatar"
|
|
|
- class="avatar-image"
|
|
|
- mode="aspectFill"
|
|
|
- ></image>
|
|
|
- <text class="avatar-hint">点击可修改头像</text>
|
|
|
- </view>
|
|
|
+ <button open-type="chooseAvatar" class="remove-button-style" @chooseavatar="handleChooseAvatar">
|
|
|
+ <view class="avatar-container">
|
|
|
+ <image
|
|
|
+ :src="formModel.avatar || DefaultAvatar"
|
|
|
+ class="avatar-image"
|
|
|
+ mode="aspectFill"
|
|
|
+ />
|
|
|
+ <text class="avatar-hint">点击可修改头像</text>
|
|
|
+ </view>
|
|
|
+ </button>
|
|
|
</view>
|
|
|
|
|
|
- <Field name="nickname" label="昵称" placeholder="请输入昵称" required />
|
|
|
+ <Field name="nickname" label="昵称" placeholder="请输入昵称" type="nickname" required />
|
|
|
<Field name="bio" multiline label="个人简介" placeholder="输入个人简介" :inputStyle="{width: '240px'}" />
|
|
|
</Form>
|
|
|
|
|
|
<Height :height="40" />
|
|
|
|
|
|
- <Button type="primary" :loading="loading" @click="submitForm" >
|
|
|
+ <NaButton type="primary" :loading="loading" @click="submitForm" >
|
|
|
保存修改
|
|
|
- </Button>
|
|
|
+ </NaButton>
|
|
|
<Height :height="20" />
|
|
|
- <Button type="primary" scheme="plain" @click="back()">
|
|
|
+ <NaButton type="primary" scheme="plain" @click="back()">
|
|
|
返回
|
|
|
- </Button>
|
|
|
+ </NaButton>
|
|
|
</FlexCol>
|
|
|
</template>
|
|
|
|
|
|
@@ -44,10 +46,12 @@ import CommonContent from '@/api/CommonContent';
|
|
|
import Form from '@/components/form/Form.vue';
|
|
|
import Field from '@/components/form/Field.vue';
|
|
|
import FlexCol from '@/components/layout/FlexCol.vue';
|
|
|
-import Button from '@/components/basic/Button.vue';
|
|
|
+import NaButton from '@/components/basic/Button.vue';
|
|
|
import Height from '@/components/layout/space/Height.vue';
|
|
|
import type { Rules } from 'async-validator';
|
|
|
import { back } from '@/components/utils/PageAction';
|
|
|
+import Dialog from '@/components/dialog/Dialog.vue';
|
|
|
+import Avatar from '@/components/display/Avatar.vue';
|
|
|
|
|
|
const DefaultAvatar = 'https://mncdn.wenlvti.net/app_static/minnan/images/home/UserHead.png';
|
|
|
const authStore = useAuthStore();
|
|
|
@@ -71,25 +75,16 @@ const rules : Rules = {
|
|
|
],
|
|
|
};
|
|
|
|
|
|
-// 处理头像点击事件
|
|
|
-const handleAvatarClick = async () => {
|
|
|
+
|
|
|
+
|
|
|
+const handleChooseAvatar = async (e: { detail: { avatarUrl: string } }) => {
|
|
|
try {
|
|
|
- // 选择图片
|
|
|
- const chooseResult = await uni.chooseImage({
|
|
|
- count: 1,
|
|
|
- sizeType: ['compressed'],
|
|
|
- sourceType: ['album', 'camera'],
|
|
|
- });
|
|
|
-
|
|
|
- const tempFilePath = chooseResult.tempFilePaths[0];
|
|
|
-
|
|
|
+ const tempFilePath = e.detail.avatarUrl;
|
|
|
// 上传图片
|
|
|
uploading.value = true;
|
|
|
const uploadResult = await CommonContent.uploadFile(tempFilePath, 'image');
|
|
|
-
|
|
|
// 更新头像并保存到服务器
|
|
|
- await updateAvatar(uploadResult.fullurl);
|
|
|
-
|
|
|
+ await updateAvatar(uploadResult.fullurl);
|
|
|
} catch (error: any) {
|
|
|
if (error.errMsg !== 'chooseImage:fail cancel') {
|
|
|
uni.showToast({
|
|
|
@@ -102,7 +97,6 @@ const handleAvatarClick = async () => {
|
|
|
uploading.value = false;
|
|
|
}
|
|
|
};
|
|
|
-// 更新头像到服务器
|
|
|
const updateAvatar = async (avatarUrl: string) => {
|
|
|
try {
|
|
|
await UserApi.updateUserInfo({
|