hookehuyr

feat: 优化用户界面和头像上传功能

- 在Dashboard页面添加"家庭设置"文字标签
- 使用默认头像替换Profile页面的占位图
- 优化EditFamily页面的输入框间距和删除按钮大小
- 实现EditProfile页面的真实头像上传功能,添加大小限制和错误处理
......@@ -4,8 +4,9 @@
<view class="relative h-48">
<image src="https://placehold.co/800x400/e2f3ff/0369a1?text=LFX&font=roboto" alt="Family background" class="w-full h-full object-cover" />
<view class="absolute inset-0 bg-black bg-opacity-30 flex flex-col justify-end p-5">
<view class="absolute top-4 right-4 text-white" @click="goToProfile">
<view class="absolute top-4 right-4 text-white flex items-center" @click="goToProfile">
<Setting size="24" />
<text class="ml-2">家庭设置</text>
</view>
<h1 class="text-white text-2xl font-bold">张爷爷的家庭</h1>
<p class="text-white opacity-90">每日走万步,全家一起行</p>
......
<!--
* @Date: 2025-08-27 17:44:53
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2025-08-28 12:55:02
* @LastEditTime: 2025-08-28 21:18:07
* @FilePath: /lls_program/src/pages/EditFamily/index.vue
* @Description: 文件描述
-->
......@@ -10,9 +10,9 @@
<!-- <AppHeader title="编辑家庭" /> -->
<view class="flex-1 px-4 py-6 overflow-auto">
<view class="mb-6">
<view class="text-gray-600 mb-6">
<!-- <view class="text-gray-600 mb-6">
请填写家庭信息,创建您的专属家庭空间
</view>
</view> -->
<!-- Family Name -->
<view class="mb-6">
<view class="bg-white rounded-lg border border-gray-200 p-4">
......@@ -82,6 +82,7 @@
@blur="handleBlur(index)"
class="w-full h-full bg-transparent text-center"
style="font-size: 38rpx;"
:cursorSpacing="100"
/>
</view>
</view>
......@@ -114,7 +115,7 @@
/>
<view
@click="deleteAvatar"
class="absolute -top-2 -right-2 w-5 h-5 bg-red-500 rounded-full flex items-center justify-center"
class="absolute -top-2 -right-2 w-4 h-4 bg-red-500 rounded-full flex items-center justify-center"
>
<view class="text-white text-xs">×</view>
</view>
......
......@@ -86,6 +86,7 @@
import { ref, reactive, onMounted } from 'vue';
import Taro from '@tarojs/taro';
import { My, Date as DateIcon, Right } from '@nutui/icons-vue-taro';
import BASE_URL from '@/utils/config';
/**
* @description 表单数据
......@@ -171,20 +172,40 @@ const changeAvatar = () => {
sizeType: ['compressed'],
sourceType: ['album', 'camera'],
success: (res) => {
const tempFilePath = res.tempFilePaths[0];
// In a real app, you would upload this file to your server
// and get back a URL. For this demo, we'll just use the local path.
const tempFile = res.tempFiles[0];
if (tempFile.size > 10 * 1024 * 1024) {
Taro.showToast({
title: '图片大小不能超过10MB',
icon: 'none',
});
return;
}
Taro.showLoading({ title: '上传中...' });
// Mock upload process
setTimeout(() => {
formData.avatar_url = tempFilePath;
Taro.hideLoading();
Taro.showToast({ title: '上传成功', icon: 'success' });
}, 1000);
Taro.uploadFile({
url: BASE_URL + '/admin/?m=srv&a=upload',
filePath: tempFile.path,
name: 'file',
success: (uploadRes) => {
Taro.hideLoading();
const data = JSON.parse(uploadRes.data);
if (data.code === 0) {
formData.avatar_url = data.data.url;
Taro.showToast({ title: '上传成功', icon: 'success' });
} else {
Taro.showToast({ title: data.msg || '上传失败', icon: 'none' });
}
},
fail: () => {
Taro.hideLoading();
Taro.showToast({ title: '上传失败,请稍后重试', icon: 'none' });
},
});
},
fail: () => {
Taro.showToast({ title: '选择图片失败', icon: 'none' });
}
Taro.showToast({ title: '选择图片失败', icon: 'none' });
},
});
};
......
<!--
* @Date: 2025-08-27 17:47:46
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2025-08-28 11:16:24
* @LastEditTime: 2025-08-28 21:12:23
* @FilePath: /lls_program/src/pages/Profile/index.vue
* @Description: 文件描述
-->
......@@ -14,7 +14,7 @@
<!-- User profile section -->
<view class="px-4 pt-8 pb-6 flex items-center justify-between">
<view class="flex items-center">
<image src="https://placehold.co/400x400/e2f3ff/0369a1?text=LFX&font=roboto" alt="User avatar" class="w-16 h-16 rounded-full border-2 border-white" />
<image :src="defaultAvatar" alt="User avatar" class="w-16 h-16 rounded-full border-2 border-white" />
<view class="ml-4">
<h1 class="text-xl font-bold text-white">张爷爷</h1>
</view>
......@@ -48,6 +48,8 @@ import { ref, shallowRef } from 'vue';
import Taro from '@tarojs/taro';
import BottomNav from '../../components/BottomNav.vue';
import { Shop3, Cart, Message, Tips, Right } from '@nutui/icons-vue-taro';
// 默认头像
const defaultAvatar = 'https://cdn.ipadbiz.cn/mlaj/images/icon_1.jpeg'
const menuItems = shallowRef([
{
......
......@@ -391,6 +391,7 @@ const saveMedia = async () => {
Taro.reLaunch({
url: '/pages/Dashboard/index'
});
// Taro.navigateBack();
}, 2000);
} catch (error) {
console.error('上传失败:', error);
......