Im.js
6.17 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
// // pages/crowdfunding/components/Im/Im.js
// import {
// shopmallApi
// } from '~/pages/crowdfunding/api/index'
// import USERAPI from '~/api/usersApi/index'
// import IM from './tim.js'
// let timObj = null
// const msgMaxNum = 100
// Component({
// /**
// * 组件的属性列表
// */
// properties: {
// liveDetail: {
// type: Object,
// value: () => {
// return {
// imGroupId: '',
// imSdkAppId: ''
// }
// }
// },
// detail: {
// type: Object,
// value: () => { }
// },
// isAction: {
// type: Boolean,
// value: false
// }
// },
// /**
// * 组件的初始数据
// */
// data: {
// userInfo: {},
// isFocus: false,
// notifyTxt: '直播间内严禁出现违法违规、低俗、涉黄、吸烟酗酒等内容,直播期间请勿相信私下交易,诱导购买等信息,以防人身或财产损失。请大家注意财产安全,谨防网络诈骗,文明观看直播。',
// messageContent: '',
// messageList: []
// },
// lifetimes: {
// created() {
// this.getInfo().then(() => {
// this.getUserSig()
// })
// wx.$eventbus.on('updateImNick', () => {
// this.updateProfile()
// })
// },
// },
// /**
// * 组件的方法列表
// */
// methods: {
// // fixInputBeCovered({ target }) {
// // setTimeout(function () {
// // target.scrollIntoView(true)
// // }, 100)
// // },
// // handleInputFocus() {
// // clearTimeout(this.timer)
// // this.timer = setTimeout(() => {
// // this.isFocus = !this.isFocus
// // }, 300)
// // },
// imOnShow() {
// this.getUserSig()
// },
// getInfo() {
// return new Promise(async resolve => {
// let { openId } = await USERAPI.getWXUserInfo()
// const { nickName } = wx.$storage.get('user_profile') || wx.$storage.get('srcm_shopmall_user_info') || {}
// this.setData({
// userInfo: { openId: openId, nickName: nickName }
// })
// resolve()
// })
// },
// h5Login() {
// this.triggerEvent('h5Login')
// },
// destroyIm() {
// if (timObj) {
// timObj.destroy().then(() => {
// timObj = null
// })
// }
// },
// async getUserSig() {
// if(timObj) {
// return true
// }
// let merchantId = wx.$storage.get('srcm_shopmall_merchant_id') || '',
// systemInfo = wx.$storage.get('system_info')
// this.setData({
// systemInfo
// })
// // sourceShopId-来源门店;visitSource-访问来源;bizType-业务类型(0-众筹);bizCode-业务标识(众筹-活动ID)
// let params = {
// userId: this.data.userInfo.openId,
// sourceShopId: merchantId || '',
// visitSource: '小程序-众筹',
// bizType: 0,
// bizCode: this.data.detail.id
// }
// shopmallApi.getLiveSig(params).then(res => {
// let { data } = res
// this.userSig = data.userSig
// this.setData({
// userSig: data.userSig
// })
// this.initTim()
// })
// },
// initTim() {
// const _this = this
// const imOptions = {
// userID: this.data.userInfo.openId,
// userSig: this.data.userSig,
// groupID: this.data.liveDetail.imGroupId,
// SDKAppID: this.data.liveDetail.imSdkAppId,
// onMessageReceived: data => this.onMessageReceived(this, data),
// onNetStateChange: this.onNetStateChange
// }
// timObj = new IM(imOptions)
// timObj.join(imOptions).then(res => {
// _this.updateProfile()
// })
// },
// updateProfile() {
// if(!this.data.userInfo?.nickName) {
// const { nickName } = wx.$storage.get('user_profile') || wx.$storage.get('srcm_shopmall_user_info') || {}
// this.setData({
// ['userInfo.nickName']: nickName
// })
// }
// timObj && timObj.updateMyProfile({ nick: this.data.userInfo.nickName || ('游客' + this.data.userInfo.openId.slice(-3)) })
// },
// // 收到消息触发
// onMessageReceived(_this, data) {
// // console.log('收到消息:', data)
// let msgLen = _this.data.messageList.length
// let dataLen = data.length
// if (msgLen + dataLen > msgMaxNum) {
// _this.setData({
// messageList: _this.data.messageList.slice(msgLen - dataLen)
// })
// }
// data.forEach(item => {
// // 根据消息类型判断,执行不同操作
// if (item.type == 'TIMTextElem') {
// // 群成员发送消息
// // let eleData = JSON.parse()
// let eleData = {
// userName: item.nick,
// content: item.payload.text
// }
// // 获取群聊消息,消息上屏
// _this.updateMessageList(eleData, _this)
// }
// })
// },
// // 网络异常处理
// onNetStateChange(notify) {
// // wx.$api.showToast(notify)
// },
// // 更新数据push进消息列表
// updateMessageList(data) {
// const list = [...this.data.messageList, data]
// this.setData({
// messageList: list
// }, () => {
// this.scrollToBottom()
// })
// },
// // changeChatHeight(height = '230px') {
// // var chatBoxDom = this.$el.querySelector('.chatBox-middle')
// // chatBoxDom.style.height = height
// // this.scrollToBottom()
// // },
// // handleFocus() {
// // this.changeChatHeight('116px')
// // },
// //发送聊天
// sendTextMessage(e) {
// clearTimeout(this.time)
// this.time = setTimeout(() => {
// //里面写你的操作
// let { value } = e.detail
// if (value === '' || value.trim().length === 0) {
// return
// }
// timObj.send(value)
// this.setData({
// messageContent: ''
// })
// }, 200)
// },
// scrollToBottom() {
// this.setData({
// toView: `item${this.data.messageList.length - 1}`
// })
// }
// }
// })