loginPage.mixin.js 2.3 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 24 25 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 60 61 62
	data(){
		return {
			// 用户协议页面跳转
			link: [{
				text: '用户协议',
				to: '/pages/ucenter/agree-list/service/service'
			}, {
				text: '隐私政策',
				to: '/pages/ucenter/agree-list/privacy/privacy'
			}],
			formData:{
				phone:'',
				code:'',
				pwd:''
			},
			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位',
						}
					]
				}
			}
		}
	},
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
	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;
		}
	},
提交  
芊里 已提交
80 81 82
	methods:{
		...mapMutations({
			setUserInfo: 'user/login'
83 84
		}),
		loginSuccess(result){
DCloud_JSON's avatar
DCloud_JSON 已提交
85
			loginSuccess(result)
86 87
			delete result.userInfo.token
			this.setUserInfo(result.userInfo)
DCloud_JSON's avatar
DCloud_JSON 已提交
88 89 90 91 92 93 94 95 96
			// 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)
97
			
DCloud_JSON's avatar
DCloud_JSON 已提交
98 99 100 101 102 103 104 105
			// 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})
106
		}
提交  
芊里 已提交
107
	}
芊里 已提交
108 109
}
export default mixin