经营品牌: 强力巨彩 海佳彩亮 飞利浦 利亚德 创维 京东方 海康威视 仰邦 诺瓦 卡莱特 小鸟羽控
027-89992224
LED显示屏专业解决方案服务商
Professional solution service provider
首页 › 自言自语 › shopxo,附件下载插件修改记录

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

附件需要登录后才能下载

请先登录或注册后刷新本页。

×

下载插件后端修改

在位置:app/api/controller/goods.php
1、大约在24行的位置

use app\service\GoodsBrowseService;
use app\service\GoodsCartService;

下面增加

/*下载接口补充开始*/
use app\plugins\goods_pdf\service\BaseService as GoodsPdfService;
/*下载接口补充结束*/

2、大约在103行的位置

                    // 最新3条评价
                    $goods['comments_data'] = GoodsCommentsService::GoodsFirstSeveralComments($goods_id);
                }

在下面增加

    /*下载接口补充开始*/
				// 附件
				$goods['pdfs'] = GoodsPdfService::GoodsPdfsData($goods_id);
				/*下载接口补充结束*/

附件:Goods.php (9 KB)

评论 (8 条)

王铭 2024-5-19

uniapp位置:pages/goods-detail/goods-detail.vue

在上方插入

    <!-- 商品附件 -->
                                <view class="spacing-mb">
                                    <view class="spacing-nav-title">
                                        <text class="line"></text>
                                        <text class="text-wrapper">商品附件</text>
                                    </view>
                                    <view v-if="(goods.pdfs || null) != null && goods.pdfs.length > 0" class="goods-parameters border-radius-main padding-main bg-white">
                                        <view class="content-item oh">
                                            <block v-for="(item, index) in goods.pdfs" :key="index">
                                                <view v-if="index <= 5" class="single-text cr-base text-size-xs">
                                                                        <view v-if="!item.url==false" class="pr cp"  @tap="downloadFile(item.url)">
                                                                                <text class="name">
                                                                                        {{ item.title }} 
                                                                                        <uni-icons type="cloud-download" size="50rpx" color="#bbb"></uni-icons>
                                                                                </text>
                                                                        </view>
                                                </view>
                                            </block>
                                        </view>
                                    </view>                                        
                                    <view v-else class="goods-parameters border-radius-main padding-main bg-white">
                                        <view class="content-item oh">
                                            <view class="cr-grey-d tc spacing-mb flex-row jc-c align-c">
                                                <image :src="common_static_url + 'no-comment.png'" mode="widthFix" class="no-comment margin-right-main" />
                                                此商品暂时还没有附件哦~
                                            </view>
                                        </view>
                                    </view>
                                </view>

附件:goods-detail.vue (86.9 KB)

王铭 2024-5-19

接楼上文件,在623行

在 export default {
前插入

 var weburl = app.globalData.data.request_url;
        function containsHttp(url) {
            // 使用正则表达式来判断URL是否包含http或https
            const regex = /^http(s)?:/;
            return regex.test(url);
        }

王铭 2024-5-19

在1486行代码开始

           // 下单类型切换事件、数据刷新事件
            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) {
				var url = "";
				if (containsHttp(e)) {
				    url = e;
				} else {
				    url = app.globalData.data.request_url+e;
				}
				// #ifdef H5
				    window.open(url, '_blank');
				// #endif
				// #ifndef H5
			    uni.downloadFile({
					method: 'GET',
					url: url,
					timeout: 2000,
					header:{
						authorization:"",
					},
					success: (data) => {
						if (data.statusCode === 200) {
						uni.saveFile({
							tempFilePath: data.tempFilePath,
							success:(res)=>{
								uni.showModal({
									title: '提示',
									content: '文件已保存:' + res.savedFilePath,
									cancelText: '我知道了',
									confirmText: '打开文件',
									success: function (red) {
										if (red.confirm) {
											uni.openDocument({
												filePath: res.savedFilePath,
												success: (sus) => {
													
												}
											})
										}
									}
								});
							},
							fail:(err)=>{
				
							}
						})
						}				
					},
					fail: (err) => {
						uni.showToast({
							icon: 'none',
							mask: true,
							title: '失败请重新下载',
						});
					},
				})
				// #endif
			},
        }
    };
</script>
<style>
    @import './goods-detail.css';
</style>

王铭 2024-5-19

电脑版,附件文字名称过长后,显示不正常修改。

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

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

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

.introduce-main .am-tab-panel .parameters-detail li {
    width: calc(100% - 1rem);
}

王铭 2024-5-22

附件:goods-detail.vue (87.4 KB)

2024.05.22修改版
调整了会员才能下载及其它部份功能修复。

王铭 2025-1-23

附件:goods-detail3.vue (92.5 KB)

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>

王铭 2025-1-23

3、在以下代码

                <!-- 商品详情参数 -->
                <view v-if="(goods.parameters || null) != null && (goods.parameters.detail || null) != null && goods.parameters.detail.length > 0" class="spacing-mb">
                    <view class="spacing-nav-title">
                        <text class="line"></text>
                        <text class="text-wrapper">{{$t('goods-detail.goods-detail.l7dzv2')}}</text>
                    </view>
                    <view class="goods-parameters border-radius-main padding-main bg-white">
                        <view class="content-item oh">
                            <view class="oh">
                                <block v-for="(item, index) in goods.parameters.detail" :key="index">
                                    <view v-if="index <= 3" class="item single-text cr-base text-size-xs">
                                        <text class="name">{{ item.name }}:</text>
                                        <text class="value">{{ item.value }}</text>
                                    </view>
                                </block>
                            </view>
                            <view class="tc margin-top-lg">
                                <text class="cr-grey text-size-xs" @tap="popup_params_event" data-value="detail">查看全部参数 >></text>
                            </view>
                        </view>
                    </view>
                </view>

下面增加


				<!-- 商品附件 -->
				<view class="spacing-mb">
				    <view class="spacing-nav-title">
				        <text class="line"></text>
				        <text class="text-wrapper">商品附件</text>
				    </view>
				    <view v-if="(goods.pdfs || null) != null && goods.pdfs.length > 0" class="goods-parameters border-radius-main padding-main bg-white">
				        <view class="content-item oh">
							<view class="oh">
								<block v-for="(item, index) in goods.pdfs" :key="index">
									<view v-if="index <= 5" class="single-text cr-base text-size-xs">
										<view v-if="!item.url==false" class="pr cp"  @tap="downloadFile(item.url)">
											<text class="name">
												{{ item.title }} 
											</text>
											<text>	
												<!-- #ifdef APP-->
												<uni-icons type="cloud-download" size="50rpx" color="#bbb"></uni-icons>
												<!-- #endif -->
												<!-- #ifdef MP-WEIXIN || H5 || APP-->
												点击下载
												<!-- #endif -->
											</text>
										</view>
									</view>
								</block>
							</view>
				        </view>
				    </view>					
				    <view v-else class="goods-parameters border-radius-main padding-main bg-white">
				        <view class="content-item oh">
				            <view class="cr-grey-d tc spacing-mb flex-row jc-c align-c">
				                <image :src="common_static_url + 'no-comment.png'" class="no-comment margin-right-main" style="height:70px;width:90px;"/>
				                此商品暂时还没有附件哦~
				            </view>
				        </view>
				    </view>
				</view>

王铭 2025-11-4

附件:Goods-6.71附件修改版.php (9.1 KB)

具体修改方法见一楼。

网站首页
网站首页
案例展示
案例展示
在线客服
在线客服
一键拨号
一键拨号
返回顶部