From a64e10aa17886a51ad7ad0d831b06b65874a5e4c Mon Sep 17 00:00:00 2001 From: taohebin Date: Sat, 1 Jul 2023 12:57:57 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages.json | 45 ++- pages/API/download-file/download-file.uvue | 75 +++-- pages/API/request/request.uvue | 93 +++--- pages/API/upload-file/upload-file.uvue | 48 ++- .../websocket-global/websocket-global.uvue | 315 +++++++++--------- .../websocket-socketTask.uvue | 75 +++-- pages/component/list/list.uvue | 87 +++++ .../scroll-view/scroll-view-refresher.uvue | 5 +- pages/tabBar/component/component.uvue | 6 +- 9 files changed, 462 insertions(+), 287 deletions(-) create mode 100644 pages/component/list/list.uvue diff --git a/pages.json b/pages.json index 46337859..a19b268f 100644 --- a/pages.json +++ b/pages.json @@ -84,24 +84,24 @@ "style": { "navigationBarTitleText": "image" } - }, - { - "path": "pages/component/image/image-format", - "style": { - "navigationBarTitleText": "image-format" - } - }, - { - "path": "pages/component/image/image-mode", - "style": { - "navigationBarTitleText": "image-mode" - } - }, - { - "path": "pages/component/image/image-path", - "style": { - "navigationBarTitleText": "image-path" - } + }, + { + "path": "pages/component/image/image-format", + "style": { + "navigationBarTitleText": "image-format" + } + }, + { + "path": "pages/component/image/image-mode", + "style": { + "navigationBarTitleText": "image-mode" + } + }, + { + "path": "pages/component/image/image-path", + "style": { + "navigationBarTitleText": "image-path" + } }, { "path": "pages/component/web-view/web-view", @@ -530,6 +530,15 @@ } } + ,{ + "path" : "pages/component/list/list", + "style" : + { + "navigationBarTitleText": "", + "enablePullDownRefresh": false + } + + } ], "globalStyle": { "pageOrientation": "portrait", diff --git a/pages/API/download-file/download-file.uvue b/pages/API/download-file/download-file.uvue index 61a7af82..6bb7cebb 100644 --- a/pages/API/download-file/download-file.uvue +++ b/pages/API/download-file/download-file.uvue @@ -1,8 +1,8 @@ + .img { + width: 500rpx; + height: 500rpx; + margin: 0 auto; + } + + .image-container { + display: flex; + justify-content: center; + align-items: center; + } + \ No newline at end of file diff --git a/pages/API/request/request.uvue b/pages/API/request/request.uvue index 29268258..3d27b480 100644 --- a/pages/API/request/request.uvue +++ b/pages/API/request/request.uvue @@ -15,55 +15,70 @@ + \ No newline at end of file diff --git a/pages/API/upload-file/upload-file.uvue b/pages/API/upload-file/upload-file.uvue index a5f26a60..edcb14d3 100644 --- a/pages/API/upload-file/upload-file.uvue +++ b/pages/API/upload-file/upload-file.uvue @@ -10,15 +10,24 @@ - - + this.pageVisible = false; + const closeOptions = new CloseSocketOptions(); + uni.closeSocket(closeOptions); + uni.hideLoading() + }, + methods: { + connect() { + if (this.connected || this.connecting) { + uni.showModal({ + content: '正在连接或者已经连接,请勿重复连接', + showCancel: false + }) + return + } + this.connecting = true + uni.showLoading({ + title: '连接中...' + }) + uni.connectSocket({ + url: 'ws://192.168.12.106:8080/ws', + success(res) { + // 这里是接口调用成功的回调,不是连接成功的回调,请注意 + }, + fail(err) { + // 这里是接口调用失败的回调,不是连接失败的回调,请注意 + } + }) + uni.onSocketOpen((res) => { + if (this.pageVisible) { + this.connecting = false + this.connected = true + uni.hideLoading() + + uni.showToast({ + icon: 'none', + title: '连接成功' + }) + console.log('onOpen', res); + } + }) + uni.onSocketError((err) => { + if (this.pageVisible) { + this.connecting = false + this.connected = false + uni.hideLoading() + + uni.showModal({ + content: '连接失败,可能是websocket服务不可用,请稍后再试', + showCancel: false + }) + console.log('onError', err); + } + }) + uni.onSocketMessage((res) => { + if (this.pageVisible) { + this.msg = res.data as string + console.log('onMessage', res) + } + }) + uni.onSocketClose((res) => { + if (this.pageVisible) { + this.connected = false + this.msg = "" + console.log('onClose', res) + } + }) + }, + send() { + uni.sendSocketMessage({ + data: 'from ' + platform + ' : ' + parseInt((Math.random() * 10000).toString()).toString(), + success(res) { + console.log(res); + }, + fail(err) { + console.log(err); + } + }) + }, + close() { + const closeSocketOptions = new CloseSocketOptions(); + uni.closeSocket(closeSocketOptions) + } + } + } + + + \ No newline at end of file diff --git a/pages/API/websocket-socketTask/websocket-socketTask.uvue b/pages/API/websocket-socketTask/websocket-socketTask.uvue index de19b878..06f474b0 100644 --- a/pages/API/websocket-socketTask/websocket-socketTask.uvue +++ b/pages/API/websocket-socketTask/websocket-socketTask.uvue @@ -24,8 +24,9 @@ connected: false, connecting: false, socketTask: null as SocketTask | null, - msg: "", - platform :"", + msg: "", + platform: "", + pageVisible: false } }, computed: { @@ -40,14 +41,16 @@ return '尚未连接' } } - }, - onReady() { - this.platform = uni.getSystemInfoSync().platform; + }, + onLoad() { + this.platform = uni.getSystemInfoSync().platform; + this.pageVisible = true; }, onUnload() { + this.pageVisible = false; uni.hideLoading() - let task = this.socketTask; - if (task != null) { + let task = this.socketTask; + if (task != null) { const closeOptions = new CloseSocketOptions(); task.close(closeOptions) } @@ -64,7 +67,7 @@ this.connecting = true uni.showLoading({ title: '连接中...' - }) + }) this.socketTask = uni.connectSocket({ url: 'ws://192.168.12.106:8080/ws', success(res) { @@ -73,36 +76,44 @@ fail(err) { // 这里是接口调用失败的回调,不是连接失败的回调,请注意 } - }) + }) this.socketTask?.onOpen((res) => { - this.connecting = false - this.connected = true - uni.hideLoading() - uni.showToast({ - icon: 'none', - title: '连接成功' - }) - console.log('onOpen', res); + if (this.pageVisible) { + this.connecting = false + this.connected = true + uni.hideLoading() + uni.showToast({ + icon: 'none', + title: '连接成功' + }) + console.log('onOpen', res); + } }) this.socketTask?.onError((err) => { - this.connecting = false - this.connected = false - uni.hideLoading() - uni.showModal({ - content: '连接失败,可能是websocket服务不可用,请稍后再试', - showCancel: false - }) - console.log('onError', err); + if (this.pageVisible) { + this.connecting = false + this.connected = false + uni.hideLoading() + uni.showModal({ + content: '连接失败,可能是websocket服务不可用,请稍后再试', + showCancel: false + }) + console.log('onError', err); + } }) this.socketTask?.onMessage((res) => { - this.msg = res.data as string - console.log('onMessage', res) + if (this.pageVisible) { + this.msg = res.data as string + console.log('onMessage', res) + } }) this.socketTask?.onClose((res) => { - this.connected = false - this.socketTask = null - this.msg = "" - console.log('onClose', res) + if (this.pageVisible) { + this.connected = false + this.socketTask = null + this.msg = "" + console.log('onClose', res) + } }) }, send() { @@ -116,7 +127,7 @@ }, close() { let task = this.socketTask; - if (task != null) { + if (task != null) { let closeOptions = new CloseSocketOptions(); task.close(closeOptions) } diff --git a/pages/component/list/list.uvue b/pages/component/list/list.uvue new file mode 100644 index 00000000..504d81b6 --- /dev/null +++ b/pages/component/list/list.uvue @@ -0,0 +1,87 @@ + + + + \ No newline at end of file diff --git a/pages/component/scroll-view/scroll-view-refresher.uvue b/pages/component/scroll-view/scroll-view-refresher.uvue index 25ff6458..b1ed10ad 100644 --- a/pages/component/scroll-view/scroll-view-refresher.uvue +++ b/pages/component/scroll-view/scroll-view-refresher.uvue @@ -10,7 +10,8 @@ -