From 5732cbbab10e53ad8686b2ec328e08520b4ed7f4 Mon Sep 17 00:00:00 2001 From: linju-json Date: Tue, 22 Jun 2021 18:17:46 +0800 Subject: [PATCH] =?UTF-8?q?1.=20=E6=96=B0=E5=A2=9E=E4=B8=80=E9=94=AE?= =?UTF-8?q?=E7=99=BB=E5=BD=95=E6=8E=88=E6=9D=83=E7=95=8C=E9=9D=A2=E7=9A=84?= =?UTF-8?q?=E5=85=B6=E4=BB=96=E5=BF=AB=E6=8D=B7=E7=99=BB=E9=99=86=E6=8C=89?= =?UTF-8?q?=E9=92=AE=202.=20=E4=BC=98=E5=8C=96uni-quick-login=E7=BB=84?= =?UTF-8?q?=E4=BB=B6=E4=BB=A3=E7=A0=81=20=203.=20=E8=B0=83=E6=95=B4?= =?UTF-8?q?=E9=9A=90=E7=A7=81=E6=94=BF=E7=AD=96=E5=8D=8F=E8=AE=AE=E6=A1=86?= =?UTF-8?q?=E5=8B=BE=E9=80=89=E9=80=BB=E8=BE=91=EF=BC=9A=E5=9C=A8=E7=99=BB?= =?UTF-8?q?=E9=99=86=E9=A1=B5=E9=9D=A2=E5=B7=B2=E5=8B=BE=E9=80=89=EF=BC=8C?= =?UTF-8?q?=E5=90=8C=E6=AD=A5=E5=8B=BE=E9=80=89=E3=80=82=E5=A6=82=E6=9E=9C?= =?UTF-8?q?=E6=B2=A1=E5=8B=BE=E9=80=89=E9=9C=80=E8=A6=81=E6=89=8B=E5=8A=A8?= =?UTF-8?q?=E5=8B=BE=E9=80=89=EF=BC=88=E4=B8=BA=E7=AC=A6=E5=90=88=E5=BA=94?= =?UTF-8?q?=E7=94=A8=E5=B8=82=E5=9C=BA=E4=B8=8A=E6=9E=B6=E8=A6=81=E6=B1=82?= =?UTF-8?q?=EF=BC=89=204.=20=E8=B0=83=E6=95=B4=E7=99=BB=E9=99=86=E9=A1=B5?= =?UTF-8?q?=E9=9A=90=E7=A7=81=E6=94=BF=E7=AD=96=E5=8D=8F=E8=AE=AE=E6=A1=86?= =?UTF-8?q?=E4=BD=8D=E7=BD=AE=E3=80=82=20=205.=20=E5=A2=9E=E5=BC=BA?= =?UTF-8?q?=E8=B7=AF=E7=94=B1=E6=8B=A6=E6=88=AA=EF=BC=8C=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E5=88=A4=E6=96=ADtoken=E6=98=AF=E5=90=A6=E8=BF=87=E6=9C=9F?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- App.vue | 2 +- changelog.md | 6 + common/appInit.js | 16 +- .../uni-quick-login/uni-quick-login.vue | 248 +++++++++--------- .../uni-send-sms-code/uni-send-sms-code.vue | 21 +- main.js | 1 - package.json | 2 +- .../ucenter/login-page/common/login-page.css | 6 +- .../ucenter/login-page/common/loginSuccess.js | 5 - pages/ucenter/login-page/index/index.vue | 51 +--- .../login-page/phone-code/phone-code.vue | 9 +- .../login-page/pwd-login/pwd-login.vue | 9 +- .../ucenter/login-page/register/register.vue | 5 + pages/ucenter/ucenter.vue | 6 +- pages/ucenter/userinfo/userinfo.vue | 2 +- store/modules/user.js | 6 +- uni-starter.config.js | 2 +- .../uni-config-center/uni-id/config.json | 2 +- .../cloudfunctions/uni-id-cf/index.js | 12 +- uni_modules_tools/change_after.js | 2 +- .../uni-config-center/uni-id/config.json | 2 +- 21 files changed, 203 insertions(+), 212 deletions(-) diff --git a/App.vue b/App.vue index 180858f9..e96fdc44 100644 --- a/App.vue +++ b/App.vue @@ -56,7 +56,7 @@ // #endif }, onShow: function() { - console.log('App Show') + console.log('App Show') }, onHide: function() { console.log('App Hide') diff --git a/changelog.md b/changelog.md index 63a81b6d..878f1737 100644 --- a/changelog.md +++ b/changelog.md @@ -1,3 +1,9 @@ +## 1.0.22(2021-06-22) +1. 新增一键登录授权界面的其他快捷登陆按钮 +2. 优化uni-quick-login组件代码 +3. 调整隐私政策协议框勾选逻辑:在登陆页面已勾选,同步勾选。如果没勾选需要手动勾选(为符合应用市场上架要求) +4. 调整登陆页隐私政策协议框位置。 +5. 增强路由拦截,新增判断token是否过期。 ## 1.0.21(2021-06-21) 优化:uni_modules模式使用uni-id-cf,方便uni-starter与uniCloud-admin的uni-id-cf同步更新。 ## 1.0.20(2021-06-18) diff --git a/common/appInit.js b/common/appInit.js index fc99de6e..605630e2 100644 --- a/common/appInit.js +++ b/common/appInit.js @@ -8,7 +8,7 @@ import interceptorChooseImage from '@/uni_modules/json-interceptor-chooseImage/j // #endif const db = uniCloud.database() export default function() { - + // #ifndef H5 setTimeout(()=>{ // #endif @@ -33,6 +33,7 @@ export default function() { code, // 错误码详见https://uniapp.dcloud.net.cn/uniCloud/clientdb?id=returnvalue message }) { + console.log('onDBError'); // 处理错误 console.log(code,message); if([ @@ -199,8 +200,6 @@ export default function() { tokenExpired }) } - - console.log(e.result.code); switch (e.result.code){ case 403: uni.navigateTo({ @@ -212,6 +211,11 @@ export default function() { url: "/pages/ucenter/login-page/index/index" }) break; + case 30203: + uni.navigateTo({ + url: "/pages/ucenter/login-page/index/index" + }) + break; case 50101: uni.showToast({ title: e.result.msg, @@ -235,11 +239,13 @@ export default function() { // console.log(e); //获取用户的token const token = uni.getStorageSync('uni_id_token') + //token是否已失效 + const tokenExpired = (uni.getStorageSync('uni_id_token_expired') - Date.now()) < 0 //获取当前页面路径(即url去掉"?"和"?"后的参数) const url = e.url.split('?')[0] //控制登录优先级 let pages = getCurrentPages(); - if ( + if ( //判断当前窗口是否为登陆页面,如果是则不重定向路由 url == '/pages/ucenter/login-page/index/index' && pages[pages.length - 1].route.split('/')[2]!='login-page' @@ -253,7 +259,7 @@ export default function() { } }else{ //拦截强制登录页面 - if (needLogin.includes(url) && token == '') { + if (needLogin.includes(url) && (token == ''||tokenExpired)) { uni.showToast({ title: '请先登录', icon: 'none' diff --git a/components/uni-quick-login/uni-quick-login.vue b/components/uni-quick-login/uni-quick-login.vue index c1ed8f81..1fd8f73a 100644 --- a/components/uni-quick-login/uni-quick-login.vue +++ b/components/uni-quick-login/uni-quick-login.vue @@ -18,6 +18,9 @@ computed: { loginConfig() { return getApp().globalData.config.router.login + }, + agreements() { + return getApp().globalData.config.about.agreements || [] } }, data() { @@ -35,126 +38,110 @@ "path": "/pages/ucenter/login-page/index/index" } ], - oauthServices: [] + oauthServices: [], + config: { + "weixin": { + "text": "微信登录", + "logo": "/static/uni-quick-login/wechat.png", + }, + "apple": { + "text": "苹果登录", + "logo": "/static/uni-quick-login/apple.png", + }, + "univerify": { + "text": "一键登录", + "logo": "/static/uni-quick-login/univerify.png", + }, + "qq": { + "text": "QQ登录",//暂未提供该登录方式的接口示例 + "logo": "/static/uni-quick-login/univerify.png", + }, + "xiaomi": { + "text": "小米登录",//暂未提供该登录方式的接口示例 + "logo": "/static/uni-quick-login/univerify.png", + }, + "sinaweibo": { + "text": "微博登录",//暂未提供该登录方式的接口示例 + "logo": "/static/uni-quick-login/univerify.png", + } + }, + univerifyStyle:{ //一键登录弹出窗的样式配置参数 + "fullScreen": true, // 是否全屏显示,true表示全屏模式,false表示非全屏模式,默认值为false。 + "backgroundColor": "#ffffff", // 授权页面背景颜色,默认值:#ffffff + "buttons": { // 自定义登陆按钮 + "iconWidth": "45px", // 图标宽度(高度等比例缩放) 默认值:45px + "list": [] + }, + "privacyTerms": { + "defaultCheckBoxState": false, // 条款勾选框初始状态 默认值: true + "textColor": "#BBBBBB", // 文字颜色 默认值:#BBBBBB + "termsColor": "#5496E3", // 协议文字颜色 默认值: #5496E3 + "prefix": "我已阅读并同意", // 条款前的文案 默认值:“我已阅读并同意” + "suffix": "并使用本机号码登录", // 条款后的文案 默认值:“并使用本机号码登录” + "privacyItems": [] + } + } } - }, + }, + watch: { + agree(agree) { + this.univerifyStyle.privacyTerms.defaultCheckBoxState = agree + } + }, props: { agree: { type: Boolean, default () { return false } - }, - config: { - type: Object, - default () { - return { - "weixin": { - "text": "微信登录", - "logo": "/static/uni-quick-login/wechat.png", - "isChecked": true - }, - "apple": { - "text": "苹果登录", - "logo": "/static/uni-quick-login/apple.png", - "isChecked": true - }, - "univerify": { - "text": "一键登录", - "logo": "/static/uni-quick-login/univerify.png", - "isChecked": true - }, - "qq": { - "text": "QQ登录", - "logo": "/static/uni-quick-login/univerify.png", - "isChecked": false //暂未提供该登录方式的接口示例 - }, - "xiaomi": { - "text": "小米登录", - "logo": "/static/uni-quick-login/univerify.png", - "isChecked": false //暂未提供该登录方式的接口示例 - }, - "sinaweibo": { - "text": "微博登录", - "logo": "/static/uni-quick-login/univerify.png", - "isChecked": false //暂未提供该登录方式的接口示例 - } - } - } - }, - univerifyStyle: { - type: Object, - default () { - return { //一键登录弹出窗的样式配置参数 - "fullScreen": true, // 是否全屏显示,true表示全屏模式,false表示非全屏模式,默认值为false。 - "backgroundColor": "#ffffff", // 授权页面背景颜色,默认值:#ffffff - } - } - }, - }, - created() { - // console.log('loginConfig', this.loginConfig); - // console.log('this.getRoute(1)', this.getRoute(1)); - let servicesList = this.servicesList - //去掉当前页面对应的登录选项 - for (var i = 0; i < servicesList.length; i++) { - if (servicesList[i].path == this.getRoute(1)) { - servicesList.splice(i, 1) - } } - //去掉配置项中不存在的项 - for (var i = 0; i < servicesList.length; i++) { - if (!this.loginConfig.includes(servicesList[i].id)) { - console.log('去掉配置项中不存在的项', servicesList[i].id); - servicesList.splice(i, 1) - } - } - // console.log('servicesList', servicesList); }, - mounted() { - //获取当前环境能用的快捷登录方式 - // #ifdef APP-PLUS - plus.oauth.getServices(oauthServices => { - this.oauthServices = oauthServices - oauthServices.forEach(({ - id - }) => { - if (this.config[id].isChecked && this.loginConfig.includes(id)) { - if (id == 'weixin') { - if (!plus.runtime.isApplicationExist({ - pname: 'com.tencent.mm', - action: 'weixin://' - })) { - console.log("微信应用未安装"); - return - } - } - this.servicesList.push({ - ...this.config[id], - id - }) - } - }) - // console.log('oauthServices',oauthServices); - }, err => { - uni.hideLoading() - uni.showModal({ - title: '获取服务供应商失败:' + JSON.stringify(err), - showCancel: false, - confirmText: '知道了' - }); - console.error('获取服务供应商失败:' + JSON.stringify(err)); - }) - // #endif - // #ifdef MP-WEIXIN - let id = 'weixin' - if (this.loginConfig.includes(id)) { - this.servicesList.push({ - ...this.config[id], - id - }) - } + async created() { + this.univerifyStyle.privacyTerms.privacyItems = this.agreements + + let servicesList = this.servicesList + //获取当前环境能用的快捷登录方式 + // #ifdef MP-WEIXIN + let id = 'weixin' + if (this.loginConfig.includes(id)) { + servicesList.push({ + ...this.config[id], + id + }) + } // #endif + // #ifdef APP-PLUS + this.oauthServices = await new Promise((callBack)=>{ + plus.oauth.getServices(oauthServices => { + callBack(oauthServices.filter(({nativeClient,id})=>nativeClient&&this.loginConfig.includes(id))) + //只返回1.应用支持 && 2.手机已安装对应客户端 && 3.uni-starter.config.js配置项中存在的快捷登录方式 + }, err => { + callBack([]) + uni.hideLoading() + uni.showModal({ + title: '获取服务供应商失败:' + JSON.stringify(err), + showCancel: false, + confirmText: '知道了' + }); + console.error('获取服务供应商失败:' + JSON.stringify(err)); + }) + }) + // #endif + //添加已配置且可用的第三方快捷登陆项 + servicesList = servicesList.concat(this.oauthServices.map( ({id})=>{ + return {...this.config[id],id} + })) + //设置一键登录功能底下的快捷登陆按钮 + servicesList.forEach(({id,logo})=>{ + if(id != 'univerify'){ + this.univerifyStyle.buttons.list.push({"iconPath":logo,"provider":id}) + } + }) + //去掉当前页面对应的登录选项 + this.servicesList = servicesList.filter(item=>{ + return item.path != this.getRoute(1) + }) + console.log('servicesList',servicesList,this.servicesList); }, methods: { ...mapMutations({ @@ -179,7 +166,7 @@ } }, login_before(type, navigateBack = true) { - if (!this.agree) { + if (!this.agree&&type!='univerify') { return uni.showToast({ title: '你未同意隐私政策协议', icon: 'none' @@ -218,7 +205,7 @@ "provider": type, "univerifyStyle": this.univerifyStyle, complete: (e) => { - console.log(9527, e); + console.log(e); }, success: async e => { console.log(e); @@ -249,6 +236,12 @@ icon: 'none' }); } + if (err.errMsg) { + uni.showToast({ + title: "一键登录:" + err.errMsg, + icon: 'none' + }); + } switch (err.errCode) { case 30002: console.log('在一键登录界面,点击其他登录方式'); @@ -272,17 +265,14 @@ title: '点击了第三方登陆', icon: 'none' }); - switch (err.index) { - case 0: - this.login_before('weixin', false) - break; - case 1: - this.login_before('apple', false) - break; - default: - break; + console.log('点击了第三方登陆,provider:',err.provider); + let {path} = this.servicesList.find(item=>item.id==err.provider)||{} + console.log('path',path); + if(path&&path!=this.getRoute(1)){ //存在路径,且并不是当前已经打开的路径 + this.to(path) + }else{ + this.login_before(err.provider) } - break; default: console.log(9527, err); @@ -297,12 +287,13 @@ console.log({ params, type - }); - let action = 'loginBy'+ type.trim().toLowerCase().replace(type[0], type[0].toUpperCase()) + }); + let action = 'loginBy' + type.trim().toLowerCase().replace(type[0], type[0].toUpperCase()) uniCloud.callFunction({ name: 'uni-id-cf', data: { - action,params + action, + params }, success: ({ result @@ -316,12 +307,17 @@ loginSuccess(result) delete result.userInfo.token this.setUserInfo(result.userInfo) + } else { + uni.showModal({ + content: result.msg, + showCancel: false + }); } }, complete: () => { uni.hideLoading() } - }) + }) }, async getUserInfo(e) { return new Promise((resolve, reject) => { diff --git a/components/uni-send-sms-code/uni-send-sms-code.vue b/components/uni-send-sms-code/uni-send-sms-code.vue index d58cf743..7df82fa6 100644 --- a/components/uni-send-sms-code/uni-send-sms-code.vue +++ b/components/uni-send-sms-code/uni-send-sms-code.vue @@ -85,13 +85,20 @@ }, success: ({result}) => { console.log(result); - uni.showToast({ - title: "短信验证码发送成功", - icon: 'none' - }); - this.reverseNumber = Number(this.count); - this.getCode(); - this.$emit('getCode'); + if(result.code===0){ + uni.showToast({ + title: "短信验证码发送成功", + icon: 'none' + }); + this.reverseNumber = Number(this.count); + this.getCode(); + this.$emit('getCode'); + }else{ + uni.showModal({ + content: result.msg, + showCancel: false + }); + } } }) }, diff --git a/main.js b/main.js index 4b427584..9139f7d4 100644 --- a/main.js +++ b/main.js @@ -6,7 +6,6 @@ import openApp from './common/openApp.js'; Vue.config.productionTip = false openApp(); App.mpType = 'app' - const app = new Vue({ ...App, store diff --git a/package.json b/package.json index 2a9e86cf..2a0a1e29 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "id": "uni-starter", "displayName": "uni-starter", - "version": "1.0.21", + "version": "1.0.22", "description": "云端一体应用快速开发基本项目模版", "keywords": [ "uni-starter", diff --git a/pages/ucenter/login-page/common/login-page.css b/pages/ucenter/login-page/common/login-page.css index 579819e0..0fa69907 100644 --- a/pages/ucenter/login-page/common/login-page.css +++ b/pages/ucenter/login-page/common/login-page.css @@ -5,7 +5,7 @@ } .input-box{ padding:0 15px; - margin-top: 15px; + margin-bottom: 10px; background-color: #F8F8F8; border-radius: 6px; font-size: 28rpx; @@ -17,8 +17,8 @@ color: #FFFFFF; } .input-box,.get-code{ - height: 50px; - line-height: 50px; + height: 45px; + line-height: 45px; } .title{ text-align: center; diff --git a/pages/ucenter/login-page/common/loginSuccess.js b/pages/ucenter/login-page/common/loginSuccess.js index d5d16835..edaef77c 100644 --- a/pages/ucenter/login-page/common/loginSuccess.js +++ b/pages/ucenter/login-page/common/loginSuccess.js @@ -4,11 +4,6 @@ export default function(result){ icon: 'none' }); console.log('登录成功',result); - 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(); diff --git a/pages/ucenter/login-page/index/index.vue b/pages/ucenter/login-page/index/index.vue index 279bfd0f..78fda3ef 100644 --- a/pages/ucenter/login-page/index/index.vue +++ b/pages/ucenter/login-page/index/index.vue @@ -2,15 +2,15 @@ 登录后即可展示自己 - - 未注册的手机号验证通过后将自动注册 - + @@ -20,59 +20,19 @@ data() { return { phone: "", - agree: false, - univerifyStyle: { - "fullScreen": true, // 是否全屏显示,true表示全屏模式,false表示非全屏模式,默认值为false。 - "backgroundColor": "#ffffff", // 授权页面背景颜色,默认值:#ffffff - "buttons": { // 自定义登陆按钮 - "iconWidth": "45px", // 图标宽度(高度等比例缩放) 默认值:45px - "list": [] - }, - "privacyTerms": { - "defaultCheckBoxState": "true", // 条款勾选框初始状态 默认值: true - "textColor": "#BBBBBB", // 文字颜色 默认值:#BBBBBB - "termsColor": "#5496E3", // 协议文字颜色 默认值: #5496E3 - "prefix": "我已阅读并同意", // 条款前的文案 默认值:“我已阅读并同意” - "suffix": "并使用本机号码登录", // 条款后的文案 默认值:“并使用本机号码登录” - "privacyItems": [] - } - } + agree: false } }, computed: { isPhone() { return /^1\d{10}$/.test(this.phone); - }, - agreements() { - return getApp().globalData.config.about.agreements || [] } }, onLoad(e) { - uni.getProvider({ - service: 'oauth', - success: res => { - if (~res.provider.indexOf('weixin')&&plus.runtime.isApplicationExist({ - pname: 'com.tencent.mm', - action: 'weixin://' - })) { - this.univerifyStyle.buttons.list.push({ - "iconPath": "/static/uni-quick-login/wechat.png" - }) - } - if (~res.provider.indexOf('apple')) { - this.univerifyStyle.buttons.list.push({ - "iconPath": "/static/uni-quick-login/apple.png" - }) - } - } - }); - - //是否优先启动一键登录。即:页面一加载就启动一键登录 univerify_first = e.univerify_first //#ifdef APP-PLUS if (univerify_first) { - this.univerifyStyle.privacyTerms.privacyItems = this.agreements const pages = getCurrentPages(); currentWebview = pages[pages.length - 1].$getAppWebview(); currentWebview.setStyle({ @@ -85,7 +45,6 @@ //#ifdef APP-PLUS if (univerify_first) { // console.log('开始一键登录'); - this.agree = true setTimeout(() => { this.$refs.uniQuickLogin.login_before('univerify') }, 100) diff --git a/pages/ucenter/login-page/phone-code/phone-code.vue b/pages/ucenter/login-page/phone-code/phone-code.vue index 70a8dbb9..731e37f8 100644 --- a/pages/ucenter/login-page/phone-code/phone-code.vue +++ b/pages/ucenter/login-page/phone-code/phone-code.vue @@ -52,7 +52,14 @@ }, }, success: ({result}) => { - this.loginSuccess(result) + if(result.code === 0){ + this.loginSuccess(result) + }else{ + uni.showModal({ + content: result.msg, + showCancel: false + }); + } } }) diff --git a/pages/ucenter/login-page/pwd-login/pwd-login.vue b/pages/ucenter/login-page/pwd-login/pwd-login.vue index a6a7c1ea..ac17d007 100644 --- a/pages/ucenter/login-page/pwd-login/pwd-login.vue +++ b/pages/ucenter/login-page/pwd-login/pwd-login.vue @@ -2,13 +2,13 @@ 用户名密码登录 - - + + @@ -108,6 +108,11 @@ success: ({result}) => { if (result.code === 0) { this.captchaBase64 = result.captchaBase64 + }else{ + uni.showModal({ + content: result.msg, + showCancel: false + }); } } }) diff --git a/pages/ucenter/login-page/register/register.vue b/pages/ucenter/login-page/register/register.vue index 1f8f4a01..38193998 100644 --- a/pages/ucenter/login-page/register/register.vue +++ b/pages/ucenter/login-page/register/register.vue @@ -73,6 +73,11 @@ import mixin from '../common/login-page.mixin.js'; console.log(result); if(result.code === 0){ this.loginSuccess(result) + }else{ + uni.showModal({ + content: result.msg, + showCancel: false + }); } } }) diff --git a/pages/ucenter/ucenter.vue b/pages/ucenter/ucenter.vue index 020a5278..67751e1b 100644 --- a/pages/ucenter/ucenter.vue +++ b/pages/ucenter/ucenter.vue @@ -1,5 +1,5 @@