阅行客电子档案
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

318 lines
9.3 KiB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
  1. <template>
  2. <div class="navbar">
  3. <logo v-if="showLogo" :collapse="isCollapse" />
  4. <div class="right-menu">
  5. <!-- 主题切换 -->
  6. <div class="themeBox" style="font-size:12px; margin-right:20px; cursor: pointer;">
  7. <span @click="changetheme('dark')">深色主题</span>
  8. <span @click="changetheme('light')">浅色主题</span>
  9. </div>
  10. <div style="font-size: 18px; color: #1C1C1C; margin-right: 30px; cursor: pointer;" class="iconfont icon-jieyueche-ding" />
  11. <!-- 消息中心 -->
  12. <el-dropdown ref="messageDrop" class="message-center right-menu-item hover-effect" trigger="click">
  13. <div class="message-icon">
  14. <span class="iconfont icon-xiaoxi" />
  15. <i v-if="msgList.length > 0" class="message-num">{{ msgList.length }}</i>
  16. </div>
  17. <el-dropdown-menu slot="dropdown" class="message-dropdown" style="width: 420px;">
  18. <div style="display: flex; justify-content: flex-end; padding: 0 20px; height: 40px; line-height: 40px; color: #339CFF; font-size: 14px; border-bottom: 1px solid #339CFF;">
  19. <span style="cursor: pointer;" @click="handleAllRead">全部标记为已读</span>
  20. <!-- 消息中心router -->
  21. <span style="color:#fff; margin-left: 10px; cursor: pointer;" @click="toAllMessage">去查看</span>
  22. </div>
  23. <div style="max-height: 450px; overflow: hidden; overflow-y: scroll;">
  24. <el-dropdown-item v-if="msgList.length===0" class="message-list-item">
  25. <div style="text-align:center">暂无最新消息</div>
  26. </el-dropdown-item>
  27. <el-dropdown-item v-for="(item,index) in msgList" :key="index" class="message-list-item">
  28. <router-link :to="{ path: '/user/center', query: { activeIndex: 1 }}">
  29. <p>{{ item.noticeContent }}</p>
  30. <span>{{ item.create_time | parseTime }}</span>
  31. <i class="el-icon-arrow-right" />
  32. </router-link>
  33. </el-dropdown-item>
  34. </div>
  35. </el-dropdown-menu>
  36. </el-dropdown>
  37. <el-dropdown class="avatar-container right-menu-item hover-effect" trigger="click">
  38. <div class="avatar-wrapper">
  39. <div class="user-img-cover">
  40. <img :src="user.avatarName ? baseApi + '/avatar/' + user.avatarName : Avatar" class="user-avatar" :onerror="defaultImg">
  41. </div>
  42. <div class="user-name">{{ user.username }}</div>
  43. <i class="el-icon-caret-bottom" />
  44. </div>
  45. <el-dropdown-menu slot="dropdown">
  46. <router-link :to="{ path: '/user/center', query: { activeIndex: 0 }}">
  47. <el-dropdown-item>
  48. 个人中心
  49. </el-dropdown-item>
  50. </router-link>
  51. <router-link :to="{ path: '/user/center', query: { activeIndex: 1 }}">
  52. <el-dropdown-item>
  53. 我的消息
  54. </el-dropdown-item>
  55. </router-link>
  56. <span style="display:block;" @click="open">
  57. <el-dropdown-item>
  58. 退出登录
  59. </el-dropdown-item>
  60. </span>
  61. </el-dropdown-menu>
  62. </el-dropdown>
  63. </div>
  64. </div>
  65. </template>
  66. <script>
  67. import { mapGetters } from 'vuex'
  68. import Logo from '@/layout/components/Sidebar/Logo'
  69. // import Breadcrumb from '@/components/Breadcrumb'
  70. // import Hamburger from '@/components/Hamburger'
  71. // import Doc from '@/components/Doc'
  72. // import Screenfull from '@/components/Screenfull'
  73. // import SizeSelect from '@/components/SizeSelect'
  74. // import Search from '@/components/HeaderSearch'
  75. import Avatar from '@/assets/images/avatar.png'
  76. import { getUserNotice, isread } from '@/api/system/logs'
  77. export default {
  78. inject: ['reload'],
  79. components: {
  80. // Breadcrumb,
  81. // Hamburger,
  82. // Screenfull,
  83. // SizeSelect,
  84. // Search,
  85. // Doc,
  86. Logo
  87. },
  88. data() {
  89. return {
  90. Avatar: Avatar,
  91. defaultImg: 'this.src="' + require('@/assets/images/avatar.png') + '"',
  92. msgList: [],
  93. themeValue: localStorage.getItem('themeValue') ? localStorage.getItem('themeValue') : 'dark'
  94. }
  95. },
  96. computed: {
  97. ...mapGetters([
  98. 'sidebar',
  99. 'device',
  100. 'user',
  101. 'baseApi'
  102. ]),
  103. show: {
  104. get() {
  105. return this.$store.state.settings.showSettings
  106. },
  107. set(val) {
  108. this.$store.dispatch('settings/changeSetting', {
  109. key: 'showSettings',
  110. value: val
  111. })
  112. }
  113. },
  114. showLogo() {
  115. return this.$store.state.settings.sidebarLogo
  116. },
  117. isCollapse() {
  118. return !this.sidebar.opened
  119. }
  120. },
  121. created() {
  122. this.getMsgList()
  123. if (!localStorage.getItem('themeValue')) {
  124. this.changetheme('dark')
  125. }
  126. },
  127. methods: {
  128. // 获取未读消息
  129. async getMsgList() {
  130. const params = {
  131. page: 0,
  132. size: 10,
  133. sort: 'createTime,desc'
  134. }
  135. const list = []
  136. const allList = await this.getAllNoRead(params, list)
  137. allList.forEach(item => {
  138. item.pushUserName = item.noticeUsers[0].pushUserName
  139. item.isRead = item.noticeUsers[0].isRead
  140. })
  141. const arr = allList.filter(item => { return !item.isRead })
  142. if (arr.length > 20) {
  143. this.msgList = arr.slice(0, 20)
  144. } else {
  145. this.msgList = arr
  146. }
  147. },
  148. // 全部已读
  149. async handleAllRead() {
  150. const params = {
  151. page: 0,
  152. size: 10,
  153. sort: 'createTime,desc'
  154. }
  155. const list = []
  156. const ids = []
  157. const allList = await this.getAllNoRead(params, list)
  158. allList.forEach(item => {
  159. item.noticeUsers.forEach(i => {
  160. ids.push(i.id)
  161. })
  162. })
  163. isread(ids).then(res => {
  164. if (res) {
  165. this.msgList = []
  166. if (this.$route.path.includes('user/center') || this.$route.path.includes('system/notifyManage')) {
  167. this.reload()
  168. }
  169. }
  170. })
  171. },
  172. // 递归获取所有消息列表
  173. async getAllNoRead(params, list) {
  174. const allList = await getUserNotice(params).then(res => {
  175. list = list.concat(res.content)
  176. if ((list.length) < res.totalElements) {
  177. params.page++
  178. return this.getAllNoRead(params, list)
  179. } else {
  180. return list
  181. }
  182. })
  183. return allList
  184. },
  185. toggleSideBar() {
  186. this.$store.dispatch('app/toggleSideBar')
  187. },
  188. toAllMessage() {
  189. this.$router.push({ path: '/user/center', query: { activeIndex: 1 }})
  190. this.$refs.messageDrop.hide()
  191. },
  192. open() {
  193. this.$confirm('确定注销并退出系统吗?', '提示', {
  194. confirmButtonText: '确定',
  195. cancelButtonText: '取消',
  196. type: 'warning'
  197. }).then(() => {
  198. this.logout()
  199. })
  200. },
  201. logout() {
  202. this.$store.dispatch('LogOut').then(() => {
  203. location.reload()
  204. })
  205. },
  206. handleClose(done) {
  207. done()
  208. },
  209. changetheme(theme) {
  210. window.document.documentElement.setAttribute('data-theme', theme)
  211. localStorage.setItem('themeValue', theme)
  212. }
  213. }
  214. }
  215. </script>
  216. <style lang="scss" scoped>
  217. @import "~@/assets/styles/mixin.scss";
  218. @import "~@/assets/styles/variables.scss";
  219. .navbar {
  220. display: flex;
  221. justify-content: space-between;
  222. width: 100%;
  223. height: $headerHeight;
  224. overflow: hidden;
  225. position: relative;
  226. @include shadow-set;
  227. .errLog-container {
  228. display: inline-block;
  229. vertical-align: top;
  230. }
  231. .right-menu {
  232. display: flex;
  233. line-height: 64px;
  234. &:focus {
  235. outline: none;
  236. }
  237. .right-menu-item {
  238. display: inline-block;
  239. height: 100%;
  240. font-size: 18px;
  241. color: #5a5e66;
  242. vertical-align: text-bottom;
  243. &.hover-effect {
  244. cursor: pointer;
  245. transition: background .3s;
  246. &:hover {
  247. background: rgba(0, 0, 0, .025)
  248. }
  249. }
  250. }
  251. .message-center{
  252. margin-right: 40px;
  253. .message-icon{
  254. position: relative;
  255. .icon-xiaoxi{
  256. font-size: 20px;
  257. @include icon_color;
  258. }
  259. .message-num{
  260. position: absolute;
  261. top: 0;
  262. right: -8px;
  263. display: block;
  264. width: 20px;
  265. height: 20px;
  266. font-size: 14px;
  267. text-align: center;
  268. line-height: 20px;
  269. border-radius: 50%;
  270. background-color: #F91832;
  271. color: #fff;
  272. }
  273. }
  274. }
  275. .avatar-container {
  276. margin-right: 40px;
  277. .avatar-wrapper {
  278. display: flex;
  279. flex-direction: row;
  280. justify-content: space-between;
  281. align-items: center;
  282. @include icon_color;
  283. .user-img-cover{
  284. width: 24px;
  285. height: 24px;
  286. }
  287. .user-avatar {
  288. display: block;
  289. width: 100%;
  290. height: 100%;
  291. border-radius: 50%;
  292. // border: 1px solid red;
  293. cursor: pointer;
  294. }
  295. .user-name{
  296. margin: 0 37px 0 8px;
  297. flex: 1;
  298. font-size: 14px;
  299. }
  300. .el-icon-caret-bottom {
  301. cursor: pointer;
  302. font-size: 14px;
  303. }
  304. }
  305. }
  306. }
  307. }
  308. </style>