message.vue 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  1. <template>
  2. <view class="message-v">
  3. <view class="search-box_sticky">
  4. <view class="reply-item u-border-bottom u-flex " @click="openPage('/pages/message/message/index?type=')">
  5. <view class="reply-item-img-sysMsg reply-item-icon u-flex u-row-center reply-item-icon-color2">
  6. <text class="icon-ym icon-ym-xitong" />
  7. </view>
  8. <view class="reply-item-txt u-flex-1">
  9. <view class="reply-item-cell reply-item-title u-flex u-row-between">
  10. <text class="title">站内消息</text>
  11. <text
  12. class="u-font-24">{{msgInfo.messageDate?$u.timeFormat(msgInfo.messageDate, 'mm-dd hh:MM'):''}}</text>
  13. </view>
  14. <view class="reply-item-cell u-flex u-row-between">
  15. <text class="reply-item-txt-msg u-line-1 againColor">{{msgInfo.messageText}}</text>
  16. <u-badge type="error" :count="msgInfo.messageCount" :absolute="false"
  17. v-if="msgInfo.messageCount" />
  18. </view>
  19. </view>
  20. </view>
  21. <view class="reply-item u-border-bottom u-flex " @click="openPage('/pages/message/contacts/index')">
  22. <view class="reply-item-img-sysMsg reply-item-icon u-flex u-row-center reply-item-icon-color">
  23. <text class="icon-ym icon-ym-contacts" />
  24. </view>
  25. <view class="reply-item-txt u-flex-1">
  26. <view class="reply-item-cell reply-item-title u-flex u-row-between" style="margin: 0;">
  27. <text class="title">通讯录</text>
  28. </view>
  29. </view>
  30. </view>
  31. </view>
  32. <mescroll-body ref="mescrollRef" @init="mescrollInit" @down="downCallback" :sticky="false" :up="upOption"
  33. :bottombar="false">
  34. <!-- #ifndef APP-HARMONY -->
  35. <view class="message-list">
  36. <view class="message-list-box">
  37. <uni-swipe-action ref="swipeAction">
  38. <uni-swipe-action-item v-for="(item, index) in list" :key="item.id" :right-options="options"
  39. @click="handleRelocation(item.id)">
  40. <view class="reply-item u-border-bottom u-flex" @click="toIm(item)" :id="'item'+index"
  41. ref="mydom">
  42. <view class="reply-item-img">
  43. <u-avatar :src="baseURL+item.headIcon" mode="square" size="96" />
  44. </view>
  45. <view class="reply-item-txt u-flex-1">
  46. <view class="reply-item-cell reply-item-title u-flex u-row-between">
  47. <text class="title">{{item.realName}}/{{item.account}}</text>
  48. <text class="u-font-24 againColor">{{jnpf.toDateText(item.latestDate)}}</text>
  49. </view>
  50. <view class="reply-item-cell u-flex u-row-between">
  51. <text
  52. class="reply-item-txt-msg u-line-1 againColor">{{getMsgText(item.latestMessage,item.messageType)}}</text>
  53. <u-badge type="error" :count="item.unreadMessage" :absolute="false" />
  54. </view>
  55. </view>
  56. </view>
  57. </uni-swipe-action-item>
  58. </uni-swipe-action>
  59. </view>
  60. </view>
  61. <!-- #endif -->
  62. <!-- #ifdef APP-HARMONY -->
  63. <view class="message-list">
  64. <view class="message-list-box" :key="key">
  65. <u-swipe-action v-show="swipeAction" v-for="(item, index) in list" :key="key" :options="options"
  66. @open="openAction" @click="handleRelocation(item.id)" :show="item.show" :index="index">
  67. <view class="reply-item u-border-bottom u-flex" @click="toIm(item)" :id="'item'+index"
  68. ref="mydom">
  69. <view class="reply-item-img">
  70. <u-avatar :src="baseURL+item.headIcon" mode="square" size="96" />
  71. </view>
  72. <view class="reply-item-txt u-flex-1">
  73. <view class="reply-item-cell reply-item-title u-flex u-row-between">
  74. <text class="title">{{item.realName}}/{{item.account}}</text>
  75. <text class="u-font-24 againColor">{{jnpf.toDateText(item.latestDate)}}</text>
  76. </view>
  77. <view class="reply-item-cell u-flex u-row-between">
  78. <text
  79. class="reply-item-txt-msg u-line-1 againColor">{{getMsgText(item.latestMessage,item.messageType)}}</text>
  80. <u-badge type="error" :count="item.unreadMessage" :absolute="false" />
  81. </view>
  82. </view>
  83. </view>
  84. </u-swipe-action>
  85. </view>
  86. </view>
  87. <!-- #endif -->
  88. </mescroll-body>
  89. </view>
  90. </template>
  91. <script>
  92. import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
  93. import IndexMixin from './mixin.js'
  94. import {
  95. useChatStore
  96. } from '@/store/modules/chat'
  97. import {
  98. getIMReply,
  99. relocation
  100. } from '@/api/message.js'
  101. export default {
  102. mixins: [MescrollMixin, IndexMixin],
  103. data() {
  104. return {
  105. key: +new Date(),
  106. keyword: '',
  107. list: [],
  108. options: [{
  109. text: '移除',
  110. style: {
  111. backgroundColor: '#dd524d'
  112. }
  113. }],
  114. upOption: {
  115. use: false
  116. },
  117. swipeAction: false
  118. }
  119. },
  120. watch: {
  121. badgeNum(val) {
  122. this.setTabBarBadge()
  123. },
  124. },
  125. computed: {
  126. msgInfo() {
  127. const chatStore = useChatStore()
  128. return chatStore.getMsgInfo
  129. },
  130. baseURL() {
  131. return this.define.baseURL
  132. },
  133. },
  134. onLoad() {
  135. uni.$on('updateList', data => {
  136. this.$nextTick(() => {
  137. this.mescroll.triggerDownScroll()
  138. })
  139. })
  140. uni.$on('updateMsgNum', id => {
  141. this.updateMsgNum(id)
  142. })
  143. },
  144. onUnload() {
  145. uni.$off('updateList')
  146. uni.$off('updateMsgNum')
  147. },
  148. methods: {
  149. openAction(index) {
  150. this.list[index].show = true;
  151. this.list.map((val, idx) => {
  152. if (index != idx) this.list[idx].show = false;
  153. });
  154. },
  155. handleRelocation(id) {
  156. relocation(id).then(res => {
  157. this.init()
  158. })
  159. },
  160. isJSON(str) {
  161. try {
  162. var obj = JSON.parse(str);
  163. if (typeof obj == 'object' && obj) {
  164. return true;
  165. } else {
  166. return false;
  167. }
  168. } catch (e) {
  169. return false;
  170. }
  171. },
  172. downCallback(page) {
  173. this.init()
  174. },
  175. init() {
  176. getIMReply().then(res => {
  177. this.mescroll.endSuccess(res.data.list.length, false);
  178. this.list = res.data.list || [];
  179. this.swipeAction = true
  180. uni.hideLoading()
  181. }).catch(() => {
  182. this.mescroll && this.mescroll.endErr();
  183. })
  184. },
  185. search() {
  186. return
  187. this.searchTimer && clearTimeout(this.searchTimer)
  188. this.searchTimer = setTimeout(() => {
  189. this.list = [];
  190. this.mescroll.resetUpScroll();
  191. }, 300)
  192. },
  193. updateMsgNum(id) {
  194. const chatStore = useChatStore()
  195. const len = this.list.length
  196. for (let i = 0; i < len; i++) {
  197. if (id === this.list[i].id) {
  198. const num = this.list[i].unreadMessage
  199. chatStore.reduceBadgeNum(num)
  200. this.list[i].unreadMessage = 0
  201. break
  202. }
  203. }
  204. },
  205. getMsgText(text, type) {
  206. if (!text) return ""
  207. let message = ''
  208. switch (type) {
  209. case 'voice':
  210. message = '[语音]'
  211. break;
  212. case 'image':
  213. message = '[图片]'
  214. break;
  215. default:
  216. message = text
  217. break;
  218. }
  219. return message
  220. },
  221. openPage(path) {
  222. if (!path) return
  223. uni.navigateTo({
  224. url: path
  225. })
  226. },
  227. toIm(item) {
  228. const chatStore = useChatStore()
  229. const name = item.realName + '/' + item.account
  230. if (item.unreadMessage) {
  231. chatStore.reduceBadgeNum(item.unreadMessage)
  232. item.unreadMessage = 0
  233. }
  234. uni.navigateTo({
  235. url: '/pages/message/im/index?name=' + name + '&formUserId=' + item.id + '&headIcon=' + item
  236. .headIcon
  237. })
  238. }
  239. }
  240. }
  241. </script>
  242. <style lang="scss">
  243. page {
  244. background-color: #f0f2f6;
  245. }
  246. .message-v {
  247. .search-box_sticky {
  248. margin-bottom: 20rpx;
  249. padding: 0 20rpx;
  250. }
  251. .replyList {
  252. padding: 0 20rpx;
  253. background-color: #fff;
  254. .againColor {
  255. color: #909399;
  256. }
  257. }
  258. .reply-item {
  259. height: 142rpx;
  260. background-color: #fff;
  261. padding: 0 20rpx;
  262. .reply-item-img-sysMsg {
  263. width: 96rpx;
  264. height: 96rpx;
  265. border-radius: 16rpx;
  266. overflow: hidden;
  267. margin-right: 16rpx;
  268. flex-shrink: 0;
  269. }
  270. .reply-item-img {
  271. width: 96rpx;
  272. height: 96rpx;
  273. border-radius: 50%;
  274. overflow: hidden;
  275. margin-right: 16rpx;
  276. flex-shrink: 0;
  277. }
  278. .reply-item-icon-color {
  279. background-color: #2bd34f;
  280. }
  281. .reply-item-icon-color2 {
  282. background-color: #3B87F7;
  283. }
  284. .reply-item-icon {
  285. .icon-ym {
  286. color: #fff;
  287. font-size: 50rpx;
  288. }
  289. }
  290. .reply-item-txt {
  291. .reply-item-cell {
  292. height: 40rpx;
  293. color: #C6C6C6;
  294. font-size: 24rpx;
  295. &.reply-item-title {
  296. height: 44rpx;
  297. margin-bottom: 4px;
  298. .title {
  299. font-size: 28rpx;
  300. color: #303133;
  301. }
  302. }
  303. .reply-item-txt-msg {
  304. width: 480rpx;
  305. }
  306. }
  307. }
  308. }
  309. }
  310. .search-box_sticky {
  311. padding: 0 32rpx;
  312. }
  313. .message-list .uni-swipe {
  314. margin-bottom: 0px !important;
  315. border-radius: 0px !important;
  316. }
  317. .message-list {
  318. .message-list-box {
  319. margin: 0px !important;
  320. ::v-deep .u-swipe-action {
  321. border-radius: 0;
  322. }
  323. }
  324. }
  325. </style>