|
@@ -1,69 +1,85 @@
|
|
|
<template>
|
|
|
<view class="index">
|
|
|
- <block v-for="item in list" :key="item._id">
|
|
|
- <view class="card" @click="goDetail(item)">
|
|
|
- <image class="card-img" :src="item.thumbnail" mode="aspectFill"></image>
|
|
|
- <text class="card-num-view">{{ item.views }} 次浏览</text>
|
|
|
- <view class="card-bottm row">
|
|
|
- <view class="car-title-view row">
|
|
|
- <text class="card-title">{{ item.title }}</text>
|
|
|
+ <view v-if="login">
|
|
|
+ <block v-for="item in list" :key="item._id">
|
|
|
+ <view class="card" @click="goDetail(item)">
|
|
|
+ <image
|
|
|
+ class="card-img"
|
|
|
+ :src="item.thumbnail"
|
|
|
+ mode="aspectFill"
|
|
|
+ ></image>
|
|
|
+ <text class="card-num-view">{{ item.views }} 次浏览</text>
|
|
|
+ <view class="card-bottm row">
|
|
|
+ <view class="car-title-view row">
|
|
|
+ <text class="card-title">{{ item.title }}</text>
|
|
|
+ </view>
|
|
|
</view>
|
|
|
</view>
|
|
|
+ </block>
|
|
|
+ <view class="loadMore">
|
|
|
+ <text>{{ hasMore ? "加载中..." : "没有更多了" }}</text>
|
|
|
</view>
|
|
|
- </block>
|
|
|
- <view class="loadMore">
|
|
|
- <text>加载中...</text>
|
|
|
+ </view>
|
|
|
+ <view v-else class="auth_card">
|
|
|
+ <text>还未登录, </text>
|
|
|
+ <navigator class="text" url="/pages/login/index">去登录</navigator>
|
|
|
</view>
|
|
|
</view>
|
|
|
</template>
|
|
|
|
|
|
<script>
|
|
|
+import { getDesignList } from "../../services/https/promotion";
|
|
|
export default {
|
|
|
data() {
|
|
|
return {
|
|
|
+ login: false,
|
|
|
+ hasMore: true,
|
|
|
refreshing: false,
|
|
|
list: [],
|
|
|
fetchPageNum: 1,
|
|
|
};
|
|
|
},
|
|
|
onLoad() {
|
|
|
- this.getData();
|
|
|
+ const token = uni.getStorageSync("access-token");
|
|
|
+ if (token) {
|
|
|
+ this.login = true;
|
|
|
+ this.getData();
|
|
|
+ }
|
|
|
},
|
|
|
onReachBottom() {
|
|
|
- console.log("滑动到页面底部");
|
|
|
+ // console.log("滑动到页面底部");
|
|
|
+ if (!this.hasMore) return;
|
|
|
this.getData();
|
|
|
},
|
|
|
onPullDownRefresh() {
|
|
|
- console.log("下拉刷新");
|
|
|
+ // console.log("下拉刷新");
|
|
|
this.refreshing = true;
|
|
|
+ this.fetchPageNum = 1;
|
|
|
this.getData();
|
|
|
},
|
|
|
methods: {
|
|
|
- getData() {
|
|
|
- uni.request({
|
|
|
- url:
|
|
|
- this.$serverUrl + "/h5/list?page=" + this.fetchPageNum + "&size=10",
|
|
|
- header: {
|
|
|
- Authorization: "Bearer " + uni.getStorageSync("access-token"),
|
|
|
- },
|
|
|
- success: (ret) => {
|
|
|
- // console.log("data", ret.data);
|
|
|
- if (ret.statusCode !== 200 || ret.data.errorNo !== 200) {
|
|
|
- console.log("失败!");
|
|
|
- } else {
|
|
|
- const list = ret.data.result.list;
|
|
|
- if (this.refreshing) {
|
|
|
- this.refreshing = false;
|
|
|
- uni.stopPullDownRefresh();
|
|
|
- this.list = list;
|
|
|
- this.fetchPageNum = 2;
|
|
|
- } else {
|
|
|
- this.list = this.list.concat(list);
|
|
|
- this.fetchPageNum += 1;
|
|
|
- }
|
|
|
- }
|
|
|
- },
|
|
|
+ async getData() {
|
|
|
+ const data = await getDesignList({
|
|
|
+ page: this.fetchPageNum,
|
|
|
+ size: 5,
|
|
|
});
|
|
|
+
|
|
|
+ if (data.errorNo === 401) {
|
|
|
+ uni.clearStorageSync("access-token");
|
|
|
+ this.login = false;
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ const result = data.result;
|
|
|
+ this.hasMore = result.total > result.size * result.page;
|
|
|
+ if (this.refreshing) {
|
|
|
+ this.refreshing = false;
|
|
|
+ uni.stopPullDownRefresh();
|
|
|
+ this.list = result.list;
|
|
|
+ this.fetchPageNum = 2;
|
|
|
+ } else {
|
|
|
+ this.list = this.list.concat(result.list);
|
|
|
+ this.fetchPageNum += 1;
|
|
|
+ }
|
|
|
},
|
|
|
goDetail(data) {
|
|
|
uni.navigateTo({
|
|
@@ -140,7 +156,7 @@ export default {
|
|
|
text-align: left;
|
|
|
color: #555555;
|
|
|
text-overflow: ellipsis;
|
|
|
- lines: 2;
|
|
|
+ /* lines: 2; */
|
|
|
display: -webkit-box;
|
|
|
white-space: normal;
|
|
|
display: -webkit-box;
|
|
@@ -148,4 +164,16 @@ export default {
|
|
|
-webkit-line-clamp: 2;
|
|
|
overflow: hidden;
|
|
|
}
|
|
|
+.auth_card {
|
|
|
+ height: 100vh;
|
|
|
+ display: flex;
|
|
|
+ align-items: center;
|
|
|
+ justify-content: center;
|
|
|
+ font-size: 30rpx;
|
|
|
+ color: #666;
|
|
|
+}
|
|
|
+.text {
|
|
|
+ color: #41969c;
|
|
|
+ text-decoration: underline;
|
|
|
+}
|
|
|
</style>
|