Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
黄粱一梦--Y
hello uni-app x
提交
b005f4c3
H
hello uni-app x
项目概览
黄粱一梦--Y
/
hello uni-app x
与 Fork 源项目一致
Fork自
DCloud / hello uni-app x
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
H
hello uni-app x
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
b005f4c3
编写于
7月 05, 2023
作者:
taohebin@dcloud.io
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
1. websocket替换地址 2. list示例修改
上级
21f4f7c9
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
66 addition
and
53 deletion
+66
-53
pages.json
pages.json
+2
-2
pages/API/websocket-global/websocket-global.uvue
pages/API/websocket-global/websocket-global.uvue
+1
-1
pages/API/websocket-socketTask/websocket-socketTask.uvue
pages/API/websocket-socketTask/websocket-socketTask.uvue
+1
-1
pages/component/list/detail/detail.uvue
pages/component/list/detail/detail.uvue
+7
-6
pages/component/list/list.uvue
pages/component/list/list.uvue
+55
-43
未找到文件。
pages.json
浏览文件 @
b005f4c3
...
...
@@ -540,7 +540,7 @@
"path"
:
"pages/component/list/list"
,
"style"
:
{
"navigationBarTitleText"
:
""
,
"navigationBarTitleText"
:
"
列表到详情示例
"
,
"enablePullDownRefresh"
:
false
}
...
...
@@ -558,7 +558,7 @@
"path"
:
"pages/component/list/detail/detail"
,
"style"
:
{
"navigationBarTitleText"
:
""
,
"navigationBarTitleText"
:
"
详情示例
"
,
"enablePullDownRefresh"
:
false
}
...
...
pages/API/websocket-global/websocket-global.uvue
浏览文件 @
b005f4c3
...
...
@@ -63,7 +63,7 @@
title: '连接中...'
})
uni.connectSocket({
url: 'ws://
192.168.12.106:8080/ws
',
url: 'ws://
websocket.dcloud.net.cn
',
success(res) {
// 这里是接口调用成功的回调,不是连接成功的回调,请注意
},
...
...
pages/API/websocket-socketTask/websocket-socketTask.uvue
浏览文件 @
b005f4c3
...
...
@@ -69,7 +69,7 @@
title: '连接中...'
})
this.socketTask = uni.connectSocket({
url: 'ws://
192.168.12.106:8080/ws
',
url: 'ws://
websocket.dcloud.net.cn
',
success(res) {
// 这里是接口调用成功的回调,不是连接成功的回调,请注意
},
...
...
pages/component/list/detail/detail.uvue
浏览文件 @
b005f4c3
...
...
@@ -26,7 +26,7 @@
this.pageVisible = true;
this.post_id = event["post_id"] ?? "";
this.cover = event["cover"] ?? "";
this.title = event["title"] ?? "";
this.title = event["title"] ?? "";
this.getDetail();
},
onUnload() {
...
...
@@ -36,11 +36,12 @@
getDetail() {
uni.request({
url: 'https://unidemo.dcloud.net.cn/api/news/36kr/' + this.post_id,
success: (data) => {
if (data.statusCode == 200) {
const result = data.data as UTSJSONObject
// var htmlString = result["content"].replace(/\\/g, "").replace(/<img/g, "<img style=\"display:none;\"");
this.htmlNodes = result["content"] as string;
success: (data) => {
if(this.pageVisible){
if (data.statusCode == 200) {
const result = data.data as UTSJSONObject
this.htmlNodes = result["content"] as string;
}
}
},
fail: () => {
...
...
pages/component/list/list.uvue
浏览文件 @
b005f4c3
<template>
<view style="width: 100%;height: 100%;">
<view class="banner">
<view class="banner"
@click="bannerClick(banner)"
>
<image class="banner-img" :src="banner.cover"></image>
<text class="banner-title">{{ banner.title }}</text>
</view>
...
...
@@ -31,7 +31,8 @@
import JSONArray from 'com.alibaba.fastjson.JSONArray';
type Banner = {
cover: string | null,
title: string | null,
title: string | null,
post_id: string | null
}
type Item = {
author_name: string,
...
...
@@ -50,8 +51,6 @@
banner: {} as Banner,
listData: [] as Item[],
last_id: '',
reload: false,
status: 'more',
contentText: {
contentdown: '上拉加载更多',
contentrefresh: '加载中',
...
...
@@ -63,7 +62,7 @@
onLoad() {
this.pageVisible = true;
this.getBanner();
this.getList();
this.getList();
},
onUnload() {
this.pageVisible = false;
...
...
@@ -76,15 +75,17 @@
uni.request({
url: 'https://unidemo.dcloud.net.cn/api/banner/36kr',
data: data,
success: data => {
// uni.stopPullDownRefresh();
this.refresherTriggered = false
if (data.statusCode == 200) {
let result = data.data as UTSJSONObject;
this.banner = {
cover: result["cover"] as string,
title: result["title"] as string
} as Banner;
success: data => {
if(this.pageVisible){
this.refresherTriggered = false
if (data.statusCode == 200) {
let result = data.data as UTSJSONObject;
this.banner = {
cover: result["cover"] as string,
title: result["title"] as string,
post_id: result["post_id"] as string
} as Banner;
}
}
},
fail: (e) => {
...
...
@@ -93,32 +94,34 @@
});
},
getList() {
let data = {
column: 'id,post_id,title,author_name,cover,published_at', //需要的字段名
};
if (this.last_id != "") {
//说明已有数据,目前处于上拉加载
this.status = 'loading';
data["minId"] = this.last_id;
data["time"] = new Date().getTime() + '';
data["pageSize"] = 10;
}
let url = "https://unidemo.dcloud.net.cn/api/news?column=id,post_id,title,author_name,cover,published_at";
if (this.last_id != "") {
const minId = (this.last_id).toInt();
const time = new Date().getTime() + '';
const pageSize = 10;
url = url + "&minId=" + minId + "&time=" + time + "&pageSize=" + pageSize;
}
uni.request({
url: 'https://unidemo.dcloud.net.cn/api/news',
data: data,
success: (data) => {
if (data.statusCode == 200) {
const result = data.data as UTSJSONObject
let list = this.setTime(result);
this.listData = this.reload ? list : this.listData.concat(list);
this.last_id = list[list.length - 1].id + "";
this.reload = false;
this.refresherTriggered = false
url: url,
method:"GET",
success: (data) => {
if(this.pageVisible){
if (data.statusCode == 200) {
const result = data.data as UTSJSONObject
let list = this.setTime(result);
this.listData = list.concat(this.listData);
console.log("after ",this.listData.size);
this.last_id = listData[0].id + "";
this.refresherTriggered = false;
}
}
},
fail: (res) => {
console.log('fail', res);
this.refresherTriggered = false
fail: (res) => {
if(this.pageVisible){
console.log('fail', res);
this.refresherTriggered = false
}
}
});
},
...
...
@@ -130,12 +133,21 @@
uni.navigateTo({
url: 'pages/component/list/detail/detail?post_id=' + post_id + "&cover=" + cover + "&title=" + title
});
},
bannerClick(e:Banner){
const detail = e;
const post_id = detail.post_id;
const cover = detail.cover;
const title = detail.title;
uni.navigateTo({
url: 'pages/component/list/detail/detail?post_id=' + post_id + "&cover=" + cover + "&title=" + title
});
},
setTime(items: UTSJSONObject): Item[] {
let newItems = [] as Item[];
if (items.isJSONArray()) {
const array = items.toJSONObject() as JSONArray;
for (let i =
0; i < array.size - 1; i++
) {
for (let i =
array.size - 1; i >= 0; i--
) {
const e = array.get(i) as JSONObject;
newItems.push({
author_name: e["author_name"] as string,
...
...
@@ -150,11 +162,11 @@
return newItems;
},
onRefresherrefresh() {
this.refresherTriggered = true
this.reload = true;
this.last_id = ''
;
this.getBanner();
this.getList();
if(this.pageVisible){
this.refresherTriggered = true
this.getBanner()
;
this.getList();
}
}
}
};
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录