analysis.js 1.9 KB
/*
 * @Author: yangming yangming@didihu.com.cn
 * @Date: 2023-01-31 15:41:18
 * @LastEditors: yangming qianduan01@didihu.com.cn
 * @LastEditTime: 2023-02-21 16:04:57
 * @FilePath: \h5Demo\src\mixins\analysis.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
export default {
  props: {
    dataObject: {
      type: Object,
    },
    popupState: {
      type: Boolean,
      default: true,
    },
    finishNum: {
      type: Number,
    },
  },
  inject: ["countdown"],
  data() {
    return {
      memberList: [], //成员列表
      isEnd: false, //是否结束
      timer: null,
      answerData: {
        body: {
          size: null,
          currentSize: null,
          timeLimit: null,
          rightNum: null,
          question: null,
          choice: [],
        },
      },
    };
  },
  watch: {
    // 监听服务器返回的数据变化
    dataObject(newData) {
      // if (this.dataObject.command == 3 && this.dataObject.body.type == 4) {
      //   this.$store.commit("setGameType", "");
      // }
      // 答题动作
      GPJSSDK.Game.knowAction({
        // 原始数据
        data: newData,
        // 状态
        status: (info) => {},
        // 游戏开始倒计时
        start: (duration) => {
          clearInterval(this.timer);
          this.duration = duration || newData.body.timeLimit;
          this.timer = setInterval(() => {
            this.duration--;
            if (this.duration <= 0) return clearInterval(this.timer);
          }, 1000);
        },
        // 游戏结束,并初始化数据
        end: () => {
          clearInterval(this.timer);
          this.isEnd = true;
          // this.$store.commit("setGameType", "");
        },
      });
    },
  },
  methods: {
    clearTimeLimit() {
      clearInterval(this.timer);
    },
  },
};