提交 a64e10aa 编写于 作者: taohebin@dcloud.io's avatar taohebin@dcloud.io

修改问题

上级 600823ad
...@@ -529,6 +529,15 @@ ...@@ -529,6 +529,15 @@
"enablePullDownRefresh": false "enablePullDownRefresh": false
} }
}
,{
"path" : "pages/component/list/list",
"style" :
{
"navigationBarTitleText": "",
"enablePullDownRefresh": false
}
} }
], ],
"globalStyle": { "globalStyle": {
......
...@@ -17,35 +17,51 @@ ...@@ -17,35 +17,51 @@
</view> </view>
</template> </template>
<script> <script>
import DownloadTask from 'uts.sdk.modules.DCloudUniNetwork.DownloadTask';
export default { export default {
data() { data() {
return { return {
title: 'downloadFile', title: 'downloadFile',
imageSrc: '' imageSrc: '',
task: null as DownloadTask | null,
pageVisible: false
} }
}, },
onLoad() {
this.pageVisible = true;
},
onUnload() { onUnload() {
this.imageSrc = ''; this.imageSrc = '';
this.pageVisible = false;
uni.hideLoading();
this.task?.abort();
}, },
methods: { methods: {
downloadImage: function () { downloadImage: function() {
uni.showLoading({ uni.showLoading({
title:'下载中' title: '下载中'
}) })
var self = this var self = this
let task = uni.downloadFile({ this.task = uni.downloadFile({
url: "http://192.168.12.106:8080/downloadfile", url: "https://web-assets.dcloud.net.cn/unidoc/zh/uni-app.png",
success(res) { success(res) {
if (this.pageVisible) {
console.log('downloadFile success, res is', res) console.log('downloadFile success, res is', res)
self.imageSrc = res.tempFilePath; self.imageSrc = res.tempFilePath;
uni.hideLoading(); uni.hideLoading();
}
}, },
fail: (err) => { fail: (err) => {
if (this.pageVisible) {
console.log('downloadFile fail, err is:', err) console.log('downloadFile fail, err is:', err)
uni.hideLoading();
}
} }
}); });
task!.onProgressUpdate((update) => { this.task?.onProgressUpdate((update) => {
if (this.pageVisible) {
console.log("progress : ", update.progress); console.log("progress : ", update.progress);
}
}) })
} }
} }
...@@ -53,14 +69,15 @@ ...@@ -53,14 +69,15 @@
</script> </script>
<style> <style>
.img { .img {
width: 500rpx; width: 500rpx;
height: 500rpx; height: 500rpx;
margin: 0 auto; margin: 0 auto;
} }
.image-container {
.image-container {
display: flex; display: flex;
justify-content: center; justify-content: center;
align-items: center; align-items: center;
} }
</style> </style>
\ No newline at end of file
...@@ -15,20 +15,31 @@ ...@@ -15,20 +15,31 @@
</view> </view>
</template> </template>
<script> <script>
import RequestTask from 'uts.sdk.modules.DCloudUniNetwork.RequestTask';
const duration = 2000 const duration = 2000
export default { export default {
data() { data() {
return { return {
title: 'request', title: 'request',
loading: false, loading: false,
res: '' res: '',
task: null as RequestTask | null,
pageVisible: false
} }
}, },
onLoad() {
this.pageVisible = true;
},
onUnload() {
this.pageVisible = false;
uni.hideLoading();
this.task?.abort();
},
methods: { methods: {
sendRequest() { sendRequest() {
this.loading = true; this.loading = true;
uni.request({ this.task = uni.request({
url: "http://192.168.12.106:8080/postHalo", url: "https://unidemo.dcloud.net.cn/ajax/echo/text?name=uni-app",
dataType: "json", dataType: "json",
responseType: "json", responseType: "json",
method: "POST", method: "POST",
...@@ -43,6 +54,7 @@ ...@@ -43,6 +54,7 @@
withCredentials: false, withCredentials: false,
firstIpv4: false, firstIpv4: false,
success(res) { success(res) {
if (this.pageVisible) {
console.log('request success', res) console.log('request success', res)
uni.showToast({ uni.showToast({
title: '请求成功', title: '请求成功',
...@@ -51,13 +63,16 @@ ...@@ -51,13 +63,16 @@
duration: duration duration: duration
}); });
this.res = '请求结果 : ' + JSON.stringify(res); this.res = '请求结果 : ' + JSON.stringify(res);
}
}, },
fail(err) { fail(err) {
if (this.pageVisible) {
console.log('request fail', err); console.log('request fail', err);
uni.showModal({ uni.showModal({
content: err.errMsg, content: err.errMsg,
showCancel: false showCancel: false
}); });
}
}, },
complete() { complete() {
this.loading = false; this.loading = false;
......
...@@ -10,15 +10,24 @@ ...@@ -10,15 +10,24 @@
</view> </view>
</template> </template>
<script> <script>
import UploadTask from 'uts.sdk.modules.DCloudUniNetwork.UploadTask';
export default { export default {
data() { data() {
return { return {
title: 'uploadFile', title: 'uploadFile',
imageSrc: '' imageSrc: '',
task: null as UploadTask | null,
pageVisible: false
} }
}, },
onLoad() {
this.pageVisible = true;
},
onUnload() { onUnload() {
this.imageSrc = ''; this.imageSrc = '';
this.pageVisible = false;
uni.hideLoading();
this.task?.abort();
}, },
methods: { methods: {
chooseImage: function() { chooseImage: function() {
...@@ -29,28 +38,37 @@ ...@@ -29,28 +38,37 @@
success: (res) => { success: (res) => {
console.log('chooseImage success, temp path is', res.tempFilePaths[0]) console.log('chooseImage success, temp path is', res.tempFilePaths[0])
var imageSrc = res.tempFilePaths[0] var imageSrc = res.tempFilePaths[0]
uni.uploadFile({ uni.showLoading({
url: 'http://192.168.12.106:8080/uploadFile', //仅为示例,非真实的接口地址 title: '上传中'
})
this.task = uni.uploadFile({
url: 'https://unidemo.dcloud.net.cn/upload', //仅为示例,非真实的接口地址
filePath: imageSrc, filePath: imageSrc,
name: 'file', name: 'file',
formData: { formData: {
'user': 'test' 'user': 'test'
}, },
success: (res) => { success: (res) => {
if (this.pageVisible) {
console.log('uploadImage success, res is:', res) console.log('uploadImage success, res is:', res)
uni.hideLoading();
uni.showToast({ uni.showToast({
title: '上传成功', title: '上传成功',
icon: 'success', icon: 'success',
duration: 1000 duration: 1000
}) })
this.imageSrc = imageSrc this.imageSrc = imageSrc
}
}, },
fail: (err) => { fail: (err) => {
if (this.pageVisible) {
console.log('uploadImage fail', err); console.log('uploadImage fail', err);
uni.hideLoading();
uni.showModal({ uni.showModal({
content: err.errMsg, content: err.errMsg,
showCancel: false showCancel: false
}); });
}
}, },
}); });
}, },
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
</template> </template>
<script> <script>
import CloseSocketOptions from 'uts.sdk.modules.DCloudUniWebsocket.CloseSocketOptions'; import CloseSocketOptions from 'uts.sdk.modules.DCloudUniWebsocket.CloseSocketOptions';
export default { export default {
data() { data() {
return { return {
...@@ -22,11 +22,12 @@ import CloseSocketOptions from 'uts.sdk.modules.DCloudUniWebsocket.CloseSocketOp ...@@ -22,11 +22,12 @@ import CloseSocketOptions from 'uts.sdk.modules.DCloudUniWebsocket.CloseSocketOp
connecting: false, connecting: false,
msg: "", msg: "",
roomId: '', roomId: '',
platform :"", platform: "",
pageVisible: false
} }
}, },
computed: { computed: {
showMsg():string { showMsg(): string {
if (this.connected) { if (this.connected) {
if (this.msg.length > 0) { if (this.msg.length > 0) {
return '收到消息:' + this.msg return '收到消息:' + this.msg
...@@ -40,8 +41,10 @@ import CloseSocketOptions from 'uts.sdk.modules.DCloudUniWebsocket.CloseSocketOp ...@@ -40,8 +41,10 @@ import CloseSocketOptions from 'uts.sdk.modules.DCloudUniWebsocket.CloseSocketOp
}, },
onLoad() { onLoad() {
this.platform = uni.getSystemInfoSync().platform; this.platform = uni.getSystemInfoSync().platform;
this.pageVisible = true;
}, },
onUnload() { onUnload() {
this.pageVisible = false;
const closeOptions = new CloseSocketOptions(); const closeOptions = new CloseSocketOptions();
uni.closeSocket(closeOptions); uni.closeSocket(closeOptions);
uni.hideLoading() uni.hideLoading()
...@@ -69,33 +72,43 @@ import CloseSocketOptions from 'uts.sdk.modules.DCloudUniWebsocket.CloseSocketOp ...@@ -69,33 +72,43 @@ import CloseSocketOptions from 'uts.sdk.modules.DCloudUniWebsocket.CloseSocketOp
} }
}) })
uni.onSocketOpen((res) => { uni.onSocketOpen((res) => {
if (this.pageVisible) {
this.connecting = false this.connecting = false
this.connected = true this.connected = true
uni.hideLoading() uni.hideLoading()
uni.showToast({ uni.showToast({
icon: 'none', icon: 'none',
title: '连接成功' title: '连接成功'
}) })
console.log('onOpen', res); console.log('onOpen', res);
}
}) })
uni.onSocketError((err) => { uni.onSocketError((err) => {
if (this.pageVisible) {
this.connecting = false this.connecting = false
this.connected = false this.connected = false
uni.hideLoading() uni.hideLoading()
uni.showModal({ uni.showModal({
content: '连接失败,可能是websocket服务不可用,请稍后再试', content: '连接失败,可能是websocket服务不可用,请稍后再试',
showCancel: false showCancel: false
}) })
console.log('onError', err); console.log('onError', err);
}
}) })
uni.onSocketMessage((res) => { uni.onSocketMessage((res) => {
if (this.pageVisible) {
this.msg = res.data as string this.msg = res.data as string
console.log('onMessage', res) console.log('onMessage', res)
}
}) })
uni.onSocketClose((res) => { uni.onSocketClose((res) => {
if (this.pageVisible) {
this.connected = false this.connected = false
this.msg = "" this.msg = ""
console.log('onClose', res) console.log('onClose', res)
}
}) })
}, },
send() { send() {
...@@ -142,7 +155,7 @@ import CloseSocketOptions from 'uts.sdk.modules.DCloudUniWebsocket.CloseSocketOp ...@@ -142,7 +155,7 @@ import CloseSocketOptions from 'uts.sdk.modules.DCloudUniWebsocket.CloseSocketOp
color: #666666; color: #666666;
} }
.websocket-tips{ .websocket-tips {
padding: 40px 0px; padding: 40px 0px;
text-align: center; text-align: center;
font-size: 14px; font-size: 14px;
......
...@@ -25,7 +25,8 @@ ...@@ -25,7 +25,8 @@
connecting: false, connecting: false,
socketTask: null as SocketTask | null, socketTask: null as SocketTask | null,
msg: "", msg: "",
platform :"", platform: "",
pageVisible: false
} }
}, },
computed: { computed: {
...@@ -41,10 +42,12 @@ ...@@ -41,10 +42,12 @@
} }
} }
}, },
onReady() { onLoad() {
this.platform = uni.getSystemInfoSync().platform; this.platform = uni.getSystemInfoSync().platform;
this.pageVisible = true;
}, },
onUnload() { onUnload() {
this.pageVisible = false;
uni.hideLoading() uni.hideLoading()
let task = this.socketTask; let task = this.socketTask;
if (task != null) { if (task != null) {
...@@ -75,6 +78,7 @@ ...@@ -75,6 +78,7 @@
} }
}) })
this.socketTask?.onOpen((res) => { this.socketTask?.onOpen((res) => {
if (this.pageVisible) {
this.connecting = false this.connecting = false
this.connected = true this.connected = true
uni.hideLoading() uni.hideLoading()
...@@ -83,8 +87,10 @@ ...@@ -83,8 +87,10 @@
title: '连接成功' title: '连接成功'
}) })
console.log('onOpen', res); console.log('onOpen', res);
}
}) })
this.socketTask?.onError((err) => { this.socketTask?.onError((err) => {
if (this.pageVisible) {
this.connecting = false this.connecting = false
this.connected = false this.connected = false
uni.hideLoading() uni.hideLoading()
...@@ -93,16 +99,21 @@ ...@@ -93,16 +99,21 @@
showCancel: false showCancel: false
}) })
console.log('onError', err); console.log('onError', err);
}
}) })
this.socketTask?.onMessage((res) => { this.socketTask?.onMessage((res) => {
if (this.pageVisible) {
this.msg = res.data as string this.msg = res.data as string
console.log('onMessage', res) console.log('onMessage', res)
}
}) })
this.socketTask?.onClose((res) => { this.socketTask?.onClose((res) => {
if (this.pageVisible) {
this.connected = false this.connected = false
this.socketTask = null this.socketTask = null
this.msg = "" this.msg = ""
console.log('onClose', res) console.log('onClose', res)
}
}) })
}, },
send() { send() {
......
<template>
<view style="height: 100%;width: 100%;">
<page-head :title="title"></page-head>
<view class="container">
<list class="uni-list" :refresher-enabled="true" @refresherrefresh="onRefresherrefresh"
:refresher-triggered="refresherTriggered">
<cell class="list_cell" v-for="(item, index) in dataList" :key="item.id">
<view class="list-item">
<text class="list-item-title" :value="item.name"></text>
</view>
</cell>
</list>
</view>
</view>
</template>
<script lang="ts">
import RefresherEvent from 'io.dcloud.uniapp.runtime.RefresherEvent';
type Item = {
id : string,
name : string
}
export default {
data() {
return {
title: 'list',
refresherTriggered: false,
dataList: [] as Item[],
}
},
onLoad() {
for (var i = 0; i < 25; i++) {
const item : Item = { id: i + "", name: "item " + i }
this.dataList.push(item)
}
},
methods: {
onRefresherrefresh(e : RefresherEvent) {
this.refresherTriggered = true
setTimeout(function () {
this.refresherTriggered = false
}, 1000)
}
}
}
</script>
<style>
.uni-list {
background-color: #eee;
position: relative;
width: 100%;
flex: 1;
display: flex;
flex-direction: column;
border-color: red;
}
.container {
display: flex;
flex-direction: column;
border: dashed;
height: 100%;
width: 100%;
}
.list_cell{
display: flex;
justify-content: center;
align-items: center;
}
.list-item {
margin-left: 12px;
margin-right: 12px;
margin-top: 12px;
padding: 20px;
background-color: #fff;
border-radius: 5px;
}
.list-item-title {
font-size: 30px;
font-weight: bold;
color: #444;
width: 100%;
}
</style>
\ No newline at end of file
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
</view> </view>
</template> </template>
<script> <script>
import RefresherEvent from 'io.dcloud.uniapp.runtime.RefresherEvent';
export default { export default {
data() { data() {
......
...@@ -69,6 +69,10 @@ ...@@ -69,6 +69,10 @@
enable: false enable: false
}, },
// #endif // #endif
{
name:'list',
enable:false
}
] as Page[] ] as Page[]
}, { }, {
id: 'content', id: 'content',
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册