receptionTrackMixin.js 1.2 KB
export default {
  watch: {
    id: {
      immediate: true,
      handler (key) {
        if (!key || this.type == 'preview') return
        let item = this.media.find(e => e.id == key),
          value = this.receptionTrack[key]
        if (value) {
          value.openCount += 1
          value.entryTime = Date.now()
        } else {
          value = {
            openCount: 1,
            materialName: item.detailTitle,
            materialId: item.id,
            stayDuration: 0,
            entryTime: Date.now()
          }
        }
        this.$store.dispatch("setReceptionTrack", { key, value })
      }
    }
  },
  computed: {
    receptionTrack () {
      return this.$store.state.user.receptionTrack
    }
  },
  methods: {
    receptionTrackLeave (keyName = 'id') {
      if (this.type == 'preview') return
      let key = this[keyName],
        value = this.receptionTrack[key]
      value.stayDuration += Number(Date.now() - value.entryTime)
      this.$store.dispatch("setReceptionTrack", { key, value })
      if (keyName == 'id' && key == 1) {
        let [receptionRef] = this.$refs.media1
        receptionRef.previewLeave && receptionRef.previewLeave(receptionRef.currentItem)
      }

    }
  }
}