提交 bdbdacc1 编写于 作者: DCloud_JSON's avatar DCloud_JSON

新增了合并了无聊的this.loginSuccess() 和注册功能

新增了合并了无聊的this.loginSuccess() 和注册功能
上级 1dc56d7b
...@@ -4,31 +4,12 @@ import checkUpdate from '@/uni_modules/uni-upgrade-center-app/utils/check-update ...@@ -4,31 +4,12 @@ import checkUpdate from '@/uni_modules/uni-upgrade-center-app/utils/check-update
import callCheckVersion from '@/uni_modules/uni-upgrade-center-app/utils/call-check-version'; import callCheckVersion from '@/uni_modules/uni-upgrade-center-app/utils/call-check-version';
// #endif // #endif
export default function() { export default function() {
// 初始化appVersion(仅app生效) // 初始化appVersion(仅app生效)
initAppVersion(); initAppVersion();
//自定义路由拦截 //自定义路由拦截
const {"router":{needLogin,login}} = baseappConfig //需要登陆的页面 const {"router":{needLogin,login}} = baseappConfig //需要登陆的页面
// changeAction(["navigateTo", "redirectTo", "reLaunch", "switchTab"], {
// before_action: e => {
// let token = uni.getStorageSync('uni-id-token')
// let url = e.url.split('?')[0]
// if (needLogin.includes(url) && token == '') {
// console.log('该页面需要登陆,即将跳转到login页面');
// uni.showToast({title:'该页面需要登陆,即将跳转到login页面',icon:'none'})
// uni.navigateTo({
// url:"/uni_modules/uni-login-page/pages/index/index"
// })
// return false
// }
// return true
// }
// })
//uni.addInterceptor的写法 //uni.addInterceptor的写法
let list = ["navigateTo", "redirectTo", "reLaunch", "switchTab"]; let list = ["navigateTo", "redirectTo", "reLaunch", "switchTab"];
list.forEach(item=>{ list.forEach(item=>{
uni.addInterceptor(item,{ uni.addInterceptor(item,{
...@@ -76,35 +57,14 @@ export default function() { ...@@ -76,35 +57,14 @@ export default function() {
})// 移除拦截器API removeInterceptor('request') })// 移除拦截器API removeInterceptor('request')
}) })
//提示网络变化 //提示网络变化
eventListenerNetwork() eventListenerNetwork()
/* /*
当某个权限调用失败 当某个权限调用失败
1.先检测手机的该模块是否打开 1.先检测手机的该模块是否打开
2.检测当前应用是否被授权了该模块对应的权限 2.检测当前应用是否被授权了该模块对应的权限
提示,并点击跳转到设置 提示,并点击跳转到设置
*/ */
// #ifndef H5
// changeAction('chooseImage', {
// after_action: e => {
// console.log('changeAction', e);
// if(e.errCode === 11){
// uni.showModal({
// content: '无权限',
// confirmText:"前往设置",
// success(e) {
// if(e.confirm){
// permision.gotoAppPermissionSetting()
// }
// }
// });
// }
// }
// })
// #endif
} }
/** /**
* // 初始化appVersion * // 初始化appVersion
...@@ -167,30 +127,3 @@ function eventListenerNetwork () { ...@@ -167,30 +127,3 @@ function eventListenerNetwork () {
} }
}); });
} }
\ No newline at end of file
function changeAction(actions, {before_action,after_action}) {
if(typeof actions == 'string'){
actions = [actions]
}
if (!before_action) {
before_action = () => true
}
actions.forEach(action=>{
let old_action = uni[action]
uni[action] = e => {
if (before_action(e)) {
// console.log(after_action);
if (after_action) {
var compose = function(f, g) {
return function(x) {
return f(x,g(x));
};
};
e.complete = compose(e.complete,after_action)
}
old_action(e)
}
}
})
}
\ No newline at end of file
...@@ -211,11 +211,7 @@ ...@@ -211,11 +211,7 @@
"condition": { "condition": {
"list": [ "list": [
{ {
"path": "pages/list/list", "path": "pages/list/list"
"style": {
"navigationStyle": "custom",
"enablePullDownRefresh": true
}
}, },
{ {
"path": "uni_modules/uni-login-page/pages/index/index" "path": "uni_modules/uni-login-page/pages/index/index"
...@@ -227,7 +223,7 @@ ...@@ -227,7 +223,7 @@
"path":"pages/ucenter/settings/settings" "path":"pages/ucenter/settings/settings"
} }
], ],
"current":0 "current":1
}, },
"tabBar": { "tabBar": {
"color": "#7A7E83", "color": "#7A7E83",
......
...@@ -36,13 +36,13 @@ ...@@ -36,13 +36,13 @@
// document.documentElement.style.fontSize = document.documentElement.clientWidth / 20 + 'px' // document.documentElement.style.fontSize = document.documentElement.clientWidth / 20 + 'px'
// }) // })
setTimeout(()=>{ // setTimeout(()=>{
document.querySelector('#gg').addEventListener('click',e=>{ // document.querySelector('#gg').addEventListener('click',e=>{
console.log(e); // console.log(e);
alert(12) // alert(12)
window.location.href = "https://m3w.cn/uniapp" // window.location.href = "https://m3w.cn/uniapp"
}) // })
},1000) // },1000)
</script> </script>
<link rel="stylesheet" href="<%= BASE_URL %>static/index.<%= VUE_APP_INDEX_CSS_HASH %>.css" /> <link rel="stylesheet" href="<%= BASE_URL %>static/index.<%= VUE_APP_INDEX_CSS_HASH %>.css" />
...@@ -54,8 +54,8 @@ ...@@ -54,8 +54,8 @@
<noscript> <noscript>
<strong>Please enable JavaScript to continue.</strong> <strong>Please enable JavaScript to continue.</strong>
</noscript> </noscript>
<div id="gg" style="width: 99px;height: 99px;background-color: #007AFF;" <!-- <div id="gg" style="width: 99px;height: 99px;background-color: #007AFF;"
>下载app</div> >下载app</div> -->
<div style="margin-top: 100px;" id="app"></div> <div style="margin-top: 100px;" id="app"></div>
<!-- built files will be auto injected --> <!-- built files will be auto injected -->
<script> <script>
......
...@@ -40,7 +40,9 @@ page { ...@@ -40,7 +40,9 @@ page {
font-weight: 600; font-weight: 600;
padding-top: 50rpx; padding-top: 50rpx;
} }
.content /deep/ .uni-easyinput{
padding: 6px 0;
}
.login-iknow { .login-iknow {
padding-top: 24rpx; padding-top: 24rpx;
padding-bottom: 48rpx; padding-bottom: 48rpx;
......
...@@ -79,7 +79,27 @@ let mixin = { ...@@ -79,7 +79,27 @@ let mixin = {
methods:{ methods:{
...mapMutations({ ...mapMutations({
setUserInfo: 'user/login' setUserInfo: 'user/login'
}),
loginSuccess(result){
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)
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})
}
} }
} }
export default mixin export default mixin
\ No newline at end of file
...@@ -181,29 +181,11 @@ ...@@ -181,29 +181,11 @@
this.request('user-center/login_by_'+type,params,(data,result)=>{ this.request('user-center/login_by_'+type,params,(data,result)=>{
console.log(result); console.log(result);
if(result.code === 0){ if(result.code === 0){
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)
if(type=='univerify'){ if(type=='univerify'){
uni.closeAuthView() uni.closeAuthView()
} }
uni.showToast({
title: '登陆成功',
icon: 'none'
});
uni.hideLoading() uni.hideLoading()
var delta = 0 this.loginSuccess(result)
//判断需要返回几层
let pages = getCurrentPages();
pages.forEach((page,index)=>{
if(pages[pages.length-index-1].route.split('/')[1] == 'uni-login-page'){
delta ++
}
})
uni.navigateBack({delta})
} }
},{showLoading:true}) },{showLoading:true})
}, },
......
...@@ -69,19 +69,7 @@ ...@@ -69,19 +69,7 @@
uni.hideLoading() uni.hideLoading()
console.log(e.result); console.log(e.result);
if(e.result.code === 0){ if(e.result.code === 0){
uni.setStorageSync('uni_id_uid', e.result.uid) this.loginSuccess(e.result)
uni.setStorageSync('uni_id_token', e.result.token)
uni.setStorageSync('uni_id_token_expired', e.result.tokenExpired)
// console.log('66666=',e.result.uid,e.result.token,e.result.tokenExpired);
delete e.result.userInfo.token
this.setUserInfo(e.result.userInfo)
uni.showToast({
title: '登陆成功',
icon: 'none'
});
uni.switchTab({
url:"/pages/list/list"
})
}else{ }else{
uni.showModal({ uni.showModal({
title: '错误', title: '错误',
......
...@@ -23,12 +23,12 @@ ...@@ -23,12 +23,12 @@
<button class="send-btn-box" :disabled="!canLogin" :type="canLogin?'primary':'default'" <button class="send-btn-box" :disabled="!canLogin" :type="canLogin?'primary':'default'"
@click="pwdLogin">登录</button> @click="pwdLogin">登录</button>
</uni-forms> </uni-forms>
<!-- 忘记密码 --> <!-- 忘记密码 -->
<view class="auth-box"> <view class="auth-box">
<text class="login-text login-text-sub">忘记了?</text> <text class="login-text login-text-sub">忘记了?</text>
<text class="login-text" @click="toRetrievePwd">找回密码</text> <text class="login-text" @click="toRetrievePwd">找回密码</text>
</view> </view>
<button type="primary" class="toRegister" @click="toRegister">注册账号</button>
</view> </view>
</view> </view>
<uni-quick-login ref="uniQuickLogin"></uni-quick-login> <uni-quick-login ref="uniQuickLogin"></uni-quick-login>
...@@ -81,19 +81,7 @@ ...@@ -81,19 +81,7 @@
uni.hideLoading() uni.hideLoading()
console.log(e.result); console.log(e.result);
if(e.result.code === 0){ if(e.result.code === 0){
uni.setStorageSync('uni_id_uid', e.result.uid) this.loginSuccess(e.result)
uni.setStorageSync('uni_id_token', e.result.token)
uni.setStorageSync('uni_id_token_expired', e.result.tokenExpired)
// console.log('66666=',e.result.uid,e.result.token,e.result.tokenExpired);
delete e.result.userInfo.token
this.setUserInfo(e.result.userInfo)
uni.showToast({
title: '登陆成功',
icon: 'none'
});
uni.switchTab({
url:"/pages/list/list"
})
}else{ }else{
uni.showModal({ uni.showModal({
title: '错误', title: '错误',
...@@ -127,6 +115,13 @@ ...@@ -127,6 +115,13 @@
}); });
// this.currenPhoneArea = this.phoneArea[event.detail.value]; // this.currenPhoneArea = this.phoneArea[event.detail.value];
}, },
/* 前往注册 */
toRegister(e){
console.log(e);
uni.navigateTo({
url:'/uni_modules/uni-login-page/pages/register/register'
})
}
} }
} }
</script> </script>
...@@ -143,4 +138,8 @@ ...@@ -143,4 +138,8 @@
.login-text-sub { .login-text-sub {
color: #8a8f8b; color: #8a8f8b;
} }
.toRegister{
margin-top: 80px;
width: 600rpx;
}
</style> </style>
<template> <template>
<view class="uni-container"> <view class="uni-container">
<uni-forms ref="form" :value="formData" :rules="rules" validate-trigger="submit" err-show-type="toast"> <uni-forms ref="form" :value="formData" :rules="rules" validate-trigger="submit" err-show-type="undertext">
<uni-forms-item name="username" label="用户名" required> <uni-forms-item name="username" label="用户名" required>
<uni-easyinput placeholder="请输入用户名" v-model="formData.username" trim="both" /> <uni-easyinput placeholder="请输入用户名" v-model="formData.username" trim="both" />
</uni-forms-item> </uni-forms-item>
<uni-forms-item name="gender" label="性别" required> <uni-forms-item name="gender" label="性别">
<uni-data-checkbox v-model="formData.gender" :localdata="formOptions.gender_localdata" /> <uni-data-checkbox v-model="formData.gender" :localdata="formOptions.gender_localdata" />
</uni-forms-item> </uni-forms-item>
<uni-forms-item name="nickname" label="昵称" required> <uni-forms-item name="nickname" label="昵称">
<uni-easyinput placeholder="请输入用户昵称" v-model="formData.nickname" trim="both" /> <uni-easyinput placeholder="请输入用户昵称" v-model="formData.nickname" trim="both" />
</uni-forms-item> </uni-forms-item>
<uni-forms-item name="pwd" label="密码" v-model="formData.pwd" required> <uni-forms-item name="password" label="密码" v-model="formData.password" required>
<uni-easyinput placeholder="请输入6-20位密码" type="password" v-model="formData.pwd" trim="both" /> <uni-easyinput placeholder="请输入6-20位密码" type="password" v-model="formData.password" trim="both" />
</uni-forms-item> </uni-forms-item>
<uni-forms-item name="pwd2" label="确认密码" v-model="formData.pwd2" required> <uni-forms-item name="pwd2" label="确认密码" v-model="formData.pwd2" required>
<uni-easyinput placeholder="再次输入密码" type="password" v-model="formData.pwd2" trim="both" /> <uni-easyinput placeholder="再次输入密码" type="password" v-model="formData.pwd2" trim="both" />
...@@ -24,32 +24,18 @@ ...@@ -24,32 +24,18 @@
</template> </template>
<script> <script>
import { import rules from './validator.js';
validator import mixin from '../../common/loginPage.mixin.js';
} from '../../js_sdk/validator/uni-id-users.js';
const db = uniCloud.database();
const dbCollectionName = 'uni-id-users';
function getValidator(fields) {
let reuslt = {}
for (let key in validator) {
if (fields.indexOf(key) > -1) {
reuslt[key] = validator[key]
}
}
return reuslt
}
export default { export default {
mixins:[mixin],
data() { data() {
return { return {
formData: { formData: {
"username": "", "username": "",
"gender": 0, "gender": 0,
"nickname": "", "nickname": "",
'pwd':'', 'password':'123456',
'pwd2':'' 'pwd2':'123456'
}, },
formOptions: { formOptions: {
"gender_localdata": [{ "gender_localdata": [{
...@@ -65,9 +51,7 @@ ...@@ -65,9 +51,7 @@
} }
] ]
}, },
rules: { rules
...getValidator(["username", "gender", "nickname", 'pwd', 'pwd2'])
}
} }
}, },
onReady() { onReady() {
...@@ -78,15 +62,10 @@ ...@@ -78,15 +62,10 @@
* 触发表单提交 * 触发表单提交
*/ */
submit() { submit() {
uni.showLoading({ uni.showLoading({
mask: true mask: true
}) })
this.$refs.form.submit().then((res) => { this.$refs.form.submit().then((res) => {
if(res.pwd != res.pwd2)return uni.showToast({
title: '两次输入密码不一致',
icon: 'none'
});
this.submitForm(res) this.submitForm(res)
}).catch((errors) => { }).catch((errors) => {
console.log(errors); console.log(errors);
...@@ -95,9 +74,13 @@ ...@@ -95,9 +74,13 @@
uni.hideLoading() uni.hideLoading()
}) })
}, },
submitForm(value) { submitForm(value) {
this.request('user-center/register',value,(data,result)=>{
console.log(result);
if(result.code === 0){
this.loginSuccess(result)
}
})
} }
} }
} }
......
// 表单校验规则由 schema2code 生成,不建议直接修改校验规则,而建议通过 schema2code 生成, 详情: https://uniapp.dcloud.net.cn/uniCloud/schema export default {
const validator = {
"gender": {
"rules": [{
"format": "int"
},
{
"range": [{
"text": "未知",
"value": 0
},
{
"text": "",
"value": 1
},
{
"text": "",
"value": 2
}
]
}
],
"defaultValue": 0,
"label": "性别"
},
"username": { "username": {
"rules": [{ "rules": [{
required: true, required: true,
errorMessage: '请输入用户名', errorMessage: '请输入用户名',
}, },
{ {
minLength: 3, minLength: 3,
maxLength: 10, maxLength: 32,
errorMessage: '用户名长度在 {minLength} 到 {maxLength} 个字符', errorMessage: '用户名长度在 {minLength} 到 {maxLength} 个字符',
}
],
"label": "用户名"
},
"nickname": {
"rules": [{
required: true,
errorMessage: '请输入昵称',
}, },
{ {
minLength: 3, validateFunction:function(rule,value,data,callback){
maxLength: 10, console.log(value);
errorMessage: '昵称长度在 {minLength} 到 {maxLength} 个字符', if(/^1\d{10}$/.test(value) || /^(\w-*\.*)+@(\w-?)+(\.\w{2,})+$/.test(value)){
callback('用户名不能是:手机号或邮箱')
};
return true
}
} }
], ],
"label": "昵称" "label": "用户名"
}, },
"pwd":{ "password":{
"rules": [{ "rules": [{
required: true, required: true,
errorMessage: '请输入密码', errorMessage: '请输入密码',
}, },
{ {
minLength: 6, minLength: 6,
...@@ -82,21 +45,17 @@ const validator = { ...@@ -82,21 +45,17 @@ const validator = {
minLength: 6, minLength: 6,
maxLength: 20, maxLength: 20,
errorMessage: '密码长度在 {minLength} 到 {maxLength} 个字符', errorMessage: '密码长度在 {minLength} 到 {maxLength} 个字符',
},
{
validateFunction:function(rule,value,data,callback){
console.log(value);
if(value!=data.password){
callback('两次输入密码不一致')
};
return true
}
} }
], ],
"label": "确认密码" "label": "确认密码"
} }
} }
\ No newline at end of file
const enumConverter = {
"gender_valuetotext": {
"0": "未知",
"1": "",
"2": ""
}
}
export {
validator,
enumConverter
}
...@@ -83,7 +83,20 @@ exports.main = async (event, context) => { ...@@ -83,7 +83,20 @@ exports.main = async (event, context) => {
let res = {} let res = {}
switch (event.action) { switch (event.action) {
case 'register': case 'register':
res = await uniID.register(params); let {username,password,gender,nickname,password} = params
if(/^1\d{10}$/.test(username)){
return {
code: 401,
msg: '用户名不能是手机号'
}
};
if(/^(\w-*\.*)+@(\w-?)+(\.\w{2,})+$/.test(username)){
return {
code: 401,
msg: '用户名不能是邮箱'
}
}
res = await uniID.register({username,password,gender,nickname,password});
break; break;
case 'login': case 'login':
let passed = false; let passed = false;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册