<!– Word文件路径展示区域 –>
<view class="file-section word-section">
<text class="section-title">Word文件路径</text>
<view class="path-box" v-if="wordPath!=''">
<text class="path-text">{{ wordPath }}</text>
<view class="btn-group">
<button class="copy-btn" @click="copyPath('word')">复制路径</button>
<button class="download-btn" @click="downloadFile('word')">在线预览</button>
</view>
</view>
</view>
<!– PPT文件路径展示区域 –>
<view class="file-section ppt-section">
<text class="section-title">PPT文件路径</text>
<view class="path-box" v-if="pptPath!=''">
<text class="path-text">{{ pptPath }}</text>
<view class="btn-group">
<button class="copy-btn" @click="copyPath('ppt')">复制路径</button>
<button class="download-btn" @click="downloadFile('ppt')">在线预览</button>
</view>
</view>
</view>
getFileInfo(type) {
let filePath = "";
let fileName = "";
if (type === "word") {
filePath = this.wordPath;
fileName = filePath.substring(filePath.lastIndexOf("/") + 1) || "项目文档.docx";
} else {
filePath = this.pptPath;
fileName = filePath.substring(filePath.lastIndexOf("/") + 1) || "项目汇报.pptx";
}
return {
filePath,
fileName
};
},
downloadFile(type) {
// 防止重复下载
if (this.isDownloading) return;
this.isDownloading = true;
// 获取文件路径和文件名
const fileInfo = this.getFileInfo(type);
const {
filePath,
fileName
} = fileInfo;
// 校验文件路径
if (!filePath) {
uni.showToast({
title: "文件路径为空",
icon: "none"
});
this.isDownloading = false;
return;
}
this.downloadMp(filePath, fileName);
},
downloadMp(filePaths, fileName) {
uni.showLoading({
title: "下载中…"
});
const filePath = 'https://jyhealth.gy86.com'+filePaths
console.log(filePath, fileName,'222222222');
uni.downloadFile({
url: filePath,
success: (downloadRes) => {
if (downloadRes.statusCode === 200) {
// 小程序中打开文件(无法直接保存到本地,只能预览)
uni.openDocument({
filePath: downloadRes.tempFilePath,
showMenu: true, // 显示右上角菜单,支持转发/保存
fileType: fileName.split(".").pop(),
success: () => {
uni.hideLoading();
uni.showToast({
title: "文件打开成功",
icon: "success"
});
},
fail: (err) => {
uni.hideLoading();
uni.showToast({
title: "打开失败:" + err.errMsg,
icon: "none"
});
}
});
} else {
uni.hideLoading();
uni.showToast({
title: "下载失败:状态码异常",
icon: "none"
});
}
},
fail: (err) => {
uni.hideLoading();
uni.showToast({
title: "下载失败:" + err.errMsg,
icon: "none"
});
},
complete: () => {
this.isDownloading = false;
}
});
}





