提交 b9eae43d 编写于 作者: study夏羽's avatar study夏羽

优化体积/小程序端用wx.cropImage裁切头像

上级 52df81ed
<template>
<view @click="onClick" :style="{width,height}">
<view @click="onClick" :style="{width,height}" style="justify-content: center;">
<image v-if="cSrc" :style="{width,height}" :src="cSrc" :mode="mode"></image>
</view>
</template>
......@@ -46,13 +46,10 @@
watch: {
src:{
handler(src) {
// console.log(src);
// console.log(src.substring(0, 8));
if (src&&src.substring(0, 8) == "cloud://") {
uniCloud.getTempFileURL({
fileList: [src]
}).then(res=>{
// console.log(res);
this.cSrc = res.fileList[0].tempFileURL
})
}else{
......@@ -61,9 +58,6 @@
},
immediate: true
}
},
async mounted() {
},
methods:{
onClick(){
......
......@@ -67,7 +67,6 @@
},
methods: {
popupConfirm(){
// console.log("popupConfirm");
this.isAgree = true
retryFun()
// this.$emit('popupConfirm')
......
......@@ -48,7 +48,6 @@
async mounted() {
// #ifdef H5
this.isPC = !['ios', 'android'].includes(uni.getSystemInfoSync().platform);
// console.log(' this.isPC', this.isPC, uni.getSystemInfoSync().platform);
// #endif
},
computed: {
......@@ -68,7 +67,6 @@
mutations.updateUserInfo({avatar_file})
},
uploadAvatarImg(res) {
// console.log(this.hasLogin);
if(!this.hasLogin){
return uni.navigateTo({
url:'/uni_modules/uni-id-pages/pages/login/login-withoutpwd'
......@@ -84,7 +82,6 @@
count: 1,
crop,
success: async (res) => {
// console.log(res);
let tempFile = res.tempFiles[0],
avatar_file = {
// #ifdef H5
......@@ -95,10 +92,12 @@
// #endif
},
filePath = res.tempFilePaths[0]
//非app端剪裁头像,app端用内置的原生裁剪
// #ifndef APP-PLUS
//非app端用前端组件剪裁头像,app端用内置的原生裁剪
if (!this.isPC) {
filePath = await new Promise((callback) => {
filePath = await new Promise((callback) => {
// #ifdef H5
if (!this.isPC) {
uni.navigateTo({
url: '/uni_modules/uni-id-pages/pages/userinfo/cropImage/cropImage?path=' +
filePath + `&options=${JSON.stringify(crop)}`,
......@@ -112,10 +111,25 @@
// console.log(e);
}
});
}
// #endif
// #ifdef MP-WEIXIN
wx.cropImage({
src:filePath,
cropScale:"1:1",
success: res => {
callback(res.tempFilePath)
},
fail(e){
console.error(e)
callback(filePath)
}
})
}
// #endif
})
// #endif
// console.log(this.userInfo);
let cloudPath = this.userInfo._id + '' + Date.now()
avatar_file.name = cloudPath
uni.showLoading({
......@@ -129,9 +143,7 @@
cloudPath,
fileType: "image"
});
// console.log(result)
avatar_file.url = fileID
// console.log({avatar_file});
uni.hideLoading()
this.setAvatarFile(avatar_file)
}
......
......@@ -41,13 +41,11 @@
uniCloud.importObject("uni-id-co",{
customUI:true
}).loginByWeixin({code}).then(e=>{
// console.log(e);
resolve()
}).catch(e=>{
console.log(e);
reject()
}).finally(e=>{
// console.log(e);
uni.hideLoading()
})
},
......@@ -61,13 +59,10 @@
})
},
async bindMobileByMpWeixin(e) {
// console.log(e);
if (e.detail.errMsg == "getPhoneNumber:ok") {
// console.log(e.detail);
//检查登录信息是否过期,否则通过重新登录刷新session_key
await this.beforeGetphonenumber()
uniIdCo.bindMobileByMpWeixin(e.detail).then(e => {
// console.log(e);
this.$emit('success')
}).finally(e => {
this.closeMe()
......@@ -157,8 +152,8 @@
.agree::after {
border: none;
}
/* #endif */
.agree:active {
background-color: #F5F5F6;
}
......
......@@ -141,7 +141,6 @@
const uniIdCo = uniCloud.importObject("uni-id-co", {
customUI: true
})
// console.log('uniIdCo', uniIdCo)
console.log('sendEmailCode',{
"email": this.email,
"scene": this.type,
......@@ -152,7 +151,6 @@
"scene": this.type,
"captcha": this.captcha
}).then(result => {
// console.log(result.code);
uni.showToast({
title: "邮箱验证码发送成功",
icon: 'none',
......@@ -161,7 +159,6 @@
this.reverseNumber = Number(this.count);
this.getCode();
}).catch(e => {
// console.log(JSON.stringify(e));
if (e.code == "uni-id-invalid-mail-template") {
this.modelValue = "123456"
uni.showToast({
......
......@@ -15,13 +15,7 @@
<script>
import config from '@/uni_modules/uni-id-pages/config.js'
//前一个窗口的页面地址。控制点击切换快捷登录方式是创建还是返回
import {
store,
mutations
} from '@/uni_modules/uni-id-pages/common/store.js'
const db = uniCloud.database();
const usersTable = db.collection('uni-id-users')
import {store,mutations} from '@/uni_modules/uni-id-pages/common/store.js'
let allServicesList = []
export default {
......@@ -49,7 +43,6 @@
return this.getParentComponent().agree
},
set(agree) {
// console.log('setAgree', agree);
return this.getParentComponent().agree = agree
}
}
......@@ -59,64 +52,64 @@
servicesList: [{
"id": "username",
"text": "账号登录",
"logo": "/uni_modules/uni-id-pages/static/uni-fab-login/user.png",
"logo": "/uni_modules/uni-id-pages/static/login/uni-fab-login/user.png",
"path": "/uni_modules/uni-id-pages/pages/login/login-withpwd"
},
{
"id": "smsCode",
"text": "短信验证码",
"logo": "/uni_modules/uni-id-pages/static/uni-fab-login/sms.png",
"logo": "/uni_modules/uni-id-pages/static/login/uni-fab-login/sms.png",
"path": "/uni_modules/uni-id-pages/pages/login/login-withoutpwd?type=smsCode"
},
{
"id": "weixin",
"text": "微信登录",
"logo": "/uni_modules/uni-id-pages/static/uni-fab-login/weixin.png",
"logo": "/uni_modules/uni-id-pages/static/login/uni-fab-login/weixin.png",
},
{
"id": "apple",
"text": "苹果登录",
"logo": "/uni_modules/uni-id-pages/static/uni-fab-login/apple.png",
"logo": "/uni_modules/uni-id-pages/static/app-plus/uni-fab-login/apple.png",
},
{
"id": "univerify",
"text": "一键登录",
"logo": "/uni_modules/uni-id-pages/static/uni-fab-login/univerify.png",
"logo": "/uni_modules/uni-id-pages/static/app-plus/uni-fab-login/univerify.png",
},
{
"id": "taobao",
"text": "淘宝登录", //暂未提供该登录方式的接口示例
"logo": "/uni_modules/uni-id-pages/static/uni-fab-login/taobao.png",
"logo": "/uni_modules/uni-id-pages/static/app-plus/uni-fab-login/taobao.png",
},
{
"id": "facebook",
"text": "脸书登录", //暂未提供该登录方式的接口示例
"logo": "/uni_modules/uni-id-pages/static/uni-fab-login/facebook.png",
"logo": "/uni_modules/uni-id-pages/static/app-plus/uni-fab-login/facebook.png",
},
{
"id": "alipay",
"text": "支付宝登录", //暂未提供该登录方式的接口示例
"logo": "/uni_modules/uni-id-pages/static/uni-fab-login/alipay.png",
"logo": "/uni_modules/uni-id-pages/static/app-plus/uni-fab-login/alipay.png",
},
{
"id": "qq",
"text": "QQ登录", //暂未提供该登录方式的接口示例
"logo": "/uni_modules/uni-id-pages/static/uni-fab-login/qq.png",
"logo": "/uni_modules/uni-id-pages/static/app-plus/uni-fab-login/qq.png",
},
{
"id": "google",
"text": "谷歌登录", //暂未提供该登录方式的接口示例
"logo": "/uni_modules/uni-id-pages/static/uni-fab-login/google.png",
"logo": "/uni_modules/uni-id-pages/static/app-plus/uni-fab-login/google.png",
},
{
"id": "douyin",
"text": "抖音登录", //暂未提供该登录方式的接口示例
"logo": "/uni_modules/uni-id-pages/static/uni-fab-login/douyin.png",
"logo": "/uni_modules/uni-id-pages/static/app-plus/uni-fab-login/douyin.png",
},
{
"id": "sinaweibo",
"text": "新浪微博", //暂未提供该登录方式的接口示例
"logo": "/uni_modules/uni-id-pages/static/uni-fab-login/sinaweibo.png",
"logo": "/uni_modules/uni-id-pages/static/app-plus/uni-fab-login/sinaweibo.png",
}
],
univerifyStyle: { //一键登录弹出窗的样式配置参数
......@@ -189,7 +182,6 @@
let path = item.path ? item.path.split('?')[0] : '';
return path != this.getRoute(1)
})
//console.log('servicesList', servicesList, this.servicesList);
},
methods: {
getParentComponent(){
......@@ -206,7 +198,6 @@
},
getRoute(n = 0) {
let pages = getCurrentPages();
// console.log('route-pages-length', pages.length);
if (n > pages.length) {
return ''
}
......@@ -222,7 +213,6 @@
} else if (this.getRoute(2) == path) { // 如果上一个页面就是,马上要打开的页面,直接返回。防止重复开启
uni.navigateBack();
} else if (this.getRoute(1) != path) {
//console.log(3);
uni.navigateTo({
url: path,
animationType: 'slide-in-left',
......@@ -294,13 +284,10 @@
}
//判断是否需要弹出隐私协议授权框
// console.log(type, this.agree);
let needAgreements = (config?.agreements?.scope || []).includes('register')
// console.log({needAgreements});
if (type != 'univerify' && needAgreements && !this.agree) {
let agreementsRef = this.getParentComponent().$refs.agreements
return agreementsRef.popup(() => {
// console.log(type, navigateBack);
this.login_before(type, navigateBack, options)
})
}
......@@ -312,7 +299,6 @@
document.domain +
(window.location.href.includes('#')?'/#':'') +
'/uni_modules/uni-id-pages/pages/login/login-withoutpwd?is_weixin_redirect=true&type=weixin'
// console.log('redirectUrl----',redirectUrl);
let ua = window.navigator.userAgent.toLowerCase();
if (ua.match(/MicroMessenger/i) == 'micromessenger'){
// console.log('在微信公众号内');
......@@ -341,7 +327,6 @@
// console.log('点击了第三方登录,provider:', res, res.provider, this.univerifyStyle.buttons.list);
//同步一键登录弹出层隐私协议框是否打勾
let agree = (await uni.getCheckBoxState())[1].state
//console.log('agree',agree);
this.agree = agree
let {
path
......@@ -353,11 +338,9 @@
if (agree) {
closeUniverify()
setTimeout(() => {
//console.log('login_before');
this.login_before(res.provider)
}, 500)
} else {
//console.log("你未同意隐私政策协议");
uni.showToast({
title: "你未同意隐私政策协议",
icon: 'none',
......@@ -379,7 +362,6 @@
return univerifyManager.login({
"univerifyStyle": this.univerifyStyle,
success: res => {
// console.log('login success', res)
this.login(res.authResult, 'univerify')
},
fail(err) {
......@@ -390,7 +372,6 @@
});
},
complete: async e => {
// console.log(e);
uni.hideLoading()
//同步一键登录弹出层隐私协议框是否打勾
this.agree = (await uni.getCheckBoxState())[1].state
......@@ -400,11 +381,11 @@
})
}
if (type === 'weixinMobile') {
return this.login({
phoneCode: options.phoneNumberCode
}, type)
}
if (type === 'weixinMobile') {
return this.login({
phoneCode: options.phoneNumberCode
}, type)
}
uni.login({
"provider": type,
......@@ -413,7 +394,6 @@
"univerifyStyle": this.univerifyStyle,
// #endif
success: async e => {
// console.log(e);
if (type == 'apple') {
let res = await this.getUserInfo({
provider: "apple"
......@@ -440,7 +420,6 @@
customUI:true
})
uniIdCo[action](params).then(result => {
// console.log("login-result", result);
uni.showToast({
title: '登录成功',
icon: 'none',
......@@ -449,7 +428,7 @@
// #ifdef MP-WEIXIN
//如果是微信小程序端的微信登录,且为首次登录,就弹出获取微信昵称+头像用于绑定资料
if (['weixin', 'weixinMobile'].includes(type) && result.type == "register") {
mutations.loginSuccess({
mutations.loginSuccess({
...result,
showToast: false,
autoBack: false
......@@ -463,7 +442,6 @@
mutations.loginSuccess(result)
})
.catch(e=>{
// console.log(e);
uni.showModal({
content: e.message,
confirmText:"知道了",
......@@ -513,7 +491,6 @@
box-sizing: border-box;
flex-direction: column;
}
/* #endif */
.fab-login-box {
......@@ -552,8 +529,6 @@
/* #endif */
.logo {
width: 60rpx;
height: 60rpx;
......@@ -563,7 +538,6 @@
border: solid 1px #F6F6F6;
}
.login-title {
text-align: center;
margin-top: 6px;
......
......@@ -146,7 +146,6 @@
"scene": this.type,
"captcha": this.captcha
}).then(result => {
// console.log(result.code);
uni.showToast({
title: "短信验证码发送成功",
icon: 'none',
......@@ -155,7 +154,6 @@
this.reverseNumber = Number(this.count);
this.getCode();
}).catch(e => {
// console.log(JSON.stringify(e));
if (e.code == "uni-id-invalid-sms-template-id") {
this.modelValue = "123456"
uni.showToast({
......@@ -209,7 +207,6 @@
/* #endif */
justify-content: center;
align-items: center;
}
.inner-text {
......
......@@ -31,12 +31,10 @@
uni.getUserProfile({
desc: "用于设置账户昵称和头像",
complete: (e) => {
// console.log("getUserProfile:", e);
callBack(e)
}
})
})
// console.log("userInfo", res.userInfo);
if(res.errMsg != "getUserProfile:ok"){
return this.closeMe()
}
......@@ -46,10 +44,10 @@
uni.downloadFile({
url: avatarUrl,
success: (res) => {
if (res.statusCode === 200) {
if (res.statusCode === 200) {
// console.log('下载成功');
callBack(res.tempFilePath)
}
callBack(res.tempFilePath)
}
callBack()
},
fail: (err) => {
......@@ -62,13 +60,11 @@
})
const extName = tempFilePath.split('.').pop() || 'jpg'
const cloudPath = 'user/avatar/'+ userId+'/'+Date.now()+'-avatar.'+extName;
// console.log(tempFilePath);
const result = await uniCloud.uploadFile({
filePath: tempFilePath,
cloudPath,
fileType:'image'
});
// console.log("上传成功",{result});
let userInfo = {
"nickname":nickName,
"avatar_file":{
......@@ -89,7 +85,6 @@
})
},
doUpdate(data,callback){
// console.log('dododo',data);
// 使用 clientDB 提交数据
usersTable.where('_id==$env.uid').update(data).then((res) => {
callback(res)
......
......@@ -20,7 +20,6 @@
});
title = "页面路径错误"
}else{
// console.log(url,title);
this.url = url;
}
if(title){
......@@ -34,7 +33,3 @@
}
}
</script>
<style lang="scss">
</style>
......@@ -38,7 +38,6 @@
this.phone = phoneNumber;
},
onShow() {
// console.log('onShow');
// #ifdef H5
document.onkeydown = event => {
var e = event || window.event;
......@@ -68,14 +67,12 @@
"code": this.code,
"captcha": this.captcha
}).then(e => {
// console.log(e);
this.loginSuccess(e)
}).catch(e => {
if (e.errCode == 'uni-id-captcha-required') {
this.$refs.popup.open()
} else {
console.log(e.errMsg);
// console.log(e.errCode);
}
}).finally(e => {
this.captcha = ''
......
......@@ -52,14 +52,14 @@
return /^1\d{10}$/.test(this.phone);
},
imgSrc() { //大快捷登录按钮图
return '/uni_modules/uni-id-pages/static/login/' + this.type + '.png'
return this.type == 'weixin'? '/uni_modules/uni-id-pages/static/login/weixin.png' : '/uni_modules/uni-id-pages/static/app-plus/apple.png'
}
},
async onLoad(e) {
// console.log(e);
//获取通过url传递的参数type设置当前登录方式,如果没传递直接默认以配置的登录
let type = e.type || config.loginTypes[0]
this.type = type
// console.log("this.type: -----------",this.type);
if(type != 'univerify'){
this.focusPhone = true
}
......@@ -111,7 +111,6 @@
this.$refs.uniFabLogin.login_before(this.type, true, options)
},
toSmsPage() {
// console.log('toSmsPage',this.agree);
if (!this.isPhone) {
this.focusPhone = true
return uni.showToast({
......@@ -201,7 +200,6 @@
}
.quickLogin {
// width: 650rpx;
height: 350px;
align-items: center;
justify-content: center;
......
......@@ -108,12 +108,9 @@
},
submitForm(params) {
uniIdCo.registerAdmin(this.formData).then(e => {
// console.log(e);
uni.navigateBack()
})
.catch(e => {
// console.log(e);
// console.log(e.message);
//更好的体验:登录错误,直接刷新验证码
this.$refs.captcha.getImageCaptcha()
uni.showModal({
......
......@@ -114,7 +114,6 @@
}).catch((errors) => {
let key = errors[0].key
key = key.replace(key[0], key[0].toUpperCase())
// console.log(key);
this['focus' + key] = true
return errors
})
......
......@@ -137,8 +137,6 @@
* 完成并提交
*/
submit() {
// console.log("formData", this.formData);
// console.log('rules', this.rules);
this.$refs.form.validate()
.then(res => {
let {
......@@ -153,7 +151,6 @@
password,
captcha
}).then(e => {
// console.log(e);
uni.navigateTo({
url: '/uni_modules/uni-id-pages/pages/login/login-withpwd',
complete: (e) => {
......@@ -171,11 +168,9 @@
}).catch(errors=>{
let key = errors[0].key
if(key == 'code'){
// console.log(this.$refs.shortCode);
return this.$refs.shortCode.focusSmsCodeInput = true
}
key = key.replace(key[0], key[0].toUpperCase())
// console.log(key,'focus'+key);
this['focus'+key] = true
})
},
......
......@@ -166,8 +166,6 @@
* 完成并提交
*/
submit() {
// console.log("formData", this.formData);
// console.log('rules', this.rules);
this.$refs.form.validate()
.then(res => {
let {
......@@ -182,7 +180,6 @@
password,
captcha
}).then(e => {
// console.log(e);
uni.navigateBack()
})
.catch(e => {
......@@ -195,11 +192,9 @@
}).catch(errors=>{
let key = errors[0].key
if(key == 'code'){
// console.log(this.$refs.shortCode);
return this.$refs.shortCode.focusSmsCodeInput = true
}
key = key.replace(key[0], key[0].toUpperCase())
// console.log(key,'focus'+key);
this['focus'+key] = true
})
},
......@@ -208,11 +203,11 @@
url: '/uni_modules/uni-id-pages/pages/retrieve/retrieve-by-email'
})
},
backLogin () {
uni.redirectTo({
url: '/uni_modules/uni-id-pages/pages/login/login-withpwd'
})
}
backLogin () {
uni.redirectTo({
url: '/uni_modules/uni-id-pages/pages/login/login-withpwd'
})
}
}
}
</script>
......
......@@ -65,7 +65,6 @@
});
}
// console.log(this.formData);
const uniIdCo = uniCloud.importObject("uni-id-co")
return await uniIdCo.bindMobileBySms(this.formData).then(e => {
// console.log(e);
......
......@@ -112,7 +112,6 @@
console.log("errors: ",errors);
let key = errors[0].key
key = key.replace(key[0], key[0].toUpperCase())
// console.log(key, 'focus' + key);
this['focus' + key] = true
return errors
})
......
......@@ -39,11 +39,8 @@
content: '已经仔细阅读注销提示,知晓可能带来的后果,并确认要注销',
complete: (e) => {
if (e.confirm) {
const db = uniCloud.database();
const uniIdco = uniCloud.importObject("uni-id-co");
uniIdco.closeAccount().then((e) => {
// console.log(e);
uni.showToast({
title: '注销成功',
duration: 3000
......
......@@ -115,7 +115,6 @@ export default {
this.$refs.popup.open()
} else {
console.log(e.errMsg);
// console.log(e.errCode);
}
}).finally(e => {
this.formData.captcha = ''
......
......@@ -14,9 +14,11 @@
<uni-list-item v-if="hasPwd" class="item" @click="changePassword" title="修改密码" link>
</uni-list-item>
</uni-list>
<!-- #ifndef MP -->
<uni-list class="mt10">
<uni-list-item @click="deactivate" title="注销账号" link="navigateTo"></uni-list-item>
</uni-list>
<!-- #endif -->
<uni-popup ref="dialog" type="dialog">
<uni-popup-dialog mode="input" :value="userInfo.nickname" @confirm="setNickname" title="设置昵称"
placeholder="请输入要设置的昵称">
......@@ -30,8 +32,6 @@
</view>
</template>
<script>
const db = uniCloud.database();
const usersTable = db.collection('uni-id-users')
const uniIdCo = uniCloud.importObject("uni-id-co")
import {
store,
......@@ -82,12 +82,12 @@
}
})
},
logout(){
mutations.logout()
},
bindMobileSuccess(){
mutations.updateUserInfo()
},
logout(){
mutations.logout()
},
bindMobileSuccess(){
mutations.updateUserInfo()
},
changePassword(){
uni.navigateTo({
url: '/uni_modules/uni-id-pages/pages/userinfo/change_pwd/change_pwd',
......@@ -123,9 +123,7 @@
"provider": 'univerify',
"univerifyStyle": this.univerifyStyle,
success: async e => {
// console.log(e.authResult);
uniIdCo.bindMobileByUniverify(e.authResult).then(res => {
// console.log(res);
mutations.updateUserInfo()
}).catch(e => {
console.log(e);
......@@ -148,7 +146,6 @@
})
},
setNickname(nickname) {
// console.log(nickname);
if (nickname) {
mutations.updateUserInfo({nickname})
this.$refs.dialog.close()
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册