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