multiple-options-demo.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. <template>
  2. <view class="multiple-options">
  3. <view class="list">
  4. <block v-for="(item, index) in listData" :key="index">
  5. <view
  6. class="list__item"
  7. :class="[`tn-main-gradient-${tuniaoColorList[item.bgColorIndex]}--light`]"
  8. @tap="navOptionsPage(item.url)"
  9. >
  10. <view class="list__content">
  11. <view class="list__content__title">{{ item.title }}</view>
  12. <view class="list__content__desc">{{ item.desc }}</view>
  13. </view>
  14. <view class="list__icon">
  15. <view class="list__icon__main" :class="[`tn-icon-${item.mainIcon}`, `tn-main-gradient-${tuniaoColorList[item.bgColorIndex]}`]"></view>
  16. <view class="list__icon__sub" :class="[`tn-icon-${item.subIcon}`, `tn-main-gradient-${tuniaoColorList[item.bgColorIndex]}`]"></view>
  17. </view>
  18. </view>
  19. </block>
  20. </view>
  21. </view>
  22. </template>
  23. <script>
  24. export default {
  25. name: 'multiple-options-demo',
  26. props: {
  27. // 显示的列表数据
  28. list: {
  29. type: Array,
  30. default() {
  31. return []
  32. }
  33. }
  34. },
  35. data() {
  36. return {
  37. // 图鸟颜色列表
  38. tuniaoColorList: [
  39. 'red',
  40. 'purplered',
  41. 'purple',
  42. 'bluepurple',
  43. 'aquablue',
  44. 'blue',
  45. 'indigo',
  46. 'cyan',
  47. 'teal',
  48. 'green',
  49. 'orange',
  50. 'orangered'
  51. ],
  52. listData: []
  53. }
  54. },
  55. watch: {
  56. list(val) {
  57. this.initList()
  58. }
  59. },
  60. created() {
  61. this.initList()
  62. },
  63. methods: {
  64. // 初始化列表数据
  65. initList() {
  66. // 给列表添加背景颜色数据
  67. this.listData = this.list.map((item, index) => {
  68. item.bgColorIndex = this.getBgNum()
  69. item.mainIcon = item?.mainIcon || 'computer-fill'
  70. item.subIcon = item?.subIcon || 'share'
  71. return item
  72. })
  73. },
  74. // 跳转到对应的选项页面
  75. navOptionsPage(url) {
  76. uni.navigateTo({
  77. url: url
  78. })
  79. },
  80. // 获取酷炫背景随机数
  81. getBgNum() {
  82. return Math.floor((Math.random() * this.tuniaoColorList.length))
  83. }
  84. }
  85. }
  86. </script>
  87. <style lang="scss" scoped>
  88. .list {
  89. &__item {
  90. display: flex;
  91. flex-direction: row;
  92. align-items: center;
  93. justify-content: space-between;
  94. width: calc(100% - 60rpx);
  95. margin: 108rpx 30rpx 0rpx 30rpx;
  96. box-shadow: 0rpx 10rpx 50rpx 0rpx rgba(0, 3, 72, 0.1);
  97. border-radius: 20rpx;
  98. }
  99. &__content {
  100. flex: 1;
  101. // color: $tn-font-color;
  102. margin: 34rpx 0rpx 27rpx 37rpx;
  103. &__title {
  104. font-size: 36rpx;
  105. font-weight: bold;
  106. margin-bottom: 12rpx;
  107. }
  108. &__desc {
  109. font-size: 28rpx;
  110. }
  111. }
  112. &__icon {
  113. flex: 1;
  114. margin-right: 26rpx;
  115. position: relative;
  116. &__main, &__sub {
  117. -webkit-background-clip: text;
  118. color: transparent;
  119. position: absolute;
  120. transition: transform 0.25s ease;
  121. }
  122. &__main {
  123. font-size: 200rpx;
  124. width: 190rpx;
  125. line-height: 200rpx;
  126. top: 0;
  127. right: 0rpx;
  128. transform: translateY(-60%);
  129. }
  130. &__sub {
  131. font-size: 70rpx;
  132. top: 0;
  133. right: 175rpx;
  134. transform: translateY(-5rpx);
  135. }
  136. }
  137. }
  138. </style>