message.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391
  1. <template>
  2. <view class="page-message" @click="showMore = false">
  3. <!-- topbar -->
  4. <cl-sticky is-topbar v-if="false">
  5. <cl-topbar :title="null" :show-back="false" :border="false">
  6. <view class="content">
  7. 消息
  8. </view>
  9. <image v-if="false" src="../../static/icon/service.png" @click="navigateToService"></image>
  10. </cl-topbar>
  11. </cl-sticky>
  12. <view class="header">
  13. <view class="left">
  14. <image class="img" mode="widthFix" src="../../static/sms/sms_name.png"></image>
  15. </view>
  16. <view class="right" @tap.stop="showMore = true">
  17. <image class="img" mode="widthFix" src="../../static/sms/more.png"></image>
  18. </view>
  19. </view>
  20. <view class="pop_more" v-if="showMore">
  21. <view class="item" @click="goPage('/pages/chat/newGroup?type=newGroup')">
  22. <image class="img" mode="widthFix" src="../../static/sms/new_group.png"></image>
  23. <text>创建群聊</text>
  24. </view>
  25. <view class="line"></view>
  26. <view class="item" @click="goPage('/pages/chat/newGroup?type=joinGroup')">
  27. <image class="img" mode="widthFix" src="../../static/sms/join_group.png"></image>
  28. <text>加入群聊</text>
  29. </view>
  30. </view>
  31. <view class="tab_list">
  32. <view class="item" :class="tab==0?'active':''" @click="goTab(0)">
  33. <view class="yuan">
  34. <image class="icon" mode="widthFix" src="../../static/sms/icon1.png"></image>
  35. </view>
  36. <text>私聊</text>
  37. </view>
  38. <view class="item" :class="tab==1?'active':''" @click="goTab(1)">
  39. <view class="yuan">
  40. <image class="icon" mode="widthFix" src="../../static/sms/icon2.png"></image>
  41. </view>
  42. <text>打赏交友</text>
  43. </view>
  44. <view class="item" :class="tab==2?'active':''" @click="goTab(2)">
  45. <view class="yuan">
  46. <image class="icon" mode="widthFix" src="../../static/sms/icon3.png"></image>
  47. </view>
  48. <text>互动</text>
  49. </view>
  50. <view class="item" :class="tab==3?'active':''" @click="goTab(3)">
  51. <view class="yuan">
  52. <image class="icon" mode="widthFix" src="../../static/sms/icon4.png"></image>
  53. </view>
  54. <text>系统通知</text>
  55. </view>
  56. </view>
  57. <view class="no-content" v-if="hasNo">
  58. <image class="icon" mode="widthFix" src="../../static/home/no.png"></image>
  59. <text>还没有消息</text>
  60. </view>
  61. <block v-if="tab == 0">
  62. <view class="list">
  63. <view v-for="(item, index) in list" :key="item.conversationID" class="list-content">
  64. <next-swipe-action :btnGroup="btnGroup" :index="item.conversationID" @btnClick="onclick"
  65. @nextSwipeActive="nextSwipeActive" :activeKey="activeKey">
  66. <view class="item" @tap="navigateToChatDetail(item)">
  67. <template v-if="item.type=='GROUP' || item.type=='C2C'">
  68. <!-- 头像 -->
  69. <view class="avatar">
  70. <template v-if="item.type=='GROUP'">
  71. <!-- <view class="avatorImg">{{item.groupProfile.ava_name}}</view> -->
  72. <image lazy-load="true" :src="item.groupProfile.avator" mode="aspectFill" />
  73. </template>
  74. <template v-else>
  75. <view v-if="false" class="avatorImg2">{{item.userProfile.ava_name}}</view>
  76. <image lazy-load="true" :src="item.userProfile.avator" mode="aspectFill" />
  77. </template>
  78. <view class="number" v-if="item.unreadCount!=0">{{ item.unreadCount }}</view>
  79. </view>
  80. <view class="content">
  81. <view class="info">
  82. <template v-if="item.type=='GROUP'">
  83. <text class="name">{{ item.groupProfile.name }}</text>
  84. </template>
  85. <template v-else>
  86. <text class="name">{{ item.userProfile.nick }}</text>
  87. </template>
  88. <text class="last">{{ item.lastMessage.messageForShow }}</text>
  89. </view>
  90. <text class="time">
  91. {{ item.lastMessage.lastTimeFormat }}
  92. </text>
  93. </view>
  94. </template>
  95. </view>
  96. </next-swipe-action>
  97. </view>
  98. </view>
  99. <view style="height:100rpx;"></view>
  100. </block>
  101. <block v-if="tab == 3">
  102. <view class="listSys">
  103. <block v-for="(item, index) in sysmsg_list" :key="index">
  104. <view class="item">
  105. <view class="img">
  106. <view class="bg">
  107. <image class="icon" mode="widthFix" src="../../static/icon/icon_msg.png"></image>
  108. </view>
  109. </view>
  110. <view class="content">
  111. <view class="title">
  112. {{item.content}}
  113. </view>
  114. <text class="time">
  115. {{item.create_time}}
  116. </text>
  117. </view>
  118. </view>
  119. </block>
  120. </view>
  121. </block>
  122. <!-- <view class="kongbai" v-if="list.length == 0">
  123. <image src="../../static/images/kongbai.png" mode="widthFix"></image>
  124. <view>还没有消息哦</view>
  125. <view>赶紧去找人聊聊天吧~</view>
  126. </view> -->
  127. <uni-popup ref="popupDel" type="center">
  128. <view class="PopMain" @click="deletes()">
  129. 删除会话
  130. </view>
  131. </uni-popup>
  132. <delete-conversation ref="deleteConversation"></delete-conversation>
  133. </view>
  134. </template>
  135. <script>
  136. import deleteConversation from "./components/delete-conversation.vue"
  137. import wsRequest from '../../common/websocketUtil.js'
  138. export default {
  139. components: {
  140. deleteConversation
  141. },
  142. data() {
  143. return {
  144. skey: '',
  145. tab: 0,
  146. tabsActive: "match",
  147. tabs: [{
  148. label: "聊天",
  149. name: "match",
  150. }],
  151. can_load_more: true,
  152. offset: 0,
  153. page: 1,
  154. limit: 20,
  155. list: [],
  156. hasNo: true,
  157. showMore: false,
  158. sysmsg_list: [],
  159. conversationID: '',
  160. activeKey: '',
  161. btnGroup: [{
  162. name: '删除',
  163. action: 'del',
  164. style: {
  165. bgColor: '#ff4d4f'
  166. }
  167. }]
  168. };
  169. },
  170. onLoad(params) {
  171. this.skey = params.skey || getApp().globalData.skey;
  172. getApp().globalData.skey = this.skey;
  173. let __this = this;
  174. uni.$on('conversationUpdate', function(data) {
  175. __this.loadData();
  176. });
  177. },
  178. onShow() {
  179. // this.TIM.getConversationList();
  180. // console.log("sdf")
  181. if (getApp().globalData.isLogin == 0) {
  182. getApp().globalData.socket.send({
  183. cmd: "login",
  184. data: {
  185. "uuid": getApp().globalData.uuid,
  186. "appId": 101
  187. }
  188. });
  189. }
  190. if (getApp().globalData.socket != null) {
  191. getApp().globalData.socket.restart();
  192. }
  193. this.loadData();
  194. this.loadSystemMsg();
  195. },
  196. methods: {
  197. nextSwipeActive(activeKey) {
  198. console.log(activeKey, 'activeKeyactiveKey');
  199. this.activeKey = activeKey
  200. },
  201. onclick(e) {
  202. // this.deletec(e.index)
  203. // console.log('所点击的列表索引:', e.index)
  204. // console.log('所点击的按钮数据:', e.item)
  205. // console.log("this.activeKey", this.activeKey)
  206. uni.request({
  207. url: this.$apiHost2 + '/Chat/sessDel', //仅为示例,并非真实接口地址。
  208. data: {
  209. uuid: getApp().globalData.uuid,
  210. sessID: e.index
  211. },
  212. header: {
  213. 'content-type': 'application/json' //自定义请求头信息
  214. },
  215. success: (res) => {
  216. // console.log("----", res.data.list);
  217. if (res.data.success == 'yes') {
  218. this.page = 1;
  219. this.loadData();
  220. }
  221. }
  222. });
  223. },
  224. deletec(conversationID) {
  225. this.conversationID = conversationID;
  226. console.log("conversationID", conversationID);
  227. this.$refs.popupDel.open();
  228. },
  229. deletes() {
  230. },
  231. goTab(tabb) {
  232. this.tab = tabb;
  233. this.hasNo = true;
  234. if (tabb == 0) {
  235. if (this.list.length > 0) {
  236. // this.is_no_data = 0;
  237. this.hasNo = false;
  238. }
  239. } else if (tabb == 3) {
  240. if (this.sysmsg_list.length > 0) {
  241. // this.is_no_data = 0;
  242. this.hasNo = false;
  243. }
  244. }
  245. },
  246. goPage(page) {
  247. uni.navigateTo({
  248. url: page
  249. })
  250. },
  251. loadSystemMsg() {
  252. uni.request({
  253. url: this.$apiHost + '/Plat/getSysmsg', //仅为示例,并非真实接口地址。
  254. data: {
  255. uuid: getApp().globalData.uuid
  256. },
  257. header: {
  258. 'content-type': 'application/json' //自定义请求头信息
  259. },
  260. success: (res) => {
  261. console.log("msg", res.data)
  262. if (res.data.list == undefined || res.data.list == null) {
  263. res.data.list = []
  264. }
  265. this.sysmsg_list = res.data.list;
  266. }
  267. });
  268. },
  269. loadData() {
  270. console.log("thiskey", this.skey);
  271. var offset = (this.page - 1) * 20;
  272. uni.request({
  273. url: this.$apiHost2 + '/Chat/sessionList', //仅为示例,并非真实接口地址。
  274. data: {
  275. uuid: getApp().globalData.uuid,
  276. offset: offset
  277. },
  278. header: {
  279. 'content-type': 'application/json' //自定义请求头信息
  280. },
  281. success: (res) => {
  282. console.log("----", res.data.list);
  283. if (res.data.list == undefined || res.data.list == null) {
  284. res.data.list = []
  285. }
  286. if (res.data.list.length > 0) {
  287. // this.is_no_data = 0;
  288. this.hasNo = false;
  289. }
  290. if (this.page > 1) {
  291. this.list = this.list.concat(res.data.list)
  292. } else {
  293. this.list = res.data.list;
  294. }
  295. }
  296. });
  297. },
  298. setList() {
  299. // this.list = this.TIM.conversations;
  300. this.list = [{
  301. conversationID: 1,
  302. type: 'GROUP',
  303. unreadCount: 0,
  304. groupProfile: {
  305. name: '官方群',
  306. avatar: 'https://cool-comm.oss-cn-shenzhen.aliyuncs.com/show/imgs/chat/avatar/5.jpg'
  307. },
  308. lastMessage: {
  309. messageForShow: '最后一条消息记录',
  310. lastTimeFormat: '2024-09-20 12:30:30'
  311. }
  312. }]
  313. console.log(this.list)
  314. },
  315. activeTabs(item) {
  316. this.tabsActive = item.name;
  317. },
  318. navigateToChatDetail(item) {
  319. var jsonConversationID = encodeURIComponent(JSON.stringify(item.conversationID));
  320. var jsonConversationType = encodeURIComponent(JSON.stringify(item.type));
  321. if (item.type == "GROUP") {
  322. var jsonUserID = encodeURIComponent(JSON.stringify(item.groupProfile.groupID));
  323. var jsonNickName = encodeURIComponent(JSON.stringify(item.groupProfile.name));
  324. } else {
  325. var jsonUserID = encodeURIComponent(JSON.stringify(item.userProfile.userID));
  326. var jsonNickName = encodeURIComponent(JSON.stringify(item.userProfile.nick));
  327. }
  328. uni.navigateTo({
  329. url: "/pages/chat/detail?userID=" + jsonUserID + "&nickName=" + jsonNickName +
  330. "&conversationID=" + jsonConversationID + "&conversationType=" + jsonConversationType
  331. })
  332. },
  333. navigateToService() {
  334. let jsonUserID = encodeURIComponent(JSON.stringify("51"));
  335. let jsonNickName = encodeURIComponent(JSON.stringify("cp交友官方客服"));
  336. let jsonConversationID = encodeURIComponent(JSON.stringify("C2C51"));
  337. let jsonConversationType = encodeURIComponent(JSON.stringify("C2C"));
  338. uni.navigateTo({
  339. url: "/pages/chat/detail?userID=" + jsonUserID + "&nickName=" + jsonNickName +
  340. "&conversationID=" + jsonConversationID + "&conversationType=" + jsonConversationType
  341. })
  342. },
  343. async getUserInfoByIdNum(idNums) {
  344. let [err, res] = await this.$http.get('user/getByIdNums', {
  345. id_nums: idNums
  346. });
  347. if (!this.$http.errorCheck(err, res)) {
  348. return;
  349. }
  350. },
  351. },
  352. //滚动到底部
  353. onReachBottom() {
  354. if (this.list.length > 0) {
  355. this.page++;
  356. this.loadData()
  357. }
  358. },
  359. //下拉刷新
  360. onPullDownRefresh() {
  361. this.list = []
  362. this.page = 1
  363. // console.log(this.lx)
  364. this.loadData()
  365. // setTimeout(() => {
  366. // uni.stopPullDownRefresh()
  367. // },1000)
  368. },
  369. };
  370. </script>
  371. <style lang="scss" scoped>
  372. @import 'message.scss';
  373. </style>