FrequentFeatures.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. <template>
  2. <div class="frequent-features">
  3. <h2 class="section-title">高频功能</h2>
  4. <div class="feature-container">
  5. <div
  6. v-for="(feature, index) in features"
  7. :key="index"
  8. class="feature-card floating-card"
  9. @click="handleFeatureClick(feature)">
  10. <div class="feature-icon" :style="{ backgroundColor: feature.color.bgcolor }">
  11. <i
  12. v-if="feature.icon && feature.icon.startsWith('fa ')"
  13. :class="feature.icon"
  14. :style="{ color: feature.color.color }">
  15. </i>
  16. <svg-icon
  17. v-else
  18. :icon-class="feature.icon"
  19. :style="{ color: feature.color.color }">
  20. </svg-icon>
  21. </div>
  22. <div class="feature-name">{{ feature.name }}</div>
  23. </div>
  24. </div>
  25. </div>
  26. </template>
  27. <script>
  28. import { getHighUse } from '@/api/system/dashboard'
  29. export default {
  30. name: 'FrequentFeatures',
  31. data() {
  32. return {
  33. colorList: {
  34. blue:{color: '#165dff', bgcolor: '#e7eeff'},
  35. cyan:{color: '#36cfc9', bgcolor: '#ebfaf9'},
  36. orange:{color: '#faad14', bgcolor: '#fef7e7'},
  37. gray:{color: '#4e5969', bgcolor: '#edeef0'},
  38. red:{color: '#ff4d4f', bgcolor: '#ffeded'},
  39. green:{color: '#67C23A', bgcolor: '#edf9e8'},
  40. },
  41. features: []
  42. }
  43. },
  44. created() {
  45. this.fetchHighUseFeatures()
  46. },
  47. methods: {
  48. // 获取高频功能数据
  49. async fetchHighUseFeatures() {
  50. try {
  51. const response = await getHighUse()
  52. // 根据返回的数据结构处理 features
  53. this.features = response.highUse.map(item => {
  54. // 使用后端返回的颜色信息
  55. const colorKey = item.color || 'blue'
  56. return {
  57. name: item.title,
  58. icon: item.icon || 'fa fa-tasks',
  59. color: this.colorList[colorKey] || this.colorList.blue
  60. }
  61. })
  62. } catch (error) {
  63. console.error('获取高频功能数据失败:', error)
  64. // 如果获取失败,使用默认数据
  65. this.features = [
  66. { name: '工单管理', icon: 'fa fa-tasks', color: this.colorList.blue },
  67. { name: '班组管理', icon: 'fa fa-users', color: this.colorList.cyan },
  68. { name: '工分管理', icon: 'fa fa-star', color: this.colorList.orange },
  69. { name: '工时分析', icon: 'fa fa-clock', color: this.colorList.gray },
  70. { name: '通知中心', icon: 'fa fa-bell', color: this.colorList.red }
  71. ]
  72. }
  73. },
  74. // 处理功能块点击事件
  75. handleFeatureClick(feature) {
  76. this.$message.info(`点击了 ${feature.name}`)
  77. // 实际项目中可以跳转到对应页面
  78. // this.$emit('feature-click', feature)
  79. }
  80. }
  81. }
  82. </script>
  83. <style scoped>
  84. .section-title {
  85. font-size: 18px;
  86. font-weight: 600;
  87. color: #303133;
  88. margin-bottom: 20px;
  89. padding-bottom: 10px;
  90. }
  91. /* 悬浮卡片通用样式 */
  92. .floating-card {
  93. box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
  94. transition: all 0.3s ease;
  95. }
  96. .floating-card:hover {
  97. transform: translateY(-8px);
  98. box-shadow: 0 12px 30px rgba(0, 0, 0, 0.15);
  99. }
  100. .feature-container {
  101. display: flex;
  102. flex-wrap: wrap;
  103. gap: 20px; /* 替代 el-row 的 gutter */
  104. }
  105. .feature-card {
  106. flex: 0 0 calc(20% - 16px); /* 每行 5 个(20% 宽度),减去 gap 的影响 */
  107. min-width: 0; /* 防止内容溢出 */
  108. box-sizing: border-box;
  109. background: white;
  110. border-radius: 8px;
  111. padding: 16px;
  112. text-align: center;
  113. cursor: pointer;
  114. transition: transform 0.3s, box-shadow 0.3s;
  115. }
  116. .feature-card:hover {
  117. transform: translateY(-5px);
  118. box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  119. }
  120. .feature-icon {
  121. display: inline-flex; /* 让背景圆形和 icon 居中 */
  122. align-items: center;
  123. justify-content: center;
  124. width: 48px; /* 圆形背景的宽度 */
  125. height: 48px; /* 圆形背景的高度 */
  126. border-radius: 50%; /* 圆形背景 */
  127. background-color: rgba(59, 130, 246, 0.1); /* 浅色背景(蓝色示例) */
  128. margin-bottom: 8px;
  129. }
  130. .feature-icon .icon {
  131. font-size: 20px; /* icon 大小 */
  132. color: #3b82f6; /* icon 颜色(蓝色示例) */
  133. }
  134. .feature-name {
  135. font-size: 14px;
  136. }
  137. </style>