問題和使用場景描述:
uniapp app web-view中圖片無法長按保存,IOS下是正常的,但是Android下長按無反應
解決方案:
下載mui.min.js,放到項目中的static下(下載見最上面的壓縮包)
在static目錄下新建script.js
mui.init({gestureConfig: {longtap: true},//側滑關閉 swipeBack: true, //Boolean(默認false)啟用右滑關閉功能 //監聽Android手機的back、menu按鍵 keyEventBind: {backbutton: false, //Boolean(默認truee)關閉back按鍵監聽 menubutton: false //Boolean(默認true)關閉menu按鍵監聽 },
});
document.addEventListener('longtap', function(e) {if (e.target.tagName == "IMG") {console.log(e.target.src);mui.confirm('是否下圖片', '確認下載', '下載', function(d) {if (d.index == 0) {var down = plus.downloader.createDownload(e.target.src, {}, function(e, a) {console.log(e);plus.gallery.save(e.filename, function(e) {mui.toast('下載成功,請查看系統相冊')console.log("下載成功,請查看系統相冊");}, function(e) {console.log("下載失敗,請重試");})})down.start()}})}
})
webview使用:
<view><web-view :src="weburl"></web-view></view>
onReady() {// #ifdef APP-PLUS var currentWebview = this.$scope.$getAppWebview()setTimeout(function() {let wv = currentWebview.children()[0]if (uni.getSystemInfoSync().osName == 'android') {wv.appendJsFile('_www/static/mui.min.js')setTimeout(function() {wv.appendJsFile('_www/static/script.js')}, 1000)}}, 1000);// #endif },