openpdf.js 993 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. //#ifdef H5
  2. const BASEURL = ''
  3. //#endif
  4. //#ifndef H5
  5. const BASEURL = getApp().globalData.url
  6. //#endif
  7. function previepdf(url) {
  8. uni.showLoading({
  9. title: '加载中'
  10. });
  11. const manage = uni.getFileSystemManager();
  12. uni.downloadFile({
  13. url: BASEURL + url,
  14. success(res) {
  15. let path = res.tempFilePath;
  16. // #ifdef MP-WEIXIN
  17. var savePath = uni.env.USER_DATA_PATH + "/" + fileName
  18. if (res.statusCode == 200) {
  19. manage.saveFile({
  20. tempFilePath: res.tempFilePath,
  21. filePath: savePath+'.pdf',
  22. success:function(res){
  23. uni.openDocument({
  24. filePath: res.savedFilePath,
  25. fileType: "pdf",
  26. success: function (res) {
  27. uni.hideLoading()
  28. }
  29. })
  30. }
  31. })
  32. }
  33. // #endif
  34. // #ifndef MP-WEIXIN
  35. uni.openDocument({
  36. filePath: path,
  37. showMenu: true,
  38. success: function (res) {
  39. // console.log('打开文档成功');
  40. }
  41. });
  42. // #endif
  43. }
  44. });
  45. }
  46. module.exports = {
  47. previepdf
  48. };