OperateLogV2.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <template>
  2. <!-- TODO @puhui999:左边不用有空隙哈 -->
  3. <div class="pt-20px">
  4. <el-timeline>
  5. <el-timeline-item
  6. v-for="(log, index) in logList"
  7. :key="index"
  8. :timestamp="formatDate(log.createTime)"
  9. placement="top"
  10. >
  11. <div class="el-timeline-right-content">
  12. <el-tag class="mr-10px" type="success">{{ log.userName }}</el-tag>
  13. {{ log.action }}
  14. </div>
  15. <template #dot>
  16. <span :style="{ backgroundColor: getUserTypeColor(log.userType) }" class="dot-node-style">
  17. {{ getDictLabel(DICT_TYPE.USER_TYPE, log.userType)[0] }}
  18. </span>
  19. </template>
  20. </el-timeline-item>
  21. </el-timeline>
  22. </div>
  23. </template>
  24. <script lang="ts" setup>
  25. import { OperateLogV2VO } from '@/api/system/operatelog'
  26. import { formatDate } from '@/utils/formatTime'
  27. import { DICT_TYPE, getDictLabel, getDictObj } from '@/utils/dict'
  28. import { ElTag } from 'element-plus'
  29. defineOptions({ name: 'OperateLogV2' })
  30. interface Props {
  31. logList: OperateLogV2VO[] // 操作日志列表
  32. }
  33. withDefaults(defineProps<Props>(), {
  34. logList: () => []
  35. })
  36. /** 获得 userType 颜色 */
  37. const getUserTypeColor = (type: number) => {
  38. const dict = getDictObj(DICT_TYPE.USER_TYPE, type)
  39. switch (dict?.colorType) {
  40. case 'success':
  41. return '#67C23A'
  42. case 'info':
  43. return '#909399'
  44. case 'warning':
  45. return '#E6A23C'
  46. case 'danger':
  47. return '#F56C6C'
  48. }
  49. return '#409EFF'
  50. }
  51. </script>
  52. <style lang="scss" scoped>
  53. // 时间线样式调整
  54. :deep(.el-timeline) {
  55. margin: 10px 0 0 110px;
  56. .el-timeline-item__wrapper {
  57. position: relative;
  58. top: -20px;
  59. .el-timeline-item__timestamp {
  60. position: absolute !important;
  61. top: 10px;
  62. left: -150px;
  63. }
  64. }
  65. .el-timeline-right-content {
  66. display: flex;
  67. align-items: center;
  68. min-height: 30px;
  69. padding: 10px;
  70. background-color: #fff;
  71. &::before {
  72. position: absolute;
  73. top: 10px;
  74. left: 13px; /* 将伪元素水平居中 */
  75. border-color: transparent #fff transparent transparent; /* 尖角颜色,左侧朝向 */
  76. border-style: solid;
  77. border-width: 8px; /* 调整尖角大小 */
  78. content: ''; /* 必须设置 content 属性 */
  79. }
  80. }
  81. }
  82. .dot-node-style {
  83. position: absolute;
  84. left: -5px;
  85. display: flex;
  86. width: 20px;
  87. height: 20px;
  88. font-size: 10px;
  89. color: #fff;
  90. border-radius: 50%;
  91. justify-content: center;
  92. align-items: center;
  93. }
  94. </style>