personal.vue 9.82 KB
<template>
	<view class="personal">
		<!-- 公共组件-每个页面必须引入 -->
		<public-module></public-module>
		<view class="headBox">
			<!-- #ifdef MP -->
			<!-- 登录 -->
			<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">
					<view @click="openPersonalInfo" class="u-m-r-20"><image class="avatar" mode="aspectFill" :src="userInfo.avatar || '/static/default.png'"></image></view>
					<view @click="openPersonalInfo" class="u-flex-1">
						<view class="nickName u-flex">
							<view class="name u-m-r-10" v-if="userInfo.realName">
								<text style="#FFFFFF;font-size: 18px;">{{ userInfo.realName }}</text>
							</view>
						</view>
						<view style="color:#FFFFFF;font-size: 14px;" v-if="userInfo.phoneNumber">{{ userInfo.phoneNumber | phone }}</view>
						<view v-else><text style="color:#FFFFFF;font-size: 14px;">手机号:未绑定</text></view>
					</view>
				</block>
				<block v-else>
					<view class="u-m-r-20" @click="openLoginFunc">
						<view class="avatar u-flex"><u-icon name="account-fill" color="black" size="30"></u-icon></view>
					</view>
					<view class="u-flex-1" @click="openLoginFunc">
						<view class="u-font-lg click-login login-btn ">请点击登录</view>
						<view v-if="userInfo.isToken" @click="clickAccountFunc" class="detail"><text class="text">绑定账号</text></view>
					</view>
				</block>
				<view v-if="userInfo.isToken"><u-icon name="arrow-right" color="white" size="13"></u-icon></view>
			</view>
			<!-- #endif -->
			<!-- #ifndef MP -->
			<!-- 登录 -->
			<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">
					<view @click="openPersonalInfo" class="u-m-r-20"><image class="avatar" mode="aspectFill" :src="userInfo.avatar || '/static/default.png'"></image></view>
					<view @click="openPersonalInfo" class="u-flex-1">
						<view class="nickName u-flex">
							<view class="name u-m-r-10" v-if="userInfo.realName">
								<text style="#FFFFFF;font-size: 18px;">{{ userInfo.realName }}</text>
							</view>
						</view>
						<view style="color:#FFFFFF;font-size: 14px;" v-if="userInfo.phoneNumber">{{ userInfo.phoneNumber | phone }}</view>
						<view v-else><text style="color:#FFFFFF;font-size: 14px;">手机号:未绑定</text></view>
					</view>
				</block>
				<block v-else>
					<view class="u-m-r-20" @click="openLoginFunc">
						<view class="avatar u-flex" style="justify-content: center"><u-icon name="account-fill" color="black" size="30"></u-icon></view>
					</view>
					<view class="u-flex-1" @click="openLoginFunc">
						<view class="u-font-lg login-btn">登录</view>
						<view v-if="userInfo.isToken" @click="clickAccountFunc" style="color: black" class="detail">绑定账号</view>
					</view>
				</block>
				<view><u-icon name="arrow-right" color="black" size="13"></u-icon></view>
			</view>
			<!-- #endif -->
		</view>
		<view class="u-flex my-nav">
			<view class="nav-main">
				<view @click="onTokenJump('/sysNotifySubPage/sysNotifyPage/systemNotify')" class="u-flex nav-link">
					<view class="nav-image"><image class="image" src="../../static/sys-not.png"></image></view>
					<view class="nav-center"><text class="text">系统通知</text></view>
					<view class="nav-right"><image class="image" src="../../static/arrow-right.png"></image></view>
				</view>
				<view @click="onTokenJump('/feedBackSubPage/feedback/feedback')" class="u-flex nav-link">
					<view class="nav-image"><image class="image" src="../../static/find-sugg.png"></image></view>
					<view class="nav-center"><text class="text">意见反馈</text></view>
					<view class="nav-right"><image class="image" src="../../static/arrow-right.png"></image></view>
				</view>
			</view>
			<view v-if="userInfo.isToken" class="u-flex" style="justify-content: center; width: 600rpx">
				<button class="submit" size="default" @click.top="onLoginoutFunc"><text class="text">退出账号</text></button>
			</view>
		</view>
		<!-- 绑定账号 -->
		<view>
			<u-modal :showConfirmButton="false" :show="show" :title="title">
				<view v-if="!bindPhone" class="loginPhone">
					<view class="form-row">
						<u--input shape="circle" class="input" prefixIcon="account-fill" type="text" placeholder="登录账号" v-model="bindAccountObj.account"></u--input>
					</view>
					<view class="form-row item-bind">
						<u--input
							class="input"
							shape="circle"
							prefixIcon="lock-fill"
							suffixIconStyle="color: #909399"
							type="password"
							placeholder="登录密码"
							v-model="bindAccountObj.password"
							@change="passwordChange"
						></u--input>
					</view>
					<view class="u-flex item-phone">
						<view class="phone-hide">手机验证码登录</view>
						<view class="bind-phone-text" @click="bindPhoneFunc">手机绑定</view>
					</view>
				</view>
				<view v-else class="loginPhone">
					<view class="form-row">
						<u--input
							shape="circle"
							class="input"
							type="text"
							v-model="bindPhoneObj.phoneNumber"
							placeholder="请输入手机号码"
							placeholder-style="font-weight:normal;color:#bbbbbb;"
						></u--input>
					</view>
					<view class="form-row row-top">
						<u--input
							shape="circle"
							class="input"
							type="text"
							v-model="bindPhoneObj.code"
							placeholder="请输入验证码"
							placeholder-style="font-weight:normal;color:#bbbbbb;"
						></u--input>
						<view style="color: #377dff" class="getvcode" :class="{ forhidden: readonly }" @click="getVcode">{{ codeText }}</view>
					</view>
					<view class="u-flex item-phone">
						<view class="phone-hide">手机验证码登录</view>
						<view class="bind-phone-text" @click="bindAccountFunc">账号绑定</view>
					</view>
				</view>
				<view class="bottom-content">
					<view class="u-flex content">
						<view class="cancel"><u-button @click="show = false" type="info" shape="circle" text="取消"></u-button></view>
						<view class="confrim"><u-button @click="bindConfirm" type="primary" shape="circle" text="确认"></u-button></view>
					</view>
				</view>
			</u-modal>
		</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.top="logoutBtn" class="main"><text style="color: #f95e5a">退出登录</text></view>
					<view class="main1"><text @click.top="closeLogout" style="color: #3478f7">取消</text></view>
				</view>
			</u-popup>
		</view>
		<!-- 退出登录 -->
		<f-tabbar></f-tabbar>
	</view>
</template>

<script>
var clear;
import base from '@/config/baseUrl';
import fTabbar from '@/components/module/f-tabbar/f-tabbar';
import fNavbar from '@/components/module/f-navbar/f-navbar';
import { mapState, mapMutations } from 'vuex';

export default {
	components: {
		fTabbar,
		fNavbar
	},
	data() {
		return {
			PrimaryColor: '#0079fe', //主题色
			showLogout: false,
			readonly: false,
			codeText: '获取验证码',
			phone: '', //号码
			tips: '验证码',
			bindPhone: false,
			show: false,
			title: '绑定账号',
			systemInfo: base.systemInfo,
			PrimaryButtonColor: '#0079fe', //主题色
			bindAccountObj: {
				username: '',
				password: ''
			},
			bindPhoneObj: {
				phoneNumber: '',
				code: ''
			}
		};
	},
	onLoad() {
		// 隐藏原生的tabbar
		uni.hideTabBar();
	},
	computed: {
		...mapState(['userInfo'])
	},
	methods: {
		...mapMutations(['emptyUserInfo']),
		// 跳转前判断登录
		onTokenJump(url) {
			this.judgeLogin(() => {
				uni.navigateTo({
					url: url
				});
			});
		},
		onJump(url) {
			uni.navigateTo({
				url: url
			});
		},
		openLoginFunc() {
			uni.navigateTo({
				url: '/publicLoginSubPage/public/login'
			});
		},
		openPersonalInfo() {
			let obj = {
				data: this.userInfo
			};
			uni.navigateTo({
				url: '/publicLoginSubPage/other/set?data=' + JSON.stringify(obj)
			});
		},
		clickAccountFunc() {
			this.show = true;
		},
		bindConfirm() {
			if (!this.bindPhone) {
				console.log('Account submit', this.bindAccountObj);
			} else {
				console.log('Phone submit', this.bindPhoneObj);
			}
		},
		bindPhoneFunc() {
			this.bindPhone = true;
		},
		bindAccountFunc() {
			this.bindPhone = false;
		},
		//验证码按钮文字状态
		getCodeState() {
			const _this = this;
			this.readonly = true;
			this.codeText = '60S后重新获取';
			var s = 60;
			clear = setInterval(() => {
				s--;
				_this.codeText = s + 'S后重新获取';
				if (s <= 0) {
					clearInterval(clear);
					_this.codeText = '获取验证码';
					_this.readonly = false;
				}
			}, 1000);
		},
		//获取验证码
		getVcode() {
			console.log('getVcode');
			if (this.readonly) {
				uni.showToast({
					title: '验证码已发送~',
					icon: 'none'
				});
				return;
			}
			if (this.phone == '') {
				uni.showToast({
					title: '请输入手机号~',
					icon: 'none'
				});
				return;
			}
			const phoneRegular = /^1\d{10}$/;
			if (!phoneRegular.test(this.phone)) {
				uni.showToast({
					title: '手机号格式不正确~',
					icon: 'none'
				});
				return;
			}
			let httpData = {};
			// 获取验证码接口
			// uni.$u.http.post('您的接口', httpData).then(res => {
			this.getCodeState(); //开始倒计时
			// })
		},
		onLoginoutFunc() {
			this.showLogout = true;
		},
		closeLogout() {
			this.showLogout = false;
		},
		logoutBtn() {
			let that = this;
			uni.showModal({
				title: '退出登录',
				content: '你确定退出登录吗?',
				success(res) {
					if (res.confirm) {
						that.emptyUserInfo();
						that.showLogout = false;
						setTimeout(() => {
							uni.navigateTo({
								url: '/publicLoginSubPage/public/login'
							});
						}, 500);
					} else if (res.cancel) {
					}
				}
			});
		}
	}
};
</script>

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