提交 01083056 编写于 作者: W wanganxp

微调

上级 a377db11
<template> <template>
<view> <view>
<page-head :title="title"></page-head> <page-head :title="title"></page-head>
<view class="uni-hello-text"> <view style="padding: 4px;">
<text class="hello-text">当前示例基于操作系统自身定位能力,暂不支持gcj标准,逆地理信息等功能,如果需要类似能力可以使用腾讯定位等三方定位服务,参考示例:</text> <text class="hello-text">
真机运行标准基座仅包含系统定位,即system。\n
部分手机因gms兼容不好可能导致无法定位。\n
gcj国标、逆地理信息等功能需三方sdk定位。如果需要类似能力可以下载腾讯定位插件,打包自定义基座。参考示例:</text>
<u-link :href="'https://gitcode.net/dcloud/uni-api/'" :text="'https://gitcode.net/dcloud/uni-api/'" :inWhiteList="true"></u-link> <u-link :href="'https://gitcode.net/dcloud/uni-api/'" :text="'https://gitcode.net/dcloud/uni-api/'" :inWhiteList="true"></u-link>
</view> </view>
......
...@@ -50,7 +50,7 @@ ...@@ -50,7 +50,7 @@
}; };
}, },
onLoad() { onLoad() {
this.pageVisible = true; this.pageVisible = true; //设这个变量是为了避免联网结束后页面已经关闭,此时还继续执行回调逻辑的问题。不是必须的
this.getBanner(); this.getBanner();
this.getList(); this.getList();
}, },
...@@ -85,24 +85,25 @@ ...@@ -85,24 +85,25 @@
}, },
getList() { getList() {
let url = "https://unidemo.dcloud.net.cn/api/news?column=id,post_id,title,author_name,cover,published_at"; let url = "https://unidemo.dcloud.net.cn/api/news?column=id,post_id,title,author_name,cover,published_at";
if (this.last_id != "") { /* if (this.last_id != "") {
const minId = (this.last_id).toInt(); const minId = parseInt((this.last_id))
const time = new Date().getTime() + ''; const time = new Date().getTime() + '';
const pageSize = 10; const pageSize = 10;
url = url + "&minId=" + minId + "&time=" + time + "&pageSize=" + pageSize; url = url + "&minId=" + minId + "&time=" + time + "&pageSize=" + pageSize;
} } */
uni.request({ uni.request<Item[]>({
url: url, url: url,
method:"GET", method:"GET",
success: (data) => { success: (res) => {
if(this.pageVisible){ if(this.pageVisible){
if (data.statusCode == 200) { if (res.statusCode == 200) {
const result = data.data as UTSJSONObject[] console.log(res);
const result = res.data
if(result != null){ if(result != null){
let list = this.setTime(result); this.listData = result //因本接口没有更多分页数据,所以重新赋值。正常有分页的列表应该如下面push方式增加数组项
this.listData = list.concat(this.listData); // this.listData.push(...result)
this.last_id = listData[0].id + ""; // this.last_id = this.listData[0].id + "";
} }
this.refresherTriggered = false; this.refresherTriggered = false;
} }
...@@ -134,21 +135,6 @@ ...@@ -134,21 +135,6 @@
url: '/pages/template/list-news/detail/detail?post_id=' + post_id + "&cover=" + cover + "&title=" + title url: '/pages/template/list-news/detail/detail?post_id=' + post_id + "&cover=" + cover + "&title=" + title
}); });
}, },
setTime(items: UTSJSONObject[]): Item[] {
let newItems = [] as Item[];
for(const item in items){
const e = item;
newItems.push({
author_name: e["author_name"] as string,
cover: e["cover"] as string,
id: e["id"] as number,
post_id: e["post_id"] as string,
published_at: e["published_at"] as string,
title: e["title"] as string
} as Item);
}
return newItems;
},
onRefresherrefresh() { onRefresherrefresh() {
if(this.pageVisible){ if(this.pageVisible){
this.refresherTriggered = true this.refresherTriggered = true
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册
新手
引导
客服 返回
顶部