提交 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
import callCheckVersion from '@/uni_modules/uni-upgrade-center-app/utils/call-check-version';
// #endif
export default function() {
// 初始化appVersion(仅app生效)
initAppVersion();
//自定义路由拦截
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的写法
let list = ["navigateTo", "redirectTo", "reLaunch", "switchTab"];
list.forEach(item=>{
uni.addInterceptor(item,{
......@@ -76,35 +57,14 @@ export default function() {
})// 移除拦截器API removeInterceptor('request')
})
//提示网络变化
eventListenerNetwork()
/*
当某个权限调用失败
1.先检测手机的该模块是否打开
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
......@@ -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 @@
"condition": {
"list": [
{
"path": "pages/list/list",
"style": {
"navigationStyle": "custom",
"enablePullDownRefresh": true
}
"path": "pages/list/list"
},
{
"path": "uni_modules/uni-login-page/pages/index/index"
......@@ -227,7 +223,7 @@
"path":"pages/ucenter/settings/settings"
}
],
"current":0
"current":1
},
"tabBar": {
"color": "#7A7E83",
......
......@@ -36,13 +36,13 @@
// document.documentElement.style.fontSize = document.documentElement.clientWidth / 20 + 'px'
// })
setTimeout(()=>{
document.querySelector('#gg').addEventListener('click',e=>{
console.log(e);
alert(12)
window.location.href = "https://m3w.cn/uniapp"
})
},1000)
// setTimeout(()=>{
// document.querySelector('#gg').addEventListener('click',e=>{
// console.log(e);
// alert(12)
// window.location.href = "https://m3w.cn/uniapp"
// })
// },1000)
</script>
<link rel="stylesheet" href="<%= BASE_URL %>static/index.<%= VUE_APP_INDEX_CSS_HASH %>.css" />
......@@ -54,8 +54,8 @@
<noscript>
<strong>Please enable JavaScript to continue.</strong>
</noscript>
<div id="gg" style="width: 99px;height: 99px;background-color: #007AFF;"
>下载app</div>
<!-- <div id="gg" style="width: 99px;height: 99px;background-color: #007AFF;"
>下载app</div> -->
<div style="margin-top: 100px;" id="app"></div>
<!-- built files will be auto injected -->
<script>
......
......@@ -40,7 +40,9 @@ page {
font-weight: 600;
padding-top: 50rpx;
}
.content /deep/ .uni-easyinput{
padding: 6px 0;
}
.login-iknow {
padding-top: 24rpx;
padding-bottom: 48rpx;
......
......@@ -79,7 +79,27 @@ let mixin = {
methods:{
...mapMutations({
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
\ No newline at end of file
......@@ -181,29 +181,11 @@
this.request('user-center/login_by_'+type,params,(data,result)=>{
console.log(result);
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'){
uni.closeAuthView()
}
uni.showToast({
title: '登陆成功',
icon: 'none'
});
uni.hideLoading()
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})
this.loginSuccess(result)
}
},{showLoading:true})
},
......
......@@ -69,19 +69,7 @@
uni.hideLoading()
console.log(e.result);
if(e.result.code === 0){
uni.setStorageSync('uni_id_uid', e.result.uid)
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"
})
this.loginSuccess(e.result)
}else{
uni.showModal({
title: '错误',
......
......@@ -23,12 +23,12 @@
<button class="send-btn-box" :disabled="!canLogin" :type="canLogin?'primary':'default'"
@click="pwdLogin">登录</button>
</uni-forms>
<!-- 忘记密码 -->
<view class="auth-box">
<text class="login-text login-text-sub">忘记了?</text>
<text class="login-text" @click="toRetrievePwd">找回密码</text>
</view>
<button type="primary" class="toRegister" @click="toRegister">注册账号</button>
</view>
</view>
<uni-quick-login ref="uniQuickLogin"></uni-quick-login>
......@@ -81,19 +81,7 @@
uni.hideLoading()
console.log(e.result);
if(e.result.code === 0){
uni.setStorageSync('uni_id_uid', e.result.uid)
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"
})
this.loginSuccess(e.result)
}else{
uni.showModal({
title: '错误',
......@@ -127,6 +115,13 @@
});
// this.currenPhoneArea = this.phoneArea[event.detail.value];
},
/* 前往注册 */
toRegister(e){
console.log(e);
uni.navigateTo({
url:'/uni_modules/uni-login-page/pages/register/register'
})
}
}
}
</script>
......@@ -143,4 +138,8 @@
.login-text-sub {
color: #8a8f8b;
}
.toRegister{
margin-top: 80px;
width: 600rpx;
}
</style>
<template>
<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-easyinput placeholder="请输入用户名" v-model="formData.username" trim="both" />
</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-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-forms-item>
<uni-forms-item name="pwd" label="密码" v-model="formData.pwd" required>
<uni-easyinput placeholder="请输入6-20位密码" type="password" v-model="formData.pwd" trim="both" />
<uni-forms-item name="password" label="密码" v-model="formData.password" required>
<uni-easyinput placeholder="请输入6-20位密码" type="password" v-model="formData.password" trim="both" />
</uni-forms-item>
<uni-forms-item name="pwd2" label="确认密码" v-model="formData.pwd2" required>
<uni-easyinput placeholder="再次输入密码" type="password" v-model="formData.pwd2" trim="both" />
......@@ -24,32 +24,18 @@
</template>
<script>
import {
validator
} 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
}
import rules from './validator.js';
import mixin from '../../common/loginPage.mixin.js';
export default {
mixins:[mixin],
data() {
return {
formData: {
"username": "",
"gender": 0,
"nickname": "",
'pwd':'',
'pwd2':''
'password':'123456',
'pwd2':'123456'
},
formOptions: {
"gender_localdata": [{
......@@ -65,9 +51,7 @@
}
]
},
rules: {
...getValidator(["username", "gender", "nickname", 'pwd', 'pwd2'])
}
rules
}
},
onReady() {
......@@ -78,15 +62,10 @@
* 触发表单提交
*/
submit() {
uni.showLoading({
mask: true
})
this.$refs.form.submit().then((res) => {
if(res.pwd != res.pwd2)return uni.showToast({
title: '两次输入密码不一致',
icon: 'none'
});
this.submitForm(res)
}).catch((errors) => {
console.log(errors);
......@@ -95,9 +74,13 @@
uni.hideLoading()
})
},
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
const validator = {
"gender": {
"rules": [{
"format": "int"
},
{
"range": [{
"text": "未知",
"value": 0
},
{
"text": "",
"value": 1
},
{
"text": "",
"value": 2
}
]
}
],
"defaultValue": 0,
"label": "性别"
},
export default {
"username": {
"rules": [{
required: true,
errorMessage: '请输入用户名',
},
{
minLength: 3,
maxLength: 10,
maxLength: 32,
errorMessage: '用户名长度在 {minLength} 到 {maxLength} 个字符',
}
],
"label": "用户名"
},
"nickname": {
"rules": [{
required: true,
errorMessage: '请输入昵称',
},
{
minLength: 3,
maxLength: 10,
errorMessage: '昵称长度在 {minLength} 到 {maxLength} 个字符',
validateFunction:function(rule,value,data,callback){
console.log(value);
if(/^1\d{10}$/.test(value) || /^(\w-*\.*)+@(\w-?)+(\.\w{2,})+$/.test(value)){
callback('用户名不能是:手机号或邮箱')
};
return true
}
}
],
"label": "昵称"
"label": "用户名"
},
"pwd":{
"password":{
"rules": [{
required: true,
errorMessage: '请输入密码',
},
{
minLength: 6,
......@@ -82,21 +45,17 @@ const validator = {
minLength: 6,
maxLength: 20,
errorMessage: '密码长度在 {minLength} 到 {maxLength} 个字符',
},
{
validateFunction:function(rule,value,data,callback){
console.log(value);
if(value!=data.password){
callback('两次输入密码不一致')
};
return true
}
}
],
"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) => {
let res = {}
switch (event.action) {
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;
case 'login':
let passed = false;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册