personal.vue 5.44 KB
<template>
	<view class="personal">
		<!-- 公共组件-每个页面必须引入 -->
		<public-module></public-module>
		<view class="head-box">
			<view class="u-flex u-p-l-30 u-p-r-20 u-p-t-75 u-p-b-30">
				<block v-if="userInfo.isToken || userInfo.isThirdLogin">
					<view @click.top="navigatorPersonal" class="u-m-r-20">
						<image class="avatar" mode="aspectFill" :src="setHeadImage"></image>
					</view>
					<view class="u-flex-1" @click.top="navigatorPersonal">
						<view class="nickName u-flex">
							<view class="name u-m-r-10" v-if="userInfo.realName || userInfo.nickName">
								<text class="nick-name">{{ userInfo.realName || userInfo.nickName }}</text>
							</view>
							<view v-if="userInfo.isThirdLogin" @click.stop="openBindAccountModal" class="detail"><text
									class="text">绑定账号</text></view>
						</view>
						<view class="phone-number" v-if="userInfo.phoneNumber">
							{{ handlePhoneFunc(userInfo.phoneNumber || '') }}
						</view>
					</view>
				</block>
				<block v-else>
					<view class="u-m-r-20" @click="navigatorLogin">
						<view class="avatar u-flex">
							<image class="avatar" mode="aspectFill" src="/static/logo.png"></image>
						</view>
					</view>
					<view class="u-flex-1">
						<view @click="navigatorLogin" class="u-font-lg click-login login-btn">请点击登录</view>
					</view>
				</block>
				<view v-if="userInfo.isToken" @click="navigatorPersonal">
					<u-icon name="arrow-right" color="white" size="13"></u-icon>
				</view>
			</view>
		</view>
		<view class="u-flex my-nav">
			<view class="nav-main">
				<view v-for="(item,index) in systemList" @click="onTokenJump(item.url)" class="u-flex nav-link">
					<view class="nav-image">
						<image class="image" :src="item.leftIcon"></image>
					</view>
					<view class="nav-center"><text class="text">{{item.text}}</text></view>
					<view class="nav-right">
						<image class="image" :src="item.rightIcon"></image>
					</view>
				</view>
			</view>
			<view @click="openLogoutPopup" class="u-flex logout-text">
				<button class="submit" size="default" @click="openLogoutPopup"><text class="text">退出账号</text></button>
			</view>
		</view>
		<!-- 绑定账号 -->
		<view>
			<bind-account-modal ref="bindAccountRef" :show="showBindAccount"
				@cancelAccountModal="handleCancelAccountModal" />
		</view>
		<!-- 退出登录 -->
		<view>
			<u-popup bgColor="transparent" :overlay="true" :show="showLogout" mode="bottom">
				<view class="u-flex logout-main">
					<view class="main"><text style="color: #999999">您确定要退出当前账号?</text></view>
					<view @click="logoutBtn" class="main"><text style="color: #f95e5a">退出登录</text></view>
					<view class="cancel-text"><text @click="closeLogoutPopup" style="color: #3478f7">取消</text>
					</view>
				</view>
			</u-popup>
		</view>
		<f-tabbar></f-tabbar>
	</view>
</template>

<script>
	import fTabbar from '@/components/module/f-tabbar/f-tabbar';
	import fNavbar from '@/components/module/f-navbar/f-navbar';
	import bindAccountModal from './components/bind-account-modal.vue'
	import {
		mapState,
		mapMutations
	} from 'vuex';
	import {
		useNavigateTo,
		useShowModal
	} from '@/plugins/utils.js'

	export default {
		components: {
			fTabbar,
			fNavbar,
			bindAccountModal
		},
		data() {
			return {
				showBindAccount: false,
				showLogout: false,
				thirdObj: {},
				systemList: [{
						url: '/sysNotifySubPage/sysNotifyPage/systemNotify',
						text: '系统通知',
						leftIcon: '/static/sys-not.png',
						rightIcon: '/static/arrow-right.png'
					},
					{
						url: '/feedBackSubPage/feedback/feedback',
						text: '意见反馈',
						leftIcon: '/static/find-sugg.png',
						rightIcon: '/static/arrow-right.png'
					}
				]
			};
		},
		onLoad(e) {
			// 隐藏原生的tabbar
			uni.hideTabBar();
		},
		computed: {
			...mapState(['userInfo', 'plateInfo']),
			setHeadImage() {
				return this.userInfo.avatar || this.thirdObj.avatarUrl || '/static/logo.png'
			}
		},
		methods: {
			...mapMutations(['emptyUserInfo', 'setUserInfo', 'setPlateInfo']),
			handlePhoneFunc(e) {
				//手机号前三后四位显示
				const result = /^(\d{3})\d{4}(\d{4})$/;
				const y = e.toString().replace(result, '$1****$2');
				return y;
			},
			// 跳转前判断登录
			onTokenJump(url) {
				this.judgeLogin(() => {
					useNavigateTo(url)
				});
			},
			onJump(url) {
				useNavigateTo(url)
			},
			navigatorLogin() {
				useNavigateTo('/publicLoginSubPage/public/login')
			},
			navigatorPersonal() {
				let data = {
					data: this.userInfo,
					third: this.thirdObj
				};
				useNavigateTo('/publicLoginSubPage/other/set?data=', data)
			},
			openBindAccountModal() {
				this.showBindAccount = true;
				this.$refs.bindAccountRef.resetFunc()
			},
			openLogoutPopup() {
				this.showLogout = true;
			},
			closeLogoutPopup() {
				this.showLogout = false;
			},
			logoutBtn() {
				const that = this
				useShowModal('您确定要退出登录吗?', '退出登录', '确定').then(res => {
					if (res.confirm) {
						that.emptyUserInfo();
						that.showLogout = false;
						useNavigateTo('/publicLoginSubPage/public/login')
					}
				})
			},
			handleCancelAccountModal() {
				this.showBindAccount = false;
			}
		}
	};
</script>

<style lang="scss" scoped>
	@import './static/personal.scss';
</style>