Commit 0321957c by 莫晓莉

mxl登录

parent 77807522
...@@ -5,12 +5,14 @@ ...@@ -5,12 +5,14 @@
"style": { "style": {
"navigationBarTitleText": "登录模板" "navigationBarTitleText": "登录模板"
} }
}, { },
{
"path": "pages/login/login", "path": "pages/login/login",
"style": { "style": {
"navigationBarTitleText": "登录" "navigationBarTitleText": "登录"
} }
}, { },
{
"path": "pages/reg/reg", "path": "pages/reg/reg",
"style": { "style": {
"navigationBarTitleText": "注册" "navigationBarTitleText": "注册"
......
...@@ -27,85 +27,119 @@ ...@@ -27,85 +27,119 @@
mapMutations mapMutations
} from 'vuex' } from 'vuex'
export default {
computed: mapState(['forcedLogin', 'hasLogin', 'userName']),
onLoad() {
const loginType = uni.getStorageSync('login_type')
if (loginType === 'local') {
this.login(uni.getStorageSync('username'))
return
}
let uniIdToken = uni.getStorageSync('uniIdToken')
if (uniIdToken) {
this.login(uni.getStorageSync('username'))
uniCloud.callFunction({
name: 'user-center',
data: {
action: 'checkToken',
},
success: (e) => {
console.log('checkToken success', e);
if (e.result.code > 0) { import {
//token过期或token不合法,重新登录 getUserByToken
if (this.forcedLogin) { } from "@/api/login"
uni.reLaunch({ export default {
url: '../login/login' onLoad: function() {
});
} else { const token=uni.getStorageSync('token')
uni.navigateTo({ console.log(token);
url: '../login/login' if(token){
}); uni.switchTab({
} url:'/pages/login/login'
}
},
fail(e) {
uni.showModal({
content: JSON.stringify(e),
showCancel: false
})
}
}) })
} else {
this.guideToLogin()
}
},
methods: {
...mapMutations(['login']),
guideToLogin() {
uni.showModal({
title: '未登录',
content: '您未登录,需要登录后才能继续',
/**
* 如果需要强制登录,不显示取消按钮
*/
showCancel: !this.forcedLogin,
success: (res) => {
if (res.confirm) {
/**
* 如果需要强制登录,使用reLaunch方式
*/
if (this.forcedLogin) {
uni.reLaunch({
url: '../login/login'
});
} else {
uni.navigateTo({
url: '../login/login'
});
}
}
}
});
} }
// getUserByToken().then(res=>{
// if (res.code == 200) {
// uni.setStorageSync('token', res.data.data);
// uni.switchTab({
// url:'/pages/login/login'
// })
// }else{
// uni.switchTab({
// url:'/pages/reg/reg'
// })
// }
// })
// const token=uni.getStorageSync('token')
// if(token){
// uni.switchTab({
// url:'/pages/index/index'
// })
// }
} }
// computed: mapState(['forcedLogin', 'hasLogin', 'userName']),
// onLoad() {
// const loginType = uni.getStorageSync('login_type')
// if (loginType === 'local') {
// this.login(uni.getStorageSync('username'))
// return
// }
// let uniIdToken = uni.getStorageSync('uniIdToken')
// if (uniIdToken) {
// this.login(uni.getStorageSync('username'))
// uniCloud.callFunction({
// name: 'user-center',
// data: {
// action: 'checkToken',
// },
// success: (e) => {
// console.log('checkToken success', e);
// if (e.result.code > 0) {
// //token过期或token不合法,重新登录
// if (this.forcedLogin) {
// uni.reLaunch({
// url: '../login/login'
// });
// } else {
// uni.navigateTo({
// url: '../login/login'
// });
// }
// }
// },
// fail(e) {
// uni.showModal({
// content: JSON.stringify(e),
// showCancel: false
// })
// }
// })
// } else {
// this.guideToLogin()
// }
// },
// methods: {
// ...mapMutations(['login']),
// guideToLogin() {
// uni.showModal({
// title: '未登录',
// content: '您未登录,需要登录后才能继续',
// /**
// * 如果需要强制登录,不显示取消按钮
// */
// showCancel: !this.forcedLogin,
// success: (res) => {
// if (res.confirm) {
// /**
// * 如果需要强制登录,使用reLaunch方式
// */
// if (this.forcedLogin) {
// uni.reLaunch({
// url: '../login/login'
// });
// } else {
// uni.navigateTo({
// url: '../login/login'
// });
// }
// }
// }
// });
// }
// }
} }
</script> </script>
<style> <style>
.hello { /* .hello {
display: flex; display: flex;
flex: 1; flex: 1;
flex-direction: column; flex-direction: column;
...@@ -124,5 +158,5 @@ ...@@ -124,5 +158,5 @@
.ul>view { .ul>view {
line-height: 25px; line-height: 25px;
} } */
</style> </style>
<template> <template>
<view class="content"> <view class="content">
<!-- <view class="input-group">
<view class="input-row border">
<text class="title">账号:</text>
<m-input type="text" focus clearable v-model="username" placeholder="请输入账号"></m-input>
</view>
<view class="input-row border">
<text class="title">密码:</text>
<m-input type="password" displayable v-model="password" placeholder="请输入密码"></m-input>
</view>
<view class="input-row">
<text class="title">确认密码:</text>
<m-input type="password" displayable v-model="confirmPassword" placeholder="请确认密码"></m-input>
</view>
</view> -->
<!-- 登录新样式start -->
<view style="text-align: center;color:#CA0000;font-size:45upx;padding:50upx;"> <view style="text-align: center;color:#CA0000;font-size:45upx;padding:50upx;">
<!-- <image class="head-icon" style="" src="../../static/login/personal.png"></image> -->
欢迎注册! 欢迎注册!
</view> </view>
<view class="login-area"> <view class="login-area">
<view class="login-item"> <view class="login-item">
<image class="login-icon" src="../../static/login/mine.png"></image> <image class="login-icon" src="../../static/login/mine.png"></image>
<input class="login-item-input" placeholder="请输入姓名" v-model="addForm.name" /> <input class="login-item-input" placeholder="请输入姓名" v-model="addForm.name" />
...@@ -49,7 +32,7 @@ ...@@ -49,7 +32,7 @@
<view class="login-item mt25"> <view class="login-item mt25">
<image class="login-icon" src="../../static/login/code.png"></image> <image class="login-icon" src="../../static/login/code.png"></image>
<input class="login-item-input" placeholder="请输入手机号码" v-model="addForm.phone" /> <input name="phone" type="number" class="login-item-input" placeholder="请输入手机号码" v-model="addForm.phone" />
<view class="code-btn" style="" @click="codeInfo.clickType ? getCode() : ''">{{codeInfo.msg}}</view> <view class="code-btn" style="" @click="codeInfo.clickType ? getCode() : ''">{{codeInfo.msg}}</view>
</view> </view>
<view class="login-item mt25"> <view class="login-item mt25">
...@@ -177,70 +160,70 @@ ...@@ -177,70 +160,70 @@
}) })
}, },
register() { // register() {
/** // /**
* 客户端对账号信息进行一些必要的校验。 // * 客户端对账号信息进行一些必要的校验。
* 实际开发中,根据业务需要进行处理,这里仅做示例。 // * 实际开发中,根据业务需要进行处理,这里仅做示例。
*/ // */
if (this.username.length < 3) { // if (this.username.length < 3) {
uni.showToast({ // uni.showToast({
icon: 'none', // icon: 'none',
title: '账号最短为 3 个字符' // title: '账号最短为 3 个字符'
}); // });
return; // return;
} // }
if (this.password.length < 6) { // if (this.password.length < 6) {
uni.showToast({ // uni.showToast({
icon: 'none', // icon: 'none',
title: '密码最短为 6 个字符' // title: '密码最短为 6 个字符'
}); // });
return; // return;
} // }
if (this.password !== this.confirmPassword) { // if (this.password !== this.confirmPassword) {
uni.showToast({ // uni.showToast({
icon: 'none', // icon: 'none',
title: '两次密码输入不一致' // title: '两次密码输入不一致'
}); // });
return; // return;
} // }
const data = { // const data = {
username: this.username, // username: this.username,
password: this.password // password: this.password
} // }
uniCloud.callFunction({ // uniCloud.callFunction({
name: 'user-center', // name: 'user-center',
data: { // data: {
action: 'register', // action: 'register',
params: data // params: data
}, // },
success(e) { // success(e) {
console.log("注册成功", e); // console.log("注册成功", e);
if (e.result.code === 0) { // if (e.result.code === 0) {
uni.showToast({ // uni.showToast({
title: '注册成功' // title: '注册成功'
}); // });
uni.setStorageSync('uniIdToken', e.result.token) // uni.setStorageSync('uniIdToken', e.result.token)
uni.setStorageSync('username', e.result.username) // uni.setStorageSync('username', e.result.username)
uni.reLaunch({ // uni.reLaunch({
url: '../main/main', // url: '../main/main',
}); // });
} else { // } else {
uni.showModal({ // uni.showModal({
content: JSON.stringify(e.result), // content: JSON.stringify(e.result),
showCancel: false // showCancel: false
}) // })
} // }
}, // },
fail(e) { // fail(e) {
uni.showModal({ // uni.showModal({
content: JSON.stringify(e), // content: JSON.stringify(e),
showCancel: false // showCancel: false
}) // })
} // }
}) // })
} // }
} }
} }
</script> </script>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment