index.vue 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <template>
  2. <div class="container">
  3. <el-tag :color="randomColor()" class="container-tag">
  4. <SvgIcon :name="props.icon" :size="25" color="#ffffff" />
  5. </el-tag>
  6. <span class="container-span">{{ $t(props.label) }}</span>
  7. </div>
  8. </template>
  9. <script setup name="shortcut">
  10. const props = defineProps({
  11. icon: {
  12. type: String,
  13. default: () => 'menu-outlined',
  14. required: false,
  15. },
  16. label: {
  17. type: String,
  18. default: () => '快捷方式',
  19. required: false,
  20. },
  21. color: {
  22. type: String,
  23. default: () => '',
  24. required: false,
  25. },
  26. });
  27. // 颜色列表
  28. const colorList = ['#7265E6', '#FFBF00', '#00A2AE', '#F56A00', '#1890FF', '#606D80'];
  29. // 获取随机颜色
  30. const randomColor = () => {
  31. if (props.color) {
  32. return props.color;
  33. }
  34. return colorList[randomNum(0, colorList.length - 1)];
  35. };
  36. // 获取minNum到maxNum内的随机数
  37. const randomNum = (minNum, maxNum) => {
  38. switch (arguments.length) {
  39. case 1:
  40. return parseInt(Math.random() * minNum + 1, 10);
  41. // eslint-disable-next-line no-unreachable
  42. break;
  43. case 2:
  44. return parseInt(Math.random() * (maxNum - minNum + 1) + minNum, 10);
  45. // eslint-disable-next-line no-unreachable
  46. break;
  47. default:
  48. return 0;
  49. // eslint-disable-next-line no-unreachable
  50. break;
  51. }
  52. };
  53. </script>
  54. <style scoped>
  55. .container {
  56. height: 60px;
  57. /*border:1px solid var(--border-color-split);*/
  58. border-radius: 5px;
  59. display: flex;
  60. align-items: center;
  61. cursor: pointer;
  62. /*实现渐变(时间变化效果)*/
  63. -webkit-transition: all 0.5s;
  64. -moz-transition: all 0.5s;
  65. -ms-transition: all 0.5s;
  66. -o-transition: all 0.5s;
  67. transition: all 0.5s;
  68. }
  69. .container:hover {
  70. background: var(--border-color-split);
  71. }
  72. .container-tag {
  73. width: 42px;
  74. height: 42px;
  75. border-radius: 10px;
  76. display: flex;
  77. align-items: center;
  78. margin-left: 10px;
  79. font-size: 24px;
  80. }
  81. .container-span {
  82. max-width: 60%;
  83. font-weight: 500;
  84. margin-left: 10px;
  85. color: #6d6b6b;
  86. }
  87. </style>