index.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. // index.js
  2. // 获取应用实例
  3. import { VueLikePage } from "../../utils/page";
  4. import { CDN_URL, API_BASE_URL, VIDEO_BASE_URL, app } from "../../config/index";
  5. VueLikePage([], {
  6. data: {
  7. cdn_url: "",
  8. baseUrl: API_BASE_URL + "/",
  9. url_link: "",
  10. id: "1",
  11. type: "",
  12. loadCompele: false,
  13. filePath: "",
  14. info: {
  15. resourceImg: {},
  16. banner: {},
  17. sceneTitleImg: {},
  18. recordTitleImg: {},
  19. rescan: {},
  20. activeSceneBdImg: {},
  21. },
  22. },
  23. methods: {
  24. onLoad: function (options) {
  25. let { rdw, id, type, projectid } = options;
  26. this.getData(projectid);
  27. let link = "";
  28. if (type == "0") {
  29. link = `${VIDEO_BASE_URL}4dvedio/${rdw}.mp4`;
  30. } else {
  31. link = `${VIDEO_BASE_URL}4dpic/${rdw}.jpg`;
  32. }
  33. this.setData({
  34. url_link: link,
  35. id,
  36. type,
  37. cdn_url: CDN_URL + "/" + projectid,
  38. });
  39. this.downloadF((data) => {
  40. this.setData({
  41. filePath: data,
  42. });
  43. });
  44. },
  45. loadcompele() {
  46. this.setData({
  47. loadCompele: true,
  48. });
  49. },
  50. cancel() {
  51. // wx.reLaunch({
  52. // url: "/pages/work/index",
  53. // });
  54. wx.navigateBack();
  55. },
  56. downloadF(cb = () => {}) {
  57. let link = this.data.url_link,
  58. m_type = "";
  59. if (this.data.type == "1") {
  60. m_type = "jpeg";
  61. } else {
  62. m_type = "video";
  63. }
  64. wx.downloadFile({
  65. url: link,
  66. success: (res) => {
  67. if (res.statusCode == "404") {
  68. return app.showAlert("作品暂未生成,请稍后再试", () => {
  69. wx.navigateBack();
  70. });
  71. }
  72. //判断是否为数组
  73. let typeType =
  74. Object.prototype.toString.call(res.header["Content-Type"]) ==
  75. "[object String]"
  76. ? res.header["Content-Type"]
  77. : res.header["Content-Type"][0];
  78. //判断不是xml文件
  79. if (typeType.indexOf(m_type) > -1) {
  80. cb(res.tempFilePath);
  81. }
  82. },
  83. fail: () => {
  84. app.showAlert("作品暂未生成,请稍后再试");
  85. },
  86. });
  87. this.setData({
  88. showModal: false,
  89. });
  90. },
  91. saveAlbum() {
  92. let type = this.data.type;
  93. wx.showLoading({
  94. title: "保存中…",
  95. mask: true,
  96. });
  97. if (this.data.filePath) {
  98. let api =
  99. type == "0" ? "saveVideoToPhotosAlbum" : "saveImageToPhotosAlbum";
  100. wx[api]({
  101. filePath: this.data.filePath,
  102. success() {
  103. wx.showModal({
  104. title: "提示",
  105. content: "已保存到相册,快去分享吧",
  106. showCancel: false,
  107. });
  108. },
  109. fail: (e) => {
  110. if (!(e.errMsg.indexOf("cancel") > -1)) {
  111. wx.showModal({
  112. title: "提示",
  113. content:
  114. "保存失败,请检查是否开启相册保存权限,可在「右上角」 - 「设置」里查看",
  115. showCancel: false,
  116. });
  117. }
  118. },
  119. complete: () => {
  120. wx.hideLoading();
  121. },
  122. });
  123. }
  124. },
  125. getData(prjId = "ZHS2305758-1") {
  126. wx.showLoading({
  127. title: "资源加载中",
  128. });
  129. this.setData({
  130. cdn_url: CDN_URL + "/" + prjId,
  131. });
  132. wx.request({
  133. url: `${VIDEO_BASE_URL}project/4dage-sxb/${prjId}/config.json`,
  134. success: ({ data: { title, ...rest } }) => {
  135. this.setData(
  136. {
  137. info: rest,
  138. },
  139. () => {
  140. wx.hideLoading();
  141. }
  142. );
  143. wx.setNavigationBarTitle({
  144. title: title,
  145. });
  146. },
  147. });
  148. },
  149. },
  150. });