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

新增微信登录功能

上级 f4a5a96b
......@@ -137,12 +137,12 @@
"enable" : false
},
"devServer" : {
"port" : -11,
"port" : 8080,
"disableHostCheck" : true,
"https" : false
},
"router" : {
"mode" : "history"
"mode" : "hash"
}
},
"_spaceID" : "9f641af8-e860-44e5-b18f-f68dd8fe3fe4",
......
{
"pages": [ //pages数组中第一项表示应用启动页,参考:https://uniapp.dcloud.io/collocation/pages
{
"path" : "pages/test/test",
"style" :
{
"navigationBarTitleText": "",
"enablePullDownRefresh": false
}
},
{
"path": "pages/index/index",
"path": "pages/index/index",
"style": {
"navigationBarTitleText": "uni-app"
}
......@@ -39,7 +47,7 @@
{
"path": "uni_modules/uni-id-pages/pages/login/login-withpwd",
"style": {
"navigationBarTitleText": ""
"navigationBarTitleText": ""
}
},
{
......@@ -80,7 +88,10 @@
"navigationBarTextStyle": "black",
"navigationBarTitleText": "uni-app",
"navigationBarBackgroundColor": "#FFF",
"backgroundColor": "#F8F8F8"
"backgroundColor": "#F8F8F8",
/* #ifdef H5 */
"navigationStyle": "custom"
/* #endif */
}
,"condition" : { //模式配置,仅开发期间生效
"current": 0, //当前激活的模式(list 的索引项)
......
<template>
<view>
<navigator url="/pages/index/index">index</navigator>
</view>
</template>
<script>
export default {
data() {
return {
}
},
methods: {
}
}
</script>
<style>
</style>
## 1.0.7(2022-07-19)
- 新增 web移动端,微信内基于公众号登录
- 新增 web电脑端,基于微信开放平台的微信扫码登录
- 未安装
- 新增 登录成功(全局)回调事件:`uni-id-pages-login-success`,支持通过[uni.$on](https://uniapp.dcloud.net.cn/api/window/communication.html#on)监听;
## 1.0.7(2022-07-19)
- 修复 uni-id-co接口 logout时没有删除token的Bug
## 1.0.6(2022-07-13)
......
......@@ -4,7 +4,7 @@ let mixin = {
data() {
return {
config,
isMounted:false
isMounted: false
}
},
onUnload() {
......@@ -15,9 +15,33 @@ let mixin = {
mounted() {
this.isMounted = true;
},
onLoad(e) {
if (e.is_weixin_redirect) {
uni.showLoading({
mask: true
})
if( window.location.href.includes('#') ){
// 将url通过 ? 分割获取后面的参数字符串 再通过 & 将每一个参数单独分割出来
let paramsArr = window.location.href.split('?')[1].split('&')
paramsArr.forEach(item=>{
let arr = item.split('=')
if(arr[0] == 'code'){
e.code = arr[1]
}
})
}
this.$nextTick(n => {
console.log(this.$refs.uniFabLogin);
this.$refs.uniFabLogin.login({
code:e.code
}, 'weixin')
})
}
},
computed: {
needAgreements(){
if(this.isMounted){
needAgreements() {
if (this.isMounted) {
if (this.$refs.agreements) {
return this.$refs.agreements.needAgreements
} else {
......@@ -27,7 +51,7 @@ let mixin = {
},
agree: {
get() {
if(this.isMounted){
if (this.isMounted) {
if (this.$refs.agreements) {
return this.$refs.agreements.isAgree
} else {
......@@ -38,7 +62,7 @@ let mixin = {
set(agree) {
if (this.$refs.agreements) {
this.$refs.agreements.isAgree = agree
}else{
} else {
console.log('不存在 隐私政策协议组件');
}
}
......@@ -48,6 +72,6 @@ let mixin = {
loginSuccess(e) {
loginSuccess(e)
}
}
}
}
export default mixin
export default mixin
......@@ -14,16 +14,24 @@ export default function(e = {}) {
}
if (autoBack) {
let delta = 0; //判断需要返回几层
let pages = getCurrentPages();
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);
// #ifdef H5
if(e.loginType == 'weixin'){
console.log('window.history',window.history);
return window.history.go(-3)
}
// #endif
uni.navigateBack({
delta
})
console.log('判断需要返回几层:', delta);
// uni.navigateBack({
// delta
// })
}
}
......@@ -229,17 +229,27 @@
// #ifdef H5
if(type == 'weixin'){
console.log('开始微信网页登录');
location.href = `https://open.weixin.qq.com/connect/qrconnect?appid=wx4dcf96ab6af4c5e8
&redirect_uri=${encodeURIComponent('http://test.0577app.com/uni_modules/uni-id-pages/pages/login/login-withoutpwd?type=weixin_redirect')}
&response_type=code&scope=snsapi_login&state=STATE#wechat_redirect`
/*location.href = `https://open.weixin.qq.com/connect/oauth2/authorize?
appid=wx32b2580e30ef8555
&redirect_uri=${encodeURIComponent('http://test.0577app.com/uni_modules/uni-id-pages/pages/login/login-withoutpwd?type=weixin_redirect')}
&response_type=code
&scope=snsapi_userinfo
&state=STATE&connect_redirect=1#wechat_redirect`;*/
let redirectUrl = location.protocol +'//'+
document.domain +
(window.location.href.includes('#')?'/#':'') +
'/uni_modules/uni-id-pages/pages/login/login-withoutpwd?is_weixin_redirect=true&type=weixin'
let ua = window.navigator.userAgent.toLowerCase();
if (ua.match(/MicroMessenger/i) == 'micromessenger'){
console.log('在微信公众号内');
return window.open(`https://open.weixin.qq.com/connect/oauth2/authorize?
appid=wx32b2580e30ef8555
&redirect_uri=${encodeURIComponent(redirectUrl)}
&response_type=code
&scope=snsapi_userinfo
&state=STATE&connect_redirect=1#wechat_redirect`);
}else{
console.log('非微信公众号内');
return location.href = `https://open.weixin.qq.com/connect/qrconnect?appid=wx4dcf96ab6af4c5e8
&redirect_uri=${encodeURIComponent(redirectUrl)}
&response_type=code&scope=snsapi_login&state=STATE#wechat_redirect`
}
}
// #endif
......@@ -426,6 +436,9 @@
})
return this.$refs.userProfile.open(result.uid)
}
// #endif
// #ifdef H5
result.loginType = type
// #endif
loginSuccess(result)
})
......@@ -489,7 +502,7 @@
width: 750rpx;
justify-content: space-around;
position: fixed;
bottom: 10rpx;
bottom: 10rpx;
left: 0;
}
......@@ -509,7 +522,7 @@
align-items: center;
height: 200rpx;
cursor: pointer;
}
}
.logo {
width: 60rpx;
......
......@@ -198,7 +198,7 @@
top: 0;
right: 8px;
width: 260rpx;
max-width: 130px;
max-width: 100px;
height: 44px;
/* #ifndef APP-NVUE */
display: flex;
......@@ -229,7 +229,7 @@
}
.box ::v-deep .content-clear-icon {
margin-right: 100px;
margin-right: 110px;
}
.box {
......
......@@ -96,11 +96,4 @@ export default async function() {
}
})
}
//5.未启用uni统计,但使用uni-id-pages+uni-push2.0,onLaunch时上报device_id至服务端
if(uni.report == undefined){
if (uni.getPushClientId) {
}
}
}
{
"name": "uni-id-pages",
"version": "1.0.7",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"version": "1.0.7",
"dependencies": {
"jweixin-module": "^1.6.0"
},
"engines": {
"HBuilderX": "^3.4.17"
}
},
"node_modules/jweixin-module": {
"version": "1.6.0",
"resolved": "https://registry.npmjs.org/jweixin-module/-/jweixin-module-1.6.0.tgz",
"integrity": "sha512-dGk9cf+ipipHmtzYmKZs5B2toX+p4hLyllGLF6xuC8t+B05oYxd8fYoaRz0T30U2n3RUv8a4iwvjhA+OcYz52w=="
}
},
"dependencies": {
"jweixin-module": {
"version": "1.6.0",
"resolved": "https://registry.npmjs.org/jweixin-module/-/jweixin-module-1.6.0.tgz",
"integrity": "sha512-dGk9cf+ipipHmtzYmKZs5B2toX+p4hLyllGLF6xuC8t+B05oYxd8fYoaRz0T30U2n3RUv8a4iwvjhA+OcYz52w=="
}
}
}
......@@ -53,15 +53,6 @@
async onLoad(e) {
console.log(e);
let type = e.type
if(type == 'weixin_redirect'){
this.$nextTick(n=>{
console.log(this.$refs.uniFabLogin);
this.$refs.uniFabLogin.login({code:e.code},'weixin')
})
}
// console.log({type});
this.type = type
if(type != 'univerify'){
......
......@@ -3,7 +3,7 @@
"required": [],
"permission": {
"read": false,
"create": false,
"create": true,
"update": false,
"delete": false
},
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册