123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345 |
- // 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)
- },
- },
- });
|