// 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"; let socket_io = require("../../utils/socket.io-mp.js") let timer = null; var g_app = getApp(); let TYPESTR = { 0:'media', 1:'pic' } import Router from "../../utils/routes"; VueLikePage([], { data: { cdn_url: CDN_URL, isIphoneX: false, canTap: true, rndWord: randomWord(false, 8), scenes: [ { id: "4", }, { id: "5", }, { id: "6", }, ], autoplay: true, interval: 3000, duration: 500, current: 0, currentScene: 4, daojishi: 0, isShot: false, isRecord: false, recordjishi: 10, type: "", }, methods: { swiperChange: function (e) { this.setData({ current: e.detail.current, }); }, onShow(){ this.setData({ rndWord: randomWord(false, 8) }) }, gotoWork() { timer && clearTimeout(timer); timer = null; Router.push({ url: "work", query: { type: this.data.type, id: this.data.currentScene, rdw: encodeURIComponent(this.data.rndWord), }, }); this.reset(); }, reset() { this.setData({ daojishi: 0, isShot: false, isRecord: false, currentScene: 1, recordjishi: 10, type: "", }); this.clearLongTime(); 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,{ transports: ['websocket'] }); app.websocket.on('connect', () => { console.log('SOCKET连接成功'); app.emitEvent.request(data=>{ console.log(data,1111111); }); }) app.websocket.on('ForceOffline', () => { app.showAlert("服务器连接失败,请稍后再试", () => { wx.reLaunch({ 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); }, }); } }); } }, }); }, onLoad: function () { 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 }) }, daojishiFn(key, time, fn = () => {}) { intel && clearInterval(intel); let intel = null; let titop = time; intel = setInterval(() => { titop -= 1; let kv = {}; kv[key] = titop; this.setData(kv); if (titop <= 0) { fn(); intel && clearInterval(intel); return; } }, 1000); }, shot: function (e) { // app.checkOperationTimeout(true); let { id } = e.currentTarget.dataset; this.setData({ type: id, rndWord: randomWord(false, 8), }); // if (!app.sendCheck()) { // return; // } //录像 if (id == "0") { let intel = null; intel && clearInterval(intel); this.setData({ isShot: true, }); setTimeout(() => { this.setData({ daojishi: 3, }); app.emitEvent.switchMachine(this.data.currentScene) setTimeout(() => { app.emitEvent.Video(TYPESTR[this.data.type]+this.data.rndWord) // 为了同步机器的倒计时 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); }); }); }, 500); }, 1000); }, 500); } //拍照 else { let intel = null; intel && clearInterval(intel); this.setData({ isShot: true, }); setTimeout(() => { this.setData({ daojishi: 3, }); app.emitEvent.switchMachine(this.data.currentScene) setTimeout(() => { app.emitEvent.Photo(TYPESTR[this.data.type]+this.data.rndWord) // 为了同步机器的倒计时 setTimeout(() => { this.daojishiFn("daojishi", this.data.daojishi, () => { wx.showLoading({ title: "生成图片中...", // mask: true, }); setTimeout(() => { this.checkTextDetail() wx.hideLoading() }, 1000); }); }, 500); }, 1000); }, 500); } // 1秒后拍照 setTimeout(() => { }, 1000); }, tapSelect: function (e) { app.checkOperationTimeout(); if (!this.data.canTap) { return; } this.clearLongTime(); let { id } = e.currentTarget.dataset; if (id == this.data.currentScene) { return; } this.setData({ canTap: false, }); setTimeout(() => { this.setData({ canTap: true, }); app.hideLoading(); }, 3 * 1000); wx.showLoading({ title: "切换中...", mask: true, }); this.setData({ currentScene: id }); app.emitEvent.switchMachine(id) }, }, });