index.vue 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <template>
  2. <div class="container">
  3. <a-tag :color="randomColor()" class="container-tag">
  4. <component :is="props.icon" class="container-tag-icon" />
  5. </a-tag>
  6. <span class="container-span">{{ 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', '#1677FF', '#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. case 2:
  42. return parseInt(Math.random() * (maxNum - minNum + 1) + minNum, 10)
  43. default:
  44. return 0
  45. }
  46. }
  47. </script>
  48. <style scoped>
  49. .container {
  50. height: 60px;
  51. /*border:1px solid var(--border-color-split);*/
  52. border-radius: 5px;
  53. display: flex;
  54. align-items: center;
  55. cursor: pointer;
  56. /*实现渐变(时间变化效果)*/
  57. -webkit-transition: all 0.5s;
  58. -moz-transition: all 0.5s;
  59. -ms-transition: all 0.5s;
  60. -o-transition: all 0.5s;
  61. transition: all 0.5s;
  62. }
  63. .container:hover {
  64. background: var(--border-color-split);
  65. }
  66. .container-tag {
  67. width: 42px;
  68. height: 42px;
  69. border-radius: 10px;
  70. display: flex;
  71. align-items: center;
  72. margin-left: 10px;
  73. }
  74. .container-tag-icon {
  75. font-size: 25px;
  76. }
  77. .container-span {
  78. max-width: 60%;
  79. font-weight: 500;
  80. }
  81. </style>