index.vue 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. <template>
  2. <view class="message-center-container">
  3. <JHeader title="消息中心" width="50" height="50" style="padding: 24upx 0 0;"></JHeader>
  4. <view v-if="messageList && messageList.length">
  5. <view class="flex-items flex-sp-between fs26 topTitBox">
  6. <view>
  7. 未读消息{{ $store.getters.userInfo.notRead }}条
  8. </view>
  9. <view v-if="$store.getters.userInfo.notRead != 0" class="allRead" @click="handleReadAllMessage">
  10. 全部已读
  11. </view>
  12. </view>
  13. <tui-swipe-action
  14. v-for="(item, index) in messageList" :key="item.footprintId"
  15. :params="{ index, noticeId: item.noticeId }" :open="item.show" :actions="options" :closable="false"
  16. class="swipe-list-item" @click="productClick"
  17. >
  18. <template #content>
  19. <view class="messageItem" @click="goToMesDetail(item.noticeId, item.only, item.jump)">
  20. <view class="messageBox">
  21. <view class="messageType">
  22. <view v-if="item.noticeType == 1" class="messageTypeL">
  23. <view class="iconBox">
  24. <tui-icon name="notice" :size="50" unit="upx" color="#ffffff"></tui-icon>
  25. <view v-if="item.ifRead === 0" class="redBox"></view>
  26. </view>
  27. <span>订单消息</span>
  28. </view>
  29. <view v-else class="messageTypeL">
  30. <view class="iconBox">
  31. <tui-icon name="notice" :size="50" unit="upx" color="#ffffff"></tui-icon>
  32. </view>
  33. <span>系统公告</span>
  34. </view>
  35. <view class="messageTypeR">{{ item.createTime }}</view>
  36. </view>
  37. <view>
  38. <rich-text class="messageInfo" :nodes="item.htmlData"></rich-text>
  39. </view>
  40. </view>
  41. </view>
  42. </template>
  43. </tui-swipe-action>
  44. </view>
  45. <view style="padding-bottom: 45upx;">
  46. <LoadingMore
  47. :status="!isEmpty && !messageList.length
  48. ? 'loading' : !isEmpty && messageList.length && (messageList.length >= messageTotal) ? 'no-more' : ''"
  49. >
  50. </LoadingMore>
  51. <tui-no-data v-if="isEmpty" :fixed="false" style="margin-top: 60upx;">暂无消息</tui-no-data>
  52. </view>
  53. </view>
  54. </template>
  55. <script>
  56. import { getAllNoticeMessageApi, deleteRemoveByIdNoticeApi, updateReadAllNoticeApi, updateReadNoticeApi } from '../../../api/anotherTFInterface'
  57. import parse from 'mini-html-parser2'
  58. export default {
  59. name: 'MessageCenter',
  60. data() {
  61. return {
  62. options: [ {
  63. name: '删除',
  64. color: '#fff',
  65. fontsize: 32,
  66. width: 80,
  67. background: '#F15C48'
  68. } ],
  69. isEmpty: false,
  70. messageList: [],
  71. messageTotal: 0,
  72. queryInfo: {
  73. page: 1,
  74. pageSize: 20
  75. }
  76. }
  77. },
  78. onShow() {
  79. this.queryInfo.page = 1
  80. this.getAllMessage()
  81. this.getUserInfo()
  82. },
  83. methods: {
  84. getUserInfo() {
  85. this.$store.dispatch('auth/refrshUserInfoAction')
  86. },
  87. formatRichText(html) {
  88. let newContent = html.replace(/<img[^>]*>/gi, function (match, capture) {
  89. match = match.replace(/style="[^"]+"/gi, '').replace(/style='[^']+'/gi, '')
  90. match = match.replace(/width="[^"]+"/gi, '').replace(/width='[^']+'/gi, '')
  91. match = match.replace(/height="[^"]+"/gi, '').replace(/height='[^']+'/gi, '')
  92. return match
  93. })
  94. newContent = newContent.replace(/style="[^"]+"/gi, function (match, capture) {
  95. match = match.replace(/width:[^;]+;/gi, 'max-width:100%;').replace(
  96. /width:[^;]+;/gi,
  97. 'max-width:100%;'
  98. )
  99. return match
  100. })
  101. newContent = newContent.replace(/<br[^>]*\/>/gi, '')
  102. newContent = newContent.replace(
  103. /\<img/gi,
  104. '<img style="max-width:100%;height:auto;display:block;margin-top:0;margin-bottom:0;"'
  105. )
  106. return newContent
  107. },
  108. getAllMessage(isLoadmore) {
  109. uni.showLoading()
  110. getAllNoticeMessageApi(this.queryInfo).then((res) => {
  111. this.messageTotal = res.data.total
  112. res.data.list = res.data.list.map((item) => {
  113. let newContent = item.noticeContent.replace(/<img[^>]*>/gi, function (match, capture) {
  114. match = match.replace(/style="[^"]+"/gi, '').replace(/style='[^']+'/gi, '')
  115. match = match.replace(/width="[^"]+"/gi, '').replace(/width='[^']+'/gi, '')
  116. match = match.replace(/height="[^"]+"/gi, '').replace(/height='[^']+'/gi, '')
  117. return match
  118. })
  119. newContent = newContent.replace(/style="[^"]+"/gi, function (match, capture) {
  120. match = match.replace(/width:[^;]+;/gi, 'max-width:100%;').replace(
  121. /width:[^;]+;/gi,
  122. 'max-width:100%;'
  123. )
  124. return match
  125. })
  126. newContent = newContent.replace(/<br[^>]*\/>/gi, '')
  127. newContent = newContent.replace(
  128. /\<img/gi,
  129. '<img style="max-width:100%;height:auto;display:block;margin-top:0;margin-bottom:0;"'
  130. )
  131. parse(newContent, (err, htmlData) => {
  132. item.htmlData = htmlData
  133. })
  134. return item
  135. })
  136. if (isLoadmore) {
  137. this.messageList.push(...res.data.list)
  138. } else {
  139. this.messageList = res.data.list
  140. }
  141. this.isEmpty = this.messageList.length === 0
  142. uni.hideLoading()
  143. })
  144. .catch((e) => {
  145. uni.hideLoading()
  146. })
  147. },
  148. // 删除消息
  149. productClick(e) {
  150. uni.showLoading()
  151. deleteRemoveByIdNoticeApi({
  152. noticeId: e.item.noticeId
  153. })
  154. .then((res) => {
  155. uni.hideLoading()
  156. this.queryInfo.page = 1
  157. this.getAllMessage()
  158. this.getUserInfo()
  159. })
  160. .catch((e) => {
  161. uni.hideLoading()
  162. })
  163. },
  164. handleReadAllMessage() {
  165. updateReadAllNoticeApi({}).then((res) => {
  166. uni.showToast({
  167. title: '全部已读',
  168. icon: 'none'
  169. })
  170. this.queryInfo.page = 1
  171. this.getAllMessage()
  172. this.getUserInfo()
  173. })
  174. },
  175. goToMesDetail(noticeId, only, jump) {
  176. updateReadNoticeApi({ noticeId })
  177. .then((res) => {
  178. if (jump == 2) {
  179. uni.navigateTo({
  180. url: `/another-tf/another-serve/orderDetails/index?orderId=${only}&noticeId=${noticeId}`
  181. })
  182. } else {
  183. uni.navigateTo({
  184. url: '/another-tf/another-serve/messageDetail/index?noticeId=' + noticeId
  185. })
  186. }
  187. })
  188. }
  189. },
  190. onReachBottom() {
  191. if (this.messageList.length < this.messageTotal) {
  192. ++this.queryInfo.page
  193. this.getAllMessage(true)
  194. }
  195. }
  196. }
  197. </script>
  198. <style lang="less" scoped>
  199. .message-center-container {
  200. min-height: 100vh;
  201. background: #ffffff;
  202. box-sizing: border-box;
  203. .topTitBox {
  204. height: 100rpx;
  205. padding: 0 20rpx;
  206. background: #f7f7f7;
  207. .allRead {
  208. width: 144rpx;
  209. height: 56rpx;
  210. line-height: 56rpx;
  211. text-align: center;
  212. color: #333333;
  213. background: #FFFFFF;
  214. }
  215. }
  216. .swipe-list-item {
  217. margin-bottom: 20upx !important;
  218. }
  219. .messageItem {
  220. width: 100%;
  221. background: #FFFFFF;
  222. border-bottom: 2rpx solid #F8F8F8;
  223. .messageBox {
  224. .messageType {
  225. padding: 30upx;
  226. display: flex;
  227. align-items: center;
  228. justify-content: space-between;
  229. .iconBox {
  230. border-radius: 50%;
  231. background: #C5AA7B;
  232. width: 60rpx;
  233. height: 60rpx;
  234. display: flex;
  235. align-items: center;
  236. justify-content: center;
  237. margin-right: 20upx;
  238. position: relative;
  239. .redBox {
  240. width: 20upx;
  241. height: 20upx;
  242. background-color: red;
  243. border-radius: 50%;
  244. position: absolute;
  245. right: 0upx;
  246. top: 0upx;
  247. }
  248. }
  249. .messageTypeL {
  250. display: flex;
  251. align-items: center;
  252. span {
  253. font-size: 32upx;
  254. color: #333333;
  255. }
  256. }
  257. .messageTypeR {
  258. color: #CCCCCC;
  259. font-size: 24upx;
  260. }
  261. }
  262. .messageInfo {
  263. width: 670upx;
  264. display: block;
  265. overflow: hidden;
  266. text-overflow: ellipsis;
  267. white-space: nowrap;
  268. margin: 20upx 40upx 20upx;
  269. img {
  270. width: 100%;
  271. margin-bottom: 25upx;
  272. }
  273. p {
  274. padding: 0 40upx;
  275. color: #999999;
  276. font-size: 28upx;
  277. }
  278. }
  279. }
  280. }
  281. }
  282. </style>