提交 6e730d49 编写于 作者: A Anne_LXM

feat: 兼容uni-app-x web端

上级 47537094
<template> <template>
<view class="content"> <view class="content">
<view class="userinfo" @click="toUserInfoPage"> <view class="userinfo" @click="toUserInfoPage">
<uni-id-pages-x-avatar class="avatar" ref="avatar" width="45px" height="45px" :readOnly="true" :border="false"></uni-id-pages-x-avatar> <uni-id-pages-x-avatar class="avatar" ref="avatar" width="45px" height="45px" :readOnly="true"
<view class="openName"> :border="false"></uni-id-pages-x-avatar>
<text class="openName-text">{{openName}}</text> <view class="openName">
</view> <text class="openName-text">{{openName}}</text>
</view>
<uni-id-pages-x-icons type="right-arrow" color="#999" /> <uni-id-pages-x-icons type="right-arrow" color="#999" />
</view> </view>
<view class="list"> <view class="list">
<view class="list-item" hover-class="list-active" @click="toLogin('smsCode')"> <view class="list-item" hover-class="list-active" @click="toLogin('smsCode')">
<text class="list-item-text">手机验证码登录</text> <text class="list-item-text">手机验证码登录</text>
<uni-id-pages-x-icons type="right-arrow" color="#999" /> <uni-id-pages-x-icons type="right-arrow" color="#999" />
</view> </view>
<view class="list-item" @click="toLogin('username')"> <view class="list-item" @click="toLogin('username')">
<text class="list-item-text">账号密码登录</text> <text class="list-item-text">账号密码登录</text>
<uni-id-pages-x-icons type="right-arrow" color="#999" /> <uni-id-pages-x-icons type="right-arrow" color="#999" />
</view> </view>
<!-- #ifdef uniVersion > 3.99 || uniVersion == 3.99 --> <!-- #ifdef uniVersion > 3.99 || uniVersion == 3.99 -->
<view class="list-item" @click="toLogin('univerify')" v-if="hasUniverify"> <view class="list-item" @click="toLogin('univerify')" v-if="hasUniverify">
<text class="list-item-text">一键登录</text> <text class="list-item-text">一键登录</text>
<uni-id-pages-x-icons type="right-arrow" color="#999" /> <uni-id-pages-x-icons type="right-arrow" color="#999" />
</view> </view>
<!-- #endif --> <!-- #endif -->
</view> </view>
</view> </view>
</template> </template>
<script> <script>
import { state } from '@/uni_modules/uni-id-pages-x/store.uts'; import { state } from '@/uni_modules/uni-id-pages-x/store.uts';
// 导入配置 // 导入配置
import config from '@/uni_modules/uni-id-pages-x/config.uts' import config from '@/uni_modules/uni-id-pages-x/config.uts'
export default { export default {
computed: { computed: {
userInfo() : UTSJSONObject { userInfo() : UTSJSONObject {
return state.userInfo return state.userInfo
}, },
isLogin() : boolean { isLogin() : boolean {
return state.isLogin return state.isLogin
}, },
openName():string{ openName() : string {
if(this.isLogin){ if (this.isLogin) {
let nickname = this.userInfo.getString("nickname") let nickname = this.userInfo["nickname"] as string | null
let username = this.userInfo.getString("username") let username = this.userInfo["username"] as string | null
let mobile = this.userInfo.getString("mobile") let mobile = this.userInfo["mobile"] as string | null
if (nickname == null) {
if(nickname == null){ nickname = "";
nickname = ""; }
} if (username == null) {
if(username == null){ username = "";
username = ""; }
} if (mobile == null) {
if(mobile == null){ mobile = "";
mobile = ""; }
} if (nickname.length != 0) {
return nickname
if(nickname.length != 0){ } else if (username.length != 0) {
return nickname return username
}else if(username.length != 0){ } else {
return username return mobile
}else { }
return mobile } else {
} return '未登录'
}else{ }
return '未登录' },
} hasUniverify() : boolean {
}, const loginTypes = config.getArray<string>('loginTypes')
hasUniverify():boolean{ if (loginTypes != null) {
const loginTypes = config.getArray<string>('loginTypes') return loginTypes.includes('univerify');
if(loginTypes != null){ }
return loginTypes.includes('univerify'); return false
}
return false
} }
}, },
data() { data() {
return {} return {}
}, },
onLoad() {}, onLoad() { },
methods: { methods: {
toLogin(loginType:string) { toLogin(loginType : string) {
uni.navigateTo({ uni.navigateTo({
url: "/uni_modules/uni-id-pages-x/pages/login/login?type=" + loginType url: "/uni_modules/uni-id-pages-x/pages/login/login?type=" + loginType
}) })
}, },
toUserInfoPage() { toUserInfoPage() {
uni.navigateTo({ uni.navigateTo({
url: "/uni_modules/uni-id-pages-x/pages/userinfo/userinfo?showLoginManage=true" url: "/uni_modules/uni-id-pages-x/pages/userinfo/userinfo?showLoginManage=true"
}) })
}, },
} }
} }
</script> </script>
<style lang="scss"> <style lang="scss">
.content { .content {
height: 100%; height: 100%;
background-color: #f5f5f5; background-color: #f5f5f5;
} }
.userinfo {
.userinfo { display: flex;
display: flex; flex-direction: row;
flex-direction: row; align-items: center;
align-items: center; justify-content: space-between;
justify-content: space-between; padding: 15px;
padding: 15px; background-color: #fff;
// padding-bottom: 30px; .openName {
background-color: #fff; flex: 1;
padding: 0 10px;
.openName { .openName-text {
flex: 1; font-size: 14px;
padding: 0 10px; color: #333;
.openName-text { }
font-size: 14px; }
color: #333; }
} .list {
} background-color: #fff;
} margin-top: 15px;
.list-item {
.list { display: flex;
background-color: #fff; flex-direction: row;
margin-top: 15px; align-items: center;
justify-content: space-between;
.list-item { padding: 0 15px;
display: flex; height: 50px;
flex-direction: row; border-bottom: 1px #f5f5f5 solid;
align-items: center; .list-item-text {
justify-content: space-between; font-size: 14px;
padding: 0 15px; }
height: 50px; }
border-bottom: 1px #f5f5f5 solid; }
.list-item-text {
font-size: 14px;
}
}
}
.arrow {
}
</style> </style>
...@@ -3,7 +3,6 @@ ...@@ -3,7 +3,6 @@
// 导入配置 // 导入配置
import config from '@/uni_modules/uni-id-pages-x/config.uts' import config from '@/uni_modules/uni-id-pages-x/config.uts'
import {state} from '@/uni_modules/uni-id-pages-x/store.uts'; import {state} from '@/uni_modules/uni-id-pages-x/store.uts';
// uni-id的云对象 // uni-id的云对象
...@@ -11,7 +10,9 @@ const uniIdCo = uniCloud.importObject('uni-id-co', { ...@@ -11,7 +10,9 @@ const uniIdCo = uniCloud.importObject('uni-id-co', {
customUI: true customUI: true
}) })
// 用户配置的登录方式、是否打开调试模式 // 用户配置的登录方式、是否打开调试模式
const loginTypes = config.getArray<string>('loginTypes'); const configLoginTypes = config.getArray<string>('loginTypes');
const loginTypes = configLoginTypes == null ? [] as string[] : configLoginTypes;
const debug = config.getBoolean('debug') as boolean; const debug = config.getBoolean('debug') as boolean;
// #ifdef APP && ( uniVersion > 3.99 || uniVersion == 3.99) // #ifdef APP && ( uniVersion > 3.99 || uniVersion == 3.99)
...@@ -27,7 +28,7 @@ export default async function () { ...@@ -27,7 +28,7 @@ export default async function () {
uniIdCo.getSupportedLoginType().then((res:UTSJSONObject)=>{ uniIdCo.getSupportedLoginType().then((res:UTSJSONObject)=>{
// console.log('7777res',res) // console.log('7777res',res)
let supportedLoginType = res.getArray<string>('supportedLoginType') let supportedLoginType = res.getArray<string>('supportedLoginType')
console.log('supportedLoginType: ',supportedLoginType); // console.log('supportedLoginType: ',supportedLoginType);
if(supportedLoginType == null){ if(supportedLoginType == null){
supportedLoginType = [] supportedLoginType = []
} }
...@@ -47,17 +48,31 @@ export default async function () { ...@@ -47,17 +48,31 @@ export default async function () {
"weixinMobile": 'weixin' "weixinMobile": 'weixin'
}; };
// 遍历客户端配置的登录方式,与服务端比对。并在错误时抛出错误提示 // 遍历客户端配置的登录方式,与服务端比对。并在错误时抛出错误提示
const list = loginTypes?.filter((type:string):boolean =>type != 'smsCode') // const list = loginTypes?.filter((type:string):boolean =>type != 'smsCode')
?.filter((type:string):boolean =>{ // ?.filter((type:string):boolean =>{
let currentType = data.getString(type); // let currentType = data.getString(type);
if(currentType == null){ // if(currentType == null){
currentType = "" // currentType = ""
// }
// return supportedLoginType?.includes(currentType) != true
// })
const list:Array<string> = [];
console.log('loginTypes: ',loginTypes);
for (let i = 0; i < loginTypes.length; i++) {
const type = loginTypes[i];
if (type != 'smsCode') {
let currentType = data.getString(type);
if (currentType === null) {
currentType = '';
}
if (!supportedLoginType.includes(currentType)) {
list.push(type);
}
} }
return supportedLoginType?.includes(currentType) != true }
}) if (list.length != 0) {
if (list?.length != 0) {
console.error( console.error(
`错误:前端启用的登录方式:${list?.join(',')};没有在服务端完成配置。配置文件路径:"/uni_modules/uni-config-center/uniCloud/cloudfunctions/common/uni-config-center/uni-id/config.json"` `错误:前端启用的登录方式:${list.join(',')};没有在服务端完成配置。配置文件路径:"/uni_modules/uni-config-center/uniCloud/cloudfunctions/common/uni-config-center/uni-id/config.json"`
) )
} }
}) })
...@@ -65,7 +80,7 @@ export default async function () { ...@@ -65,7 +80,7 @@ export default async function () {
// #ifdef APP // #ifdef APP
// 如果uni-id-pages配置的登录功能有一键登录,有则执行预登录(异步) // 如果uni-id-pages配置的登录功能有一键登录,有则执行预登录(异步)
if (loginTypes != null && loginTypes.includes('univerify')) { if (loginTypes.includes('univerify')) {
const myUniverify = new Univerify() const myUniverify = new Univerify()
const univerifyManager = uni.getUniverifyManager(); const univerifyManager = uni.getUniverifyManager();
univerifyManager.preLogin({ univerifyManager.preLogin({
......
...@@ -222,9 +222,10 @@ ...@@ -222,9 +222,10 @@
uni.removeStorage({ uni.removeStorage({
key: tempFrvInfoKey key: tempFrvInfoKey
}) })
} catch (e: UniCloudError) { } catch (e: Error) {
const error = e as UniCloudError
this.verifyFail = true this.verifyFail = true
this.verifyFailTitle = e.errMsg this.verifyFailTitle = error.errMsg
console.error(JSON.stringify(e)) console.error(JSON.stringify(e))
} }
uni.hideLoading() uni.hideLoading()
......
...@@ -58,12 +58,13 @@ ...@@ -58,12 +58,13 @@
</template> </template>
<script> <script>
import {state, mutations} from '@/uni_modules/uni-id-pages-x/store.uts'; import {state} from '@/uni_modules/uni-id-pages-x/store.uts';
import {logout} from '@/uni_modules/uni-id-pages-x/common/common.uts'; import {logout} from '@/uni_modules/uni-id-pages-x/common/common.uts';
export default { export default {
data() { data() {
return {} return {
showLoginManage: true
}
}, },
computed: { computed: {
userInfo(): UTSJSONObject { userInfo(): UTSJSONObject {
...@@ -75,19 +76,14 @@ ...@@ -75,19 +76,14 @@
realNameStatus (): number { realNameStatus (): number {
const realNameAuth = this.userInfo.getJSON('realNameInfo') const realNameAuth = this.userInfo.getJSON('realNameInfo')
const authStatus = realNameAuth?.getNumber('authStatus') const authStatus = realNameAuth?.getNumber('authStatus')
if (realNameAuth == null || authStatus == null) { if (realNameAuth == null || authStatus == null) {
return 0 return 0
} }
return authStatus as number return authStatus as number
} }
}, },
props: { onLoad(options){
showLoginManage: { this.showLoginManage = options['showLoginManage'] == 'true'
type: Boolean,
default: true
}
}, },
methods: { methods: {
setNickname() { setNickname() {
...@@ -130,7 +126,6 @@ ...@@ -130,7 +126,6 @@
} }
} }
</script> </script>
<style> <style>
.uni-content { .uni-content {
width: 750rpx; width: 750rpx;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册