long-list.uvue 3.9 KB
Newer Older
H
hdx 已提交
1
<template>
H
hdx 已提交
2
  <list-view class="list" @scrolltolower="loadData">
H
hdx 已提交
3 4
    <list-item class="list-item" v-for="(item, index) in dataList" :key="index">
      <view class="list-item-icon">
H
hdx 已提交
5
        <image class="list-item-icon-image" :src="item.img"></image>
H
hdx 已提交
6 7 8
      </view>
      <view class="list-item-fill">
        <view class="flex-row">
H
hdx 已提交
9
          <text class="title">{{item.name}}</text>
H
hdx 已提交
10 11
        </view>
        <view class="description">
H
hdx 已提交
12
          <text class="description-text">{{item.intro}}</text>
H
hdx 已提交
13
        </view>
H
hdx 已提交
14
        <!-- <view class="tag-list">
H
hdx 已提交
15
          <text class="tag-item" v-for="(item2, index2) in item.tags" :key="index2">{{item2.name}}</text>
H
hdx 已提交
16
        </view> -->
H
hdx 已提交
17 18 19
        <!-- <uts-rate></uts-rate> -->
        <view class="flex-row update-date">
          <text class="update-date-text">更新日期</text>
H
hdx 已提交
20 21
          <!-- <text class="update-date-value">{{item.updateDate}}</text> -->
          <!-- <text class="author">Dcloud</text> -->
H
hdx 已提交
22 23 24 25 26 27 28
        </view>
      </view>
    </list-item>
  </list-view>
</template>

<script>
H
hdx 已提交
29 30 31
  // TODO 临时地址
  const SERVER_URL = "https://test-ext.dcloud.net.cn/plugin/plugin-list"
  const PAGE_SIZE = 10; // 最大值 10
H
hdx 已提交
32

H
hdx 已提交
33
  // TODO 暂不支持tag,更新日期等属性
H
hdx 已提交
34
  type ListItem = {
H
hdx 已提交
35 36 37 38 39 40
    id : number,
    img : string,
    name : string,
    intro : string,
    // tags : Array<String>,
    // updateDate : string,
H
hdx 已提交
41 42 43 44 45
  }

  export default {
    data() {
      return {
H
hdx 已提交
46 47 48 49
        loading: false,
        dataList: [] as ListItem[],
        isEnded: false,
        $currentPage: 0
H
hdx 已提交
50 51 52 53 54 55 56
      }
    },
    onLoad() {
      this.loadData()
    },
    methods: {
      loadData() {
H
hdx 已提交
57 58 59
        if (this.loading || this.isEnded) {
          return
        }
H
hdx 已提交
60

H
hdx 已提交
61
        this.loading = true;
H
hdx 已提交
62

H
hdx 已提交
63 64 65 66 67 68 69 70 71 72 73
        uni.request({
          url: SERVER_URL,
          data: {
            page: this.$currentPage,
            pageSize: PAGE_SIZE
          },
          success: (res) => {
            const responseData = res.data as UTSJSONObject
            if (responseData['data'] == null) {
              return;
            }
H
hdx 已提交
74

H
hdx 已提交
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
            const responseDataList = responseData['data'] as UTSJSONObject[]
            for (const item in responseDataList) {
              this.dataList.push({
                id: item["id"] as number,
                img: 'https:' + item["img"] as string,
                name: item["name"] as string,
                intro: item["intro"] as string,
              } as ListItem)
            }

            this.isEnded = responseDataList.length <= 0;

            this.$currentPage++
          },
          fail: (err) => {
            console.log(err);
          },
          complete: () => {
            this.loading = false;
          }
        })
H
hdx 已提交
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
      }
    }
  }
</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>