download.js 577 B

1234567891011121314151617181920212223242526272829303132
  1. /*
  2. ** 下载文件
  3. */
  4. function downloadFile(url) {
  5. return new Promise((resolve, reject) => {
  6. wx.downloadFile({
  7. url,
  8. success: ({ statusCode, tempFilePath }) => {
  9. if (statusCode === 200) resolve(tempFilePath)
  10. else reject()
  11. },
  12. fail: () => reject()
  13. })
  14. })
  15. }
  16. /*
  17. ** 打开协议
  18. */
  19. function openAgreement(url) {
  20. return new Promise((resolve, reject) => {
  21. downloadFile(url).then(filePath => {
  22. wx.openDocument({
  23. filePath,
  24. success: () => resolve(),
  25. fail: () => reject()
  26. })
  27. }).catch(() => reject())
  28. })
  29. }
  30. module.exports = {openAgreement }