Blame view

uniapp_jiju/common/mixins/viewRecordMixin.js 1.12 KB
787af94f   “wangming”   完善设备查看会话记录功能,新增客户...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
  /**
   * 设备查看记录埋点 mixin
   * 用于详情页:进入时 StartViewRecord,离开时 EndViewRecord
   * 使用:在详情页 mixins: [viewRecordMixin],数据加载成功后调用 this.startViewTracking(reId, type, contentName, deviceName)
   * 记录类型、设备名称、查看内容 三字段便于定位
   */
  export default {
  	data() {
  		return {
  			viewRecordId: null
  		}
  	},
  	methods: {
  		async startViewTracking(reId, type, contentName, deviceName) {
  			if (!reId || !type) return
  			try {
  				const data = { reId: String(reId), type }
  				if (contentName) data.contentName = String(contentName)
  				if (deviceName) data.deviceName = String(deviceName)
  				const res = await this.API.startViewRecord(data)
  				if (res && res.data) {
  					this.viewRecordId = res.data
  				}
  			} catch (e) {
  				console.warn('StartViewRecord failed', e)
  			}
  		},
  		async endViewTracking() {
  			if (!this.viewRecordId) return
  			try {
  				await this.API.endViewRecord({ recordId: this.viewRecordId })
  			} catch (e) {
  				console.warn('EndViewRecord failed', e)
  			}
  			this.viewRecordId = null
  		}
  	},
  	onUnload() {
  		this.endViewTracking()
  	}
  }