This commit is contained in:
2024-08-30 17:31:35 +08:00
parent 2262031abd
commit 2c952e71a3
15 changed files with 250 additions and 279 deletions

View File

@@ -33,42 +33,57 @@ Page({
})
},
record() {
const { detail } = this.data;
wx.showModal({
title: '提示',
content: '为了您更好的体验,请复制链接,通过电脑浏览器打开下载',
showCancel: true,
cancelText: '关闭',
confirmText: '复制链接',
complete: (res) => {
if (res.confirm) {
const result = wx.getAccountInfoSync();
const { envVersion } = result.miniProgram;
let api = ""
switch (envVersion) {
// 开发版
case 'develop':
wx.setClipboardData({
data: `http://1.92.72.5:8080/recharge-print/?id=${detail.id}`,
})
break;
// 体验版
case 'trial':
wx.setClipboardData({
data: `http://1.92.72.5:8080/recharge-print/?id=${detail.id}`,
})
break;
// 正式版
case 'release':
wx.setClipboardData({
data: `https://zgd.hbhcbn.com/recharge-print/?id=${detail.id}`,
})
break;
}
const handleDownload = () => {
return new Promise((resolve, rej) => {
const { detail } = this.data;
const result = wx.getAccountInfoSync();
const { envVersion } = result.miniProgram;
let api = ""
switch (envVersion) {
// 开发版
case 'develop':
api = `http://localhost:9001`;
// api = `https://zgd.hbhcbn.com/recharge-print-api-test`;
break;
// 体验版
case 'trial':
api = `https://zgd.hbhcbn.com/recharge-print-api-test`;
break;
// 正式版
case 'release':
api = `https://zgd.hbhcbn.com/recharge-print-api`;
break;
}
}
console.log("api", `${api}/${detail.id}`)
wx.downloadFile({
url: `${api}/${detail.id}`,
success: (res) => {
console.log('res', res)
if (res.statusCode === 200) {
if (!res.tempFilePath) {
alertError("获取文件失败")
rej()
return;
}
wx.openDocument({
filePath: res.tempFilePath,
fileType: [ "pdf"], // 3. 这个必须写合法类型,不然下载不了
success: function (res) {
resolve()
},
fail: function (e) {
alertError("打开失败")
console.log('打开失败错误为', e)
rej()
}
})
}
}
})
})
}
loadingFunc(async () => {
await handleDownload();
})
},
back() {