|
@@ -1,10 +1,21 @@
|
|
|
// index.js
|
|
|
// 获取应用实例
|
|
|
-import { VueLikePage } from "../../utils/page";
|
|
|
-import { randomWord } from "../../utils/utils";
|
|
|
-import { isPhoneX } from "./../../utils/tools";
|
|
|
-
|
|
|
-import { CDN_URL, API_BASE_URL, VIDEO_BASE_URL, app } from "../../config/index";
|
|
|
+import {
|
|
|
+ VueLikePage
|
|
|
+} from "../../utils/page";
|
|
|
+import {
|
|
|
+ randomWord
|
|
|
+} from "../../utils/utils";
|
|
|
+import {
|
|
|
+ isPhoneX
|
|
|
+} from "./../../utils/tools";
|
|
|
+
|
|
|
+import {
|
|
|
+ CDN_URL,
|
|
|
+ API_BASE_URL,
|
|
|
+ VIDEO_BASE_URL,
|
|
|
+ app
|
|
|
+} from "../../config/index";
|
|
|
|
|
|
let socket_io = require("../../utils/socket.io-mp.js")
|
|
|
|
|
@@ -13,8 +24,8 @@ let timer = null;
|
|
|
var g_app = getApp();
|
|
|
|
|
|
let TYPESTR = {
|
|
|
- 0:'media',
|
|
|
- 1:'pic'
|
|
|
+ 0: 'media',
|
|
|
+ 1: 'pic'
|
|
|
}
|
|
|
|
|
|
|
|
@@ -26,105 +37,140 @@ VueLikePage([], {
|
|
|
isIphoneX: false,
|
|
|
canTap: true,
|
|
|
rndWord: randomWord(false, 8),
|
|
|
- scenes: [
|
|
|
+ scenes: [{
|
|
|
+ id: "1",
|
|
|
+ },
|
|
|
+ {
|
|
|
+ id: "2",
|
|
|
+ },
|
|
|
{
|
|
|
- id: "4",
|
|
|
+ id: "14",
|
|
|
},
|
|
|
{
|
|
|
- id: "5",
|
|
|
+ id: "15",
|
|
|
},
|
|
|
{
|
|
|
- id: "6",
|
|
|
+ id: "16",
|
|
|
},
|
|
|
],
|
|
|
+ records: [],
|
|
|
autoplay: true,
|
|
|
interval: 3000,
|
|
|
duration: 500,
|
|
|
current: 0,
|
|
|
- currentScene: 4,
|
|
|
+ currentScene: 1,
|
|
|
daojishi: 0,
|
|
|
isShot: false,
|
|
|
isRecord: false,
|
|
|
recordjishi: 10,
|
|
|
type: "",
|
|
|
+ authorCode: '',
|
|
|
+ isOtherZhanYong: true
|
|
|
},
|
|
|
methods: {
|
|
|
|
|
|
+ scanCode: function (e) {
|
|
|
+ wx.scanCode({
|
|
|
+ onlyFromCamera: true,
|
|
|
+ success(res) {
|
|
|
+ wx.reLaunch({
|
|
|
+ url: `/${res.path}`
|
|
|
+ })
|
|
|
+ }
|
|
|
+ })
|
|
|
+ },
|
|
|
+
|
|
|
swiperChange: function (e) {
|
|
|
this.setData({
|
|
|
current: e.detail.current,
|
|
|
});
|
|
|
},
|
|
|
|
|
|
- onShow(){
|
|
|
+ onShow() {
|
|
|
this.setData({
|
|
|
rndWord: randomWord(false, 8)
|
|
|
})
|
|
|
},
|
|
|
|
|
|
+ gotoRecord(e) {
|
|
|
+ let {
|
|
|
+ id
|
|
|
+ } = e.currentTarget.dataset;
|
|
|
+
|
|
|
+ let item = this.data.records.find(i => i.id == id)
|
|
|
+
|
|
|
+
|
|
|
+ Router.push({
|
|
|
+ url: "work",
|
|
|
+ query: item.codeData,
|
|
|
+ });
|
|
|
+
|
|
|
+ console.log(item)
|
|
|
+ },
|
|
|
+
|
|
|
gotoWork() {
|
|
|
+ //日期 new Date().Format("yyyy.MM.dd hh.mm.ss");
|
|
|
+ //编号 new Date().Format("yyyyMMddhhmmss");
|
|
|
timer && clearTimeout(timer);
|
|
|
timer = null;
|
|
|
+
|
|
|
+ let record = {
|
|
|
+ type: this.data.type,
|
|
|
+ id: this.data.currentScene,
|
|
|
+ rdw: encodeURIComponent(this.data.authorCode),
|
|
|
+ }
|
|
|
+
|
|
|
Router.push({
|
|
|
url: "work",
|
|
|
- query: {
|
|
|
- type: this.data.type,
|
|
|
- id: this.data.currentScene,
|
|
|
- rdw: encodeURIComponent(this.data.rndWord),
|
|
|
- },
|
|
|
+ query: record,
|
|
|
});
|
|
|
+
|
|
|
+ this.setData({
|
|
|
+ records: [{
|
|
|
+ id: new Date().Format("yyyyMMddhhmmss"),
|
|
|
+ date: new Date().Format("yyyy.MM.dd hh.mm.ss"),
|
|
|
+ type: this.data.type,
|
|
|
+ codeData: record
|
|
|
+ }].concat(this.data.records).slice(0, 15)
|
|
|
+ })
|
|
|
+
|
|
|
+ wx.setStorageSync('records', JSON.stringify(this.data.records))
|
|
|
+
|
|
|
this.reset();
|
|
|
},
|
|
|
|
|
|
- reset() {
|
|
|
+ reset(noswitch=false) {
|
|
|
this.setData({
|
|
|
daojishi: 0,
|
|
|
isShot: false,
|
|
|
isRecord: false,
|
|
|
currentScene: 1,
|
|
|
recordjishi: 10,
|
|
|
- type: "",
|
|
|
});
|
|
|
- this.clearLongTime();
|
|
|
- app.websocket && app.websocket.send({ data: "switch 1" });
|
|
|
+ if(!noswitch){
|
|
|
+ app.websocket && app.websocket.send({
|
|
|
+ data: "switch 1"
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
setTimeout(() => {
|
|
|
app.hideLoading();
|
|
|
});
|
|
|
},
|
|
|
|
|
|
- clearLongTime() {
|
|
|
- app.longtime && clearInterval(app.longtime);
|
|
|
- app.longtime = null;
|
|
|
- },
|
|
|
-
|
|
|
- closeServer(cb=null) {
|
|
|
- app.closeByVideoHandle = true
|
|
|
- if (app.websocket) {
|
|
|
- app.send("close");
|
|
|
- app.websocket.close();
|
|
|
- app.websocket = null;
|
|
|
- }
|
|
|
-
|
|
|
- if (app.longtime) {
|
|
|
- setTimeout(() => {
|
|
|
- cb && cb()
|
|
|
- },100);
|
|
|
- }
|
|
|
- },
|
|
|
-
|
|
|
handleWebSocket: function () {
|
|
|
if (app.websocket) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- app.websocket = socket_io(API_BASE_URL,{
|
|
|
+ app.websocket = socket_io(API_BASE_URL, {
|
|
|
transports: ['websocket']
|
|
|
});
|
|
|
|
|
|
app.websocket.on('connect', () => {
|
|
|
console.log('SOCKET连接成功');
|
|
|
- app.emitEvent.request(data=>{
|
|
|
- console.log(data,1111111);
|
|
|
+ app.emitEvent.request(data => {
|
|
|
+ console.log(data, 1111111);
|
|
|
});
|
|
|
})
|
|
|
|
|
@@ -134,55 +180,48 @@ VueLikePage([], {
|
|
|
url: "/pages/start/index",
|
|
|
});
|
|
|
});
|
|
|
-
|
|
|
+
|
|
|
console.log('ForceOffline成功');
|
|
|
})
|
|
|
|
|
|
},
|
|
|
|
|
|
- checkTextDetail:function () {
|
|
|
- wx.showModal({
|
|
|
- title: '作品标识码(在首页获取作品)',
|
|
|
- content: TYPESTR[this.data.type]+this.data.rndWord + app.id,
|
|
|
- showCancel: false,
|
|
|
- confirmText: '复制文本',
|
|
|
- success: (result) => {
|
|
|
- if (result.confirm) {
|
|
|
- wx.setClipboardData({
|
|
|
- data: TYPESTR[this.data.type]+this.data.rndWord + app.id,
|
|
|
- success: () => {
|
|
|
- wx.getClipboardData({
|
|
|
- success: () => {
|
|
|
- setTimeout(() => {
|
|
|
- wx.navigateBack({
|
|
|
- delta: 3
|
|
|
- });
|
|
|
- }, 1000);
|
|
|
- },
|
|
|
- });
|
|
|
- }
|
|
|
- });
|
|
|
-
|
|
|
- }
|
|
|
- },
|
|
|
- });
|
|
|
-
|
|
|
-
|
|
|
+ onHide: function () {
|
|
|
+ this.disconnect();
|
|
|
},
|
|
|
- onLoad: function () {
|
|
|
+
|
|
|
+
|
|
|
+ onLoad: function (options) {
|
|
|
+ // 1、获取二维码传参
|
|
|
+ if (options.authorCode) {
|
|
|
+ this.setData({
|
|
|
+ authorCode: decodeURIComponent(options.authorCode),
|
|
|
+ })
|
|
|
+ this.start(this.data.authorCode)
|
|
|
+ }
|
|
|
+
|
|
|
+ if (wx.getStorageSync('records')) {
|
|
|
+ this.setData({
|
|
|
+ records: JSON.parse(wx.getStorageSync('records'))
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ // wx.setStorageSync('records', JSON.stringify(this.data.records))
|
|
|
+
|
|
|
+
|
|
|
isPhoneX().then((res) => {
|
|
|
this.setData({
|
|
|
isIphoneX: res,
|
|
|
});
|
|
|
});
|
|
|
- let tmp = g_app.globalData.scenes.map(item=>{
|
|
|
- return {id:item}
|
|
|
- })
|
|
|
-
|
|
|
- this.setData({
|
|
|
- scenes: tmp,
|
|
|
- currentScene:tmp[0].id
|
|
|
- })
|
|
|
+ // let tmp = g_app.globalData.scenes.map(item=>{
|
|
|
+ // return {id:item}
|
|
|
+ // })
|
|
|
+
|
|
|
+ // this.setData({
|
|
|
+ // scenes: tmp,
|
|
|
+ // currentScene:tmp[0].id
|
|
|
+ // })
|
|
|
},
|
|
|
|
|
|
daojishiFn(key, time, fn = () => {}) {
|
|
@@ -207,13 +246,13 @@ VueLikePage([], {
|
|
|
},
|
|
|
|
|
|
shot: function (e) {
|
|
|
- // app.checkOperationTimeout(true);
|
|
|
-
|
|
|
- let { id } = e.currentTarget.dataset;
|
|
|
+ app.checkOperationTimeout(true);
|
|
|
+ let {
|
|
|
+ id
|
|
|
+ } = e.currentTarget.dataset;
|
|
|
|
|
|
this.setData({
|
|
|
type: id,
|
|
|
- rndWord: randomWord(false, 8),
|
|
|
});
|
|
|
|
|
|
// if (!app.sendCheck()) {
|
|
@@ -234,26 +273,29 @@ VueLikePage([], {
|
|
|
});
|
|
|
|
|
|
app.emitEvent.switchMachine(this.data.currentScene)
|
|
|
-
|
|
|
+
|
|
|
|
|
|
setTimeout(() => {
|
|
|
- app.emitEvent.Video(TYPESTR[this.data.type]+this.data.rndWord)
|
|
|
-
|
|
|
+ app.emitEvent.Video(this.data.authorCode)
|
|
|
+
|
|
|
// 为了同步机器的倒计时
|
|
|
setTimeout(() => {
|
|
|
this.daojishiFn("daojishi", this.data.daojishi, () => {
|
|
|
this.setData({
|
|
|
isRecord: true,
|
|
|
});
|
|
|
-
|
|
|
+
|
|
|
this.daojishiFn("recordjishi", this.data.recordjishi, () => {
|
|
|
wx.showLoading({
|
|
|
title: "生成视频中...",
|
|
|
});
|
|
|
setTimeout(() => {
|
|
|
- wx.hideLoading()
|
|
|
- this.checkTextDetail()
|
|
|
- }, 1000);
|
|
|
+ // 不发送switch
|
|
|
+ this.gotoWork()
|
|
|
+ this.disconnect(true)
|
|
|
+ wx.hideLoading()
|
|
|
+ // 上传倒计时
|
|
|
+ }, 30 * 1000);
|
|
|
});
|
|
|
});
|
|
|
}, 500);
|
|
@@ -269,6 +311,7 @@ VueLikePage([], {
|
|
|
this.setData({
|
|
|
isShot: true,
|
|
|
});
|
|
|
+
|
|
|
setTimeout(() => {
|
|
|
this.setData({
|
|
|
daojishi: 3,
|
|
@@ -278,44 +321,46 @@ VueLikePage([], {
|
|
|
app.emitEvent.switchMachine(this.data.currentScene)
|
|
|
|
|
|
setTimeout(() => {
|
|
|
- app.emitEvent.Photo(TYPESTR[this.data.type]+this.data.rndWord)
|
|
|
+ app.emitEvent.Photo(this.data.authorCode)
|
|
|
|
|
|
- // 为了同步机器的倒计时
|
|
|
- setTimeout(() => {
|
|
|
- this.daojishiFn("daojishi", this.data.daojishi, () => {
|
|
|
- wx.showLoading({
|
|
|
- title: "生成图片中...",
|
|
|
- // mask: true,
|
|
|
- });
|
|
|
- setTimeout(() => {
|
|
|
- this.checkTextDetail()
|
|
|
- wx.hideLoading()
|
|
|
- }, 1000);
|
|
|
+ // 为了同步机器的倒计时
|
|
|
+ setTimeout(() => {
|
|
|
+ this.daojishiFn("daojishi", this.data.daojishi, () => {
|
|
|
+ wx.showLoading({
|
|
|
+ title: "生成图片中...",
|
|
|
+ // mask: true,
|
|
|
});
|
|
|
- }, 500);
|
|
|
+ setTimeout(() => {
|
|
|
+ // 不发送switch
|
|
|
+ this.gotoWork()
|
|
|
+ this.disconnect(true)
|
|
|
+ wx.hideLoading()
|
|
|
+ }, 4 * 1000);
|
|
|
+ });
|
|
|
+ }, 500);
|
|
|
|
|
|
}, 1000);
|
|
|
|
|
|
-
|
|
|
+
|
|
|
}, 500);
|
|
|
}
|
|
|
|
|
|
- // 1秒后拍照
|
|
|
- setTimeout(() => {
|
|
|
-
|
|
|
- }, 1000);
|
|
|
},
|
|
|
|
|
|
tapSelect: function (e) {
|
|
|
- app.checkOperationTimeout();
|
|
|
+ app.checkOperationTimeout(false, () => {
|
|
|
+ app.showAlert("抱歉,因您长时间使用,让下一位小伙伴体验吧", () => {
|
|
|
+ this.disconnect();
|
|
|
+ });
|
|
|
+ });
|
|
|
|
|
|
if (!this.data.canTap) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- this.clearLongTime();
|
|
|
-
|
|
|
- let { id } = e.currentTarget.dataset;
|
|
|
+ let {
|
|
|
+ id
|
|
|
+ } = e.currentTarget.dataset;
|
|
|
if (id == this.data.currentScene) {
|
|
|
return;
|
|
|
}
|
|
@@ -331,7 +376,7 @@ VueLikePage([], {
|
|
|
app.hideLoading();
|
|
|
}, 3 * 1000);
|
|
|
|
|
|
-
|
|
|
+
|
|
|
wx.showLoading({
|
|
|
title: "切换中...",
|
|
|
mask: true,
|
|
@@ -341,5 +386,83 @@ VueLikePage([], {
|
|
|
});
|
|
|
app.emitEvent.switchMachine(id)
|
|
|
},
|
|
|
+
|
|
|
+ disconnect(noswitch=false) {
|
|
|
+ this.reset(noswitch);
|
|
|
+ if (app.websocket) {
|
|
|
+ app.emitEvent.close()
|
|
|
+ app.websocket.disconnect();
|
|
|
+ app.websocket = null;
|
|
|
+ this.setData({
|
|
|
+ isOtherZhanYong: true
|
|
|
+ })
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ start: function (authorCode) {
|
|
|
+ if (app.websocket) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ app.websocket = socket_io(API_BASE_URL, {
|
|
|
+ transports: ["websocket"],
|
|
|
+ });
|
|
|
+
|
|
|
+ app.websocket.on("connect", () => {
|
|
|
+ console.log("SOCKET连接成功");
|
|
|
+ wx.showLoading({
|
|
|
+ mask: true,
|
|
|
+ title: '正在连接机器',
|
|
|
+ })
|
|
|
+
|
|
|
+ let linktimer = setTimeout(() => {
|
|
|
+ clearTimeout(linktimer)
|
|
|
+ wx.showToast({
|
|
|
+ title: '网络异常,请稍后再试',
|
|
|
+ icon: 'none'
|
|
|
+ })
|
|
|
+ wx.hideLoading()
|
|
|
+ }, 5000);
|
|
|
+ app.emitEvent.request((data) => {
|
|
|
+ // 校验成功后解除被他人占用情况
|
|
|
+ clearTimeout(linktimer)
|
|
|
+ wx.hideLoading()
|
|
|
+ this.setData({
|
|
|
+ isOtherZhanYong: false
|
|
|
+ })
|
|
|
+ app.checkOperationTimeout(false, () => {
|
|
|
+ app.showAlert("抱歉,因您长时间使用,让下一位小伙伴体验吧", () => {
|
|
|
+ this.disconnect();
|
|
|
+ });
|
|
|
+ });
|
|
|
+ app.websocket.on("ForceOffline", () => {
|
|
|
+ console.log("ForceOffline成功");
|
|
|
+ app.checkOperationTimeout(true);
|
|
|
+ this.disconnect();
|
|
|
+ });
|
|
|
+
|
|
|
+ app.websocket.on("error", () => {
|
|
|
+ this.disconnect();
|
|
|
+ app.showAlert("服务器异常,请稍后再试");
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+ if (data == 808) {
|
|
|
+ // return app.showAlert("机器被占用,请稍后再试");
|
|
|
+ app.checkOperationTimeout(true);
|
|
|
+ this.disconnect();
|
|
|
+ }
|
|
|
+
|
|
|
+ if (data == 404 || data == 505) {
|
|
|
+ app.checkOperationTimeout(true);
|
|
|
+ this.disconnect();
|
|
|
+ // app.showAlert("网络异常,请稍后再试");
|
|
|
+ }
|
|
|
+ console.log(data, 'data')
|
|
|
+ }, authorCode);
|
|
|
+ });
|
|
|
+ },
|
|
|
},
|
|
|
-});
|
|
|
+});
|