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

1.0.20

上级 bf4fccfa
...@@ -128,7 +128,7 @@ ...@@ -128,7 +128,7 @@
"uniStatistics" : { "uniStatistics" : {
"enable" : false "enable" : false
}, },
"vueVersion" : "2", "vueVersion" : "3",
"h5" : { "h5" : {
"unipush" : { "unipush" : {
"enable" : false "enable" : false
......
## 1.0.20(2022-09-21)
- 新增 store 账号信息状态管理,详情:用户中心页面 路径:`/uni_modules/uni-id-pages/pages/userinfo/userinfo`
## 1.0.19(2022-09-20) ## 1.0.19(2022-09-20)
- 修复 小程序端,使用将自定义节点设置成[虚拟节点](https://uniapp.dcloud.net.cn/tutorial/vue-api.html#%E5%85%B6%E4%BB%96%E9%85%8D%E7%BD%AE)的uni-ui组件,样式错乱的问题 - 修复 小程序端,使用将自定义节点设置成[虚拟节点](https://uniapp.dcloud.net.cn/tutorial/vue-api.html#%E5%85%B6%E4%BB%96%E9%85%8D%E7%BD%AE)的uni-ui组件,样式错乱的问题
## 1.0.18(2022-09-20) ## 1.0.18(2022-09-20)
......
import pagesJson from '@/pages.json'
const uniIdCo = uniCloud.importObject("uni-id-co")
export default {
async logout() {
await uniIdCo.logout()
uni.removeStorageSync('uni_id_token');
uni.setStorageSync('uni_id_token_expired', 0)
uni.redirectTo({
url: `/${pagesJson.uniIdRouter?.loginPage ?? 'uni_modules/uni-id-pages/pages/login/login-withoutpwd'}`,
});
uni.$emit('uni-id-pages-logout')
},
}
import loginSuccess from './loginSuccess.js'; import {
store,
mutations
} from '@/uni_modules/uni-id-pages/common/store.js'
import config from '@/uni_modules/uni-id-pages/config.js' import config from '@/uni_modules/uni-id-pages/config.js'
let mixin = { let mixin = {
data() { data() {
...@@ -75,7 +78,7 @@ let mixin = { ...@@ -75,7 +78,7 @@ let mixin = {
}, },
methods: { methods: {
loginSuccess(e) { loginSuccess(e) {
loginSuccess({ mutations.loginSuccess({
...e, ...e,
uniIdRedirectUrl: this.uniIdRedirectUrl uniIdRedirectUrl: this.uniIdRedirectUrl
}) })
......
...@@ -51,7 +51,12 @@ ...@@ -51,7 +51,12 @@
.register-back{ .register-back{
display: none; display: none;
} }
uni-button{
padding-bottom: 1px;
}
/* #endif */ /* #endif */
} }
...@@ -81,13 +86,13 @@ ...@@ -81,13 +86,13 @@
} }
/* #ifdef MP */ /* #ifndef APP-NVUE */
// 解决小程序端开启虚拟节点virtualHost引起的 class = input-box丢失的问题 [详情参考](https://uniapp.dcloud.net.cn/matter.html#%E5%90%84%E5%AE%B6%E5%B0%8F%E7%A8%8B%E5%BA%8F%E5%AE%9E%E7%8E%B0%E6%9C%BA%E5%88%B6%E4%B8%8D%E5%90%8C-%E5%8F%AF%E8%83%BD%E5%AD%98%E5%9C%A8%E7%9A%84%E5%B9%B3%E5%8F%B0%E5%85%BC%E5%AE%B9%E9%97%AE%E9%A2%98) // 解决小程序端开启虚拟节点virtualHost引起的 class = input-box丢失的问题 [详情参考](https://uniapp.dcloud.net.cn/matter.html#%E5%90%84%E5%AE%B6%E5%B0%8F%E7%A8%8B%E5%BA%8F%E5%AE%9E%E7%8E%B0%E6%9C%BA%E5%88%B6%E4%B8%8D%E5%90%8C-%E5%8F%AF%E8%83%BD%E5%AD%98%E5%9C%A8%E7%9A%84%E5%B9%B3%E5%8F%B0%E5%85%BC%E5%AE%B9%E9%97%AE%E9%A2%98)
.uni-content ::v-deep .uni-easyinput__content, .uni-content ::v-deep .uni-easyinput__content,
/* #endif */ /* #endif */
.input-box { .input-box {
padding: 4px; height: 44px;
background-color: #F8F8F8 !important; background-color: #F8F8F8 !important;
border-radius: 0; border-radius: 0;
font-size: 14px; font-size: 14px;
......
import pagesJson from '@/pages.json'
export default function(e = {}) {
const {
showToast = true, toastText = '登录成功', autoBack = true, uniIdRedirectUrl = ''
} = e
console.log({
toastText,
autoBack
});
if (showToast) {
uni.showToast({
title: toastText,
icon: 'none'
});
}
if (autoBack) {
let delta = 0; //判断需要返回几层
let pages = getCurrentPages();
uni.$emit('uni-id-pages-login-success',pages)
console.log(pages);
pages.forEach((page, index) => {
if (pages[pages.length - index - 1].route.split('/')[3] == 'login') {
delta++
}
})
console.log('判断需要返回几层:',pages, delta);
if (uniIdRedirectUrl) {
return uni.reLaunch({
url: uniIdRedirectUrl
})
}
// #ifdef H5
if(e.loginType == 'weixin'){
console.log('window.history',window.history);
return window.history.go(-3)
}
// #endif
if (delta) {
const page = pagesJson.pages[0]
return uni.reLaunch({
url: `/${page.path}`
})
}
uni.navigateBack({
delta
})
}
}
import pagesJson from '@/pages.json'
const uniIdCo = uniCloud.importObject("uni-id-co")
const db = uniCloud.database();
const usersTable = db.collection('uni-id-users')
console.log(uni.getStorageSync('uni-id-pages-userInfo') || {});
const data = {
userInfo: uni.getStorageSync('uni-id-pages-userInfo') || {},
hasLogin: !!uni.getStorageSync('uni-id-pages-userInfo')
}
console.log('data', data);
// 定义 mutations, 修改属性
export const mutations = {
// data不为空,表示传递要更新的值(注意不是覆盖是合并),什么也不传时,直接查库获取更新
async updateUserInfo(data = false) {
if (data) {
usersTable.where('_id==$env.uid').update(data).then(e => {
console.log(e);
if (e.result.updated) {
uni.showToast({
title: "更新成功",
icon: 'none'
});
this.setUserInfo(data)
} else {
uni.showToast({
title: "没有改变",
icon: 'none'
});
}
})
} else {
try {
let res = await usersTable.where("'_id' == $cloudEnv_uid")
.field('mobile,nickname,user_name,email,avatar_file')
.get()
console.log('fromDbData',res.result.data);
this.setUserInfo(res.result.data[0])
} catch (e) {
this.setUserInfo({},{cover:true})
console.error(e.message, e.errCode);
}
}
},
async setUserInfo(data, {cover}={cover:false}) {
console.log('set-userInfo', data);
let userInfo = cover?data:Object.assign(store.userInfo,data)
store.userInfo = Object.assign({},userInfo)
store.hasLogin = Object.keys(store.userInfo).length != 0
console.log('store.userInfo', store.userInfo);
uni.setStorage({
key: "uni-id-pages-userInfo",
data:store.userInfo
})
return data
},
async logout() {
await uniIdCo.logout()
uni.removeStorageSync('uni_id_token');
uni.setStorageSync('uni_id_token_expired', 0)
uni.redirectTo({
url: `/${pagesJson.uniIdRouter?.loginPage ?? 'uni_modules/uni-id-pages/pages/login/login-withoutpwd'}`,
});
uni.$emit('uni-id-pages-logout')
this.setUserInfo({},{cover:true})
},
loginSuccess(e){
const {
showToast = true, toastText = '登录成功', autoBack = true, uniIdRedirectUrl = ''
} = e
console.log({
toastText,
autoBack
});
if (showToast) {
uni.showToast({
title: toastText,
icon: 'none'
});
}
this.updateUserInfo()
uni.$emit('uni-id-pages-login-success')
if (autoBack) {
let delta = 0; //判断需要返回几层
let pages = getCurrentPages();
// console.log(pages);
pages.forEach((page, index) => {
if (pages[pages.length - index - 1].route.split('/')[3] == 'login') {
delta++
}
})
console.log('判断需要返回几层:', pages, delta);
if (uniIdRedirectUrl) {
return uni.reLaunch({
url: uniIdRedirectUrl
})
}
// #ifdef H5
if (e.loginType == 'weixin') {
console.log('window.history', window.history);
return window.history.go(-3)
}
// #endif
if (delta) {
const page = pagesJson.pages[0]
return uni.reLaunch({
url: `/${page.path}`
})
}
uni.navigateBack({
delta
})
}
}
}
// #ifdef VUE2
import Vue from 'vue'
// 通过Vue.observable创建一个可响应的对象
export const store = Vue.observable(data)
// #endif
// #ifdef VUE3
import {
reactive
} from 'vue'
// 通过Vue.observable创建一个可响应的对象
export const store = reactive(data)
// #endif
...@@ -67,7 +67,7 @@ ...@@ -67,7 +67,7 @@
}, },
methods: { methods: {
popupConfirm(){ popupConfirm(){
console.log("popupConfirm"); // console.log("popupConfirm");
this.isAgree = true this.isAgree = true
retryFun() retryFun()
// this.$emit('popupConfirm') // this.$emit('popupConfirm')
......
<template> <template>
<view @click="uploadAvatarImg"> <view @click="uploadAvatarImg" class="box" :class="{'showBorder':border}" :style="{width,height,lineHeight:height}">
<cloud-image v-if="avatar_file" :src="avatar_file.url" :width="width" :height="height"></cloud-image> <cloud-image v-if="avatar_file" :src="avatar_file.url" :width="width" :height="height"></cloud-image>
<uni-icons v-else :style="{width,height,lineHeight:height}" class="chooseAvatar" type="plusempty" size="30" <uni-icons v-else :style="{width,height,lineHeight:height}" class="chooseAvatar" type="plusempty" size="30"
color="#dddddd"></uni-icons> color="#dddddd"></uni-icons>
...@@ -7,20 +7,20 @@ ...@@ -7,20 +7,20 @@
</template> </template>
<script> <script>
const db = uniCloud.database(); import {
const usersTable = db.collection('uni-id-users') store,
mutations
} from '@/uni_modules/uni-id-pages/common/store.js'
/** /**
* uni-id-pages-avatar * uni-id-pages-avatar
* @description 用户头像组件 * @description 用户头像组件
* @property {String} width 图片的宽,默认为:50px * @property {String} width 图片的宽,默认为:50px
* @property {String} height 图片的高,默认为:50px * @property {String} height 图片的高,默认为:50px
*/ */
export default { export default {
data() { data() {
return { return {
userInfo: {}, isPC: false
isPC: false,
hasLogin:false
} }
}, },
props: { props: {
...@@ -37,71 +37,38 @@ ...@@ -37,71 +37,38 @@
default () { default () {
return "50px" return "50px"
} }
},
border:{
type: Boolean,
default () {
return false
}
} }
}, },
async mounted() { async mounted() {
usersTable.where("'_id' == $cloudEnv_uid").field('avatar_file,mobile,nickname').get().then(res=>{
this.userInfo = res.result.data[0]||{}
console.log('this.userInfo', this.userInfo);
this.hasLogin = true
}).catch (e=>{
this.userInfo = {}
this.hasLogin = false
console.log(e.message, e.errCode);
})
// try {
// let res = await usersTable.where("'_id' == $cloudEnv_uid").field('avatar_file').get()
// this.userInfo = res.result.data[0]
// console.log('this.userInfo', this.userInfo);
// } catch (e) {
// console.log(e.message);
// }
// #ifdef H5 // #ifdef H5
this.isPC = !['ios', 'android'].includes(uni.getSystemInfoSync().platform); this.isPC = !['ios', 'android'].includes(uni.getSystemInfoSync().platform);
console.log(' this.isPC', this.isPC, uni.getSystemInfoSync().platform); console.log(' this.isPC', this.isPC, uni.getSystemInfoSync().platform);
// #endif // #endif
}, },
computed: { computed: {
avatar_file() { hasLogin() {
if (this.userInfo.avatar_file && this.userInfo.avatar_file.url) { return store.hasLogin
return this.userInfo.avatar_file },
} userInfo() {
return store.userInfo
},
avatar_file() {
return store.userInfo.avatar_file
} }
}, },
methods: { methods: {
setAvatarFile(avatar_file) { setAvatarFile(avatar_file) {
uni.showLoading({ // 使用 clientDB 提交数据
title: "设置中", mutations.updateUserInfo({avatar_file})
mask: true
});
// 使用 clientDB 提交数据
usersTable.where('_id==$env.uid').update({
avatar_file
}).then((res) => {
console.log(res);
if (avatar_file) {
uni.showToast({
icon: 'none',
title: "更新成功"
})
} else {
uni.showToast({
icon: 'none',
title: "删除成功"
})
}
this.$set(this.userInfo, 'avatar_file', avatar_file)
}).catch((err) => {
uni.showModal({
content: err.message || "请求失败",
showCancel: false
})
}).finally(() => {
uni.hideLoading()
})
}, },
uploadAvatarImg(res) { uploadAvatarImg(res) {
console.log(this.hasLogin);
if(!this.hasLogin){ if(!this.hasLogin){
return uni.navigateTo({ return uni.navigateTo({
url:'/uni_modules/uni-id-pages/pages/login/login-withoutpwd' url:'/uni_modules/uni-id-pages/pages/login/login-withoutpwd'
...@@ -176,13 +143,24 @@ ...@@ -176,13 +143,24 @@
} }
</script> </script>
<style> <style>
/* #ifndef APP-NVUE */
.box{
overflow: hidden;
}
/* #endif */
.chooseAvatar { .chooseAvatar {
/* #ifndef APP-NVUE */ /* #ifndef APP-NVUE */
display: inline-block; display: inline-block;
box-sizing: border-box;
/* #endif */ /* #endif */
border: dotted 1px #ddd; border: dotted 1px #ddd;
border-radius: 10px; border-radius: 10px;
text-align: center; text-align: center;
padding: 1px;
}
.showBorder{
border: solid 1px #ddd;
} }
</style> </style>
...@@ -14,8 +14,11 @@ ...@@ -14,8 +14,11 @@
</template> </template>
<script> <script>
import config from '@/uni_modules/uni-id-pages/config.js' import config from '@/uni_modules/uni-id-pages/config.js'
//前一个窗口的页面地址。控制点击切换快捷登录方式是创建还是返回 //前一个窗口的页面地址。控制点击切换快捷登录方式是创建还是返回
import loginSuccess from '../../common/loginSuccess.js'; import {
store,
mutations
} from '@/uni_modules/uni-id-pages/common/store.js'
const db = uniCloud.database(); const db = uniCloud.database();
const usersTable = db.collection('uni-id-users') const usersTable = db.collection('uni-id-users')
...@@ -438,8 +441,8 @@ ...@@ -438,8 +441,8 @@
}); });
// #ifdef MP-WEIXIN // #ifdef MP-WEIXIN
//如果是微信小程序端的微信登录,且为首次登录,就弹出获取微信昵称+头像用于绑定资料 //如果是微信小程序端的微信登录,且为首次登录,就弹出获取微信昵称+头像用于绑定资料
if (type == 'weixin' && result.type == "register") { if (type == 'weixin' && result.type == "register") {
loginSuccess({ mutations.loginSuccess({
...result, ...result,
showToast: false, showToast: false,
autoBack: false autoBack: false
...@@ -450,7 +453,7 @@ ...@@ -450,7 +453,7 @@
// #ifdef H5 // #ifdef H5
result.loginType = type result.loginType = type
// #endif // #endif
loginSuccess(result) mutations.loginSuccess(result)
}) })
.catch(e=>{ .catch(e=>{
console.log(e); console.log(e);
...@@ -469,7 +472,7 @@ ...@@ -469,7 +472,7 @@
}, },
doUserProfileNext() { doUserProfileNext() {
try { try {
loginSuccess() mutations.loginSuccess()
} catch (e) { } catch (e) {
console.log(e); console.log(e);
} }
......
{ {
"id": "uni-id-pages", "id": "uni-id-pages",
"displayName": "uni-id-pages", "displayName": "uni-id-pages",
"version": "1.0.19", "version": "1.0.20",
"description": "云端一体简单、统一、可扩展的用户中心页面模版", "description": "云端一体简单、统一、可扩展的用户中心页面模版",
"keywords": [ "keywords": [
"用户管理", "用户管理",
......
...@@ -56,8 +56,8 @@ ...@@ -56,8 +56,8 @@
}, },
async onLoad(e) { async onLoad(e) {
console.log(e); console.log(e);
let type = e.type //获取通过url传递的参数type设置当前登录方式,如果没传递直接默认以配置的登录
// console.log({type}); let type = e.type || config.loginTypes[0]
this.type = type this.type = type
if(type != 'univerify'){ if(type != 'univerify'){
this.focusPhone = true this.focusPhone = true
...@@ -65,8 +65,7 @@ ...@@ -65,8 +65,7 @@
this.$nextTick(() => { this.$nextTick(() => {
//关闭重复显示的登录快捷方式 //关闭重复显示的登录快捷方式
if (['weixin', 'apple'].includes(type)) { if (['weixin', 'apple'].includes(type)) {
this.$refs.uniFabLogin.servicesList = this.$refs.uniFabLogin.servicesList.filter(item => this.$refs.uniFabLogin.servicesList = this.$refs.uniFabLogin.servicesList.filter(item =>item.id != type)
item.id != type)
} }
}) })
uni.$on('uni-id-pages-set-login-type', type => { uni.$on('uni-id-pages-set-login-type', type => {
......
<!-- 账号密码登录页 --> <!-- 账号密码登录页 -->
<template> <template>
<view class="uni-content"> <view class="uni-content">
<view class="login-logo"> <view class="login-logo">
<image :src="logo"></image> <image :src="logo"></image>
</view> </view>
<!-- 顶部文字 --> <!-- 顶部文字 -->
<text class="title title-box">账号密码登录</text> <text class="title title-box">账号密码登录</text>
<uni-forms> <uni-forms>
<uni-forms-item name="username"> <uni-forms-item name="username">
<uni-easyinput :focus="focusUsername" @blur="focusUsername = false" class="input-box" :inputBorder="false" v-model="username" placeholder="请输入手机号/用户名/邮箱" /> <uni-easyinput :focus="focusUsername" @blur="focusUsername = false" class="input-box"
</uni-forms-item> :inputBorder="false" v-model="username" placeholder="请输入手机号/用户名/邮箱" />
<uni-forms-item name="password"> </uni-forms-item>
<uni-easyinput :focus="focusPassword" @blur="focusPassword = false" class="input-box" clearable type="password" :inputBorder="false" v-model="password" <uni-forms-item name="password">
placeholder="请输入密码" /> <uni-easyinput :focus="focusPassword" @blur="focusPassword = false" class="input-box" clearable
</uni-forms-item> type="password" :inputBorder="false" v-model="password" placeholder="请输入密码" />
</uni-forms> </uni-forms-item>
<uni-captcha v-if="needCaptcha" focus ref="captcha" scene="login-by-pwd" v-model="captcha" /> </uni-forms>
<!-- 带选择框的隐私政策协议组件 --> <uni-captcha v-if="needCaptcha" focus ref="captcha" scene="login-by-pwd" v-model="captcha" />
<uni-id-pages-agreements scope="login" ref="agreements" ></uni-id-pages-agreements> <!-- 带选择框的隐私政策协议组件 -->
<button class="uni-btn" type="primary" @click="pwdLogin">登录</button> <uni-id-pages-agreements scope="login" ref="agreements"></uni-id-pages-agreements>
<!-- 忘记密码 --> <button class="uni-btn" type="primary" @click="pwdLogin">登录</button>
<view class="link-box"> <!-- 忘记密码 -->
<view v-if="!config.isAdmin"> <view class="link-box">
<text class="forget">忘记了?</text> <view v-if="!config.isAdmin">
<text class="link" @click="toRetrievePwd">找回密码</text> <text class="forget">忘记了?</text>
</view> <text class="link" @click="toRetrievePwd">找回密码</text>
<text class="link" @click="toRegister">{{config.isAdmin ? '注册管理员账号': '注册账号'}}</text> </view>
<!-- <text class="link" @click="toRegister" v-if="!config.isAdmin">注册账号</text> --> <text class="link" @click="toRegister">{{config.isAdmin ? '注册管理员账号': '注册账号'}}</text>
</view> <!-- <text class="link" @click="toRegister" v-if="!config.isAdmin">注册账号</text> -->
<!-- 悬浮登录方式组件 --> </view>
<uni-id-pages-fab-login ref="uniFabLogin"></uni-id-pages-fab-login> <!-- 悬浮登录方式组件 -->
</view> <uni-id-pages-fab-login ref="uniFabLogin"></uni-id-pages-fab-login>
</template> </view>
</template>
<script>
import mixin from '@/uni_modules/uni-id-pages/common/login-page.mixin.js'; <script>
const uniIdCo = uniCloud.importObject("uni-id-co",{ import mixin from '@/uni_modules/uni-id-pages/common/login-page.mixin.js';
errorOptions:{ const uniIdCo = uniCloud.importObject("uni-id-co", {
type:'toast' errorOptions: {
} type: 'toast'
}) }
export default { })
mixins: [mixin], export default {
data() { mixins: [mixin],
return { data() {
"password": "", return {
"username": "", "password": "",
"captcha": "", "username": "",
"needCaptcha": false, "captcha": "",
"focusUsername":false, "needCaptcha": false,
"focusPassword":false, "focusUsername": false,
"logo": "/static/logo.png" "focusPassword": false,
} "logo": "/static/logo.png"
}, }
onShow() { },
// #ifdef H5 onShow() {
document.onkeydown = event => { // #ifdef H5
var e = event || window.event; document.onkeydown = event => {
if (e && e.keyCode == 13) { //回车键的键值为13 var e = event || window.event;
this.pwdLogin() if (e && e.keyCode == 13) { //回车键的键值为13
} this.pwdLogin()
}; }
// #endif };
}, // #endif
methods: { },
// 页面跳转,找回密码 methods: {
toRetrievePwd() { // 页面跳转,找回密码
let url = '/uni_modules/uni-id-pages/pages/retrieve/retrieve' toRetrievePwd() {
//如果刚好用户名输入框的值为手机号码,就把它传到retrieve页面,根据该手机号找回密码 let url = '/uni_modules/uni-id-pages/pages/retrieve/retrieve'
if (/^1\d{10}$/.test(this.username)) { //如果刚好用户名输入框的值为手机号码,就把它传到retrieve页面,根据该手机号找回密码
url += `?phoneNumber=${this.username}` if (/^1\d{10}$/.test(this.username)) {
} url += `?phoneNumber=${this.username}`
uni.navigateTo({ }
url uni.navigateTo({
}) url
}, })
/** },
* 密码登录 /**
*/ * 密码登录
pwdLogin() { */
if(!this.password.length){ pwdLogin() {
this.focusPassword = true if (!this.password.length) {
return uni.showToast({ this.focusPassword = true
title: '请输入密码', return uni.showToast({
icon: 'none' title: '请输入密码',
}); icon: 'none'
} });
if(!this.username.length){ }
this.focusUsername = true if (!this.username.length) {
return uni.showToast({ this.focusUsername = true
title: '请输入手机号/用户名/邮箱', return uni.showToast({
icon: 'none' title: '请输入手机号/用户名/邮箱',
}); icon: 'none'
} });
if(this.needCaptcha && this.captcha.length!=4){ }
this.$refs.captcha.getImageCaptcha() if (this.needCaptcha && this.captcha.length != 4) {
return uni.showToast({ this.$refs.captcha.getImageCaptcha()
title: '请输入验证码', return uni.showToast({
icon: 'none' title: '请输入验证码',
}); icon: 'none'
} });
}
if (this.needAgreements && !this.agree) {
return this.$refs.agreements.popup(this.pwdLogin) if (this.needAgreements && !this.agree) {
} return this.$refs.agreements.popup(this.pwdLogin)
}
let data = {
"password": this.password, let data = {
"captcha": this.captcha "password": this.password,
} "captcha": this.captcha
}
if (/^1\d{10}$/.test(this.username)) {
data.mobile = this.username if (/^1\d{10}$/.test(this.username)) {
}else if(/@/.test(this.username)) { data.mobile = this.username
data.email = this.username } else if (/@/.test(this.username)) {
}else{ data.email = this.username
data.username = this.username } else {
} data.username = this.username
}
uniIdCo.login(data).then(e => {
this.loginSuccess(e) uniIdCo.login(data).then(e => {
}).catch(e => { this.loginSuccess(e)
if(e.errCode == 'uni-id-captcha-required'){ }).catch(e => {
this.needCaptcha = true if (e.errCode == 'uni-id-captcha-required') {
}else if(this.needCaptcha){ this.needCaptcha = true
//登录失败,自动重新获取验证码 } else if (this.needCaptcha) {
this.$refs.captcha.getImageCaptcha() //登录失败,自动重新获取验证码
} this.$refs.captcha.getImageCaptcha()
}) }
}, })
/* 前往注册 */ },
toRegister() { /* 前往注册 */
uni.navigateTo({ toRegister() {
url: this.config.isAdmin ? '/uni_modules/uni-id-pages/pages/register/register-admin': '/uni_modules/uni-id-pages/pages/register/register', uni.navigateTo({
fail(e) { url: this.config.isAdmin ? '/uni_modules/uni-id-pages/pages/register/register-admin' :
console.error(e); '/uni_modules/uni-id-pages/pages/register/register',
} fail(e) {
}) console.error(e);
} }
} })
} }
</script> }
}
<style lang="scss" scoped> </script>
@import "@/uni_modules/uni-id-pages/common/login-page.scss";
@media screen and (min-width: 690px) { <style lang="scss" scoped>
@import "@/uni_modules/uni-id-pages/common/login-page.scss";
}
.forget{ @media screen and (min-width: 690px) {
font-size: 12px; .uni-content {
color: #8a8f8b; max-height: 650px;
} }
}
.link-box {
/* #ifndef APP-NVUE */ .forget {
display: flex; font-size: 12px;
/* #endif */ color: #8a8f8b;
flex-direction: row; }
justify-content: space-between;
margin-top: 20px; .link-box {
} /* #ifndef APP-NVUE */
display: flex;
.link { /* #endif */
font-size: 12px; flex-direction: row;
} justify-content: space-between;
margin-top: 20px;
}
.link {
font-size: 12px;
}
</style> </style>
...@@ -191,7 +191,7 @@ ...@@ -191,7 +191,7 @@
@media screen and (min-width: 690px) { @media screen and (min-width: 690px) {
.uni-content{ .uni-content{
padding: 30px 40px; padding: 30px 40px;
max-height: 550px; max-height: 650px;
} }
.link-box { .link-box {
/* #ifndef APP-NVUE */ /* #ifndef APP-NVUE */
......
<!-- 账号注册页 --> <!-- 账号注册页 -->
<template> <template>
<view class="uni-content"> <view class="uni-content">
<match-media :min-width="690"> <match-media :min-width="690">
<view class="login-logo"> <view class="login-logo">
<image :src="logo"></image> <image :src="logo"></image>
</view> </view>
<!-- 顶部文字 --> <!-- 顶部文字 -->
<text class="title title-box">用户名密码注册</text> <text class="title title-box">用户名密码注册</text>
</match-media> </match-media>
<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="toast">
<uni-forms-item name="username" required> <uni-forms-item name="username" required>
<uni-easyinput :inputBorder="false" :focus="focusUsername" @blur="focusUsername = false" <uni-easyinput :inputBorder="false" :focus="focusUsername" @blur="focusUsername = false"
class="input-box" placeholder="请输入用户名" v-model="formData.username" trim="both" /> class="input-box" placeholder="请输入用户名" v-model="formData.username" trim="both" />
</uni-forms-item> </uni-forms-item>
<uni-forms-item name="nickname"> <uni-forms-item name="nickname">
<uni-easyinput :inputBorder="false" :focus="focusNickname" @blur="focusNickname = false" class="input-box" placeholder="请输入用户昵称" v-model="formData.nickname" <uni-easyinput :inputBorder="false" :focus="focusNickname" @blur="focusNickname = false"
trim="both" /> class="input-box" placeholder="请输入用户昵称" v-model="formData.nickname" trim="both" />
</uni-forms-item> </uni-forms-item>
<uni-forms-item name="password" v-model="formData.password" required> <uni-forms-item name="password" v-model="formData.password" required>
<uni-easyinput :inputBorder="false" :focus="focusPassword" @blur="focusPassword = false" <uni-easyinput :inputBorder="false" :focus="focusPassword" @blur="focusPassword = false"
class="input-box" maxlength="20" :placeholder="'请输入' + (config.passwordStrength == 'weak'?'6':'8') + '-16位密码'" type="password" class="input-box" maxlength="20"
v-model="formData.password" trim="both" /> :placeholder="'请输入' + (config.passwordStrength == 'weak'?'6':'8') + '-16位密码'" type="password"
</uni-forms-item> v-model="formData.password" trim="both" />
<uni-forms-item name="password2" v-model="formData.password2" required> </uni-forms-item>
<uni-easyinput :inputBorder="false" :focus="focusPassword2" @blur="focusPassword2 =false" <uni-forms-item name="password2" v-model="formData.password2" required>
class="input-box" placeholder="再次输入密码" maxlength="20" type="password" v-model="formData.password2" <uni-easyinput :inputBorder="false" :focus="focusPassword2" @blur="focusPassword2 =false"
trim="both" /> class="input-box" placeholder="再次输入密码" maxlength="20" type="password" v-model="formData.password2"
</uni-forms-item> trim="both" />
<uni-forms-item> </uni-forms-item>
<uni-captcha ref="captcha" scene="register" v-model="formData.captcha" /> <uni-forms-item>
</uni-forms-item> <uni-captcha ref="captcha" scene="register" v-model="formData.captcha" />
<uni-id-pages-agreements scope="register" ref="agreements" ></uni-id-pages-agreements> </uni-forms-item>
<button class="uni-btn" type="primary" @click="submit">注册</button> <uni-id-pages-agreements scope="register" ref="agreements"></uni-id-pages-agreements>
<button @click="navigateBack" class="register-back">返回</button> <button class="uni-btn" type="primary" @click="submit">注册</button>
<match-media :min-width="690"> <button @click="navigateBack" class="register-back">返回</button>
<view class="link-box"> <match-media :min-width="690">
<text class="link" @click="registerByEmail">邮箱验证码注册</text> <view class="link-box">
<text class="link" @click="toLogin">已有账号?点此登录</text> <text class="link" @click="registerByEmail">邮箱验证码注册</text>
</view> <text class="link" @click="toLogin">已有账号?点此登录</text>
</match-media> </view>
</uni-forms> </match-media>
</view> </uni-forms>
</template> </view>
</template>
<script>
import rules from './validator.js'; <script>
import mixin from '@/uni_modules/uni-id-pages/common/login-page.mixin.js'; import rules from './validator.js';
import config from '@/uni_modules/uni-id-pages/config.js' import mixin from '@/uni_modules/uni-id-pages/common/login-page.mixin.js';
const uniIdCo = uniCloud.importObject("uni-id-co") import config from '@/uni_modules/uni-id-pages/config.js'
export default { import {
mixins: [mixin], store,
data() { mutations
return { } from '@/uni_modules/uni-id-pages/common/store.js'
formData: {
username: "", const {
nickname: "", loginSuccess
password: "", } = mutations
password2: "", const uniIdCo = uniCloud.importObject("uni-id-co")
captcha: "" export default {
}, mixins: [mixin],
rules, data() {
focusUsername:false, return {
focusNickname:false, formData: {
focusPassword:false, username: "",
focusPassword2:false, nickname: "",
logo: "/static/logo.png" password: "",
} password2: "",
}, captcha: ""
onReady() { },
this.$refs.form.setRules(this.rules) rules,
}, focusUsername: false,
onShow() { focusNickname: false,
// #ifdef H5 focusPassword: false,
document.onkeydown = event => { focusPassword2: false,
var e = event || window.event; logo: "/static/logo.png"
if (e && e.keyCode == 13) { //回车键的键值为13 }
this.submit() },
} onReady() {
}; this.$refs.form.setRules(this.rules)
// #endif },
}, onShow() {
methods: { // #ifdef H5
/** document.onkeydown = event => {
* 触发表单提交 var e = event || window.event;
*/ if (e && e.keyCode == 13) { //回车键的键值为13
submit() { this.submit()
this.$refs.form.validate().then((res) => { }
if(this.formData.captcha.length != 4){ };
this.$refs.captcha.focusCaptchaInput = true // #endif
return uni.showToast({ },
title: '请输入验证码', methods: {
icon: 'none' /**
}); * 触发表单提交
} */
if (this.needAgreements && !this.agree) { submit() {
return this.$refs.agreements.popup(()=>{ this.$refs.form.validate().then((res) => {
this.submitForm(res) if (this.formData.captcha.length != 4) {
}) this.$refs.captcha.focusCaptchaInput = true
} return uni.showToast({
this.submitForm(res) title: '请输入验证码',
}).catch((errors) => { icon: 'none'
let key = errors[0].key });
key = key.replace(key[0], key[0].toUpperCase()) }
console.log(key); if (this.needAgreements && !this.agree) {
this['focus'+key] = true return this.$refs.agreements.popup(() => {
}) this.submitForm(res)
}, })
submitForm(params) { }
uniIdCo.registerUser(this.formData).then(e => { this.submitForm(res)
console.log(e); }).catch((errors) => {
uni.navigateBack() let key = errors[0].key
}) key = key.replace(key[0], key[0].toUpperCase())
.catch(e => { console.log(key);
console.log(e); this['focus' + key] = true
console.log(e.message); })
//更好的体验:登录错误,直接刷新验证码 },
this.$refs.captcha.getImageCaptcha() submitForm(params) {
}) uniIdCo.registerUser(this.formData).then(e => {
}, console.log(e);
navigateBack() { loginSuccess()
uni.navigateBack() })
}, .catch(e => {
toLogin() { console.log(e);
uni.navigateTo({ console.log(e.message);
url: '/uni_modules/uni-id-pages/pages/login/login-withpwd' //更好的体验:登录错误,直接刷新验证码
}) this.$refs.captcha.getImageCaptcha()
}, })
registerByEmail() { },
uni.navigateTo({ navigateBack() {
url: '/uni_modules/uni-id-pages/pages/register/register-by-email' uni.navigateBack()
}) },
} toLogin() {
} uni.navigateTo({
} url: '/uni_modules/uni-id-pages/pages/login/login-withpwd'
</script> })
},
<style lang="scss"> registerByEmail() {
@import "@/uni_modules/uni-id-pages/common/login-page.scss"; uni.navigateTo({
url: '/uni_modules/uni-id-pages/pages/register/register-by-email'
@media screen and (max-width: 690px) { })
.uni-content{ }
margin-top: 15px; }
height: 100%; }
</script>
<style lang="scss">
@import "@/uni_modules/uni-id-pages/common/login-page.scss";
@media screen and (max-width: 690px) {
.uni-content {
margin-top: 15px;
height: 100%;
background-color: #fff; background-color: #fff;
} }
} }
@media screen and (min-width: 690px) {
.uni-content{ @media screen and (min-width: 690px) {
.uni-content {
padding: 30px 40px 60px; padding: 30px 40px 60px;
} max-height: 530px;
}
.link-box {
/* #ifndef APP-NVUE */ .link-box {
display: flex; /* #ifndef APP-NVUE */
/* #endif */ display: flex;
flex-direction: row; /* #endif */
justify-content: space-between; flex-direction: row;
margin-top: 10px; justify-content: space-between;
} margin-top: 10px;
}
.link {
font-size: 12px; .link {
} font-size: 12px;
} }
}
.uni-content ::v-deep .uni-forms-item__label {
position: absolute; .uni-content ::v-deep .uni-forms-item__label {
left: -15px; position: absolute;
} left: -15px;
}
button {
margin-top: 15px; button {
} margin-top: 15px;
}
</style> </style>
...@@ -204,6 +204,7 @@ ...@@ -204,6 +204,7 @@
@media screen and (min-width: 690px) { @media screen and (min-width: 690px) {
.uni-content{ .uni-content{
padding: 30px 40px 40px; padding: 30px 40px 40px;
max-height: 650px;
} }
.link-box { .link-box {
......
...@@ -228,6 +228,7 @@ ...@@ -228,6 +228,7 @@
@media screen and (min-width: 690px) { @media screen and (min-width: 690px) {
.uni-content{ .uni-content{
padding: 30px 40px 40px; padding: 30px 40px 40px;
max-height: 650px;
} }
.link-box { .link-box {
/* #ifndef APP-NVUE */ /* #ifndef APP-NVUE */
......
...@@ -19,6 +19,10 @@ ...@@ -19,6 +19,10 @@
</view> </view>
</template> </template>
<script> <script>
import {
store,
mutations
} from '@/uni_modules/uni-id-pages/common/store.js'
export default { export default {
data() { data() {
return { return {
...@@ -73,7 +77,7 @@ ...@@ -73,7 +77,7 @@
// #ifndef APP-NVUE // #ifndef APP-NVUE
const eventChannel = this.getOpenerEventChannel(); const eventChannel = this.getOpenerEventChannel();
// #endif // #endif
eventChannel.emit('getUserInfo') mutations.setUserInfo(this.formData)
uni.navigateBack() uni.navigateBack()
}).catch(e => { }).catch(e => {
console.log(e); console.log(e);
......
...@@ -22,9 +22,9 @@ ...@@ -22,9 +22,9 @@
placeholder="请输入要设置的昵称"> placeholder="请输入要设置的昵称">
</uni-popup-dialog> </uni-popup-dialog>
</uni-popup> </uni-popup>
<uni-id-pages-bind-mobile ref="bind-mobile-by-sms" @success="getUserInfo"></uni-id-pages-bind-mobile> <uni-id-pages-bind-mobile ref="bind-mobile-by-sms" @success="bindMobileSuccess"></uni-id-pages-bind-mobile>
<template v-if="showLoginManage"> <template v-if="showLoginManage">
<button v-if="hasLogin" @click="logout">退出登录</button> <button v-if="userInfo._id" @click="logout">退出登录</button>
<button v-else @click="login">去登录</button> <button v-else @click="login">去登录</button>
</template> </template>
</view> </view>
...@@ -33,8 +33,16 @@ ...@@ -33,8 +33,16 @@
const db = uniCloud.database(); const db = uniCloud.database();
const usersTable = db.collection('uni-id-users') const usersTable = db.collection('uni-id-users')
const uniIdCo = uniCloud.importObject("uni-id-co") const uniIdCo = uniCloud.importObject("uni-id-co")
import common from '@/uni_modules/uni-id-pages/common/common.js'; import {
store,
mutations
} from '@/uni_modules/uni-id-pages/common/store.js'
export default { export default {
computed: {
userInfo() {
return store.userInfo
}
},
data() { data() {
return { return {
univerifyStyle: { univerifyStyle: {
...@@ -45,10 +53,10 @@ ...@@ -45,10 +53,10 @@
"title": "其他号码绑定", "title": "其他号码绑定",
} }
}, },
userInfo: { // userInfo: {
mobile:'', // mobile:'',
nickname:'' // nickname:''
}, // },
hasLogin: false, hasLogin: false,
hasPwd:false, hasPwd:false,
showLoginManage:false//通过页面传参隐藏登录&退出登录按钮 showLoginManage:false//通过页面传参隐藏登录&退出登录按钮
...@@ -62,7 +70,6 @@ ...@@ -62,7 +70,6 @@
if(e.showLoginManage){ if(e.showLoginManage){
this.showLoginManage = true//通过页面传参隐藏登录&退出登录按钮 this.showLoginManage = true//通过页面传参隐藏登录&退出登录按钮
} }
this.getUserInfo()
//判断当前用户是否有密码,否则就不显示密码修改功能 //判断当前用户是否有密码,否则就不显示密码修改功能
let res = await uniIdCo.getAccountInfo() let res = await uniIdCo.getAccountInfo()
this.hasPwd = res.isPasswordSet this.hasPwd = res.isPasswordSet
...@@ -76,7 +83,12 @@ ...@@ -76,7 +83,12 @@
} }
}) })
}, },
logout:common.logout, logout(){
mutations.logout()
},
bindMobileSuccess(){
mutations.updateUserInfo()
},
changePassword(){ changePassword(){
uni.navigateTo({ uni.navigateTo({
url: '/uni_modules/uni-id-pages/pages/userinfo/change_pwd/change_pwd', url: '/uni_modules/uni-id-pages/pages/userinfo/change_pwd/change_pwd',
...@@ -85,24 +97,6 @@ ...@@ -85,24 +97,6 @@
} }
}) })
}, },
getUserInfo(e) {
uni.showLoading({
mask: true
});
usersTable.where("'_id' == $cloudEnv_uid").field('mobile,nickname,email').get().then(res => {
console.log({res});
this.userInfo = res.result.data[0]
console.log('this.userInfo', this.userInfo);
this.hasLogin = true
}).catch(e => {
this.userInfo = {}
this.hasLogin = false
console.log(e.message, e.errCode);
}).finally(e => {
// console.log(e);
uni.hideLoading()
})
},
bindMobile() { bindMobile() {
// #ifdef APP-PLUS // #ifdef APP-PLUS
uni.preLogin({ uni.preLogin({
...@@ -133,7 +127,7 @@ ...@@ -133,7 +127,7 @@
console.log(e.authResult); console.log(e.authResult);
uniIdCo.bindMobileByUniverify(e.authResult).then(res => { uniIdCo.bindMobileByUniverify(e.authResult).then(res => {
console.log(res); console.log(res);
this.getUserInfo() mutations.updateUserInfo()
}).catch(e => { }).catch(e => {
console.log(e); console.log(e);
}).finally(e=>{ }).finally(e=>{
...@@ -151,37 +145,13 @@ ...@@ -151,37 +145,13 @@
}, },
bindMobileBySmsCode() { bindMobileBySmsCode() {
uni.navigateTo({ uni.navigateTo({
url: './bind-mobile/bind-mobile', url: './bind-mobile/bind-mobile'
events: {
getUserInfo: () => {
this.getUserInfo()
}
},
complete(e) {
console.log(e);
}
}) })
}, },
setNickname(nickname) { setNickname(nickname) {
console.log(nickname); console.log(nickname);
if (nickname) { if (nickname) {
usersTable.where('_id==$env.uid').update({ mutations.updateUserInfo({nickname})
nickname
}).then(e => {
console.log(e);
if (e.result.updated) {
uni.showToast({
title: "更新成功",
icon: 'none'
});
this.userInfo.nickname = nickname
} else {
uni.showToast({
title: "没有改变",
icon: 'none'
});
}
})
this.$refs.dialog.close() this.$refs.dialog.close()
} else { } else {
this.$refs.dialog.open() this.$refs.dialog.open()
...@@ -196,7 +166,8 @@ ...@@ -196,7 +166,8 @@
} }
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
@import url("/uni_modules/uni-id-pages/common/login-page.scss");
@import "@/uni_modules/uni-id-pages/common/login-page.scss";
.uni-content { .uni-content {
padding: 0; padding: 0;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册