tremble 3 years ago
parent
commit
b9b1e78faf
3 changed files with 69 additions and 42 deletions
  1. 5 3
      config/index.js
  2. 64 38
      pages/index/index.js
  3. 0 1
      pages/work/index.js

+ 5 - 3
config/index.js

@@ -12,11 +12,13 @@ export let app = {
   is_connect_ok: null,
   is_connect_ok: null,
   is_send_msg: null,
   is_send_msg: null,
   noOperationTimeout: 35,
   noOperationTimeout: 35,
-  showAlert(msg, comfirm) {
+  closeByVideoHandle: false,
+  showAlert(msg, comfirm,confirmText='确定') {
     if (comfirm) {
     if (comfirm) {
       return (() => {
       return (() => {
         wx.showModal({
         wx.showModal({
           title: "提示",
           title: "提示",
+          confirmText,
           content: msg,
           content: msg,
           showCancel: false,
           showCancel: false,
           success(res) {
           success(res) {
@@ -76,7 +78,7 @@ export let app = {
       this.hideLoading()
       this.hideLoading()
       app.showAlert("服务器连接失败,请重新连接", () => {
       app.showAlert("服务器连接失败,请重新连接", () => {
         app.send("request");
         app.send("request");
-      });
+      },'重新连接');
       return false;
       return false;
     } else if (this.is_connect_ok === false) {
     } else if (this.is_connect_ok === false) {
       this.hideLoading()
       this.hideLoading()
@@ -90,7 +92,7 @@ export let app = {
         setTimeout(() => {
         setTimeout(() => {
           app.send("request");
           app.send("request");
         }, 1000);
         }, 1000);
-      });
+      },'重新连接');
       return false;
       return false;
     } else if (this.is_other_used) {
     } else if (this.is_other_used) {
       this.hideLoading()
       this.hideLoading()

+ 64 - 38
pages/index/index.js

@@ -59,12 +59,19 @@ VueLikePage([], {
     type: "",
     type: "",
   },
   },
   methods: {
   methods: {
+
     swiperChange: function (e) {
     swiperChange: function (e) {
       this.setData({
       this.setData({
         current: e.detail.current,
         current: e.detail.current,
       });
       });
     },
     },
 
 
+    onShow(){
+      this.setData({
+        rndWord: randomWord(false, 8)
+      })
+    },
+
     gotoWork() {
     gotoWork() {
       timer && clearTimeout(timer);
       timer && clearTimeout(timer);
       timer = null;
       timer = null;
@@ -101,14 +108,18 @@ VueLikePage([], {
     },
     },
 
 
     closeServer(cb=null) {
     closeServer(cb=null) {
+      app.closeByVideoHandle = true
       if (app.websocket) {
       if (app.websocket) {
         app.send("close");
         app.send("close");
         app.websocket.close();
         app.websocket.close();
         app.websocket = null;
         app.websocket = null;
       }
       }
-      setTimeout(() => {
-        cb && cb()
-      },100);
+      
+      if (app.longtime) {
+        setTimeout(() => {
+          cb && cb()
+        },100);
+      }
     },
     },
 
 
     handleWebSocket: function () {
     handleWebSocket: function () {
@@ -130,6 +141,7 @@ VueLikePage([], {
 
 
       app.websocket.onMessage((msg) => {
       app.websocket.onMessage((msg) => {
         console.log(msg);
         console.log(msg);
+        app.hideLoading();
         if (typeof msg.data == "string") {
         if (typeof msg.data == "string") {
           switch (msg.data) {
           switch (msg.data) {
             case "error 101":
             case "error 101":
@@ -147,16 +159,16 @@ VueLikePage([], {
               app.is_other_used = true;
               app.is_other_used = true;
 
 
               if (app.is_send_msg) {
               if (app.is_send_msg) {
-                app.hideLoading();
                 app.showAlert("服务器连接失败,请重新连接", () => {
                 app.showAlert("服务器连接失败,请重新连接", () => {
                   wx.reLaunch({
                   wx.reLaunch({
                     url: "index",
                     url: "index",
                   });
                   });
-                });
+                },'重新连接');
               }
               }
               break;
               break;
 
 
             case "error 808":
             case "error 808":
+              app.is_connect_ok = true;
               app.is_other_used = true;
               app.is_other_used = true;
               if (app.is_send_msg) {
               if (app.is_send_msg) {
                 app.showAlert("当前画屏正在被使用,请稍后");
                 app.showAlert("当前画屏正在被使用,请稍后");
@@ -206,13 +218,14 @@ VueLikePage([], {
                   success: (res) => {
                   success: (res) => {
                     //判断是否为数组
                     //判断是否为数组
                     let typeType =
                     let typeType =
-                    Object.prototype.toString.call(res.header["Content-Type"]) == "[object String]"?
+                    (Object.prototype.toString.call(res.header["Content-Type"]) == "[object String]")?
                     res.header["Content-Type"] : res.header["Content-Type"][0]
                     res.header["Content-Type"] : res.header["Content-Type"][0]
 
 
-                    console.log(Object.prototype.toString.call(res.header["Content-Type"][0]),8888);
+                    console.log(typeType,8888);
 
 
                     //判断不是xml文件
                     //判断不是xml文件
                     if (typeType.indexOf(m_type) > -1) {
                     if (typeType.indexOf(m_type) > -1) {
+                      this.clearLongTime();
                       g_app.globalData.m_file = res.tempFilePath;
                       g_app.globalData.m_file = res.tempFilePath;
                       this.gotoWork();
                       this.gotoWork();
                     }
                     }
@@ -238,7 +251,6 @@ VueLikePage([], {
 
 
             default:
             default:
               try {
               try {
-              app.hideLoading()
               // var json = JSON.parse(msg.data);
               // var json = JSON.parse(msg.data);
                 // if (json.url) {
                 // if (json.url) {
                 //   if (json.url.indexOf(this.data.rndWord) > -1) {
                 //   if (json.url.indexOf(this.data.rndWord) > -1) {
@@ -265,12 +277,14 @@ VueLikePage([], {
         app.checkOperationTimeout(true);
         app.checkOperationTimeout(true);
         app.hideLoading();
         app.hideLoading();
         app.websocket = null;
         app.websocket = null;
-        if (!app.longtime) {
+        
+        if (!app.longtime&&!app.closeByVideoHandle) {
           app.showAlert("服务器连接已关闭,请重新连接", () => {
           app.showAlert("服务器连接已关闭,请重新连接", () => {
             wx.reLaunch({
             wx.reLaunch({
               url: "index",
               url: "index",
             });
             });
-          });
+          },'重新连接');
+          app.closeByVideoHandle = false
         }
         }
       });
       });
     },
     },
@@ -311,6 +325,7 @@ VueLikePage([], {
 
 
       this.setData({
       this.setData({
         type: id,
         type: id,
+        rndWord: randomWord(false, 8),
       });
       });
 
 
       if (!app.sendCheck()) {
       if (!app.sendCheck()) {
@@ -336,24 +351,32 @@ VueLikePage([], {
 
 
           setTimeout(() => {
           setTimeout(() => {
             app.send("photo " + "0#" + this.data.rndWord);
             app.send("photo " + "0#" + this.data.rndWord);
-          }, 1000);
-
-          this.daojishiFn("daojishi", this.data.daojishi, () => {
-            this.setData({
-              isRecord: true,
-            });
-
-            this.daojishiFn("recordjishi", this.data.recordjishi, () => {
-              wx.showLoading({
-                title: "生成视频中...",
-              });
-              this.closeServer(()=>{
-                wx.showLoading({
-                  title: "生成视频中...",
+            
+            // 为了同步机器的倒计时
+            setTimeout(() => {
+              this.daojishiFn("daojishi", this.data.daojishi, () => {
+                this.setData({
+                  isRecord: true,
+                });
+    
+                this.daojishiFn("recordjishi", this.data.recordjishi, () => {
+                  wx.showLoading({
+                    title: "生成视频中...",
+                  });
+                  setTimeout(() => {
+                     this.closeServer(()=>{
+                      wx.showLoading({
+                        title: "生成视频中...",
+                      });
+                    });
+                  }, 20 * 1000);
                 });
                 });
               });
               });
-            });
-          });
+            }, 500);
+
+          }, 1000);
+
+          
         }, 500);
         }, 500);
       }
       }
 
 
@@ -375,18 +398,22 @@ VueLikePage([], {
 
 
           setTimeout(() => {
           setTimeout(() => {
             app.send("photo " + "1#" + this.data.rndWord);
             app.send("photo " + "1#" + this.data.rndWord);
+
+               // 为了同步机器的倒计时
+              setTimeout(() => {
+                this.daojishiFn("daojishi", this.data.daojishi, () => {
+                  this.closeServer(()=>{
+                    wx.showLoading({
+                      title: "生成图片中...",
+                      // mask: true,
+                    });
+                  });
+                });
+              }, 500);
+
           }, 1000);
           }, 1000);
 
 
-          this.daojishiFn("daojishi", this.data.daojishi, () => {
-            console.log(11111,'sss');
-            
-            this.closeServer(()=>{
-              wx.showLoading({
-                title: "生成图片中...",
-                // mask: true,
-              });
-            });
-          });
+          
         }, 500);
         }, 500);
       }
       }
 
 
@@ -432,8 +459,7 @@ VueLikePage([], {
           mask: true,
           mask: true,
         });
         });
         this.setData({
         this.setData({
-          currentScene: id,
-          rndWord: randomWord(false, 8),
+          currentScene: id
         });
         });
         app.send("switch " + id);
         app.send("switch " + id);
       }
       }

+ 0 - 1
pages/work/index.js

@@ -64,7 +64,6 @@ VueLikePage([], {
             });
             });
           },
           },
           fail: (e) => {
           fail: (e) => {
-            console.log(e, 1111111);
             if (!(e.errMsg.indexOf('cancel')>-1)) {
             if (!(e.errMsg.indexOf('cancel')>-1)) {
               wx.showModal({
               wx.showModal({
                 title: "提示",
                 title: "提示",