当前位置:网站首页>The function of wechat applet to cut pictures
The function of wechat applet to cut pictures
2022-07-28 22:30:00 【Summer thought】
Simple-Crop/USAGE-wechat.md at master · newbieYoung/Simple-Crop · GitHub
Download it first wechat This folder . Put it in the applet components Inside

Put it into a component to use . I rename this folder to simple-crop La .
json Introduced inside
{
"navigationBarTitleText": " essential information ",
"usingComponents": {
"simple-crop": "../components/simple-crop/index"
},
"navigationStyle": "custom"
}<button class="avatar-wrapper" bindtap='changeHead' >
<image class="avatar" src="{
{avatar1}}"></image>
</button>
<simple-crop wx:if="{
{crop.visible}}" size="{
{crop.size}}" src="{
{crop.src}}" cropSizePercent="{
{crop.cropSizePercent}}" borderColor="{
{crop.borderColor}}" bindcropUpload="uploadCallback" bindcropClose="closeCallback" bindcropCrop="cropCallback"></simple-crop>js Inside
Page({ data: { avatar1:'', crop:{ src: null, // Crop image address visible: false, // Whether or not shown size: { // Cut out the size width: 400, height: 400 }, cropSizePercent: 0.9, // Crop box display scale borderColor: '#fff', // Crop box border color result: '', // Crop result address } },// After selecting the picture uploadCallback(e){ //console.log(" Image information 0",e) }, // Close the crop picture pop-up closeCallback(e){ this.setData({ ['crop.visible']: false, }) console.log(" Image information 1",e) }, // Cut the picture pop-up and click ok cropCallback(e){ // Returns the local file path of the selected photo , Access the upload interface this.UploadImg(e.detail.resultSrc); }, // Click on the user's avatar 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 }) _this.setData({ ['crop.visible']: true, ['crop.src']: res.tempFilePaths[0], }) }, fail: function () { wx.showToast({ title: ' Picture upload failed ', icon: 'none' }) return; } }) },// Upload the avatar to the interface , Local pictures avatarUrl Turn into online pictures UploadImg(avatarUrl){ uploadFile(avatarUrl).then(res => { this.setData({ ['crop.visible']: false, avatar1:res, }) }) },// Interface encapsulation for uploading pictures
uploadFile: (filePath) => { let url = "XXXXX/uploaded_file" 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 // resolve(res.data.data) if (code === 401 || code === 402 || code === 403) { wx.redirectTo({ url: "/pages/site/login/login" }) return } else if (code === 200) { return resolve(result.data) } else { return reject(result.message) } }, fail() { reject(' Interface error , Please check ') } }) }) },})
边栏推荐
- Use webworker to perform background tasks
- [CS231N]Lecture_ 2:Image Classification pipelin
- Bugku, Web: all filtered
- Lvs+keepalived high availability deployment practical application
- [CS231N]Lecture_2:Image Classification pipelin
- Sword finger offer II 067. maximum XOR (medium prefix tree bit operation array)
- HCIP(15)
- Record the fluent to solve the problem of a renderflex overflowed by 7.3 pixels on the bottom
- MySQL built-in functions
- 阿里云CDN实践
猜你喜欢

Ordinary practice of JS DOM programming

CDN工作原理

DHCP and PPPoE protocols and packet capture analysis
![[Ruiji takeout project]day4 - dish management](/img/2a/2d9deb7a583aa37b38a67ef2c74ee7.png)
[Ruiji takeout project]day4 - dish management

ATT&CK初步了解

Ruiji takeout project - development of business development function Day2

SQL injection less34 (post wide byte injection + Boolean blind injection)

Sword finger offer II 054. Sum of all values greater than or equal to nodes (medium binary search tree DFS)

Lin Xiaobin, head of Tencent cloud database, borrowed 100 million yuan to speculate in stocks? Insider: the amount is not true

HCIP(13)
随机推荐
Learn kotlin - extension function
[leetcode] maximum depth of binary tree
网易云信 2022Q2 产品补给站,快来获取你的产品补给计划吧!
Soft exam network engineer
How to realize dynamic route switching and route caching in vuejs
Use REM to make the font size adaptive to the screen
Win11 how to open software notification
AWK空行过滤
Hcip experiment (14)
成立不到一年!MIT衍生量子计算公司完成900万美元融资
Basic introduction of Rockwell AB PLC rslogix digital quantity IO module
CDN工作原理
Use webworker to perform background tasks
JS array merging, de duplication, dimensionality reduction (es6: extended operator, set)
容器化配置启动redis集群 单机6节点 3主3从
[Ruiji takeout project] Day5 - Chapter 6 mobile verification code login
XXX port is already in use
flask之蓝图 补充openpyxl
微信小程序里button点击的时候会边框有黑线
ngx+sql环境离线安装日志(rpm安装)