123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184 |
- // index.js
- // 获取应用实例
- import { VueLikePage } from "../../utils/page";
- import { CDN_URL, API_BASE_URL, VIDEO_BASE_URL, app } from "../../config/index";
- import Router from "../../utils/routes";
- let socket_io = require("../../utils/socket.io-mp.js");
- var g_app = getApp();
- VueLikePage([], {
- data: {
- cdn_url: CDN_URL,
- rndWord: "",
- showModal: false,
- type:0
- },
- methods: {
- onLoad: function () {},
- disconnect() {
- app.websocket.disconnect();
- app.websocket = null;
- },
- wish_put: function (e) {
- this.setData({
- rndWord: e.detail.value,
- });
- },
- back() {
- this.setData({
- showModal: false,
- });
- },
- ok() {
- let link = "",
- m_type = "";
- if (this.data.rndWord.substring(0,3) == "pic") {
- this.setData({
- type:1
- })
- link = `${VIDEO_BASE_URL}4dpic/${this.data.rndWord}.jpg`;
- m_type = "jpeg";
- } else {
- link = `${VIDEO_BASE_URL}4dvedio/${this.data.rndWord}.mp4`;
- m_type = "video";
- this.setData({
- type:0
- })
- }
- console.log(link);
- wx.downloadFile({
- url: link,
- success: (res) => {
- console.log(res);
- if (res.statusCode == '404') {
- return app.showAlert("作品暂未生成,请稍后再试");
- }
- //判断是否为数组
- 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) {
- g_app.globalData.m_file = res.tempFilePath;
- this.gotoWork();
- }
- },
- fail: () => {
- app.showAlert("作品暂未生成,请稍后再试");
- },
- });
- this.setData({
- showModal: false,
- });
- },
- gotoWork() {
- Router.push({
- url: "work",
- query: {
- type: this.data.type,
- id: this.data.currentScene,
- rdw: encodeURIComponent(this.data.rndWord),
- },
- });
- },
- getWork() {
- this.setData({
- showModal: true,
- });
- // Router.push({
- // url: "work",
- // });
- },
- onShow(){
- if (app.websocket) {
- this.disconnect();
- }
- },
- checkTextDetail: function () {
- wx.showModal({
- title: "作品标识码",
- content: this.data.rndWord,
- showCancel: true,
- confirmText: "复制文本",
- success: (result) => {
- if (result.confirm) {
- wx.setClipboardData({
- data: this.data.rndWord,
- success: () => {
- wx.getClipboardData({
- success: (data) => {
- console.log(data);
- },
- });
- },
- });
- }
- },
- });
- },
- bindStart: function () {
- if (app.websocket) {
- return;
- }
- app.websocket = socket_io(API_BASE_URL, {
- transports: ["websocket"],
- });
- app.websocket.on("connect", () => {
- console.log("SOCKET连接成功");
- app.emitEvent.request((data) => {
- app.websocket.on("ForceOffline", () => {
- console.log("ForceOffline成功");
- app.showAlert("服务器连接失败,请稍后再试", () => {
- wx.reLaunch({
- url: "start",
- });
- });
- this.disconnect();
- });
- app.websocket.on("error", () => {
- this.disconnect();
- app.showAlert("服务器异常,请稍后再试");
- });
- if (data == 808) {
- return app.showAlert("机器被占用,请稍后再试");
- }
- console.log(data,4545454);
- try {
- var json = JSON.parse(data);
- g_app.globalData.scenes = [...json.scenes];
- if (g_app.globalData.scenes.length > 0) {
- Router.push({
- url: "index",
- });
- } else {
- app.showAlert("暂无场景");
- }
- } catch (error) {
- this.disconnect();
- app.showAlert("网络异常,请稍后再试");
- }
- });
- });
- },
- },
- });
|