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

重要更新 兼容微信小程序

上级 2b6bce7f
......@@ -3,18 +3,21 @@ import config from '@/uni_modules/uni-id-pages-x/config.uts';
export const loginSuccess = (_ : UTSJSONObject) => {
// console.log('loginSuccess', e);
// console.log("新用户uid", e["uid"]);
// state.currentUserInfo = uniCloud.getCurrentUserInfo()
// state.currentUserInfo = uniCloud.getCurrentUserInfo()
mutations.updateUserInfo(null)
// state.userInfo["_id"] = e["uid"]
state.isLogin = true
uni.$emit('uni-id-pages-x-login-success', '')
// 登录后重定向设置
function loginAfterToPage() {
function loginAfterToPage() {
const pages = getCurrentPages()
const currentPage = pages[pages.length - 1]
const uniIdRedirectUrl = currentPage.options["uniIdRedirectUrl"];
if (uniIdRedirectUrl != null) {
let uniIdRedirectUrl = currentPage.options["uniIdRedirectUrl"];
if (uniIdRedirectUrl != null) {
// #ifndef APP
uniIdRedirectUrl = decodeURIComponent(uniIdRedirectUrl)
// #endif
// console.log('uniIdRedirectUrl', uniIdRedirectUrl);
uni.redirectTo({
url: uniIdRedirectUrl,
......@@ -102,4 +105,4 @@ export const checkPassword = (password : string) : UTSJSONObject => {
res["pass"] = passwordRegExp.test(password);
res["errMsg"] = passwordRules.getString(passwordStrength + '.errMsg');
return res
}
}
<template>
<view class="agreements-root" v-if="agreements.length != 0">
<template v-if="needAgreements">
<checkbox-group @change="setAgree">
<checkbox class="checkbox" style="transform: scale(0.7);margin-right: -6px;padding-right: 3px;margin-left: 1px;"
:checked="!pendingAgreements" value="agreement">
<text class="checkbox-text">同意</text>
</checkbox>
<checkbox-group @change="setAgree" class="checkbox-group">
<checkbox class="checkbox" :checked="!pendingAgreements" value="agreement">
<text class="text">同意</text>
</checkbox>
</checkbox-group>
<view class="content">
<view class="agreements-item" v-for="(agreement,index) in agreements" :key="index">
......@@ -140,21 +139,41 @@
margin-left: -9px;
}
.checkbox-text {
transform: scale(1.3);
margin-left: 3px;
color: #8a8f8b;
font-size: 12px;
}
.checkbox-group {
transform: scale(0.6);
margin-left: -6px;
margin-right: -18px;
padding-right: 10px;
.checkbox {
margin-left: 5px;
padding-right: 15px;
.text {
margin-left: 8px;
margin-right: 10px;
transform: scale(1.8);
color: #8a8f8b;
font-size: 12px;
line-height: 24px;
}
}
/* #ifdef MP-WEIXIN */
// 解决微信小程序中外层有transform: scale内层再设置transform: scale无效的问题
.checkbox {
padding-right: 40px;
.text {
position: absolute;
margin-right: 0;
top: 0;
}
}
/* #endif */
}
.agreements-item {
flex-direction: row;
}
.text {
line-height: 26px;
font-size: 12px;
}
.popup-text{
line-height: 30px;
font-size:14px;
......
<template>
<view class="avatar-box-root">
<!-- #ifdef MP-WEIXIN -->
<button open-type="chooseAvatar" @chooseavatar="bindchooseavatar" @click="uploadAvatarImg" class="box"
<button open-type="chooseAvatar" @chooseavatar="bindchooseavatar" @click="uploadAvatarImg" class="box chooseAvatar"
:class="{'showBorder':border}" :style="{width,height,lineHeight:height}">
<!-- #endif -->
<!-- #ifndef MP-WEIXIN -->
......@@ -9,8 +9,7 @@
:style="{width,height}">
<!-- #endif -->
<!-- {{avatar_file!.getString("url")}} -->
<cloud-image v-if="avatar_file != null" :src="avatar_file!.getString('url')" :width="width" :height="height"></cloud-image>
<cloud-image v-if="avatar_file != null" :src="avatar_file!['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">
<uni-id-pages-x-icons :size="35" color="#eee" type="jiahao"></uni-id-pages-x-icons>
......@@ -73,7 +72,7 @@
return state.userInfo
},
avatar_file() : UTSJSONObject | null {
return this.userInfo.getJSON("avatar_file")
return this.userInfo["avatar_file"] as UTSJSONObject | null
}
},
methods: {
......@@ -81,36 +80,37 @@
// 使用 clientDB 提交数据
// mutations.updateUserInfo({avatar_file})
},
bindchooseavatar() {
// res
// let avatarUrl = res.detail.avatarUrl
// let avatar_file = {
// extname: avatarUrl.split('.')[avatarUrl.split('.').length - 1],
// name:'',
// url:''
// }
// //上传到服务器
// let cloudPath = this.userInfo._id + '' + Date.now()
// avatar_file.name = cloudPath
// try{
// uni.showLoading({
// title: "更新中",
// mask: true
// });
// let {
// fileID
// } = await uniCloud.uploadFile({
// filePath:avatarUrl,
// cloudPath,
// fileType: "image"
// });
// avatar_file.url = fileID
// uni.hideLoading()
// }catch(e){
// console.error(e);
// }
// console.log('avatar_file',avatar_file);
// this.setAvatarFile(avatar_file)
async bindchooseavatar(res:any) {
// #ifdef MP-WEIXIN
let avatarUrl = res.detail.avatarUrl
let avatar_file = {
extname: avatarUrl.split('.')[avatarUrl.split('.').length - 1],
name:'',
url:''
}
//上传到服务器
let cloudPath = this.userInfo._id + '' + Date.now()
avatar_file.name = cloudPath
try{
uni.showLoading({
title: "更新中",
mask: true
});
let {
fileID
} = await uniCloud.uploadFile({
filePath:avatarUrl,
cloudPath,
fileType: "image"
});
avatar_file.url = fileID
uni.hideLoading()
}catch(e){
console.error(e);
}
console.log('avatar_file',avatar_file);
mutations.updateUserInfo({ avatar_file } as UTSJSONObject)
// #endif
},
uploadAvatarImg() {
if(this.readOnly){
......@@ -216,10 +216,10 @@
},
fail:(err)=>{
console.error('chooseImage fail: ', err)
uni.showModal({
content: '失败,' + err.errMsg,
showCancel: false
});
// uni.showModal({
// content: '失败,' + err.errMsg,
// showCancel: false
// });
}
})
// #endif
......@@ -242,20 +242,19 @@
padding: 0;
}
.chooseAvatar {
/* #ifndef UNI-APP-X */
display: inline-block;
box-sizing: border-box;
/* #endif */
border-radius: 100px;
text-align: center;
padding: 1px;
}
/* #ifdef MP */
.chooseAvatar {
border-radius: 0;
}
.chooseAvatar:after{
display: none;
}
/* #endif */
.upload-img-icon {
border: 1px dotted #c8c8c8;
width: 55px;
height: 55px;
width: 100%;
height: 100%;
justify-content: center;
align-items: center;
}
......
<template>
<view>
<view @click="clickHandle">
<text class="uni-id-icon" :style="{color,'fontSize':size + 'px'}">{{iconCode}}</text>
</view>
</template>
<script>
export default {
emits: ["click"],
props: {
type: {
type: String,
......@@ -21,6 +22,11 @@
default: 16
},
},
methods: {
clickHandle() {
this.$emit("click");
}
},
computed: {
iconCode() : string {
const iconCode : UTSJSONObject = {
......@@ -51,4 +57,4 @@
font-size: 16px;
font-style: normal;
}
</style>
\ No newline at end of file
</style>
......@@ -4,7 +4,7 @@
<text v-if="hasTitleAndContent" class="title">{{title}}</text>
<input class="input" ref="input" :placeholder="_placeholder" :class="{'move-down':hasTitleAndContent}"
:value="modelValue" @input="updateValue" :type="type" :maxlength="maxlength"
:password="password && !visiblePwd" :focus="focus" @blur="onBlur" @focus="onFocus" @confirm="confirm"
:password="password && !visiblePwd" :focus="focusInput" @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'"
......@@ -23,9 +23,15 @@
emits: ["blur", "focus", "confirm", "update:modelValue"],
data() {
return {
visiblePwd: false
visiblePwd: false,
focusInput: false
}
},
mounted(){
if(this.focus){
this.setFocus(true)
}
},
computed: {
_placeholder() : string {
if (this.placeholder.length > 0) {
......@@ -78,7 +84,10 @@
default: "done"
},
/**
* @param touch click
* 显示密码的方式
* @type {String}
* @default click
* @example click | touch
*/
visiblePwdOption:{
type: String,
......@@ -103,31 +112,29 @@
// this.$emit('update:focus', true);
},
setFocus(state : boolean) {
const inputEl = this.$refs['input'] as UniElement
if (state) {
inputEl.focus();
} else {
inputEl.blur();
}
// console.error('setFocus',state)
this.focusInput = state
},
confirm(event : InputConfirmEvent) {
this.$emit('confirm', event)
},
setVisiblePwd(eventName:string){
console.error('eventName',eventName)
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;
// }
}else if(eventName.includes("touch") && this.visiblePwdOption == 'touch'){
console.error('eventName',eventName)
switch (eventName){
case "touchstart":
this.visiblePwd = true
break;
case "touchend":
this.visiblePwd = false
break;
case "touchcancel":
this.visiblePwd = false
break;
}
}
}
}
......@@ -137,7 +144,6 @@
<style lang="scss" scoped>
.input-box {
position: relative;
margin: 0;
background-color: #F8F8F8;
height: 50px !important;
border-radius: 5rpx;
......@@ -179,6 +185,7 @@
right: 10px;
bottom:14px;
flex-direction: row;
z-index: 2;
}
.password-icon {
......
......@@ -7,8 +7,8 @@
<view class="code-input-list">
<template v-for="(_,i) in smsCodeList" :key="i">
<!-- TODO APP :value="item" 第一次不触发@input -->
<input @input="setSmsCode(i,$event as InputEvent)" type="number" ref="code-input"
class="code-input" maxlength="7" @focus="onFocus(i)" />
<input @input="setSmsCode(i,$event as InputEvent)" type="number" ref="code-input" :value="smsCodeList[i]"
class="code-input" :maxlength="i == 0 ? 7 : 2" @focus="onFocus(i)" @blur="onBlur(i)" :focus="focusInputs[i]" />
</template>
</view>
<view class="fab-sms-code-input-foot">
......@@ -25,6 +25,7 @@
data() {
return {
smsCodeList: ["\u200b", "\u200b", "\u200b", "\u200b", "\u200b", "\u200b"],
focusInputs: [false, false, false, false, false, false],
isOpen: false
}
},
......@@ -60,11 +61,17 @@
this.$emit('update:modelValue', smsCode);
},
},
// mounted() {
// this.show()
// },
methods: {
onBlur(i : number) {
this.focusInputs[i] = false
},
show() {
(this.$refs['popup'] as UniPopupComponentPublicInstance).open();
this.$nextTick(() => {
(this.$refs["code-input"] as UniElement[])[0].focus();
this.focusInputs[0] = true;
})
this.isOpen = true
},
......@@ -75,7 +82,7 @@
clear() {
this.smsCodeList = ["\u200b", "\u200b", "\u200b", "\u200b", "\u200b", "\u200b"];
if (this.isOpen) {
(this.$refs["code-input"] as UniElement[])[0].focus();
this.focusInputs[0] = true;
// console.log('clear success');
} else {
// console.log('已经关了,不能清空');
......@@ -84,10 +91,10 @@
setSmsCode(i : number, e : InputEvent) {
const { value } = e.detail
// console.log('~~',value,value.length);
// 已满6位数就直接调登录
let $value = value.replace(/\u200b/g, '')
if ($value.length == 6) {
// (this.$refs["code-input"] as Element[])[0].focus();
$value.split('').forEach((item : string, index : number) => {
this.smsCodeList[index] = "\u200b" + item
})
......@@ -107,13 +114,13 @@
this.smsCodeList[i] = '\u200b'
})
if (i != 0) {
(this.$refs["code-input"] as UniElement[])[i - 1].focus();
this.focusInputs[i - 1] = true;
this.smsCodeList[i - 1] = ""
}
} else if (value != "\u200b") {
this.smsCodeList[i] = value;
if (i != (this.smsCodeList.length - 1)) {
(this.$refs["code-input"] as UniElement[])[i + 1].focus();
this.focusInputs[i + 1] = true;
} else {
// console.log(i, (this.smsCodeList.length - 1));
}
......
......@@ -152,8 +152,7 @@ export default async function () {
// needLogin相关代码-start(此代码仅为版本兼容提示使用,如已知晓可删除)
const needLogin = config.getArray<string>('needLogin')
const uniCompileVersionCode = uni.getSystemInfoSync().uniCompileVersionCode
if(needLogin != null && (uniCompileVersionCode >= 3.99 ) ){
if(needLogin != null){
const tipText = "uni-id-pages x v1.0.4+ 不再支持配置项config.needLogin,请升级HBuilderX 版本为3.99+,使用更强大 uni-id-router替代。详情查看:https://uniapp.dcloud.net.cn/uniCloud/uni-id/summary.html#uni-id-router"
console.error(tipText)
uni.showModal({
......
<template>
<view class="page">
<uni-navbar-lite title="设置昵称" class="uni-navbar-lite">
<template v-slot:right>
<text class="submit" :class="{disabled:!hasChange || nickname == ''}" @click="setNickname">完成</text>
<!-- #ifndef MP-WEIXIN -->
<template v-slot:right>
<text class="submit" :class="{disabled:!hasChange || nickname == ''}" @click="setNickname">完成</text>
</template>
<!-- #endif -->
</uni-navbar-lite>
<uni-id-pages-x-input class="my-input" v-model="nickname" @confirm="setNickname" placeholder="请输入昵称" :focus="true"
:maxlength="25"></uni-id-pages-x-input>
<!-- #ifdef MP-WEIXIN -->
<button class="submit-mp" :disabled="!hasChange || nickname == ''" type="primary" @click="setNickname">完成</button>
<!-- #endif -->
</view>
</template>
......@@ -24,7 +29,8 @@
return this.currentNickname != this.nickname
},
currentNickname() : string {
return state.userInfo.get("nickname") == null?'':(state.userInfo.get("nickname") as string)
const nickname = state.userInfo["nickname"]
return nickname == null ? '' : nickname as string
}
},
onLoad() {
......@@ -83,7 +89,7 @@
}
.my-input {
background-color: #FFF;
background-color: #FFF!important;
}
.uni-navbar-lite .right-content {
......@@ -106,4 +112,13 @@
background-color: #EFEFEF;
color: #AAA;
}
/* #ifdef MP-WEIXIN */
.submit-mp {
position: fixed;
bottom: 0;
left: 0;
width: 100%;
border-radius: 0;
}
/* #endif */
</style>
......@@ -9,12 +9,9 @@
<text class="title">昵称</text>
<view @click="setNickname" class="content">
<text class="unset" v-if="!isLogin">未登录</text>
<text class="value"
v-else-if="userInfo['nickname'] != null && userInfo['nickname'] != ''">{{userInfo['nickname']}}
</text>
<text class="value" v-else-if="userInfo['nickname'] != null && userInfo['nickname'] != ''">{{userInfo['nickname']}}</text>
<text class="unset" v-else>未设置</text>
<uni-id-pages-x-icons v-if="isLogin" :size="16" type="right-arrow"
class="link-icon"></uni-id-pages-x-icons>
<uni-id-pages-x-icons v-if="isLogin" :size="16" type="right-arrow" class="link-icon"></uni-id-pages-x-icons>
</view>
</view>
<view class="item">
......
......@@ -23,7 +23,7 @@ function initState() {
// #ifdef APP-IOS
userInfo = new UTSJSONObject(userInfo)
// #endif
if (userInfo instanceof UTSJSONObject) {
if (userInfo != null) {
state.userInfo = userInfo as UTSJSONObject
// console.log('init userInfo',userInfo);
}
......@@ -62,15 +62,13 @@ export const mutations = {
customUI: true
})
uniIdCo
.getRealNameInfo()
.then((realNameInfo) => {
state.userInfo = Object.assign(res.data[0], {
realNameInfo
uniIdCo.getRealNameInfo()
.then((realNameInfo) => {
state.userInfo = Object.assign(res.data[0], {
realNameInfo
}) as UTSJSONObject
afterUpdateUserInfo()
})
afterUpdateUserInfo()
})
})
.catch((err: any | null) => {
const error = err as UniCloudError
......@@ -79,7 +77,7 @@ export const mutations = {
} else {
param.toMap().forEach((value, key) => {
state.userInfo.set(key, value)
state.userInfo[key] = value
})
usersCollection
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册