提交 21b2a433 编写于 作者: C chenruilong

feat: 华为元服务登录

上级 396d84c6
......@@ -34,6 +34,9 @@
}, {
"value": "huawei",
"text": "华为登录"
}, {
"value": "huaweiMobile",
"text": "华为账号一键登录"
}]
}
},
......
......@@ -6,7 +6,7 @@
mode="widthFix"></image>
</view>
<input @blur="focusCaptchaInput = false" :focus="focusCaptchaInput" type="text" class="captcha"
:inputBorder="false" maxlength="4" v-model="val" placeholder="请输入验证码">
:inputBorder="false" maxlength="4" v-model="val" placeholder="请输入验证码"></input>
</view>
</template>
......
## 1.1.23(2024-11-05)
- uni-id-co 修复 没有配置敏感信息解密密钥时导致登录报错的问题
## 1.1.24(2024-12-20)
- 新增 支持华为元服务登录
## 1.1.23(2024-11-05)
- uni-id-co 修复 没有配置敏感信息解密密钥时导致登录报错的问题
## 1.1.22(2024-09-13)
- 注册登录时去除字符串两端的空白字符
- 删除static目录下重复资源
......
......@@ -33,7 +33,7 @@
import config from '@/uni_modules/uni-id-pages/config.js'
let retryFun = ()=>console.log('为定义')
/**
* uni-id-pages-agreements
* uni-id-pages-agreements
* @description 用户服务协议和隐私政策条款组件
* @property {String,Boolean} scope = [register|login] 作用于哪种场景如:register 注册(包括登录并注册,如:微信登录、苹果登录、短信验证码登录)、login 登录。默认值为:register
*/
......@@ -74,12 +74,22 @@
popup(Fun){
this.needPopupAgreements = true
// this.needAgreements = true
//::TODO 鸿蒙元服务暂不支持 createAnimation,等支持后再打开
// #ifdef MP-HARMONY
return uni.showModal({
title: "提示",
content: `请先阅读并同意${this.agreements.map(item=>`“${item.title}”`).join('')}`,
})
// #endif
// #ifndef MP-HARMONY
this.$nextTick(()=>{
if(Fun){
retryFun = Fun
}
this.$refs.popupAgreement.open()
})
// #endif
},
navigateTo({
url,
......@@ -100,7 +110,7 @@
this.$emit('setAgree', this.isAgree)
}
},
created() {
created() {
this.needAgreements = (config?.agreements?.scope || []).includes(this.scope)
},
data() {
......@@ -145,7 +155,7 @@
color: #04498c;
cursor: pointer;
}
.checkbox-box ::v-deep .uni-checkbox-input{
border-radius: 100%;
}
......@@ -155,13 +165,13 @@
color: #FFFFFF !important;
background-color: $uni-color-primary;
}
.content{
flex-wrap: wrap;
flex-direction: row;
}
.root ::v-deep .uni-popup__error{
color: #333333;
}
.root ::v-deep .uni-popup__error{
color: #333333;
}
</style>
......@@ -62,22 +62,29 @@
"text": "微信登录",
"logo": "/uni_modules/uni-id-pages/static/login/uni-fab-login/weixin.png",
},
{
"id": "huawei",
"text": "华为登录",
"logo": "/uni_modules/uni-id-pages/static/login/uni-fab-login/huawei.png",
"path": "/uni_modules/uni-id-pages/pages/login/login-withoutpwd?type=huawei"
},
{
"id": "huaweiMobile",
"text": "华为账号一键登录",
"logo": "/uni_modules/uni-id-pages/static/login/uni-fab-login/huawei.png",
"path": "/uni_modules/uni-id-pages/pages/login/login-withoutpwd?type=huaweiMobile"
},
// #ifndef MP-WEIXIN
{
"id": "apple",
"text": "苹果登录",
"logo": "/uni_modules/uni-id-pages/static/app/uni-fab-login/apple.png",
"logo": "/uni_modules/uni-id-pages/static/uni-fab-login/apple.png",
},
{
"id": "univerify",
"text": "一键登录",
"logo": "/uni_modules/uni-id-pages/static/app/uni-fab-login/univerify.png",
},
{
"id": "huawei",
"text": "华为登录",
"logo": "/uni_modules/uni-id-pages/static/app/uni-fab-login/univerify.png",
},
{
"id": "taobao",
"text": "淘宝登录", //暂未提供该登录方式的接口示例
......@@ -207,7 +214,7 @@
return '/' + pages[pages.length - n].route
},
toPage(path,index = 0) {
//console.log('比较', this.getRoute(1),this.getRoute(2), path)
console.log('比较', this.getRoute(1),this.getRoute(2), path)
if (this.getRoute(1) == path.split('?')[0] && this.getRoute(1) ==
'/uni_modules/uni-id-pages/pages/login/login-withoutpwd') {
//如果要被打开的页面已经打开,且这个页面是 /uni_modules/uni-id-pages/pages/index/index 则把类型参数传给他
......@@ -238,7 +245,7 @@
}
},
async login_before(type, navigateBack = true, options = {}) {
console.log(type);
console.log(type, options);
//提示空实现
if (["qq",
"xiaomi",
......@@ -256,15 +263,17 @@
});
}
console.log('检查当前环境是否支持这种登录方式')
//检查当前环境是否支持这种登录方式
// #ifdef APP
let isAppExist = true
await new Promise((callback) => {
console.log('uni.getProvider', uni.getProvider)
uni.getProvider({
service: 'oauth',
success: (res) => {
const provider = res.providers.find(item => item.id === type)
console.log('res', res)
if (provider) {
isAppExist = provider?.isAppExist ?? true
callback()
......@@ -282,6 +291,7 @@
})
})
// #endif
if (
// #ifdef APP
!isAppExist
......@@ -347,7 +357,11 @@
}
}
// #endif
console.log('login ----')
uni.showLoading({
// #ifdef MP-HARMONY
title: "正在登录",
// #endif
mask: true
})
......@@ -425,7 +439,7 @@
})
}
if (type === 'weixinMobile') {
if (type === 'weixinMobile' || type === 'huaweiMobile') {
return this.login({
phoneCode: options.phoneNumberCode
}, type)
......@@ -451,7 +465,12 @@
} : e.authResult, type)
},
fail: async (err) => {
console.log(JSON.stringify(err));
console.error(JSON.stringify(err));
uni.showModal({
content: `登录失败; code: ${err.errCode || -1}`,
confirmText: "知道了",
showCancel: false
});
uni.hideLoading()
}
})
......@@ -570,6 +589,6 @@
margin-top: 6px;
color: #999;
font-size: 10px;
width: 70px;
width: 80px;
}
</style>
......@@ -19,12 +19,18 @@ export default {
// #ifdef APP
'univerify',
// #endif
// #ifndef MP-HARMONY
'weixin',
// #endif
'username',
// #ifdef APP
'apple',
// #endif
'smsCode'
'smsCode',
// #ifdef APP-HARMONY || MP-HARMONY
'huawei',
'huaweiMobile'
// #endif
],
// 政策协议
agreements: {
......
{
"id": "uni-id-pages",
"displayName": "uni-id-pages",
"version": "1.1.23",
"version": "1.1.24",
"description": "云端一体简单、统一、可扩展的用户中心页面模版",
"keywords": [
"用户管理",
......
......@@ -7,13 +7,20 @@
<!-- 顶部文字 -->
<text class="title">请选择登录方式</text>
<!-- 快捷登录框 当url带参数时有效 -->
<template v-if="['apple','weixin', 'weixinMobile', 'huawei'].includes(type)">
<template v-if="['apple','weixin', 'weixinMobile', 'huawei', 'huaweiMobile'].includes(type)">
<text class="tip">将根据第三方账号服务平台的授权范围获取你的信息</text>
<view class="quickLogin">
<image v-if="type !== 'weixinMobile'" @click="quickLogin" :src="imgSrc" mode="widthFix"
<image v-if="type !== 'weixinMobile' && type !== 'huaweiMobile'" @click="quickLogin" :src="imgSrc" mode="widthFix"
class="quickLoginBtn"></image>
<button v-else type="primary" open-type="getPhoneNumber" @getphonenumber="quickLogin"
class="uni-btn">微信授权手机号登录</button>
<view v-else style="position: relative">
<button v-if="type ==='weixinMobile'" type="primary" open-type="getPhoneNumber" @getphonenumber="quickLogin"
class="uni-btn">微信授权手机号登录</button>
<button v-if="type === 'huaweiMobile'" open-type="getPhoneNumber" @getphonenumber="quickLogin"
class="quickLoginBtn" style="padding: 0; display: flex">
<image :src="imgSrc" mode="widthFix"></image>
</button>
<view v-if="this.needAgreements && !this.agree" class="mobile-login-agreement-layer" @click="showAgreementModal"></view>
</view>
<uni-id-pages-agreements scope="register" ref="agreements"></uni-id-pages-agreements>
</view>
</template>
......@@ -57,7 +64,8 @@
const images = {
weixin: '/uni_modules/uni-id-pages/static/login/weixin.png',
apple: '/uni_modules/uni-id-pages/static/app/apple.png',
huawei: '/uni_modules/uni-id-pages/static/app/huawei.png'
huawei: '/uni_modules/uni-id-pages/static/login/huawei.png',
huaweiMobile: '/uni_modules/uni-id-pages/static/login/huawei-mobile.png',
}
return images[this.type]
}
......@@ -73,7 +81,7 @@
}
this.$nextTick(() => {
//关闭重复显示的登录快捷方式
if (['weixin', 'apple'].includes(type)) {
if (['weixin', 'apple', 'huawei', 'huaweiMobile'].includes(type)) {
this.$refs.uniFabLogin.servicesList = this.$refs.uniFabLogin.servicesList.filter(item =>
item.id != type)
}
......@@ -133,14 +141,17 @@
"top": 0
})
},
showAgreementModal () {
this.$refs.agreements.popup()
},
quickLogin(e) {
let options = {}
console.log(e)
if (e.detail?.code) {
options.phoneNumberCode = e.detail.code
}
if (this.type === 'weixinMobile' && !e.detail?.code) return
if ((this.type === 'weixinMobile' || this.type === 'huaweiMobile') && !e.detail?.code) return
this.$refs.uniFabLogin.login_before(this.type, true, options)
},
......@@ -187,6 +198,13 @@
}
}
.mobile-login-agreement-layer {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
.uni-content,
.quickLogin {
/* #ifndef APP-NVUE */
......@@ -242,6 +260,9 @@
.quickLoginBtn {
margin: 20px 0;
width: 450rpx;
background-color: transparent;
border: none;
box-shadow: none;
/* #ifndef APP-NVUE */
max-width: 230px;
/* #endif */
......
......@@ -12,8 +12,8 @@
:inputBorder="false" v-model="username" placeholder="请输入手机号/用户名/邮箱" trim="all" />
</uni-forms-item>
<uni-forms-item name="password">
<uni-easyinput :focus="focusPassword" @blur="focusPassword = false" class="input-box" clearable
type="password" :inputBorder="false" v-model="password" placeholder="请输入密码" trim="all" />
<uni-easyinput :focus="focusPassword" @blur="focusPassword = false" class="input-box" clearable
type="password" :inputBorder="false" v-model="password" placeholder="请输入密码" trim="all" />
</uni-forms-item>
</uni-forms>
<uni-captcha v-if="needCaptcha" focus ref="captcha" scene="login-by-pwd" v-model="captcha" />
......
......@@ -34,7 +34,8 @@ const {
loginByQQ,
loginByApple,
loginByWeixinMobile,
loginByHuawei
loginByHuawei,
loginByHuaweiMobile
} = require('./module/login/index')
const {
logout
......@@ -50,7 +51,10 @@ const {
unbindWeixin,
unbindAlipay,
unbindQQ,
unbindApple
unbindApple,
bindHuawei,
unbindHuawei,
bindMobileByHuawei
} = require('./module/relate/index')
const {
setPwd,
......@@ -419,6 +423,7 @@ module.exports = {
loginByApple,
loginByWeixinMobile,
loginByHuawei,
loginByHuaweiMobile,
/**
* 用户退出登录
* @tutorial https://uniapp.dcloud.net.cn/uniCloud/uni-id-pages.html#logout
......@@ -694,5 +699,8 @@ module.exports = {
* @param {Boolean} params.decryptData 是否解密数据
* @returns
*/
getRealNameInfo
getRealNameInfo,
bindHuawei,
unbindHuawei,
bindMobileByHuawei
}
function getHuaweiPlatform () {
const platform = this.clientPlatform
switch (platform) {
case 'app':
case 'app-harmony':
return 'app-harmony'
case 'mp-harmony':
return 'mp-harmony'
default:
throw new Error('Unsupported weixin platform')
}
}
module.exports = {
getHuaweiPlatform
}
......@@ -17,5 +17,6 @@ module.exports = {
loginByFacebook: require('./login-by-facebook'),
loginByGoogle: require('./login-by-google'),
loginByWeixinMobile: require('./login-by-weixin-mobile'),
loginByHuawei: require('./login-by-huawei')
loginByHuawei: require('./login-by-huawei'),
loginByHuaweiMobile: require('./login-by-huawei')
}
......@@ -9,10 +9,8 @@ const {
postUnifiedLogin
} = require('../../lib/utils/unified-login')
const {
generateWeixinCache,
getWeixinPlatform,
saveWeixinUserKey,
} = require('../../lib/utils/weixin')
getHuaweiPlatform,
} = require('../../lib/utils/huawei')
const {
LOG_TYPE
} = require('../../common/constants')
......@@ -21,33 +19,59 @@ const {initHuawei} = require("../../lib/third-party");
/**
* 华为登录
* @tutorial https://uniapp.dcloud.net.cn/uniCloud/uni-id-pages.html#login-by-weixin
* @tutorial https://uniapp.dcloud.net.cn/uniCloud/uni-id-pages.html#login-by-huawei
* @param {Object} params
* @param {String} params.code 微信登录返回的code
* @param {String} params.code 华为登录返回的code
* @param {String} params.inviteCode 邀请码
* @returns
*/
module.exports = async function (params = {}) {
const schema = {
code: 'string',
code: {
type: 'string',
required: false
},
phoneCode: {
type: 'string',
required: false
},
inviteCode: {
type: 'string',
required: false
}
}
this.middleware.validate(params, schema)
const {
code,
inviteCode
} = params
if (!params.code && !params.phoneCode) {
throw {
errCode: ERROR.PARAM_REQUIRED,
errMsgValue: {
param: 'code or phoneCode'
}
}
}
const {
appId
} = this.getUniversalClientInfo()
const huaweiPlatform = getHuaweiPlatform.call(this)
const code = params.code || params.phoneCode
const huaweiApi = initHuawei.call(this)
let accountResult
let accessToken
try {
const {accessToken} = await huaweiApi.getUserAccessToken(code)
accountResult = await huaweiApi.getAccessTokenInfo(accessToken)
accountResult.accessToken = accessToken
const res = await huaweiApi.getUserAccessToken(code)
if (res.errCode !== 0) {
console.error(res)
throw new Error(res.errMsg)
}
accessToken = res.accessToken
} catch (error) {
console.error(error)
await this.middleware.uniIdLog({
......@@ -60,33 +84,39 @@ module.exports = async function (params = {}) {
}
const {
openId,
unionId,
accessToken
} = accountResult
openID: openId,
unionID: unionId,
purePhoneNumber: mobile,
displayName: nickname,
headPictureURL: avatar,
} = await huaweiApi.getUserInfo(accessToken)
const {
type,
user
} = await preUnifiedLogin.call(this, {
user: {
huawei_openid: openId,
huawei_unionid: unionId
huawei_openid: {
[huaweiPlatform]: openId
},
huawei_unionid: unionId,
mobile
}
})
const extraData = {
huawei_openid: openId,
huawei_openid: {
[`${huaweiPlatform}_${appId}`]: openId
},
huawei_unionid: unionId
}
if (mobile) {
extraData.mobile = mobile
extraData.mobile_confirmed = 1
}
if (type === 'register') {
const res = await huaweiApi.getUserInfo(accessToken)
console.log('userinfo', res)
const {
displayName: nickname,
headPictureURL: avatar
} = res
if (avatar) {
// eslint-disable-next-line n/no-deprecated-api
const avatarPath = url.parse(avatar).pathname
......@@ -112,7 +142,6 @@ module.exports = async function (params = {}) {
url: fileID
}
}
extraData.nickname = nickname
}
......
const {
preBind,
postBind
} = require('../../lib/utils/relate')
const {
LOG_TYPE
} = require('../../common/constants')
const {
decryptWeixinData,
getWeixinCache, getWeixinAccessToken
} = require('../../lib/utils/weixin')
const {initWeixin} = require('../../lib/third-party')
const {ERROR} = require('../../common/error')
const {initHuawei} = require("../../lib/third-party");
/**
* 通过华为账号一键登录绑定手机号
* @tutorial https://uniapp.dcloud.net.cn/uniCloud/uni-id-pages.html#bind-mobile-by-huawei
* @param {Object} params
* @param {String} params.code 华为账号一键登录获取手机号返回的code
* @returns
*/
module.exports = async function (params = {}) {
const schema = {
code: "string"
}
const {
code
} = params
this.middleware.validate(params, schema)
const huaweiApi = initHuawei.call(this)
const uid = this.authInfo.uid
const {accessToken} = await huaweiApi.getUserAccessToken(code)
const res = await huaweiApi.getUserInfo(accessToken)
const mobile = res.purePhoneNumber
const bindAccount = {
mobile
}
await preBind.call(this, {
uid,
bindAccount,
logType: LOG_TYPE.BIND_MOBILE
})
await postBind.call(this, {
uid,
bindAccount,
extraData: {
mobile_confirmed: 1
},
logType: LOG_TYPE.BIND_MOBILE
})
return {
errCode: 0
}
}
......@@ -9,5 +9,8 @@ module.exports = {
unbindWeixin: require('./unbind-weixin'),
unbindAlipay: require('./unbind-alipay'),
unbindQQ: require('./unbind-qq'),
unbindApple: require('./unbind-apple')
unbindApple: require('./unbind-apple'),
bindHuawei: require('./bind-huawei'),
unbindHuawei: require('./unbind-huawei'),
bindMobileByHuawei: require('./bind-mobile-by-huawei'),
}
......@@ -10,7 +10,7 @@
</view>
<view v-else class="uni-dialog-content">
<slot>
<input class="uni-dialog-input" v-model="val" :type="inputType" :placeholder="placeholderText" :focus="focus" >
<input class="uni-dialog-input" v-model="val" :type="inputType" :placeholder="placeholderText" :focus="focus"></input>
</slot>
</view>
<view class="uni-dialog-button-group">
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册