index.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. <template>
  2. <el-container>
  3. <el-main>
  4. <div style="display: flex">
  5. <!-- 左边部分 -->
  6. <div class="left-pane">
  7. <div class="divider-line">
  8. <div class="divider-text">
  9. <div class="avatar-box__inner">
  10. <el-avatar :size="80" :src="userInfo.avatar" @error="errorHandler">
  11. <img :src="makeTextPortrait()" />
  12. </el-avatar>
  13. </div>
  14. </div>
  15. <div class="psninfo-box">
  16. {{ userInfo.name }}
  17. &nbsp;
  18. {{ userInfo.deptName }}
  19. &nbsp;
  20. <MyClock :show-logo="false" size="small" />
  21. </div>
  22. </div>
  23. </div>
  24. <!-- 右边部分 -->
  25. <div class="right-pane">
  26. <div class="check-more" @click="fetchMoreMessages">查看更多</div>
  27. <el-timeline v-for="item in messages" :key="item.id">
  28. <el-timeline-item :timestamp="item.simpledate" placement="top" icon="el-icon-warning" color="orange">
  29. <el-card>
  30. <div style="margin-bottom: 12px; font-size: 16px; font-weight: bold">{{ item.title }}</div>
  31. <div v-html="item.content"></div>
  32. </el-card>
  33. </el-timeline-item>
  34. </el-timeline>
  35. </div>
  36. </div>
  37. </el-main>
  38. </el-container>
  39. </template>
  40. <script>
  41. import { computed, onActivated, onMounted, ref, watch } from 'vue'
  42. import { useStore } from 'vuex'
  43. import { selectSystemMessages } from '../../api/messages/index'
  44. import { formatDate } from '../../utils/date'
  45. import { getUserInfo } from '@/api/settings/user-settings'
  46. import { genTextPortrait } from '@/utils/portrait'
  47. import MyClock from '@/components/MyClock.vue'
  48. export default {
  49. name: 'Dashboard',
  50. components: {
  51. MyClock,
  52. },
  53. setup() {
  54. const store = useStore()
  55. const token = computed(() => {
  56. return store.state.user.token
  57. })
  58. watch(
  59. () => token.value,
  60. () => {
  61. setTimeout(() => {
  62. location.reload()
  63. }, 100)
  64. }
  65. )
  66. const messages = ref([])
  67. const fetchMoreMessages = () => {
  68. let lastdate = 'latest'
  69. if (messages.value.length > 0) {
  70. lastdate = formatDate(messages.value[0].simpledate)
  71. }
  72. selectSystemMessages(lastdate).then((res) => {
  73. res.forEach((item) => {
  74. messages.value.unshift(item)
  75. })
  76. })
  77. }
  78. const userInfo = ref({})
  79. const errorHandler = () => {
  80. return true
  81. }
  82. const makeTextPortrait = () => {
  83. return genTextPortrait(userInfo.value.name)
  84. }
  85. onActivated(() => {
  86. selectSystemMessages('latest').then((res) => {
  87. messages.value = res
  88. })
  89. })
  90. onMounted(() => {
  91. getUserInfo().then((res) => {
  92. userInfo.value = res
  93. })
  94. })
  95. return {
  96. messages,
  97. userInfo,
  98. errorHandler,
  99. fetchMoreMessages,
  100. makeTextPortrait,
  101. }
  102. },
  103. }
  104. </script>
  105. <style lang="scss" scoped>
  106. .left-pane {
  107. margin-top: 20px;
  108. width: 68%;
  109. background-image: linear-gradient(#d0ddee, #64b6e6);
  110. height: 120px;
  111. border-radius: 6px;
  112. box-shadow: 0 2px 4px rgba(0, 0, 0, 0.12), 0 0 6px rgba(0, 0, 0, 0.04);
  113. }
  114. .right-pane {
  115. margin-top: 20px;
  116. width: 30%;
  117. padding-right: 20px;
  118. height: 80vh;
  119. overflow-y: scroll;
  120. }
  121. .avatar-box__inner {
  122. display: flex;
  123. align-items: center;
  124. justify-content: center;
  125. width: 86px;
  126. height: 86px;
  127. border-radius: 43px;
  128. border-bottom: 3px solid #1080f0;
  129. z-index: 600;
  130. }
  131. .check-more {
  132. width: 60%;
  133. text-align: right;
  134. color: #409eff;
  135. &:hover {
  136. cursor: pointer;
  137. }
  138. }
  139. .divider-line {
  140. display: block;
  141. height: 1px;
  142. width: 100%;
  143. margin: 70px 0 50px 0;
  144. background-color: #4297ec88;
  145. position: relative;
  146. }
  147. .divider-text {
  148. left: 12px;
  149. -webkit-transform: translateY(-55%);
  150. transform: translateY(-55%);
  151. position: absolute;
  152. font-weight: 500;
  153. color: black;
  154. font-size: 14px;
  155. }
  156. .psninfo-box {
  157. display: flex;
  158. left: 108px;
  159. -webkit-transform: translateY(-120%);
  160. transform: translateY(-120%);
  161. position: absolute;
  162. font-weight: 500;
  163. color: rgb(3, 72, 94);
  164. font-size: 20px;
  165. font-weight: bold;
  166. }
  167. </style>