header-notice.vue 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  1. <!-- 顶栏消息通知 -->
  2. <template>
  3. <el-popover
  4. :width="430"
  5. trigger="click"
  6. v-model="visible"
  7. class="ele-notice-group"
  8. transition="el-zoom-in-top"
  9. popper-class="ele-notice-pop"
  10. @show="query"
  11. >
  12. <template v-slot:reference>
  13. <div class="ele-notice-group">
  14. <el-badge :value="unreadNum" :hidden="!unreadNum">
  15. <i class="el-icon-bell"></i>
  16. </el-badge>
  17. </div>
  18. </template>
  19. <div class="ele-notice-list ele-scrollbar-mini">
  20. <div v-for="(item, index) in notice" :key="index" class="ele-notice-item">
  21. <div class="ele-cell ele-notice-item-wrapper">
  22. <i :class="['el-icon-chat-dot-square', 'ele-notice-item-icon']"></i>
  23. <div class="ele-cell-content">
  24. <div class="ele-elip">{{ item.templateContent }}</div>
  25. <div
  26. style="
  27. display: flex;
  28. justify-content: space-between;
  29. align-items: center;
  30. "
  31. >
  32. <div class="ele-text-secondary ele-elip"
  33. >{{ item.createTime }}
  34. </div>
  35. <div
  36. class="el-icon-view"
  37. @click="clearNotice(item, index)"
  38. title="已读"
  39. ></div>
  40. </div>
  41. </div>
  42. </div>
  43. <el-divider />
  44. </div>
  45. </div>
  46. <div v-if="notice.length" class="ele-cell ele-notice-actions">
  47. <div class="ele-cell-content" @click="clearNotice">清空通知</div>
  48. <el-divider direction="vertical" class="line-color-light" />
  49. <router-link to="/page-wt/message" class="ele-cell-content">
  50. 查看更多
  51. </router-link>
  52. </div>
  53. <ele-empty v-if="!notice.length" text="已查看所有通知" />
  54. <!-- <el-tabs v-model="active" type="card">-->
  55. <!-- <el-tab-pane name="notice" :label="noticeTitle">-->
  56. <!-- -->
  57. <!-- </el-tab-pane>-->
  58. <!-- <el-tab-pane name="letter" :label="letterTitle">-->
  59. <!-- <div class="ele-notice-list ele-scrollbar-mini">-->
  60. <!-- <div-->
  61. <!-- v-for="(item, index) in letter"-->
  62. <!-- :key="index"-->
  63. <!-- class="ele-notice-item"-->
  64. <!-- >-->
  65. <!-- <div class="ele-cell ele-notice-item-wrapper ele-cell-align-top">-->
  66. <!-- <el-avatar :src="item.avatar" size="medium" />-->
  67. <!-- <div class="ele-cell-content">-->
  68. <!-- <div class="ele-elip">{{ item.title }}</div>-->
  69. <!-- <div class="ele-text-secondary ele-elip">-->
  70. <!-- {{ item.content }}-->
  71. <!-- </div>-->
  72. <!-- <div class="ele-cell-desc ele-elip">{{ item.time }}</div>-->
  73. <!-- </div>-->
  74. <!-- </div>-->
  75. <!-- <el-divider />-->
  76. <!-- </div>-->
  77. <!-- </div>-->
  78. <!-- <div v-if="letter.length" class="ele-cell ele-notice-actions">-->
  79. <!-- <div class="ele-cell-content" @click="clearLetter">清空私信</div>-->
  80. <!-- <el-divider direction="vertical" class="line-color-light" />-->
  81. <!-- <router-link to="/user/message?type=letter" class="ele-cell-content">-->
  82. <!-- 查看更多-->
  83. <!-- </router-link>-->
  84. <!-- </div>-->
  85. <!-- <ele-empty v-if="!letter.length" text="已读完所有私信" />-->
  86. <!-- </el-tab-pane>-->
  87. <!-- <el-tab-pane :label="todoTitle" name="todo">-->
  88. <!-- <div class="ele-notice-list ele-scrollbar-mini">-->
  89. <!-- <div-->
  90. <!-- v-for="(item, index) in todo"-->
  91. <!-- :key="index"-->
  92. <!-- class="ele-notice-item"-->
  93. <!-- >-->
  94. <!-- <div class="ele-notice-item-wrapper">-->
  95. <!-- <div class="ele-cell ele-cell-align-top">-->
  96. <!-- <div class="ele-cell-content ele-elip">{{ item.title }}</div>-->
  97. <!-- <el-tag size="mini" :type="['info', 'danger', ''][item.status]">-->
  98. <!-- {{ ['未开始', '即将到期', '进行中'][item.status] }}-->
  99. <!-- </el-tag>-->
  100. <!-- </div>-->
  101. <!-- <div class="ele-text-secondary ele-elip">-->
  102. <!-- {{ item.description }}-->
  103. <!-- </div>-->
  104. <!-- </div>-->
  105. <!-- <el-divider />-->
  106. <!-- </div>-->
  107. <!-- </div>-->
  108. <!-- <div v-if="todo.length" class="ele-cell ele-notice-actions">-->
  109. <!-- <div class="ele-cell-content" @click="clearTodo">清空待办</div>-->
  110. <!-- <el-divider direction="vertical" class="line-color-light" />-->
  111. <!-- <router-link to="/user/message?type=todo" class="ele-cell-content">-->
  112. <!-- 查看更多-->
  113. <!-- </router-link>-->
  114. <!-- </div>-->
  115. <!-- <ele-empty v-if="!todo.length" text="已完成所有任务" />-->
  116. <!-- </el-tab-pane>-->
  117. <!-- </el-tabs>-->
  118. </el-popover>
  119. </template>
  120. <script>
  121. import {
  122. getUnreadNotice,
  123. updateAllNotifyMessageReadAPI,
  124. updateNotifyMessageReadByIdAPI
  125. } from '@/api/layout';
  126. import { getToken } from '@/utils/token-util';
  127. export default {
  128. data() {
  129. return {
  130. // 是否显示
  131. visible: false,
  132. // 选项卡选中
  133. active: 'notice',
  134. // 通知数据
  135. notice: [],
  136. noticeCount: 0,
  137. timer: null,
  138. // 私信数据
  139. letter: [],
  140. // 待办数据
  141. todo: []
  142. };
  143. },
  144. computed: {
  145. // 通知标题
  146. noticeTitle() {
  147. return '通知' + (this.noticeCount > 0 ? `(${this.noticeCount})` : '');
  148. },
  149. // // 私信标题
  150. // letterTitle() {
  151. // return '私信' + (this.letter.length ? `(${this.letter.length})` : '');
  152. // },
  153. // // 待办标题
  154. // todoTitle() {
  155. // return '待办' + (this.todo.length ? `(${this.todo.length})` : '');
  156. // },
  157. // 未读数量
  158. unreadNum() {
  159. return this.noticeCount;
  160. }
  161. },
  162. created() {
  163. if (getToken()) {
  164. let url = 'ws://'+window.location.host+'/websocket/UnreadNotifyMessageCount?token='+getToken()
  165. let socket = new WebSocket(url);
  166. socket.onmessage = (event) => {
  167. console.log(event.data)
  168. this.noticeCount = event.data * 1 || 0;
  169. };
  170. }
  171. },
  172. methods: {
  173. /* 查询数据 */
  174. async query() {
  175. this.notice = await getUnreadNotice();
  176. this.notice = this.notice.slice(0, 15);
  177. },
  178. /* 清空通知 */
  179. async clearNotice(item = {}, index) {
  180. if (item.id) {
  181. await updateNotifyMessageReadByIdAPI([item.id]);
  182. this.notice.splice(index, 1);
  183. this.noticeCount = this.noticeCount - 1;
  184. } else {
  185. await updateAllNotifyMessageReadAPI();
  186. this.notice = [];
  187. this.noticeCount = 0;
  188. }
  189. },
  190. /* 清空通知 */
  191. clearLetter() {
  192. this.letter = [];
  193. },
  194. /* 清空通知 */
  195. clearTodo() {
  196. this.todo = [];
  197. }
  198. }
  199. };
  200. </script>
  201. <style lang="scss">
  202. .ele-notice-group {
  203. display: block;
  204. .el-badge {
  205. line-height: 1;
  206. display: block;
  207. }
  208. }
  209. /* 消息通知pop */
  210. .ele-notice-pop {
  211. padding: 0 !important;
  212. /* tab */
  213. .el-tabs__nav-scroll {
  214. text-align: center;
  215. }
  216. .el-tabs__nav {
  217. float: none;
  218. display: inline-block;
  219. }
  220. .el-tabs__item {
  221. height: 44px;
  222. line-height: 44px;
  223. padding: 0 20px !important;
  224. }
  225. /* 空视图 */
  226. .ele-empty {
  227. padding: 100px 0;
  228. }
  229. }
  230. /* 列表 */
  231. .ele-notice-list {
  232. padding-top: 8px;
  233. max-height: 360px;
  234. overflow: auto;
  235. }
  236. .ele-notice-item {
  237. .ele-notice-item-wrapper {
  238. padding: 12px 15px;
  239. transition: background-color 0.2s;
  240. cursor: pointer;
  241. &:hover {
  242. background-color: hsla(0, 0%, 60%, 0.05);
  243. }
  244. }
  245. .ele-text-secondary {
  246. margin-top: 5px;
  247. font-size: 13px;
  248. }
  249. .ele-cell-desc {
  250. margin-top: 3px !important;
  251. font-size: 12px !important;
  252. }
  253. }
  254. .ele-notice-item-icon {
  255. width: 32px;
  256. height: 32px;
  257. line-height: 32px !important;
  258. color: #fff;
  259. font-size: 16px;
  260. background-color: #60b2fc;
  261. border-radius: 50%;
  262. text-align: center;
  263. &.el-icon-s-check {
  264. background-color: #f5686f;
  265. }
  266. &.el-icon-video-camera {
  267. background-color: #7cd734;
  268. }
  269. &.el-icon-s-claim {
  270. background-color: #faad14;
  271. }
  272. &.el-icon-message-solid {
  273. background-color: #2bcacd;
  274. }
  275. }
  276. /* 操作按钮 */
  277. .ele-notice-actions > .ele-cell-content {
  278. line-height: 42px;
  279. text-align: center;
  280. cursor: pointer;
  281. color: inherit;
  282. &:hover {
  283. background-color: hsla(0, 0%, 60%, 0.05);
  284. }
  285. }
  286. .ele-elip {
  287. display: -webkit-box;
  288. -webkit-box-orient: vertical;
  289. -webkit-line-clamp: 3;
  290. overflow: hidden;
  291. text-overflow: ellipsis;
  292. white-space: normal !important;
  293. }
  294. </style>