Files
vpUni/.svn/pristine/be/be5160c56d7c576cb7bc01ffe9facb448e321591.svn-base
2026-03-09 16:39:03 +08:00

581 lines
12 KiB
Plaintext

<template>
<view class="settings-page">
<!-- 沉浸式状态栏 -->
<view class="status-bar"></view>
<!-- 顶部导航 -->
<view class="nav-bar">
<image class="back-icon" src="/static/icons/back.svg" @click="goBack" mode="aspectFit" />
<text class="nav-title">设置</text>
<view class="nav-placeholder"></view>
</view>
<!-- 主要内容区域 -->
<view class="content">
<!-- 个人信息卡片 -->
<view class="profile-card">
<view class="card-title">
<text class="ri-user-line title-icon"></text>
<text class="title-text">个人信息</text>
</view>
<!-- 头像 -->
<view class="setting-item" @click="uploadFImg(140,140,'Avatar','headimg')">
<view class="item-left">
<text class="item-label">头像</text>
</view>
<view class="item-right">
<image class="avatar-preview" :src="Service.GetMateUrlByImg(userInfo.headImg)"
mode="aspectFill" />
<text class="ri-arrow-right-s-line item-arrow"></text>
</view>
</view>
<!-- 昵称 -->
<view class="setting-item" @click="changeNickname">
<view class="item-left">
<text class="item-label">昵称</text>
</view>
<view class="item-right">
<text class="item-value">{{ userInfo.nick }}</text>
<text class="ri-arrow-right-s-line item-arrow"></text>
</view>
</view>
<!-- 手机号 -->
<view class="setting-item">
<view class="item-left">
<text class="item-label">手机号</text>
</view>
<view class="item-right">
<text class="item-value">{{ userInfo.phone }}</text>
</view>
</view>
<!-- 会员ID -->
<view class="setting-item">
<view class="item-left">
<text class="item-label">会员ID</text>
</view>
<view class="item-right">
<text class="item-value">{{ userInfo.userNo }}</text>
</view>
</view>
</view>
<!-- 其他设置 -->
<!-- <view class="other-settings-card">
<view class="card-title">
<text class="ri-settings-4-line title-icon"></text>
<text class="title-text">其他设置</text>
</view>
<view class="setting-item" @click="clearCache">
<view class="item-left">
<text class="item-label">清除缓存</text>
</view>
<view class="item-right">
<text class="item-value">23.5MB</text>
<text class="ri-arrow-right-s-line item-arrow"></text>
</view>
</view>
<view class="setting-item" @click="checkUpdate">
<view class="item-left">
<text class="item-label">检查更新</text>
</view>
<view class="item-right">
<text class="item-value">当前版本 v1.0.0</text>
<text class="ri-arrow-right-s-line item-arrow"></text>
</view>
</view>
<view class="setting-item" @click="viewPrivacy">
<view class="item-left">
<text class="item-label">隐私政策</text>
</view>
<view class="item-right">
<text class="ri-arrow-right-s-line item-arrow"></text>
</view>
</view>
<view class="setting-item" @click="viewAgreement">
<view class="item-left">
<text class="item-label">用户协议</text>
</view>
<view class="item-right">
<text class="ri-arrow-right-s-line item-arrow"></text>
</view>
</view>
</view> -->
<!-- <view class="logout-section">
<button class="logout-btn" @click="save()">
<text class="btn-text">保存信息</text>
</button>
</view> -->
</view>
<!-- 修改昵称弹窗 -->
<view v-if="showNicknameModal" class="modal-overlay" @click="closeNicknameModal">
<view class="modal-content" @click.stop>
<view class="modal-header">
<text class="modal-title">修改昵称</text>
<text class="ri-close-line modal-close" @click="closeNicknameModal"></text>
</view>
<view class="modal-body">
<input class="nickname-input" v-model="tempNickname" placeholder="请输入新昵称" maxlength="20" />
</view>
<view class="modal-footer">
<button class="modal-btn cancel" @click.stop="closeNicknameModal">取消</button>
<button class="modal-btn confirm" @click.stop="saveNickname">确定</button>
</view>
</view>
</view>
</view>
</template>
<script setup lang="ts">
import { onShow, onLoad } from "@dcloudio/uni-app";
import { Service } from '@/Service/Service';
import { ref } from "vue";
import { vpUserService } from '@/Service/vp/vpUserService';
import ImageCropperFunc from "@/components/ImageCropper";
const userInfo = ref<any>({
nick: '',
sex: '',
phone: '',
headImg: ''
})
// 临时昵称
const tempNickname = ref('')
onLoad(() => {
getUserinfo()
});
onShow(() => {
});
const getUserinfo = () => {
vpUserService.GetUserInfo().then(res => {
userInfo.value = res.data.userInfo
})
}
const uploadFImg = (width : any, height : any, Type : any, Name : any) => {
uni.chooseImage({
count: 1, // 最多选择3张图片
sizeType: ['original', 'compressed'], // 支持原图和压缩图
sourceType: ['album', 'camera'], // 可从相册选择或使用相机拍照
success: function (res) {
let path = res.tempFiles[0].path
let arr = path.split('.')
let name = arr[arr.length - 1]
Service.uploadH5(path, 'Avatar', (data) => {
userInfo.value.headImg = data
vpUserService.UpdateUser(userInfo.value.headImg, userInfo.value.nick, userInfo.value.sex, '').then(res => {
if (res.code == 0) {
Service.Msg('修改成功!')
getUserinfo()
} else {
Service.Msg(res.msg)
}
})
})
},
fail: function (err) {
console.error('选择失败:', err.errMsg);
}
})
}
// 修改昵称
const changeNickname = () => {
tempNickname.value = userInfo.value.nick
showNicknameModal.value = true
}
// 关闭昵称弹窗
const closeNicknameModal = () => {
showNicknameModal.value = false
}
// 保存昵称
const saveNickname = () => {
if (!tempNickname.value.trim()) {
uni.showToast({
title: '昵称不能为空',
icon: 'none'
})
return
}
vpUserService.UpdateUser(userInfo.value.headImg, tempNickname.value, userInfo.value.sex, '').then(res => {
if (res.code == 0) {
Service.Msg('修改成功!')
showNicknameModal.value = false
userInfo.value.nick = tempNickname.value
} else {
Service.Msg(res.msg)
}
})
}
// 用户信息
const user = ref({
nickname: '美食达人',
avatar: 'https://picsum.photos/200/200?random=100',
phone: '138****8888',
memberId: '8888888'
})
// 显示昵称弹窗
const showNicknameModal = ref(false)
// 返回
const goBack = () => {
uni.navigateBack({
delta: 1
})
}
// 修改头像
const changeAvatar = () => {
uni.chooseImage({
count: 1,
sizeType: ['compressed'],
sourceType: ['album', 'camera'],
success: (res) => {
// 这里应该上传到服务器,现在暂时直接使用本地路径
user.value.avatar = res.tempFilePaths[0]
uni.showToast({
title: '头像已更新',
icon: 'success'
})
}
})
}
// 清除缓存
const clearCache = () => {
uni.showModal({
title: '清除缓存',
content: '确定要清除缓存吗?',
success: (res) => {
if (res.confirm) {
uni.showLoading({
title: '清除中...'
})
setTimeout(() => {
uni.hideLoading()
uni.showToast({
title: '缓存已清除',
icon: 'success'
})
}, 1000)
}
}
})
}
// 检查更新
const checkUpdate = () => {
uni.showLoading({
title: '检查中...'
})
setTimeout(() => {
uni.hideLoading()
uni.showToast({
title: '已是最新版本',
icon: 'success'
})
}, 1500)
}
// 查看隐私政策
const viewPrivacy = () => {
uni.showToast({
title: '隐私政策页面',
icon: 'none'
})
}
// 查看用户协议
const viewAgreement = () => {
uni.showToast({
title: '用户协议页面',
icon: 'none'
})
}
// 退出登录
const logout = () => {
uni.showModal({
title: '退出登录',
content: '确定要退出登录吗?',
success: (res) => {
if (res.confirm) {
uni.showLoading({
title: '退出中...'
})
setTimeout(() => {
uni.hideLoading()
uni.showToast({
title: '已退出登录',
icon: 'success'
})
// 这里可以跳转到登录页面
}, 1000)
}
}
})
}
</script>
<style lang="scss" scoped>
.settings-page {
min-height: 100vh;
background: #F5F5F5;
display: flex;
flex-direction: column;
}
/* 状态栏 */
.status-bar {
background: linear-gradient(135deg, #FF6B00, #FF9500);
height: var(--status-bar-height);
width: 100%;
}
/* 导航栏 */
.nav-bar {
display: flex;
align-items: center;
justify-content: space-between;
padding: 60rpx 24rpx 20rpx 24rpx;
background: linear-gradient(135deg, #FF6B00, #FF9500);
}
.back-icon {
width: 48rpx;
height: 48rpx;
padding: 8rpx;
}
.nav-title {
font-size: 36rpx;
font-weight: 600;
color: #FFFFFF;
}
.nav-placeholder {
width: 48rpx;
}
/* 内容区域 */
.content {
flex: 1;
padding: 32rpx 24rpx;
}
/* 卡片通用样式 */
.profile-card,
.other-settings-card {
background: #FFFFFF;
border-radius: 24rpx;
padding: 32rpx;
box-shadow: 0 4rpx 16rpx rgba(0, 0, 0, 0.06);
margin-bottom: 20rpx;
}
.card-title {
display: flex;
align-items: center;
gap: 12rpx;
margin-bottom: 24rpx;
padding-bottom: 16rpx;
border-bottom: 2rpx solid #F5F5F5;
}
.title-icon {
font-size: 32rpx;
color: #FF6B00;
}
.title-text {
font-size: 28rpx;
font-weight: 600;
color: #222222;
}
/* 设置项 */
.setting-item {
display: flex;
align-items: center;
justify-content: space-between;
padding: 24rpx 0;
border-bottom: 1rpx solid #F5F5F5;
}
.setting-item:last-child {
border-bottom: none;
}
.item-left {
display: flex;
align-items: center;
}
.item-label {
font-size: 28rpx;
color: #222222;
font-weight: 500;
}
.item-right {
display: flex;
align-items: center;
gap: 8rpx;
}
.item-value {
font-size: 26rpx;
color: #999999;
}
.item-arrow {
font-size: 28rpx;
color: #CCCCCC;
}
.avatar-preview {
width: 80rpx;
height: 80rpx;
border-radius: 40rpx;
}
/* 退出登录按钮 */
.logout-section {
margin-top: 32rpx;
}
.logout-btn {
width: 100%;
height: 88rpx;
background: #FFFFFF;
border: 2rpx solid #F44336;
border-radius: 44rpx;
display: flex;
align-items: center;
justify-content: center;
}
.btn-text {
font-size: 32rpx;
font-weight: 600;
color: #F44336;
}
/* 弹窗样式 */
.modal-overlay {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: rgba(0, 0, 0, 0.5);
display: flex;
align-items: center;
justify-content: center;
z-index: 9999;
}
.modal-content {
width: 560rpx;
background: #FFFFFF;
border-radius: 24rpx;
padding: 32rpx;
}
.modal-header {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 32rpx;
}
.modal-title {
font-size: 32rpx;
font-weight: 600;
color: #222222;
}
.modal-close {
font-size: 40rpx;
color: #999999;
}
.modal-body {
margin-bottom: 32rpx;
}
.nickname-input {
width: 100%;
height: 80rpx;
padding: 0 20rpx;
background: #F5F5F5;
border-radius: 12rpx;
font-size: 28rpx;
color: #222222;
}
.modal-footer {
display: flex;
gap: 16rpx;
}
.modal-btn {
flex: 1;
height: 80rpx;
border-radius: 12rpx;
display: flex;
align-items: center;
justify-content: center;
font-size: 28rpx;
font-weight: 600;
border: none;
}
.modal-btn.cancel {
background: #F5F5F5;
color: #666666;
}
.modal-btn.confirm {
background: linear-gradient(135deg, #FF6B00, #FF9500);
color: #FFFFFF;
}
</style>