当前位置:网站首页>Applet - uniapp realizes the functions of two-dimensional code picture pop-up and picture saving
Applet - uniapp realizes the functions of two-dimensional code picture pop-up and picture saving
2022-06-13 04:29:00 【Radix notoginseng and small sugar】
Applet uniapp You need to click a button , Pop up the QR code picture , And it has the function of saving pictures .
Code implementation :
html part :
Use uniapp Medium unipopup Component pop-up
<uni-popup ref="kefu" type="center" :mask-click="false" class="kefu">
<view class="popup">
<view class="icon-close">
<uni-icons type="close" size="30" @click="close" color="#fff">
</uni-icons>
</view>
<image src="../../static/images/showModal/qrcode.png" mode="widthFix" class="QRcode"></image>
<button type="warn" size="default" class="btn-savecode" @click="saveQRcode"> Save the picture </button>
</view>
</uni-popup>
css part :
matters needing attention :
because uniapp Of unipoup The component has a hidden white background , And when the Font Icon needs to appear in the upper right corner of the picture , So you need to modify the component class css Medium background-color For transparency ,overfloew-y Prevent icons from being hidden away from the picture
/deep/.uni-popup__wrapper.uni-custom.center .uni-popup__wrapper-box{
background-color: transparent;
position: relative;
max-width: 80%;
max-height: 80%;
overflow-y: visible; .popup{
width: 100%; .icon-close{
display: block;
text-align: right;
margin-right: -60rpx;
}
.QRcode{
width: 450rpx;
display: block;
}
.btn-savecode{
margin: 20rpx 100rpx;
border-radius: 50rpx;
font-size: 30rpx;
}
}
}
JS part :
Uniapp In the use of uni.authorize When authorizing , If the user clicks reject for the first time , When you want to authorize again , The authorization page cannot pop up , The authorization will fail directly , Very affecting the user experience . You need to pop up a reminder , Let the user set the authorization manually .
saveQRcode(){
uni.getSetting({
success:(res)=>{
if(res.authSetting['scope.writePhotosAlbum']){
// Verify that the user is authorized to access the album
this.saveQRcodeToPhotosAlbum();
}else{
uni.authorize({
scope:'scope.writePhotosAlbum',
success:(res)=>{
console.log(' Authorized information :',res);
this.saveQRcodeToPhotosAlbum();
},
fail:(err)=>{
// Get authorization after canceling authorization , It needs to be set manually
uni.showModal({
content:' It is detected that you do not have permission to open and save photo album , Whether to set on ',
confirmText:' confirm ',
cancelText:' Cancel ',
success(res){
if(res.confirm){
uni.openSetting({
success(res) {
console.log(' Authorized success ');
}
})
}else{
console.log(' Cancel Authorization ');
}
}
})
}
})
}
}
})
},
saveQRcodeToPhotosAlbum(){
let that = this
uni.saveImageToPhotosAlbum({
filePath:'static/images/showModal/qrcode.png',
success(res) {
uni.showToast({
title:' Saved successfully ',
icon:'success'
})
that.close()
},
fail(err){
console.log(err);
}
})
}
边栏推荐
- Reread the classic: end to end object detection with transformers
- 120. triangle minimum path sum - Dynamic Planning
- Single chip microcomputer: main index of a/d (analog-to-digital conversion)
- SCM: introduction and operation of EEPROM
- PAT 1054 The Dominant Color
- Redis-HyperLogLog-基数统计算法
- The data obtained from mongodb query data command is null
- Ultra quicksort reverse sequence pair
- Uni app Ali font icon does not display
- 120. 三角形最小路径和-动态规划
猜你喜欢
【自动化测试】关于unittest你需要知道的事
Explanation of line segment tree
环评图件制作-数据处理+图件制作
Advanced Mathematics (Seventh Edition) Tongji University exercises 1-3 personal solutions
重读经典:《End-to-End Object Detection with Transformers》
Analysis of the implementation principle of an open source markdown to rich text editor
The could not find com scwang. smart:refresh-layout-kernel:2.0.3. Required by: project: the app cannot load the third-party package
Redis数据持久化
Differences and relations between three-tier architecture and MVC
Google Chrome browser reports an error: net:: err_ BLOCKED_ BY_ CLIENT
随机推荐
JSTL -- JSP standard tag library
R: Airline customer value analysis practice
MCU: pcf8591 hardware interface
[sword finger offer] interview question 25 Merge two ordered linked lists
Message scrolling JS implementation
Detailed explanation of KOA development process
Notes on uni app
ACM ICPC
Hugo 博客搭建教程
Interpretation and implementation of proxy mode
Checkmarks and crosses to collect
Principle, composition and functions of sensors of Dajiang UAV flight control system
CTFSHOW SQL注入篇(211-230)
php开发16退出模块
How to use debounce in lodash to realize anti shake
El expression
Suffix Automaton
Billions of data to determine whether the element exists
Get verification code
Summary of webdriver API for web automated testing