当前位置:网站首页>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 ')
}
})
})
},
边栏推荐
- Plato farm has a new way of playing, and the arbitrage eplato has secured super high returns
- Effect Hook
- STM32 serial port based on Hal library accepts interrupts and idle interrupts
- els 兼容性DC、传递图片到窗口
- 地平线 旭日X3 PI (四) 板上运行(未写完)
- Webpack packaging Vue project adds confusion to solve the cache problem
- Post analysis of Data Analyst
- 【HCIP】重发布、重分布、重分发实验
- Yolov4网络详解
- F - Pre-order and In-order(Atcoder 255)
猜你喜欢

【C语言】递归详解汉诺塔问题

IP第十四天笔记

安全第四次课后练习

Using webmvcconfigurer to intercept interface requests is being enhanced (with source code)

Remember the major performance problems caused by a TCP packet loss

【软件工程期末复习】知识点+大题详解(E-R图、数据流图、N-S盒图、状态图、活动图、用例图....)

卷积神经网络——灰度图像的卷积

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

Brightcove任命Dan Freund为首席营收官

项目参数做成可配置项,@ConfigurationProperties注解的使用
随机推荐
QString转换char*
STM32基于HAL库的串口接受中断和空闲中断
C get UUID
【C语言】递归详解汉诺塔问题
[day02] Introduction to data type conversion, operators and methods
Oracle数据库字段date怎么才能走索引?
【day02】数据类型转换、运算符、方法入门
Nacos startup and login
els 兼容性DC、传递图片到窗口
匿名命名管道, 共享内存的进程间通信理解与使用
你了解微信商户分账吗?
Convolution neural network -- convolution of gray image
Practice of microservice in solving Library Download business problems
2022杭电多校联赛第三场 题解
ISG index shows that the it and business service market in the Asia Pacific region fell sharply in the second quarter
好用移动APP自动化测试框架哪里找?收藏这份清单就好了!
佳明手表怎么设置用户定制显示
管理信息系统期末复习
[leetcode] day104 no overlapping interval
人很话不多,工程师不耍嘴皮子