goods-detail3.vue
(92.53 KB, 下载次数: 0)
6.3版本,最后付费调整的一次,具体调整如下:
1、在下面代码- var win_width = parseInt(system_info.windowWidth || system_info.screenWidth || 0);
复制代码 后面增加
- // 附件插件新增部份开始
- var weburl = app.globalData.data.request_url;
- function containsHttp(url) {
- // 使用正则表达式来判断URL是否包含http或https
- const regex = /^http(s)?:/;
- return regex.test(url);
- }
- // 在方法中调用复制到剪贴板的操作
- function copyText(content,title) {
- // 不支持复制数字类型所以需要先转为字符串
- content = typeof content === 'string' ? content : content.toString()
- //#ifndef H5
- uni.setClipboardData({
- data: content,
- success: function() {
- console.log('success');
- uni.showToast({
- title: title,
- icon:'none',
- duration: 2000
- });
- }
- });
- //#endif
-
- // #ifdef H5
- if (!document.queryCommandSupported('copy')) {
- uni.showToast({
- title: '浏览器不支持',
- icon: 'none',
- duration: 2000
- });
- return;
- }
- let textarea = document.createElement("textarea")
- textarea.value = content
- textarea.readOnly = "readOnly"
- document.body.appendChild(textarea)
- textarea.select() // 选择对象
- textarea.setSelectionRange(0, content.length) //核心
- let result = document.execCommand("copy") // 执行浏览器复制命令
- if (result) {
- uni.showToast({
- title: title,
- icon:'none',
- duration: 2000
- });
- }
- textarea.remove()
- // #endif
- }
- // 附件插件新增部份结束
复制代码
2、将下面代码- // 下单类型切换事件、数据刷新事件
- refresh_loading_event(params) {
- this.setData({params: {...this.params, ...params}});
- this.init();
- }
- }
- };
- </script>
- <style>
- @import './goods-detail.css';
- </style>
复制代码 替换为:
- // 下单类型切换事件、数据刷新事件
- refresh_loading_event(params) {
- this.setData({params: {...this.params, ...params}});
- this.init();
- },
- // 附件下载
- downloadFile(e) {
- uni.showLoading({
- title: '下载中',
- mask: true,
- });
- var url = "";
- if (containsHttp(e)) {
- url = e;
- } else {
- url = app.globalData.data.request_url+e;
- }
- // 附件登录限制
- var user = app.globalData.get_user_info(this, 'init');
- if (user != false) {
-
- } else {
- url = "";
- this.setData({
- user: null,
- data_list_loding_status: 0,
- data_list_loding_msg: this.$t('extraction-apply.extraction-apply.m3xdif'),
- });
- }
- if(url == ""){
- return false;
- }
- // #ifdef H5
- window.open(url, '_blank');
- // #endif
- // #ifndef H5
- var platform = uni.getSystemInfoSync().platform;
- console.log("platform",platform);
- if(platform == 'ios'){
- copyText(url,'请打开浏览器粘贴到地址栏打开或下载文件!');
- return false;
- }
-
- uni.downloadFile({
- method: 'GET',
- url: url,
- timeout: 2000,
- header:{
- authorization:"",
- },
- success: (data) => {
- if (data.statusCode === 200) {
- uni.hideLoading();
- const fileManager = uni.getFileSystemManager();
- fileManager.saveFile({ //文件保存到本地
- tempFilePath: data.tempFilePath, //临时路径
- success: function(res) {
- console.log('tempFilePath:',res.savedFilePath)
- uni.showModal({
- title: '提示',
- content: '文件已保存:' + res.savedFilePath,
- cancelText: '复制链接',
- confirmText: '打开文件',
- success: function (red) {
- if (red.confirm) {
- uni.openDocument({
- filePath: res.savedFilePath,
- //fileType: 'pdf', // 指定文件的格式
- showMenu: true, // 允许出现分享功能
- success: r => {
- console.log(r)
- },
- fail: openError => {
- console.log('打开失败: ', openError)
- copyText(url,'请打开浏览器粘贴到地址栏打开或下载文件!')
- }
- })
- }else{
- copyText(url,'请打开浏览器粘贴到地址栏打开或下载文件!')
- }
- }
- });
- },
- fail:(err)=>{console.log('err1:',err)}
- });
- }
- },
- fail: (err) => {
- console.log('err2:',err)
- uni.hideLoading();
- uni.showToast({
- icon: 'none',
- mask: true,
- title: '失败请重新下载',
- });
- },
- })
- // #endif
- },
- }
- };
- </script>
- <style>
- @import './goods-detail.css';
- </style>
复制代码
|