深度合作品牌: 强力巨彩 海佳彩亮 仰邦 利亚德 创维 京东方 海康威视
400-027-0096
LED显示屏专业解决方案服务商
Professional solution service provider

shopxo,附件下载插件修改记录

 火... [复制链接]
王铭 发表于 2024-5-19 09:57:26 | 显示全部楼层 |阅读模式
下载插件

在位置:app/api/controller/goods.php

  1.                 // 最新3条评价
  2.                 $goods['comments_data'] = GoodsCommentsService::GoodsFirstSeveralComments($goods_id);
复制代码
增加以下内容
  1. /*下载接口补充开始*/

  2. // 附件
  3. $goods['pdfs']= GoodsPdfservice::GoodsPdfsData($goods id);
复制代码


shopxo,附件下载插件修改记录 Goods.php (8.97 KB, 下载次数: 0)




相关帖子

 楼主| 王铭 发表于 2024-5-19 09:59:42 | 显示全部楼层
uniapp位置:pages/goods-detail/goods-detail.vue

在<!-- 商品详情 -->上方插入

  1.     <!-- 商品附件 -->
  2.                                 <view class="spacing-mb">
  3.                                     <view class="spacing-nav-title">
  4.                                         <text class="line"></text>
  5.                                         <text class="text-wrapper">商品附件</text>
  6.                                     </view>
  7.                                     <view v-if="(goods.pdfs || null) != null && goods.pdfs.length > 0" class="goods-parameters border-radius-main padding-main bg-white">
  8.                                         <view class="content-item oh">
  9.                                             <block v-for="(item, index) in goods.pdfs" :key="index">
  10.                                                 <view v-if="index <= 5" class="single-text cr-base text-size-xs">
  11.                                                                         <view v-if="!item.url==false" class="pr cp"  @tap="downloadFile(item.url)">
  12.                                                                                 <text class="name">
  13.                                                                                         {{ item.title }}
  14.                                                                                         <uni-icons type="cloud-download" size="50rpx" color="#bbb"></uni-icons>
  15.                                                                                 </text>
  16.                                                                         </view>
  17.                                                 </view>
  18.                                             </block>
  19.                                         </view>
  20.                                     </view>                                       
  21.                                     <view v-else class="goods-parameters border-radius-main padding-main bg-white">
  22.                                         <view class="content-item oh">
  23.                                             <view class="cr-grey-d tc spacing-mb flex-row jc-c align-c">
  24.                                                 <image :src="common_static_url + 'no-comment.png'" mode="widthFix" class="no-comment margin-right-main" />
  25.                                                 此商品暂时还没有附件哦~
  26.                                             </view>
  27.                                         </view>
  28.                                     </view>
  29.                                 </view>
复制代码

shopxo,附件下载插件修改记录 goods-detail.vue (86.86 KB, 下载次数: 0)

 楼主| 王铭 发表于 2024-5-19 10:45:49 | 显示全部楼层
接楼上文件,在623行

在    export default {
前插入
  1. var weburl = app.globalData.data.request_url;
  2.         function containsHttp(url) {
  3.             // 使用正则表达式来判断URL是否包含http或https
  4.             const regex = /^http(s)?:/;
  5.             return regex.test(url);
  6.         }
复制代码


 楼主| 王铭 发表于 2024-5-19 10:48:56 | 显示全部楼层
在1486行代码开始

  1.            // 下单类型切换事件、数据刷新事件
  2.             refresh_loading_event(params) {
  3.                 this.setData({params: {...this.params, ...params}});
  4.                 this.init();
  5.             }
  6.         }
  7.     };
  8. </script>
  9. <style>
  10.     @import './goods-detail.css';
  11. </style>
复制代码


替换为
  1.             // 下单类型切换事件、数据刷新事件
  2.             refresh_loading_event(params) {
  3.                 this.setData({params: {...this.params, ...params}});
  4.                 this.init();
  5.             },
  6.                         // 附件下载
  7.                         downloadFile(e) {
  8.                                 var url = "";
  9.                                 if (containsHttp(e)) {
  10.                                     url = e;
  11.                                 } else {
  12.                                     url = app.globalData.data.request_url+e;
  13.                                 }
  14.                                 // #ifdef H5
  15.                                     window.open(url, '_blank');
  16.                                 // #endif
  17.                                 // #ifndef H5
  18.                             uni.downloadFile({
  19.                                         method: 'GET',
  20.                                         url: url,
  21.                                         timeout: 2000,
  22.                                         header:{
  23.                                                 authorization:"",
  24.                                         },
  25.                                         success: (data) => {
  26.                                                 if (data.statusCode === 200) {
  27.                                                 uni.saveFile({
  28.                                                         tempFilePath: data.tempFilePath,
  29.                                                         success:(res)=>{
  30.                                                                 uni.showModal({
  31.                                                                         title: '提示',
  32.                                                                         content: '文件已保存:' + res.savedFilePath,
  33.                                                                         cancelText: '我知道了',
  34.                                                                         confirmText: '打开文件',
  35.                                                                         success: function (red) {
  36.                                                                                 if (red.confirm) {
  37.                                                                                         uni.openDocument({
  38.                                                                                                 filePath: res.savedFilePath,
  39.                                                                                                 success: (sus) => {
  40.                                                                                                        
  41.                                                                                                 }
  42.                                                                                         })
  43.                                                                                 }
  44.                                                                         }
  45.                                                                 });
  46.                                                         },
  47.                                                         fail:(err)=>{
  48.                                
  49.                                                         }
  50.                                                 })
  51.                                                 }                               
  52.                                         },
  53.                                         fail: (err) => {
  54.                                                 uni.showToast({
  55.                                                         icon: 'none',
  56.                                                         mask: true,
  57.                                                         title: '失败请重新下载',
  58.                                                 });
  59.                                         },
  60.                                 })
  61.                                 // #endif
  62.                         },
  63.         }
  64.     };
  65. </script>
  66. <style>
  67.     @import './goods-detail.css';
  68. </style>
复制代码


 楼主| 王铭 发表于 2024-5-20 02:27:03 | 显示全部楼层
电脑版,附件文字名称过长后,显示不正常修改。

/public/static/index/default/css/goods.css

第1207行下的width: calc(50% - 1rem)改为
(100% - 1rem)

第1244行下的width: calc (33.33333333% - 1rem)改为
(100% - 1rem)

  1. .introduce-main .am-tab-panel .parameters-detail li {
  2.     width: calc(100% - 1rem);
  3. }
复制代码


 楼主| 王铭 发表于 2024-5-22 17:47:25 | 显示全部楼层
shopxo,附件下载插件修改记录 goods-detail.vue (87.4 KB, 下载次数: 1)


2024.05.22修改版
调整了会员才能下载及其它部份功能修复。
 楼主| 王铭 发表于 2025-1-23 12:11:11 | 显示全部楼层
shopxo,附件下载插件修改记录 goods-detail3.vue (92.53 KB, 下载次数: 0)
6.3版本,最后付费调整的一次,具体调整如下:
1、在下面代码
  1. var win_width = parseInt(system_info.windowWidth || system_info.screenWidth || 0);
复制代码
后面增加
  1. // 附件插件新增部份开始
  2.         var weburl = app.globalData.data.request_url;
  3.         function containsHttp(url) {
  4.             // 使用正则表达式来判断URL是否包含http或https
  5.             const regex = /^http(s)?:/;
  6.             return regex.test(url);
  7.         }
  8.         // 在方法中调用复制到剪贴板的操作
  9.         function copyText(content,title) {
  10.                 // 不支持复制数字类型所以需要先转为字符串
  11.                 content = typeof content === 'string' ? content : content.toString()
  12.                 //#ifndef H5
  13.                 uni.setClipboardData({
  14.                         data: content,
  15.                         success: function() {
  16.                                 console.log('success');
  17.                                 uni.showToast({
  18.                                         title: title,
  19.                                         icon:'none',
  20.                                         duration: 2000
  21.                                 });
  22.                         }
  23.                 });
  24.                 //#endif
  25.                
  26.                 // #ifdef H5
  27.                 if (!document.queryCommandSupported('copy')) {
  28.                         uni.showToast({
  29.                                 title: '浏览器不支持',
  30.                                 icon: 'none',
  31.                                 duration: 2000
  32.                         });
  33.                         return;
  34.                 }
  35.                 let textarea = document.createElement("textarea")
  36.                 textarea.value = content
  37.                 textarea.readOnly = "readOnly"
  38.                 document.body.appendChild(textarea)
  39.                 textarea.select() // 选择对象
  40.                 textarea.setSelectionRange(0, content.length) //核心
  41.                 let result = document.execCommand("copy") // 执行浏览器复制命令
  42.                 if (result) {
  43.                         uni.showToast({
  44.                                 title: title,
  45.                                 icon:'none',
  46.                                 duration: 2000
  47.                         });
  48.                 }
  49.                 textarea.remove()
  50.                 // #endif
  51.         }
  52. // 附件插件新增部份结束
复制代码

2、将下面代码
  1. // 下单类型切换事件、数据刷新事件
  2.             refresh_loading_event(params) {
  3.                 this.setData({params: {...this.params, ...params}});
  4.                 this.init();
  5.             }
  6.         }
  7.     };
  8. </script>
  9. <style>
  10.     @import './goods-detail.css';
  11. </style>
复制代码
替换为:
  1.             // 下单类型切换事件、数据刷新事件
  2.             refresh_loading_event(params) {
  3.                 this.setData({params: {...this.params, ...params}});
  4.                 this.init();
  5.             },
  6.                         // 附件下载
  7.                         downloadFile(e) {
  8.                                 uni.showLoading({
  9.                                         title: '下载中',
  10.                                         mask: true,
  11.                                 });
  12.                                 var url = "";
  13.                                 if (containsHttp(e)) {
  14.                                     url = e;
  15.                                 } else {
  16.                                     url = app.globalData.data.request_url+e;
  17.                                 }
  18.                                 // 附件登录限制
  19.                                 var user = app.globalData.get_user_info(this, 'init');
  20.                                 if (user != false) {
  21.                                     
  22.                                 } else {
  23.                                     url = "";
  24.                                         this.setData({
  25.                                             user: null,
  26.                                             data_list_loding_status: 0,
  27.                                             data_list_loding_msg: this.$t('extraction-apply.extraction-apply.m3xdif'),
  28.                                         });
  29.                                 }
  30.                                 if(url == ""){
  31.                                         return false;
  32.                                 }
  33.                                 // #ifdef H5
  34.                                     window.open(url, '_blank');
  35.                                 // #endif
  36.                                 // #ifndef H5
  37.                                 var platform = uni.getSystemInfoSync().platform;
  38.                                 console.log("platform",platform);
  39.                                 if(platform == 'ios'){
  40.                                         copyText(url,'请打开浏览器粘贴到地址栏打开或下载文件!');
  41.                                         return false;
  42.                                 }
  43.                                
  44.                             uni.downloadFile({
  45.                                         method: 'GET',
  46.                                         url: url,
  47.                                         timeout: 2000,
  48.                                         header:{
  49.                                                 authorization:"",
  50.                                         },
  51.                                         success: (data) => {
  52.                                                 if (data.statusCode === 200) {
  53.                                                         uni.hideLoading();
  54.                                                         const fileManager = uni.getFileSystemManager();
  55.                                                         fileManager.saveFile({ //文件保存到本地
  56.                                                         tempFilePath: data.tempFilePath, //临时路径
  57.                                                         success: function(res) {
  58.                                                                 console.log('tempFilePath:',res.savedFilePath)
  59.                                                                 uni.showModal({
  60.                                                                         title: '提示',
  61.                                                                         content: '文件已保存:' + res.savedFilePath,
  62.                                                                         cancelText: '复制链接',
  63.                                                                         confirmText: '打开文件',
  64.                                                                         success: function (red) {
  65.                                                                                 if (red.confirm) {
  66.                                                                                         uni.openDocument({
  67.                                                                                                 filePath: res.savedFilePath,
  68.                                                                                                 //fileType: 'pdf', // 指定文件的格式
  69.                                                                                                 showMenu: true, // 允许出现分享功能
  70.                                                                                                 success: r => {
  71.                                                                                                   console.log(r)
  72.                                                                                                 },
  73.                                                                                                 fail: openError => {
  74.                                                                                                   console.log('打开失败: ', openError)
  75.                                                                                                   copyText(url,'请打开浏览器粘贴到地址栏打开或下载文件!')
  76.                                                                                                 }
  77.                                                                                         })
  78.                                                                                 }else{
  79.                                                                                         copyText(url,'请打开浏览器粘贴到地址栏打开或下载文件!')
  80.                                                                                 }
  81.                                                                         }
  82.                                                                 });
  83.                                                         },
  84.                                                         fail:(err)=>{console.log('err1:',err)}
  85.                                                         });
  86.                                                 }
  87.                                         },
  88.                                         fail: (err) => {
  89.                                                 console.log('err2:',err)
  90.                                                 uni.hideLoading();
  91.                                                 uni.showToast({
  92.                                                         icon: 'none',
  93.                                                         mask: true,
  94.                                                         title: '失败请重新下载',
  95.                                                 });
  96.                                         },
  97.                                 })
  98.                                 // #endif
  99.                         },
  100.         }
  101.     };
  102. </script>
  103. <style>
  104.     @import './goods-detail.css';
  105. </style>
复制代码


 楼主| 王铭 发表于 2025-1-23 12:26:13 | 显示全部楼层
3、在以下代码

  1.                 <!-- 商品详情参数 -->
  2.                 <view v-if="(goods.parameters || null) != null && (goods.parameters.detail || null) != null && goods.parameters.detail.length > 0" class="spacing-mb">
  3.                     <view class="spacing-nav-title">
  4.                         <text class="line"></text>
  5.                         <text class="text-wrapper">{{$t('goods-detail.goods-detail.l7dzv2')}}</text>
  6.                     </view>
  7.                     <view class="goods-parameters border-radius-main padding-main bg-white">
  8.                         <view class="content-item oh">
  9.                             <view class="oh">
  10.                                 <block v-for="(item, index) in goods.parameters.detail" :key="index">
  11.                                     <view v-if="index <= 3" class="item single-text cr-base text-size-xs">
  12.                                         <text class="name">{{ item.name }}:</text>
  13.                                         <text class="value">{{ item.value }}</text>
  14.                                     </view>
  15.                                 </block>
  16.                             </view>
  17.                             <view class="tc margin-top-lg">
  18.                                 <text class="cr-grey text-size-xs" @tap="popup_params_event" data-value="detail">查看全部参数 >></text>
  19.                             </view>
  20.                         </view>
  21.                     </view>
  22.                 </view>
复制代码
下面增加


  1.                                 <!-- 商品附件 -->
  2.                                 <view class="spacing-mb">
  3.                                     <view class="spacing-nav-title">
  4.                                         <text class="line"></text>
  5.                                         <text class="text-wrapper">商品附件</text>
  6.                                     </view>
  7.                                     <view v-if="(goods.pdfs || null) != null && goods.pdfs.length > 0" class="goods-parameters border-radius-main padding-main bg-white">
  8.                                         <view class="content-item oh">
  9.                                                         <view class="oh">
  10.                                                                 <block v-for="(item, index) in goods.pdfs" :key="index">
  11.                                                                         <view v-if="index <= 5" class="single-text cr-base text-size-xs">
  12.                                                                                 <view v-if="!item.url==false" class="pr cp"  @tap="downloadFile(item.url)">
  13.                                                                                         <text class="name">
  14.                                                                                                 {{ item.title }}
  15.                                                                                         </text>
  16.                                                                                         <text>       
  17.                                                                                                 <!-- #ifdef APP-->
  18.                                                                                                 <uni-icons type="cloud-download" size="50rpx" color="#bbb"></uni-icons>
  19.                                                                                                 <!-- #endif -->
  20.                                                                                                 <!-- #ifdef MP-WEIXIN || H5 || APP-->
  21.                                                                                                 点击下载
  22.                                                                                                 <!-- #endif -->
  23.                                                                                         </text>
  24.                                                                                 </view>
  25.                                                                         </view>
  26.                                                                 </block>
  27.                                                         </view>
  28.                                         </view>
  29.                                     </view>                                       
  30.                                     <view v-else class="goods-parameters border-radius-main padding-main bg-white">
  31.                                         <view class="content-item oh">
  32.                                             <view class="cr-grey-d tc spacing-mb flex-row jc-c align-c">
  33.                                                 <image :src="common_static_url + 'no-comment.png'" class="no-comment margin-right-main" style="height:70px;width:90px;"/>
  34.                                                 此商品暂时还没有附件哦~
  35.                                             </view>
  36.                                         </view>
  37.                                     </view>
  38.                                 </view>
复制代码


您需要登录后才可以回帖 登录 | 注册

本版积分规则

联系电话
案例展示
产品中心
网上商城
返回顶部