personal.vue 5.1 KB
<template>
	<view class="personal-page">
		<!-- 公共组件-每个页面必须引入 -->
		<public-module></public-module>
		<view class="header-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">{{ $t('login.bindAccount') }}</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">{{ $t('login.pleaseClickLogin') }}</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" :key="index" @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">{{$t(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">{{ $t('login.accountOut') }}</text></button>
			</view>
		</view>
		<!-- 绑定账号 -->
		<bind-account-modal ref="bindAccountRef" :show="showBindAccount" @cancelAccountModal="handleCancelAccountModal" />
		<!-- 退出登录 -->
		<logout-account-modal ref="logoutAccountRef" :show="showLogout" @logoutBtn="logoutBtn"  @closeLogoutPopup="closeLogoutPopup"/>
		<f-tabbar></f-tabbar>
	</view>
</template>

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

	export default {
		components: {
			fTabbar,
			bindAccountModal,
			logoutAccountModal,
		},
		data() {
			return {
				showBindAccount: false,
				showLogout: false,
				thirdObj: {},
				systemList,
			};
		},
		onLoad(e) {
			// 隐藏原生的tabbar
			uni.hideTabBar();
		},
		onShow(){
			this.$nextTick(()=>{
				uni.setNavigationBarTitle({
					title:this.$t('menu.userCenter')
				})
			})
		},
		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) {
				if(!url) return
				this.judgeLogin(() => {
					useNavigateTo(url)
				});
			},
			onJump(url) {
				if(!url) return
				useNavigateTo(url)
			},
			navigatorLogin() {
				useNavigateTo('/login-subpackage/public/login')
			},
			navigatorPersonal() {
				let data = {
					data: this.userInfo,
					third: this.thirdObj
				};
				useNavigateTo('/login-subpackage/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(this.$t('login.isLoginPut'), this.$t('login.loginOut'), this.$t('common.confirm'),this.$t('common.cancelText')).then(res => {
					if (res.confirm) {
						that.emptyUserInfo();
						that.showLogout = false;
						//不能使用navigatorTo,会显示返回按钮
						useReLaunch('/login-subpackage/public/login')
					}
				})
			},
			handleCancelAccountModal() {
				this.showBindAccount = false;
			}
		}
	};
</script>

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