提交 a0ba05a5 编写于 作者: A Anne_LXM

feat: 兼容uni-app-x web端

上级 5e52c620
......@@ -34,7 +34,9 @@
}
</script>
<style>
<style>
@import url("/uni_modules/uni-id-pages-x/common/common.scss");
/*每个页面公共css */
.uni-row {
flex-direction: row;
......@@ -43,4 +45,4 @@
.uni-column {
flex-direction: column;
}
</style>
\ No newline at end of file
</style>
......@@ -11,7 +11,7 @@
<script>
export default {
emits: ["modelValue"],
emits: ["update:modelValue"],
props: {
cursorSpacing: {
type: Number,
......@@ -101,7 +101,7 @@
}).then((result : UTSJSONObject) => {
this.captchaBase64 = (result.getString('captchaBase64') as string)
})
.catch<void>((err : any | null) : void => {
.catch((err : any | null) : void => {
const error = err as UniCloudError
console.error(error)
console.error(error.code)
......@@ -177,4 +177,4 @@
.opacity {
opacity: 0.5;
}
</style>
\ No newline at end of file
</style>
......@@ -16,7 +16,7 @@
<script>
let confirmCallBack = ():void=>console.log('未传入回调函数')
export default {
emits:["modelValue","confirm","cancel"],
emits:["confirm","cancel","update:modelValue"],
data() {
return {
focus: false,
......@@ -48,12 +48,12 @@
// #ifdef VUE2
this.$emit('input', val);
// #endif
// TODO 兼容 vue3
// #ifdef VUE3
this.$emit('update:modelValue', val)
// #endif
if(val.length == 4){
this.confirm()
}
......@@ -127,4 +127,4 @@
color: #fff;
margin-left: 5px;
}
</style>
\ No newline at end of file
</style>
......@@ -46,7 +46,7 @@
name: "uni-id-pages-x-agreements",
computed: {
agreements():Agreement[]{
const agreements = config.getJSON('agreements')
const agreements = config.getJSON('agreements')
if(agreements === null){
return []
}else{
......@@ -75,11 +75,11 @@
data() {
return {
needAgreements:true,
$popupComponent:null as null | UniPopupComponentPublicInstance
popupComponent:null as null | UniPopupComponentPublicInstance
}
},
mounted() {
const scopeList = config.getArray<string>('agreements.scopeList')
if(scopeList == null){
this.needAgreements = false
......@@ -87,8 +87,8 @@
this.needAgreements = scopeList.includes(this.scope)
}
state.pendingAgreements = this.needAgreements;
this.$popupComponent = (this.$refs['popup'] as UniPopupComponentPublicInstance)
this.popupComponent = (this.$refs['popup'] as UniPopupComponentPublicInstance)
// this.showPopupAgreements(()=>{
// console.log('showPopupAgreements after');
// })
......@@ -116,17 +116,17 @@
},
showPopupAgreements(callback: () => void){
confirmCallBack = callback;
this.$popupComponent!.open()
this.popupComponent!.open()
},
cancel(){
state.pendingAgreements = true;
this.$popupComponent!.close()
this.popupComponent!.close()
},
confirm(){
state.pendingAgreements = false;
// console.log('state.pendingAgreements',state.pendingAgreements);
confirmCallBack();
this.$popupComponent!.close()
this.popupComponent!.close()
}
},
}
......@@ -214,4 +214,4 @@
color: #115ff7;
border-left: solid 1px #eee;
}
</style>
\ No newline at end of file
</style>
......@@ -9,7 +9,7 @@
:style="{width,height}">
<!-- #endif -->
<!-- {{avatar_file!.getString("url")}} -->
<!-- {{avatar_file!.getString("url")}} -->
<cloud-image v-if="avatar_file != null" :src="avatar_file!.getString('url')" :width="width" :height="height"></cloud-image>
<image v-else-if="readOnly" class="default-avatarUrl" src="@/uni_modules/uni-id-pages-x/static/default-avatar.png" mode="widthFix"></image>
<view v-else class="upload-img-icon">
......@@ -28,7 +28,7 @@
<script>
import { state, mutations } from '@/uni_modules/uni-id-pages-x/store.uts';
/**
* uni-id-pages-x-avatar
* uni-id-pages-x-avatar
* @description 用户头像组件
* @property {String} width 图片的宽,默认为:50px
* @property {String} height 图片的高,默认为:50px
......@@ -113,12 +113,12 @@
// this.setAvatarFile(avatar_file)
},
uploadAvatarImg() {
if(this.readOnly){
return
return
}
// #ifdef MP-WEIXIN
return // 微信小程序走 bindchooseavatar方法
// #endif
......@@ -151,11 +151,9 @@
if (tempFilePath == null) {
tempFilePath = ""
}
// console.log(9527,tempFileName.length);
// console.error('tempFileName',tempFileName);
// console.error('tempFilePath',tempFilePath);
let avatar_file = {
// #ifdef H5
extname: tempFileName.split(".")[tempFileName.split(".").length - 1],
......@@ -211,13 +209,13 @@
filePath,
cloudPath,
})
.then<void>(function (res) {
.then(function (res) {
// console.log('res777777777',res);
avatar_file.url = res.fileID
// console.log('avatar_file111', avatar_file);
mutations.updateUserInfo({ avatar_file } as UTSJSONObject)
})
.catch<void>(function (err : any | null) {
.catch(function (err : any | null) {
const error = err as UniCloudError
uni.showModal({
content: '上传失败,' + error.errMsg,
......@@ -243,6 +241,10 @@
</script>
<style>
.default-avatarUrl{
width:44px;
height:44px;
}
.avatar-box-root {
background-color: #fff;
}
......@@ -257,7 +259,6 @@
display: inline-block;
box-sizing: border-box;
/* #endif */
border-radius: 100px;
text-align: center;
padding: 1px;
......@@ -274,4 +275,4 @@
.showBorder {
border: solid 1px #ddd;
}
</style>
\ No newline at end of file
</style>
......@@ -71,7 +71,7 @@
},
watch: {
agree(agree) {
this.univerifyStyle.privacyTerms.defaultCheckBoxState = agree
this.univerifyStyle.privacyTerms!.defaultCheckBoxState = agree
}
},
methods: {
......@@ -127,8 +127,8 @@
.fab-login-box {
width: 750rpx;
position: fixed;
bottom: 30;
left: 0;
bottom: 30px;
left: 0px;
flex-direction: row;
flex-wrap: wrap;
justify-content: space-around;
......
......@@ -7,8 +7,8 @@
:password="password && !visiblePwd" :focus="focus" @blur="onBlur" @focus="onFocus" @confirm="confirm"
:confirm-type="confirmType" />
<view class="my-input-icon-box" v-if="modelValue">
<uni-id-pages-x-icons v-if="password" :color="visiblePwd?'#0070ff':'#ddd'"
@click="setVisiblePwd('click')" @touchstart="setVisiblePwd('touchstart')" @touchend="setVisiblePwd('touchend')" @touchcancel="setVisiblePwd('touchcancel')"
<uni-id-pages-x-icons v-if="password" :color="visiblePwd?'#0070ff':'#ddd'"
@click="setVisiblePwd('click')" @touchstart="setVisiblePwd('touchstart')" @touchend="setVisiblePwd('touchend')" @touchcancel="setVisiblePwd('touchcancel')"
type="eyes" />
<view class="password-icon">
<uni-id-pages-x-icons @click="clearValue" type="clear" color="#ddd" />
......@@ -20,7 +20,7 @@
<script>
export default {
name: 'MyInput',
emits: ["modelValue", "blur", "focus", "confirm"],
emits: ["blur", "focus", "confirm", "update:modelValue"],
data() {
return {
visiblePwd: false
......@@ -117,17 +117,17 @@
if(eventName == "click" && this.visiblePwdOption == 'click'){
this.visiblePwd = !this.visiblePwd
}else if(eventName == "touch"){
switch (eventName){
case "touchstart":
this.visiblePwd = true
break;
case "touchend":
this.visiblePwd = false
break;
case "touchcancel":
this.visiblePwd = false
break;
}
// switch (eventName){
// case "touchstart":
// this.visiblePwd = true
// break;
// case "touchend":
// this.visiblePwd = false
// break;
// case "touchcancel":
// this.visiblePwd = false
// break;
// }
}
}
}
......@@ -184,4 +184,4 @@
.password-icon {
margin-left: 5px;
}
</style>
\ No newline at end of file
</style>
......@@ -7,12 +7,12 @@
<uni-id-pages-x-agreements class="agreements-box" ref="agreements" scope="login"/>
<button class="uni-btn" :type="password.length > 0 && username.length >0 ? 'primary' : '' " @click="loginByPwd">登录</button>
</view>
<view class="link-group">
<text class="link" @click="toRetrievePwd">忘记密码</text>
<text class="link" @click="toRegister">注册账号</text>
</view>
<!-- 多次登录错误时,获取登录时专用的图形验证码 (悬浮) -->
<uni-popup-captcha ref="popup-captcha" scene="login-by-pwd" v-model="loginCaptcha" title="请输入验证码"></uni-popup-captcha>
</template>
......@@ -81,11 +81,10 @@
}
data.set(keyName, this.username)
// console.log('data',data);
console.log('data',data);
if (state.pendingAgreements) {
this.showPopupCaptcha(() => {
// console.log('state.pendingAgreements', state.pendingAgreements);
if (!state.pendingAgreements) {
this.loginByPwd()
}
......@@ -102,11 +101,11 @@
uni.hideLoading()
this.loginCaptcha = ""
})
.then(e => {
// console.log('uniIdCo.login res',e);
.then((e:UTSJSONObject) => {
console.log('uniIdCo.login res',e);
loginSuccess(e)
})
.catch<void>((err : any | null) : void => {
.catch((err : any | null) : void => {
const error = err as UniCloudError
console.error(error)
console.error(error.code)
......@@ -160,4 +159,4 @@
color: #083679;
font-size: 12px;
}
</style>
\ No newline at end of file
</style>
<template>
<view>
<text class="tip">未注册的账号验证通过后将自动注册</text>
<view class="form">
<!-- 获取验证码组件(输入手机号码+发送短信验证码所需的图形验证码,获得短信验证码) -->
<uni-id-pages-x-smsCode ref="smsCode" @input="smsCodeInput" ></uni-id-pages-x-smsCode>
......@@ -9,14 +9,13 @@
<uni-id-pages-x-agreements class="agreements-box" ref="agreements" scope="login"/>
<button class="uni-btn" type="primary" @click="sendSmsCode">获取手机验证码</button>
</view>
<!-- 多次登录错误时,获取登录时专用的图形验证码 (悬浮) -->
<uni-popup-captcha ref="captcha" scene="login-by-sms" v-model="captcha" title="请输入验证码"></uni-popup-captcha>
</view>
</template>
<script>
import { state } from '@/uni_modules/uni-id-pages-x/store.uts';
import { loginSuccess } from '@/uni_modules/uni-id-pages-x/common/common.uts';
const uniIdCo = uniCloud.importObject("uni-id-co", { "customUI": true })
export default {
......@@ -24,17 +23,15 @@
data() {
return {
captcha: "",
$smsCodeRef: null as null | UniIdPagesXSmsCodeComponentPublicInstance
smsCodeRef: null as null | UniIdPagesXSmsCodeComponentPublicInstance
}
},
computed: {
},
mounted() {
this.$smsCodeRef = (this.$refs["smsCode"] as UniIdPagesXSmsCodeComponentPublicInstance)
this.smsCodeRef = (this.$refs["smsCode"] as UniIdPagesXSmsCodeComponentPublicInstance)
},
methods: {
sendSmsCode() {
this.$smsCodeRef!.$callMethod('sendSmsCode');
this.smsCodeRef!.$callMethod('sendSmsCode');
},
smsCodeInput(param : UTSJSONObject) {
// console.log('smsCodeInput param', param);
......@@ -53,18 +50,17 @@
.finally(() : void => {
uni.hideLoading()
})
.then<void>((e : UTSJSONObject) : void => {
// console.log('then');
.then((e : UTSJSONObject) : void => {
// console.log(e);
this.$smsCodeRef!.$callMethod("hideCodeInput");
this.smsCodeRef!.$callMethod("hideCodeInput");
uni.showToast({
title: '登录成功',
icon: 'none'
});
loginSuccess(e)
this.$smsCodeRef!.$callMethod('clearCodeInput')
this.smsCodeRef!.$callMethod('clearCodeInput')
})
.catch<void>((err : any | null) : void => {
.catch((err : any | null) : void => {
const error = err as UniCloudError
console.error(error)
console.error(error.code)
......@@ -78,7 +74,7 @@
icon: 'none',
mask: false
});
this.$smsCodeRef!.$callMethod('clearCodeInput')
this.smsCodeRef!.$callMethod('clearCodeInput')
this.captcha = ""
}
})
......@@ -92,4 +88,4 @@
font-size: 12px;
padding: 0 0 5px 10px;
}
</style>
\ No newline at end of file
</style>
......@@ -14,7 +14,7 @@
<script>
let confirmCallBack = (_ : string) : void => {}// console.log('未传入回调函数,value:', value)
export default {
emits: ["confirm"],
emits: ["confirm","cancel"],
data() {
return {
title: "默认标题" as string,
......@@ -97,4 +97,4 @@
color: #115ff7;
border-left: solid 1px #eee;
}
</style>
\ No newline at end of file
</style>
......@@ -20,7 +20,7 @@
<script>
export default {
emits: ["modelValue", "blur", "focus", "reGetSmsCode"],
emits: ["update:modelValue","reGetSmsCode","blur", "focus" ],
data() {
return {
smsCodeList: ["\u200b", "\u200b", "\u200b", "\u200b", "\u200b", "\u200b"],
......@@ -177,7 +177,7 @@
margin: 10px 5px;
text-align: center;
}
.fab-sms-code-input-foot {
margin-top: 5px;
margin-left: 300rpx;
......@@ -194,7 +194,7 @@
text-align: center;
margin-right: 26rpx;
}
.get-sms-code-tip,
.get-sms-code-tip-active {
font-size: 12px;
......@@ -205,4 +205,4 @@
.get-sms-code-tip-active {
color: #005eca;
}
</style>
\ No newline at end of file
</style>
......@@ -24,13 +24,14 @@
export default {
name: "uni-id-pages-x-smsCode",
components: { fabSmsCodeInput },
emits:["input"],
data() {
return {
mobile: "",
sendSmsCaptcha: "",
smsCode: "",
$fabSmsCodeInputEl: null as null | ComponentPublicInstance,
$sendSmsCaptchaCP: null as null | UniCaptchaComponentPublicInstance,
fabSmsCodeInputEl: null as null | ComponentPublicInstance,
sendSmsCaptchaCP: null as null | UniCaptchaComponentPublicInstance,
reverseNumber: 0
}
},
......@@ -51,7 +52,7 @@
mobile(mobile) {
this.emitInput()
if (mobile.length == 11) {
this.$sendSmsCaptchaCP!.setFocus(true);
this.sendSmsCaptchaCP!.setFocus(true);
// 倒计时归零,允许再次发送
this.reverseNumber = 0
}
......@@ -68,8 +69,8 @@
}
},
mounted() {
this.$fabSmsCodeInputEl = this.$refs["fab-sms-code-input"] as ComponentPublicInstance;
this.$sendSmsCaptchaCP = this.$refs["sendSmsCaptcha"] as UniCaptchaComponentPublicInstance;
this.fabSmsCodeInputEl = this.$refs["fab-sms-code-input"] as ComponentPublicInstance;
this.sendSmsCaptchaCP = this.$refs["sendSmsCaptcha"] as UniCaptchaComponentPublicInstance;
// 加载好,手机号码输入框就自动获取焦点
// TO 临时方案解决 this.$nextTick 无效,由setTimeout 300 代替
......@@ -82,7 +83,7 @@
(this.$refs['mobileInput'] as UniIdPagesXInputComponentPublicInstance).setFocus(val);
},
showCodeInput() {
if (reverseNumber == 0) {
if (this.reverseNumber == 0) {
this.reverseNumber = 6
//开始倒计时
let reverseTimer = function () { }
......@@ -96,7 +97,7 @@
}
reverseTimer()
}
this.$fabSmsCodeInputEl?.$callMethod('show', true);
this.fabSmsCodeInputEl?.$callMethod('show', true);
},
emitInput() {
const param : UTSJSONObject = {
......@@ -116,13 +117,13 @@
reGetSmsCode() {
this.hideCodeInput();
this.clearCodeInput();
this.$sendSmsCaptchaCP!.getImageCaptcha(true);
this.sendSmsCaptchaCP!.getImageCaptcha(true);
},
hideCodeInput() {
this.$fabSmsCodeInputEl!.$callMethod("hide");
this.fabSmsCodeInputEl!.$callMethod("hide");
},
clearCodeInput() {
this.$fabSmsCodeInputEl!.$callMethod('clear')
this.fabSmsCodeInputEl!.$callMethod('clear')
},
reset() {
this.smsCode = ""
......@@ -135,9 +136,8 @@
// console.log("state.pendingAgreements", state.pendingAgreements);
if (state.pendingAgreements) {
// uni.hideKeyboard();
this.$sendSmsCaptchaCP!.setFocus(false);
this.sendSmsCaptchaCP!.setFocus(false);
(this.$parent as ComponentPublicInstance).$callMethod("showPopupCaptcha", () => {
// console.log('state.pendingAgreements', state.pendingAgreements);
if (!state.pendingAgreements) {
this.sendSmsCode()
}
......@@ -166,7 +166,7 @@
}
if (this.sendSmsCaptcha.length != 4) {
this.$sendSmsCaptchaCP!.setFocus(true)
this.sendSmsCaptchaCP!.setFocus(true)
uni.showToast({
title: '请先输入图形验证码',
icon: 'none',
......@@ -175,7 +175,7 @@
return
}
// const param : UTSJSONObject
// const param : UTSJSONObject
// console.log('sendSmsCode',{
// "mobile": this.mobile,
// "scene": "login-by-sms",
......@@ -201,7 +201,7 @@
// console.log('result', result);
this.showCodeInput()
})
.catch<void>((err : any | null) : void => {
.catch((err : any | null) : void => {
const error = err as UniCloudError
// console.error(error.message)
// console.error(error.code)
......@@ -214,7 +214,7 @@
duration: 3000,
mask: false
});
this.$sendSmsCaptchaCP!.getImageCaptcha(true);
this.sendSmsCaptchaCP!.getImageCaptcha(true);
this.sendSmsCaptcha = "";
break;
case "uni-id-invalid-sms-template-id":
......@@ -265,4 +265,4 @@
.send-sms-captcha-box {
margin-top: 10px;
}
</style>
\ No newline at end of file
</style>
......@@ -13,10 +13,10 @@ export default {
]
},
"loginTypes":[
"smsCode",
// #ifdef APP && ( uniVersion > 3.99 || uniVersion == 3.99)
"univerify",
// #endif
"smsCode",
"username",
// 以下登录方式 uni-app x 暂不支持
/*
......
// 导入 autoReportPushClientId 模块,将再重新登录会 token 续期后自动将客户端上报到服务端
// import reportPushClientId from '@/uni_modules/uni-id-pages-x/lib/autoReportPushClientId.uts'
// 导入配置
// 导入配置
import config from '@/uni_modules/uni-id-pages-x/config.uts'
import {state} from '@/uni_modules/uni-id-pages-x/store.uts';
// uni-id的云对象
const uniIdCo = uniCloud.importObject('uni-id-co', {
customUI: true
})
// 用户配置的登录方式、是否打开调试模式
// uni-id的云对象
const uniIdCo = uniCloud.importObject('uni-id-co', {
customUI: true
})
// 用户配置的登录方式、是否打开调试模式
const loginTypes = config.getArray<string>('loginTypes');
const debug = config.getBoolean('debug') as boolean;
// #ifdef APP
// #ifdef APP && ( uniVersion > 3.99 || uniVersion == 3.99)
import Univerify from '@/uni_modules/uni-id-pages-x/lib/Univerify.uts'
// #endif
// #endif
export default async function () {
// 有打开调试模式的情况下
if (debug) {
// 1. 检查本地uni-id-pages中配置的登录方式,服务器端是否已经配置正确。否则提醒并引导去配置
// 有打开调试模式的情况下
if (debug) {
// 1. 检查本地uni-id-pages中配置的登录方式,服务器端是否已经配置正确。否则提醒并引导去配置
// 调用云对象,获取服务端已正确配置的登录方式
uniIdCo.getSupportedLoginType().then(res=>{
uniIdCo.getSupportedLoginType().then((res:UTSJSONObject)=>{
// console.log('7777res',res)
let supportedLoginType = res.getArray('supportedLoginType')
let supportedLoginType = res.getArray<string>('supportedLoginType')
console.log('supportedLoginType: ',supportedLoginType);
if(supportedLoginType == null){
supportedLoginType = []
}
// 登录方式,服务端和客户端的映射关系
const data:UTSJSONObject = {
"smsCode": 'mobile-code',
"univerify": 'univerify',
"username": 'username-password',
"weixin": 'weixin',
......@@ -46,23 +47,24 @@ export default async function () {
"weixinMobile": 'weixin'
};
// 遍历客户端配置的登录方式,与服务端比对。并在错误时抛出错误提示
const list = loginTypes?.filter((type:string):boolean =>{
const list = loginTypes?.filter((type:string):boolean =>type != 'smsCode')
?.filter((type:string):boolean =>{
let currentType = data.getString(type);
if(currentType == null){
currentType = ""
}
return !(supportedLoginType.includes(currentType))
return supportedLoginType?.includes(currentType) != true
})
if (list?.length != 0) {
console.error(
`错误:前端启用的登录方式:${list?.join(',')};没有在服务端完成配置。配置文件路径:"/uni_modules/uni-config-center/uniCloud/cloudfunctions/common/uni-config-center/uni-id/config.json"`
)
}
})
}
// #ifdef APP
// 如果uni-id-pages配置的登录功能有一键登录,有则执行预登录(异步)
})
}
// #ifdef APP
// 如果uni-id-pages配置的登录功能有一键登录,有则执行预登录(异步)
if (loginTypes != null && loginTypes.includes('univerify')) {
const myUniverify = new Univerify()
const univerifyManager = uni.getUniverifyManager();
......@@ -114,23 +116,22 @@ export default async function () {
handleInterceptor(e.url)
}
})
}
// #endif
// // 3. 绑定clientDB错误事件
// // clientDB对象
// const db = uniCloud.database()
// db.on('error', onDBError)
// // clientDB的错误提示
// function onDBError ({
// code, // 错误码详见https://uniapp.dcloud.net.cn/uniCloud/clientdb?id=returnvalue
// message
// }) {
// // console.error('onDBError', {code,message});
// }
// // 解绑clientDB错误事件
// #endif
// // 3. 绑定clientDB错误事件
// // clientDB对象
// const db = uniCloud.database()
// db.on('error', onDBError)
// // clientDB的错误提示
// function onDBError ({
// code, // 错误码详见https://uniapp.dcloud.net.cn/uniCloud/clientdb?id=returnvalue
// message
// }) {
// // console.error('onDBError', {code,message});
// }
// // 解绑clientDB错误事件
// // db.off('error', onDBError)
......@@ -183,4 +184,4 @@ export default async function () {
}
// needLogin相关代码-end
}
}
......@@ -26,19 +26,19 @@ const loginTypes = config.getArray<string>('loginTypes');
const univerifyManager = uni.getUniverifyManager();
export default class Univerify {
verify(fullScreen : boolean) {
// 校验预登录是否有效
const isPreLoginValid = univerifyManager.isPreLoginValid();
if (isPreLoginValid) {
// 预登录有效,执行登录
this.login(fullScreen);
} else {
// 预登录无效,执行预登录
// 校验预登录是否有效
const isPreLoginValid = univerifyManager.isPreLoginValid();
if (isPreLoginValid) {
// 预登录有效,执行登录
this.login(fullScreen);
} else {
// 预登录无效,执行预登录
univerifyManager.preLogin({
success() {
success() {
console.log("pre login success");
this.login(fullScreen);
},
fail(err : PreLoginFail) {
this.login(fullScreen);
},
fail(err : PreLoginFail) {
console.error("pre login fail => " + JSON.stringify(err));
// 当前页面不是登录页面时,一键登录不可用,且还存在一键登录以外的登录方式,就跳转至此登录方式
const pages = getCurrentPages()
......@@ -70,48 +70,48 @@ export default class Univerify {
})
}
}
}
} as PreLoginOptions);
}
}
} as PreLoginOptions);
}
}
login(fullScreen : boolean) {
univerifyManager.login({
// 登录页样式
univerifyStyle: {
fullScreen: fullScreen,
backgroundColor: "#FFFFFF",
loginBtnText: "一键登录",
univerifyManager.login({
// 登录页样式
univerifyStyle: {
fullScreen: fullScreen,
backgroundColor: "#FFFFFF",
loginBtnText: "一键登录",
logoPath: "/static/logo.png",
// buttons:{
// "iconWidth": "45px", // 图标宽度(高度等比例缩放) 默认值:45px
// "list":buttonsList
// }
} as UniverifyStyle,
success(res : LoginSuccess) {
console.log("login success => " + JSON.stringify(res));
// }
} as UniverifyStyle,
success(res : LoginSuccess) {
console.log("login success => " + JSON.stringify(res));
// 云函数取号
const uniIdCo = uniCloud.importObject("uni-id-co")
uniIdCo.loginByUniverify({
access_token: res.accessToken, // 客户端一键登录接口返回的access_token
openid: res.openId // 客户端一键登录接口返回的openid
uniIdCo.loginByUniverify({
access_token: res.accessToken, // 客户端一键登录接口返回的access_token
openid: res.openId // 客户端一键登录接口返回的openid
}).then(res => {
console.log('res',res)
loginSuccess(res)
univerifyManager.close();
}).catch(err => {
console.error(JSON.stringify(err));
// 关闭登录页
univerifyManager.close();
});
},
fail(err : LoginFail) {
console.error("login fail => " + err);
// uni.showToast({
// title: "登录失败",
// icon: "error"
// });
}
} as LoginOptions);
}
}).catch(err => {
console.error(JSON.stringify(err));
// 关闭登录页
univerifyManager.close();
});
},
fail(err : LoginFail) {
console.error("login fail => " + err);
// uni.showToast({
// title: "登录失败",
// icon: "error"
// });
}
} as LoginOptions);
}
}
// #endif
......@@ -80,7 +80,7 @@
}
</script>
<style lang="scss" scoped>
<style lang="scss">
@import url("/uni_modules/uni-id-pages-x/common/common.scss");
.app-logo {
......
......@@ -57,7 +57,7 @@
password2: this.password2,
captcha:this.captcha
};
// 校验是否为空,并聚焦 (注意:这里使用数组格式,以确保校验按顺序执行)
[
["username", "用户名",],
......@@ -77,8 +77,8 @@
throw Error(errMsg)
}
});
// 校验用户名规则
const usernameRegExp = new RegExp("^(?=.*[a-z])(?=.*\\d)[a-z\\d]{3,20}$");
if (!usernameRegExp.test(this.username)) {
......@@ -90,7 +90,7 @@
confirmText: "知道了"
});
}
// 校验昵称规则
if (this.nickname.length > 0) {
const nicknameRegExp = new RegExp("^[\u4e00-\u9fa5a-z0-9]{3,20}$");
......@@ -104,7 +104,7 @@
});
}
}
let checkPasswordRes = checkPassword(this.password);
let isPass = checkPasswordRes.getBoolean("pass") as Boolean
if (!isPass) {
......@@ -162,7 +162,7 @@
}
const uniIdCo = uniCloud.importObject("uni-id-co", { customUI: true });
uni.showLoading({ "title": "请求中" })
uniIdCo.registerUser(data)
.finally(() => uni.hideLoading())
.then(e => {
......@@ -173,7 +173,7 @@
});
loginSuccess(e)
})
.catch<void>((err : any | null) : void => {
.catch((err : any | null) : void => {
const error = err as UniCloudError
console.error(error)
console.error(error.code)
......@@ -213,4 +213,4 @@
left: 0px;
top: 15px;
}
</style>
\ No newline at end of file
</style>
......@@ -23,14 +23,14 @@
data() {
return {
smsCode: "",
$smsCodeRef: null as null | UniIdPagesXSmsCodeComponentPublicInstance,
smsCodeRef: null as null | UniIdPagesXSmsCodeComponentPublicInstance,
password: "",
password2: "",
captcha: ""
}
},
mounted() {
this.$smsCodeRef = (this.$refs["smsCode"] as UniIdPagesXSmsCodeComponentPublicInstance)
this.smsCodeRef = (this.$refs["smsCode"] as UniIdPagesXSmsCodeComponentPublicInstance)
},
onLoad(param : Map<string, string>) {
const mobile = param.get("mobile")
......@@ -40,7 +40,7 @@
if (mobile != null) {
this.$nextTick(() => {
this.$smsCodeRef!.mobile = mobile
this.smsCodeRef!.mobile = mobile
})
}
},
......@@ -85,7 +85,7 @@
}
});
}
this.$smsCodeRef!.sendSmsCode();
this.smsCodeRef!.sendSmsCode();
},
resetPwdBySms(param : UTSJSONObject) {
uni.showLoading({ "title": "请求中" })
......@@ -95,17 +95,17 @@
.finally(() : void => {
uni.hideLoading()
})
.then<void>((_ : UTSJSONObject) : void => {
.then((_ : UTSJSONObject) : void => {
// console.log('then');
// console.log(e);
this.$smsCodeRef!.hideCodeInput();
this.smsCodeRef!.hideCodeInput();
uni.showToast({
title: '重置成功',
icon: 'none'
});
uni.navigateBack()
})
.catch<void>((err : any | null) : void => {
.catch((err : any | null) : void => {
const error = err as UniCloudError
console.error(error)
console.error(error.code)
......@@ -119,7 +119,7 @@
icon: 'none',
mask: false
});
this.$smsCodeRef!.clearCodeInput()
this.smsCodeRef!.clearCodeInput()
this.captcha = ""
}
})
......@@ -139,4 +139,4 @@
.form {
margin:50rpx 50rpx 0 50rpx;
}
</style>
\ No newline at end of file
</style>
......@@ -18,7 +18,7 @@
export default {
data() {
return {
$smsCodeEl: null as null | UniIdPagesXSmsCodeComponentPublicInstance,
smsCodeEl: null as null | UniIdPagesXSmsCodeComponentPublicInstance,
needCaptcha: false,
captcha: ""
}
......@@ -28,11 +28,11 @@
watch: {
},
mounted() {
this.$smsCodeEl = (this.$refs["smsCode"] as UniIdPagesXSmsCodeComponentPublicInstance)
this.smsCodeEl = (this.$refs["smsCode"] as UniIdPagesXSmsCodeComponentPublicInstance)
},
methods: {
sendSmsCode() {
this.$smsCodeEl!.sendSmsCode();
this.smsCodeEl!.sendSmsCode();
},
smsCodeInput(param : UTSJSONObject) {
// console.log('smsCodeInput param', param);
......@@ -69,9 +69,9 @@
.finally(() : void => {
uni.hideLoading()
})
.then<void>((e : UTSJSONObject) : void => {
.then((e : UTSJSONObject) : void => {
// console.log('then');
// console.log(e);
console.log(e);
uni.showToast({
title: '绑定成功',
icon: 'none',
......@@ -84,7 +84,7 @@
"mobile": param.getString("mobile")
} as UTSJSONObject)
})
.catch<void>((err : any | null) : void => {
.catch((err : any | null) : void => {
const error = err as UniCloudError
console.error(error)
console.error(error.code)
......@@ -93,9 +93,9 @@
//登录失败,自动重新获取验证码
return setCaptchaRetry()
} else if (error.code == "uni-id-mobile-verify-code-error") {
this.$smsCodeEl!.clearCodeInput();
this.smsCodeEl!.clearCodeInput();
} else {
this.$smsCodeEl!.reset();
this.smsCodeEl!.reset();
this.captcha = ""
}
uni.showToast({
......@@ -108,7 +108,7 @@
},
popupCaptchaCancel() {
// console.log('popupCaptchaCancel');
this.$smsCodeEl!.reset();
this.smsCodeEl!.reset();
this.captcha = ""
}
}
......
......@@ -57,11 +57,11 @@
.update({
"nickname": this.nickname
})
.then<void>(() => {
.then(() => {
mutations.updateUserInfo({ "nickname": this.nickname } as UTSJSONObject)
uni.navigateBack()
})
.catch<void>((err : any | null) => {
.catch((err : any | null) => {
const error = err as UniCloudError
console.error('error', error);
})
......@@ -106,4 +106,4 @@
background-color: #EFEFEF;
color: #AAA;
}
</style>
\ No newline at end of file
</style>
......@@ -83,8 +83,6 @@
return authStatus as number
}
},
onShow() {
},
props: {
showLoginManage: {
type: Boolean,
......
......@@ -35,7 +35,7 @@ type Mutations = {
}
export const mutations = {
updateUserInfo(param: null | UTSJSONObject) {
// console.log('updateUserInfo', param); // param为 null 时从云端获取数据更新,为UTSJSONObject时直接根据传入的值来更新
console.log('updateUserInfo', param); // param为 null 时从云端获取数据更新,为UTSJSONObject时直接根据传入的值来更新
function afterUpdateUserInfo() {
// console.log('afterUpdateUserInfo', state.userInfo);
uni.setStorageSync('uni-id-pages-x-userInfo', state.userInfo)
......@@ -50,7 +50,7 @@ export const mutations = {
.doc(user_id)
.field('_id,username,nickname,avatar_file,mobile')
.get()
.then<void>(res => {
.then(res => {
const uniIdCo = uniCloud.importObject('uni-id-co', {
customUI: true
})
......@@ -65,14 +65,14 @@ export const mutations = {
afterUpdateUserInfo()
})
})
.catch<void>((err: any | null) => {
.catch((err: any | null) => {
const error = err as UniCloudError
console.error(error.errMsg, '错误')
})
}
} else {
param.toMap().forEach((value, key) => {
// console.log("updateUserInfo.", key, value)
console.log("updateUserInfo.", key, value)
state.userInfo.set(key, value)
})
afterUpdateUserInfo()
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册