123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166 |
- // index.js
- // 获取应用实例
- import { VueLikePage } from "../../utils/page";
- import { CDN_URL, API_BASE_URL, VIDEO_BASE_URL, app } from "../../config/index";
- VueLikePage([], {
- data: {
- cdn_url: "",
- baseUrl: API_BASE_URL + "/",
- url_link: "",
- id: "1",
- type: "",
- loadCompele: false,
- filePath: "",
- info: {
- resourceImg: {},
- banner: {},
- sceneTitleImg: {},
- recordTitleImg: {},
- rescan: {},
- activeSceneBdImg: {},
- },
- },
- methods: {
- onLoad: function (options) {
- let { rdw, id, type, projectid } = options;
- this.getData(projectid);
- let link = "";
- if (type == "0") {
- link = `${VIDEO_BASE_URL}4dvedio/${rdw}.mp4`;
- } else {
- link = `${VIDEO_BASE_URL}4dpic/${rdw}.jpg`;
- }
- this.setData({
- url_link: link,
- id,
- type,
- cdn_url: CDN_URL + "/" + projectid,
- });
- this.downloadF((data) => {
- this.setData({
- filePath: data,
- });
- });
- },
- loadcompele() {
- this.setData({
- loadCompele: true,
- });
- },
- cancel() {
- // wx.reLaunch({
- // url: "/pages/work/index",
- // });
- wx.navigateBack();
- },
- downloadF(cb = () => {}) {
- let link = this.data.url_link,
- m_type = "";
- if (this.data.type == "1") {
- m_type = "jpeg";
- } else {
- m_type = "video";
- }
- wx.downloadFile({
- url: link,
- success: (res) => {
- if (res.statusCode == "404") {
- return app.showAlert("作品暂未生成,请稍后再试", () => {
- wx.navigateBack();
- });
- }
- //判断是否为数组
- let typeType =
- Object.prototype.toString.call(res.header["Content-Type"]) ==
- "[object String]"
- ? res.header["Content-Type"]
- : res.header["Content-Type"][0];
- //判断不是xml文件
- if (typeType.indexOf(m_type) > -1) {
- cb(res.tempFilePath);
- }
- },
- fail: () => {
- app.showAlert("作品暂未生成,请稍后再试");
- },
- });
- this.setData({
- showModal: false,
- });
- },
- saveAlbum() {
- let type = this.data.type;
- wx.showLoading({
- title: "保存中…",
- mask: true,
- });
- if (this.data.filePath) {
- let api =
- type == "0" ? "saveVideoToPhotosAlbum" : "saveImageToPhotosAlbum";
- wx[api]({
- filePath: this.data.filePath,
- success() {
- wx.showModal({
- title: "提示",
- content: "已保存到相册,快去分享吧",
- showCancel: false,
- });
- },
- fail: (e) => {
- if (!(e.errMsg.indexOf("cancel") > -1)) {
- wx.showModal({
- title: "提示",
- content:
- "保存失败,请检查是否开启相册保存权限,可在「右上角」 - 「设置」里查看",
- showCancel: false,
- });
- }
- },
- complete: () => {
- wx.hideLoading();
- },
- });
- }
- },
- getData(prjId = "ZHS2305758-1") {
- wx.showLoading({
- title: "资源加载中",
- });
- this.setData({
- cdn_url: CDN_URL + "/" + prjId,
- });
- wx.request({
- url: `${VIDEO_BASE_URL}project/4dage-sxb/${prjId}/config.json`,
- success: ({ data: { title, ...rest } }) => {
- this.setData(
- {
- info: rest,
- },
- () => {
- wx.hideLoading();
- }
- );
- wx.setNavigationBarTitle({
- title: title,
- });
- },
- });
- },
- },
- });
|