loginPage.mixin.js 2.8 KB
Newer Older
芊里 已提交
1
const helpPage = '/pages/ucenter/help/help';	// 帮助页面
L
23  
linju 已提交
2
import {mapMutations} from 'vuex';
DCloud_JSON's avatar
DCloud_JSON 已提交
3
import loginSuccess from './loginSuccess.js';
芊里 已提交
4
let mixin = {
L
123  
linju 已提交
5 6 7 8 9 10
	// // 监听帮助按钮
	// onNavigationBarButtonTap(event) {
	// 	uni.navigateTo({
	// 		url:helpPage
	// 	})
	// },
芊里 已提交
11 12 13 14 15 16 17 18 19 20 21 22 23
	data(){
		return {
			// 用户协议页面跳转
			link: [{
				text: '用户协议',
				to: '/pages/ucenter/agree-list/service/service'
			}, {
				text: '隐私政策',
				to: '/pages/ucenter/agree-list/privacy/privacy'
			}],
			formData:{
				phone:'',
				code:'',
芊里 已提交
24 25
				pwd:'',
				pwd2:''
芊里 已提交
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
			},
			rules: {
				phone:{
					rules:[{
							required: true,
							errorMessage: '请输入手机号',
						},
						{
							pattern: /^1\d{10}$/,
							errorMessage: '手机号格式不正确',
						}
					]
				},
				code: {
					rules: [{
							required: true,
							errorMessage: '请输入验证码',
						},
						{
							pattern: /^.{6}$/,
							errorMessage: '请输入6位验证码',
						}
					]
				},
				pwd:{
					rules: [{
							required: true,
							errorMessage: '请输入密码',
						},
						{
							pattern: /^.{6,20}$/,
							errorMessage: '密码应为6到20位',
						}
					]
芊里 已提交
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
				},
				pwd2:{
					rules:[{
							required: true,
							errorMessage: '请确认密码',
						},
						{
							pattern: /^.{6,20}$/,
							errorMessage: '密码应为6到20位',
						},
						{
							validateFunction:function(rule,value,data,callback){
								console.log(value);
								if(value!=data.pwd){
									callback('两次输入密码不一致')
								};
								return true
							}
						}
					]
芊里 已提交
80 81 82 83
				}
			}
		}
	},
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
	computed: {
		isPhone(){
			let reg_phone = /^1\d{10}$/;
			let isPhone = reg_phone.test(this.formData.phone);
			return isPhone;
		},
		isPwd(){
			let reg_pwd = /^.{6,20}$/;
			let isPwd = reg_pwd.test(this.formData.pwd);
			return isPwd;
		},
		isCode(){
			let reg_code = /^\d{6}$/;
			let isCode = reg_code.test(this.formData.code);
			return isCode;
		}
	},
提交  
芊里 已提交
101 102 103
	methods:{
		...mapMutations({
			setUserInfo: 'user/login'
104 105
		}),
		loginSuccess(result){
DCloud_JSON's avatar
DCloud_JSON 已提交
106
			loginSuccess(result)
107 108
			delete result.userInfo.token
			this.setUserInfo(result.userInfo)
DCloud_JSON's avatar
DCloud_JSON 已提交
109 110 111 112 113 114 115 116 117
			// uni.showToast({
			// 	title: '登陆成功',
			// 	icon: 'none'
			// });
			// uni.setStorageSync('uni_id_uid', result.uid)
			// uni.setStorageSync('uni_id_token', result.token)
			// uni.setStorageSync('uni_id_token_expired', result.tokenExpired)
			// delete result.userInfo.token
			// this.setUserInfo(result.userInfo)
118
			
DCloud_JSON's avatar
DCloud_JSON 已提交
119 120 121 122 123 124 125 126
			// var delta = 0//判断需要返回几层
			// let pages = getCurrentPages();
			// pages.forEach((page,index)=>{
			// 	if(pages[pages.length-index-1].route.split('/')[1] == 'uni-login-page'){
			// 		delta ++
			// 	}
			// })
			// uni.navigateBack({delta})
127
		}
提交  
芊里 已提交
128
	}
芊里 已提交
129 130
}
export default mixin