long-list.uvue 3.9 KB
Newer Older
H
hdx 已提交
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 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194
<template>
  <list-view class="list" @loadmore="loadData">
    <list-item class="list-item" v-for="(item, index) in dataList" :key="index">
      <view class="list-item-icon">
        <image class="list-item-icon-image" :src="item.image"></image>
        <text class="list-item-icon-index">{{item.index}}</text>
      </view>
      <view class="list-item-fill">
        <view class="flex-row">
          <text class="title">{{item.title}}</text>
        </view>
        <view class="description">
          <text class="description-text">{{item.description}}</text>
        </view>
        <view class="tag-list">
          <text class="tag-item" v-for="(item2, index2) in item.tags" :key="index2">{{item2.name}}</text>
        </view>
        <!-- <uts-rate></uts-rate> -->
        <view class="flex-row update-date">
          <text class="update-date-text">更新日期</text>
          <text class="update-date-value">{{item.updateDate}}</text>
          <text class="author">Dcloud</text>
        </view>
      </view>
    </list-item>
  </list-view>
</template>

<script>
  // 测试数据 - 标题
  const TEST_DATA_TITLE_LIST = [
    '升级中心 uni-upgrade-center',
    'schema2code',
    'uni-sec-check',
    'uni-starter',
    'uni-admin 基础框架',
    '有奖猜歌游戏',
    '看图App模板',
    '网赚游戏管理后台',
    '云端一体搜索模板',
  ]

  // 测试数据 - 标签
  const TEST_DATA_TAG_LIST = [
    'uni-ai-chat',
    'gpt',
    'chatgpt',
    'openai',
  ]

  type TagItem = {
    index : string,
    name : string
  }

  type ListItem = {
    index : string,
    image : string,
    title : string,
    description : string,
    tags : Array<TagItem>,
    updateDate : string,
  }

  export default {
    data() {
      return {
        dataList: [] as ListItem[]
      }
    },
    onLoad() {
      this.loadData()
    },
    methods: {
      // 滚动到页面底部时调用
      loadData() {
        let index = this.dataList.length

        // 生成 20 条测试数据, 随机标题、标签
        const updateDate = new Date().toISOString().split('T')[0]
        for (let i = 0; i < 20; i++) {
          // 标签
          let tags : TagItem[] = []
          for (let j = 0; j < 3; j++) {
            tags.push({
              index: i + '_' + j,
              name: TEST_DATA_TAG_LIST[parseInt((Math.random() * (TEST_DATA_TAG_LIST.length - 1)) + '')],
            } as TagItem)
          }

          this.dataList.push({
            index: index.toString(),
            image: '/static/uni.png',
            title: TEST_DATA_TITLE_LIST[parseInt((Math.random() * (TEST_DATA_TITLE_LIST.length - 1)) + '')],
            description: '描述',
            tags: tags,
            updateDate
          } as ListItem)

          index++
        }
      }
    }
  }
</script>

<style>
  .flex-row {
    flex-direction: row;
  }

  .list {
    flex: 1;
    background-color: #ffffff;
  }

  .list-item {
    flex-direction: row;
    margin-top: 10px;
    padding: 10px;
  }

  .list-item-icon {
    position: relative;
  }

  .list-item-icon-image {
    width: 80px;
    height: 80px;
  }

  .list-item-icon-index {
    font-size: 12px;
    color: #cccccc;
    position: absolute;
    left: 2px;
    bottom: 2px;
  }

  .list-item-fill {
    flex: 1;
    margin-left: 15px;
  }

  .index {
    margin-left: 10px;
  }

  .description {
    margin-top: 5px;
  }

  .description-text {
    font-size: 13px;
    color: #666;
    margin-top: 5px;
  }

  .tag-list {
    flex-direction: row;
    margin-top: 5px;
  }

  .tag-item {
    font-size: 14px;
    font-weight: bold;
    background-color: #EFF9F0;
    color: #639069;
    border-radius: 20px;
    margin-right: 5px;
    padding: 2px 5px;
  }

  .update-date {
    margin-top: 10px;
  }

  .update-date-text {
    font-size: 12px;
    color: #888888;
  }

  .update-date-value {
    font-size: 12px;
    color: #777777;
    margin-left: 5px;
  }

  .author {
    font-size: 12px;
    color: #008000;
    margin-left: auto;
  }
</style>