当前位置:网站首页>Wechat applet editor Avatar
Wechat applet editor Avatar
2022-07-27 04:36:00 【Summer thought】
Avatar nickname filling | Wechat open documents There is a way to edit the avatar of wechat , But the test found that the upload avatar is particularly slow . Need at least 5s. If you access the interface data after modification, it will take longer . The reason is because
It takes time to carry out safety inspection , Avoid uploading sensitive pictures .
But when we actually use it, the test is too slow , You can only change your mind , I wrote
<button class="avatar-wrapper"bindtap='changeHead'> <image class="avatar" src="{ {avatar}}"></image> </button>
changeHead(){
var _this = this;
wx.showActionSheet({
itemList: [" Taking pictures ", " Choose from the album "],
itemColor: "#000000",
success: function (res) {
if (!res.cancel) {
if (res.tapIndex == 0) {
_this.imgWShow("camera") // Taking pictures
} else if (res.tapIndex == 1) {
_this.imgWShow("album") // Photo album
}
}
}
})
},
// Click to call mobile photo album / Taking pictures
imgWShow: function (type) {
var _this = this;
let len = 0;
if (_this.data.imgList != null) {
len = _this.data.imgList.length
} // Get the currently existing picture
wx.chooseImage({
count:1, // The maximum number of pictures that can be uploaded , You can upload up to 1 Zhang
sizeType: ['original', 'compressed'], // You can specify whether it is original or compressed , By default, both of them have
sourceType: [type], // You can specify whether the source is an album or a camera , By default, both of them have
success: function (res) {
wx.showToast({
title: ' Uploading ...',
icon: "loading",
mask: true,
duration: 1000
})
// Returns a list of local file paths for the selected photo ,tempFilePaths It can be used as img Labeled scr Property display image
var imgList = res.tempFilePaths
_this.UploadImg(imgList[0])// The access interface gives the uploaded image to the interface
},
fail: function () {
wx.showToast({
title: ' Picture upload failed ',
icon: 'none'
})
return;
}
})
},
UploadImg(avatarUrl){
console.log(avatarUrl)
this.uploadFile(avatarUrl).then(res => {
this.setData({
avatar:avatarUrl,
})
})
},uploadFile: (filePath) => {
let url = "http://XXXXX/uploaded_file"// Upload interface
return new Promise((resolve, reject) => {
wx.uploadFile({
url: url,
filePath: filePath,
name: "file",
header: {
'content-type': 'application/json',
'token': getToken(),
},
success: (res) => {
console.log(res)
let result = JSON.parse(res.data)
let {code} = result
if (code === 200) {
return resolve(result.data)
} else {
return reject(result.message)
}
},
fail() {
reject(' Interface error , Please check ')
}
})
})
},
边栏推荐
- 利用JSON类型在mysql中实现数组功能
- Post analysis of Data Analyst
- 使用Unity做一个艺术字系统
- ros 相机标定 sensor_msgs/CameraInfo Message 数据类型及含义
- RSA asymmetric encryption and decryption signature verification tool
- Chapter 6: cloud database
- 5.component动态组件的展示
- Playwright web crawler actual battle case sharing
- F - Pre-order and In-order(Atcoder 255)
- Eureka service registry
猜你喜欢

佳明手表怎么设置用户定制显示

使用Unity做一个艺术字系统

安全第四次课后练习

好用的shell快捷键

Navicat exports Mysql to table structure and field description

Remember the major performance problems caused by a TCP packet loss

VSCode开启Pull Request更新代码分支可视化新篇章

Convolution neural network -- a detailed introduction to convolution of 24 bit color images

干货 | 独立站运营怎么提高在线聊天客户服务?

Prometheus Node Exporter 常用监控指标
随机推荐
Preliminary understanding of NiO
微信小程序编辑头像
Wechat input component adds a clear icon, and clicking clear does not take effect
QString转换char*
Ffmpeg merge video function
哈希表刷题(下)
详解左值、右值、左值引用以及右值引用
【day02】数据类型转换、运算符、方法入门
ISG index shows that the it and business service market in the Asia Pacific region fell sharply in the second quarter
redux三大核心
[final review of software engineering] knowledge points + detailed explanation of major problems (E-R diagram, data flow diagram, N-S box diagram, state diagram, activity diagram, use case diagram...)
好用的shell快捷键
BSN IPFs (interstellar file system) private network introduction, functions, architecture and characteristics, access instructions
微服务的feign调用header头被丢弃两种解决方案(附源码)
安全第四次课后练习
结构型模式-适配器模式
The data in echart histogram is displayed at the top of the chart
P1438 无聊的数列 线段树+差分
Ribbon load balancing principle and some source codes
Oracle数据库字段date怎么才能走索引?