| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545 |
- <template>
- <view class="container">
- <!-- ===== 未登录状态 ===== -->
- <view v-if="!isLoggedIn" class="login-prompt">
- <view class="prompt-icon">👤</view>
- <text class="prompt-title">登录浠艾福</text>
- <text class="prompt-desc">登录后可查看个人资料、积分记录等</text>
- <button class="login-btn" @click="goLogin">登录 / 注册</button>
- </view>
- <!-- ===== 已登录状态 ===== -->
- <template v-else>
- <!-- 退出切换按钮(仅家长切换到孩子状态时显示) -->
- <view class="exit-switch" v-if="isSwitchedChild" @click="exitSwitch">
- <text>🔄 退出切换</text>
- </view>
-
- <view class="user-card">
- <view class="avatar">👤</view>
- <view class="user-info">
- <view class="nickname">{{ nickname || '未设置昵称' }}</view>
- <view class="role">{{ role === 'parent' ? '家长模式' : (role === 'child' ? '孩子模式' : '成长规划师模式') }}</view>
- <view class="system-points" v-if="role === 'parent' && children.length > 0">🏅 系统积分: {{ children[0].systemPoints || 0 }}</view>
- </view>
- <!-- 切换按钮仅在非切换状态下显示 -->
- <button class="btn-switch" v-if="!isSwitchedChild" @click="switchMode">切换</button>
- </view>
- <view class="menu-list">
- <!-- 修改个人资料:所有角色可见 -->
- <view class="menu-item" @click="goToEditInfo">
- <text>📝 修改个人资料</text>
- <text class="arrow">›</text>
- </view>
- <!-- 我的孩子:仅家长可见 -->
- <view class="menu-item" v-if="role === 'parent'" @click="goToChildren">
- <text>👶 我的孩子</text>
- <text class="arrow">›</text>
- </view>
- <!-- 家庭成员 -->
- <view class="menu-item" v-if="role === 'parent'" @click="goToFamilyMembers">
- <text>👨👩👧👦 家庭成员</text>
- <text class="arrow">›</text>
- </view>
- <view class="menu-item" @click="goToPointsLogs">
- <text>📊 积分记录</text>
- <text class="arrow">›</text>
- </view>
- <!-- 设置/重置密码:仅家长和成长规划师可见,孩子不可见 -->
- <view class="menu-item" v-if="role === 'parent'" @click="showPasswordModal = true">
- <text>🔐 {{ hasPassword ? '重置密码' : '设置密码' }}</text>
- <text class="arrow">›</text>
- </view>
- <button class="menu-item menu-item-btn" open-type="share" @click="inviteFamily" v-if="role === 'parent'">
- <text>👨👩👧👦 邀请家人</text>
- <text class="arrow">›</text>
- </button>
- <button class="menu-item menu-item-btn" open-type="share" @click="inviteTeacher" v-if="role === 'parent'">
- <text>👨🏫 邀请规划师</text>
- <text class="arrow">›</text>
- </button>
- <!-- 会员中心(浠艾福俱乐部) -->
- <view class="menu-item" @click="goToMembership">
- <text>👑 会员中心</text>
- <text class="arrow">›</text>
- </view>
- <!-- 服务商中心(仅已通过服务商可见) -->
- <view class="menu-item" v-if="isVendor" @click="goToVendorCenter">
- <text>🏪 服务商中心</text>
- <text class="arrow">›</text>
- </view>
- <view class="menu-item" @click="goToPromotion">
- <text>📢 推广中心</text>
- <text class="arrow">›</text>
- </view>
- <view class="menu-item" @click="logout">
- <text>🚪 退出登录</text>
- <text class="arrow">›</text>
- </view>
- </view>
- <!-- 设置/重置密码弹窗 -->
- <view class="modal-mask" v-if="showPasswordModal" @click="showPasswordModal = false">
- <view class="modal" @click.stop>
- <view class="modal-title">{{ hasPassword ? '重置密码' : '设置密码' }}</view>
- <view class="form-item" v-if="hasPassword">
- <input v-model="oldPassword" type="number" password placeholder="输入旧密码" maxlength="6" />
- </view>
- <view class="form-item">
- <input v-model="newPassword" type="number" password placeholder="输入新密码" maxlength="6" />
- </view>
- <view class="form-item">
- <input v-model="confirmPassword" type="number" password placeholder="确认新密码" maxlength="6" />
- </view>
- <view class="modal-btns">
- <button @click="showPasswordModal = false">取消</button>
- <button class="btn-primary" @click="savePassword">确定</button>
- </view>
- </view>
- </view>
- </template>
- </view>
- </template>
- <script>
- import { setPassword, verifyPassword, getChildren, vendorStatus } from '../../utils/api.js'
- export default {
- data() {
- return {
- nickname: '',
- role: 'parent',
- hasPassword: false,
- showPasswordModal: false,
- oldPassword: '',
- newPassword: '',
- confirmPassword: '',
- children: [],
- isSwitchedChild: false,
- shareData: null,
- isVendor: false
- }
- },
- computed: {
- isLoggedIn() {
- return !!uni.getStorageSync('token')
- }
- },
- onShareAppMessage() {
- if (this.shareData) {
- return {
- title: this.shareData.title,
- path: this.shareData.path,
- imageUrl: '/static/invite-card.png'
- }
- }
- },
- onShow() {
- if (!uni.getStorageSync('token')) return
- const currentRole = uni.getStorageSync('currentRole') || uni.getStorageSync('role') || 'parent'
- if (currentRole === 'teacher') {
- uni.redirectTo({ url: '/pages/teacher/teacher-profile' })
- return
- }
- var userInfo = uni.getStorageSync('userInfo')
- this.nickname = this.$store.state.nickname || (userInfo && userInfo.nickname) || ''
- // 使用 currentRole(视图角色),而非 role(实际角色)
- this.role = currentRole
- this.hasPassword = !!uni.getStorageSync('passwordSet')
- // 获取切换标记
- this.isSwitchedChild = uni.getStorageSync('isSwitchedChild') || false
- this.loadChildren()
- this.checkVendorStatus()
- },
- methods: {
- goLogin() {
- uni.navigateTo({ url: '/pages/login/login' })
- },
- async loadChildren() {
- try {
- const res = await getChildren()
- this.children = res.data || []
- } catch (e) {
- console.error('获取孩子列表失败', e)
- }
- },
- goToEditInfo() {
- uni.navigateTo({ url: '/pages/user-edit/user-edit' })
- },
- goToChildren() {
- uni.navigateTo({ url: '/pages/profile/children' })
- },
- goToFamilyMembers() {
- uni.navigateTo({ url: '/pages/profile/family-members' })
- },
- goToPointsLogs() {
- uni.navigateTo({ url: '/pages/points/points' })
- },
- switchMode() {
- if (this.role === 'child') {
- this.verifyPasswordForSwitch(() => {
- this.doSwitchMode()
- })
- } else {
- this.doSwitchMode()
- }
- },
- doSwitchMode() {
- const newRole = this.role === 'parent' ? 'child' : 'parent'
- if (newRole === 'child') {
- if (this.children.length === 0) {
- this.loadChildren()
- }
- if (this.children.length === 0) {
- uni.showModal({
- title: '提示',
- content: '您还没有添加孩子,是否现在去添加?',
- success: (res) => {
- if (res.confirm) {
- uni.navigateTo({ url: '/pages/profile/create-child' })
- }
- }
- })
- return
- }
- if (this.children.length === 1) {
- this.$store.commit('switchToChild', this.children[0].id)
- this.role = newRole
- uni.showToast({ title: '已切换为孩子模式', icon: 'success' })
- return
- }
- uni.showActionSheet({
- itemList: this.children.map(c => c.nickname),
- success: (res) => {
- const selectedChild = this.children[res.tapIndex]
- this.$store.commit('switchToChild', selectedChild.id)
- this.role = newRole
- uni.showToast({ title: `已切换为${selectedChild.nickname}模式`, icon: 'success' })
- }
- })
- return
- }
- this.$store.commit('switchBackToParent')
- this.role = newRole
- uni.showToast({ title: `已切换为${newRole === 'parent' ? '家长' : '孩子'}模式`, icon: 'success' })
- },
- verifyPasswordForSwitch(callback) {
- uni.showModal({
- title: '验证密码',
- content: '请输入家长密码',
- editable: true,
- success: async (res) => {
- if (res.confirm && res.content) {
- try {
- const result = await verifyPassword(res.content)
- if (result.code === 200) {
- callback && callback()
- } else {
- uni.showToast({ title: '密码错误', icon: 'none' })
- }
- } catch (e) {
- uni.showToast({ title: '验证失败', icon: 'none' })
- }
- }
- }
- })
- },
- async savePassword() {
- if (this.newPassword.length !== 6) {
- uni.showToast({ title: '请输入6位密码', icon: 'none' })
- return
- }
- if (this.newPassword !== this.confirmPassword) {
- uni.showToast({ title: '两次密码不一致', icon: 'none' })
- return
- }
- if (this.hasPassword && this.oldPassword.length !== 6) {
- uni.showToast({ title: '请输入旧密码', icon: 'none' })
- return
- }
- try {
- if (this.hasPassword) {
- const verifyRes = await verifyPassword(this.oldPassword)
- if (verifyRes.code !== 200) {
- uni.showToast({ title: '旧密码错误', icon: 'none' })
- return
- }
- }
- await setPassword(this.newPassword)
- uni.setStorageSync('passwordSet', true)
- this.hasPassword = true
- uni.showToast({ title: '密码设置成功', icon: 'success' })
- this.showPasswordModal = false
- this.oldPassword = ''
- this.newPassword = ''
- this.confirmPassword = ''
- } catch (e) {
- console.error('设置密码失败', e)
- }
- },
- logout() {
- uni.showModal({
- title: '确认退出',
- content: '确定要退出登录吗?',
- success: (res) => {
- if (res.confirm) {
- this.$store.commit('logout')
- uni.reLaunch({ url: '/pages/login/login' })
- }
- }
- })
- },
- inviteFamily() {
- const userInfo = uni.getStorageSync('userInfo')
- const familyId = uni.getStorageSync('familyId')
- if (!familyId) {
- uni.showToast({ title: '您暂未加入家庭', icon: 'none' })
- return
- }
- this.inviteFamilyGenerate(familyId, userInfo)
- },
- async inviteFamilyGenerate(familyId, userInfo) {
- try {
- const { generateInviteCard } = require('../../utils/api.js')
- const res = await generateInviteCard('family', familyId)
- const code = res.data.code
- this.shareData = {
- title: (userInfo && userInfo.nickname ? userInfo.nickname : '家人') + ' 邀请你加入家庭',
- path: '/pages/login/login?invite_code=' + code
- }
- uni.showToast({ title: '点击右上角转发给TA', icon: 'none' })
- } catch (e) {
- uni.showToast({ title: e.message || '生成邀请失败', icon: 'none' })
- }
- },
- inviteTeacher() {
- const userInfo = uni.getStorageSync('userInfo')
- const familyId = uni.getStorageSync('familyId')
- if (!familyId) {
- uni.showToast({ title: '您暂未加入家庭', icon: 'none' })
- return
- }
- this.inviteTeacherGenerate(familyId, userInfo)
- },
- async inviteTeacherGenerate(familyId, userInfo) {
- try {
- const { generateInviteCard } = require('../../utils/api.js')
- const res = await generateInviteCard('guide', familyId)
- const code = res.data.code
- this.shareData = {
- title: (userInfo && userInfo.nickname ? userInfo.nickname : '家长') + ' 邀请你成为家庭成长规划师',
- path: '/pages/login/login?invite_code=' + code
- }
- uni.showToast({ title: '点击右上角转发给规划师', icon: 'none' })
- } catch (e) {
- uni.showToast({ title: e.message || '生成邀请失败', icon: 'none' })
- }
- },
- goToMembership() {
- uni.showToast({ title: '即将上线', icon: 'none' })
- },
- goToVendorCenter() {
- uni.navigateTo({ url: '/pages/vendor/center' })
- },
- goToPromotion() {
- uni.navigateTo({ url: '/pages/promotion/index' })
- },
- async checkVendorStatus() {
- try {
- const res = await vendorStatus()
- this.isVendor = res.data && res.data.vendorStatus === 'approved'
- } catch (e) {
- this.isVendor = false
- }
- },
- exitSwitch() {
- if (!this.isSwitchedChild) return
- uni.showModal({
- title: '退出切换',
- content: '请输入家长密码以确认退出',
- editable: true,
- success: async (res) => {
- if (res.confirm && res.content) {
- try {
- const verifyResult = await verifyPassword(res.content)
- if (verifyResult.code === 200) {
- this.$store.commit('switchBackToParent')
- this.isSwitchedChild = false
- this.role = 'parent'
- uni.showToast({ title: '已退出切换', icon: 'success' })
- // 刷新首页
- uni.reLaunch({ url: '/pages/index/index' })
- } else {
- uni.showToast({ title: '密码错误', icon: 'none' })
- }
- } catch (e) {
- uni.showToast({ title: '验证失败', icon: 'none' })
- }
- }
- }
- })
- }
- }
- }
- </script>
- <style scoped>
- .container {
- padding: 30rpx;
- }
- .user-card {
- background: linear-gradient(135deg, #5B9BD5 0%, #3A7CC4 100%);
- border-radius: 20rpx;
- padding: 40rpx;
- display: flex;
- align-items: center;
- color: #fff;
- }
- .avatar {
- font-size: 80rpx;
- margin-right: 30rpx;
- }
- .user-info {
- flex: 1;
- }
- .nickname {
- font-size: 36rpx;
- font-weight: bold;
- }
- .role {
- font-size: 24rpx;
- opacity: 0.8;
- }
- .system-points {
- font-size: 22rpx;
- color: #D6EAF8;
- margin-top: 8rpx;
- font-weight: 500;
- }
- .btn-switch {
- background: rgba(255, 255, 255, 0.2);
- color: #fff;
- font-size: 24rpx;
- padding: 10rpx 20rpx;
- border-radius: 20rpx;
- }
- .menu-list {
- margin-top: 30rpx;
- background: #fff;
- border-radius: 16rpx;
- }
- .menu-item {
- padding: 30rpx;
- border-bottom: 1rpx solid #f0f0f0;
- display: flex;
- justify-content: space-between;
- font-size: 28rpx;
- }
- .menu-item:last-child {
- border-bottom: none;
- }
- .arrow {
- color: #ccc;
- font-size: 32rpx;
- }
- .menu-item-btn {
- display: flex;
- justify-content: space-between;
- align-items: center;
- width: 100%;
- padding: 28rpx 24rpx;
- border: none;
- background: transparent;
- font-size: 28rpx;
- color: #333;
- }
- .menu-item-btn::after { border: none; }
- .modal-mask {
- 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;
- }
- .modal {
- background: #fff;
- border-radius: 20rpx;
- padding: 40rpx;
- width: 80%;
- }
- .modal-title {
- font-size: 32rpx;
- font-weight: bold;
- margin-bottom: 30rpx;
- text-align: center;
- }
- .form-item {
- margin-bottom: 20rpx;
- }
- .form-item input {
- border: 1rpx solid #ddd;
- border-radius: 10rpx;
- padding: 20rpx;
- font-size: 28rpx;
- }
- .modal-btns {
- display: flex;
- gap: 20rpx;
- margin-top: 30rpx;
- }
- .modal-btns button {
- flex: 1;
- }
- /* ===== 未登录提示 ===== */
- .login-prompt {
- display: flex;
- flex-direction: column;
- align-items: center;
- justify-content: center;
- min-height: 80vh;
- padding: 60rpx;
- }
- .prompt-icon {
- font-size: 120rpx;
- margin-bottom: 30rpx;
- width: 160rpx;
- height: 160rpx;
- line-height: 160rpx;
- text-align: center;
- background: #f5f5f5;
- border-radius: 50%;
- }
- .prompt-title {
- font-size: 36rpx;
- font-weight: bold;
- color: #333;
- margin-bottom: 16rpx;
- }
- .prompt-desc {
- font-size: 26rpx;
- color: #999;
- text-align: center;
- margin-bottom: 40rpx;
- }
- .login-prompt .login-btn {
- width: 60%;
- height: 80rpx;
- line-height: 80rpx;
- background: linear-gradient(135deg, #5B9BD5, #3A7CC4);
- color: #fff;
- font-size: 30rpx;
- font-weight: bold;
- border-radius: 40rpx;
- text-align: center;
- border: none;
- }
- .login-prompt .login-btn::after {
- border: none;
- }
- </style>
|