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

update: 去除过时代码

上级 e2f07cee
......@@ -27,17 +27,14 @@
title: 'downloadFile',
imageSrc: '',
task: null as DownloadTask | null,
pageVisible: false,
//自动化测试例专用
jest_result: false
}
},
onLoad() {
this.pageVisible = true;
},
onUnload() {
this.imageSrc = '';
this.pageVisible = false;
uni.hideLoading();
this.task?.abort();
},
......@@ -50,23 +47,17 @@
this.task = uni.downloadFile({
url: "https://web-assets.dcloud.net.cn/unidoc/zh/uni-app.png",
success: (res) => {
if (this.pageVisible) {
console.log('downloadFile success, res is', res)
self.imageSrc = res.tempFilePath;
uni.hideLoading();
}
},
fail: (err) => {
if (this.pageVisible) {
console.log('downloadFile fail, err is:', err)
uni.hideLoading();
}
}
});
this.task?.onProgressUpdate((update) => {
if (this.pageVisible) {
console.log("progress : ", update.progress);
}
})
},
//自动化测试例专用
......
......@@ -27,21 +27,18 @@
hasNetworkType: false,
networkType: '',
connectedWifi: '',
pageVisible: false,
//自动化测试例专用
jest_result:false,
jest_result: false,
}
},
onLoad() {
this.pageVisible = true;
},
onUnload: function() {
this.pageVisible = false;
onUnload: function () {
this.networkType = '';
this.hasNetworkType = false;
},
methods: {
getNetworkType: function() {
getNetworkType: function () {
uni.getNetworkType({
success: (res) => {
console.log(res)
......@@ -49,22 +46,20 @@
this.networkType = res.networkType
},
fail: () => {
if (this.pageVisible) {
uni.showModal({
content: '获取失败!',
showCancel: false
})
}
}
})
},
clear: function() {
clear: function () {
this.hasNetworkType = false;
this.networkType = '';
this.connectedWifi = '';
},
//自动化测试例专用
jest_getNetworkType(){
jest_getNetworkType() {
uni.getNetworkType({
success: () => {
this.jest_result = true;
......
......@@ -87,7 +87,6 @@
title: 'request',
res: '',
task: null as RequestTask | null,
pageVisible: false,
host: "http://request.dcloud.net.cn",
url: "/api/http/method/get",
method: "GET" as RequestMethod | null,
......@@ -135,10 +134,8 @@
}
},
onLoad() {
this.pageVisible = true;
},
onUnload() {
this.pageVisible = false;
uni.hideLoading();
this.task?.abort();
},
......@@ -191,7 +188,6 @@
withCredentials: false,
firstIpv4: false,
success: (res) => {
if (this.pageVisible) {
console.log('request success', JSON.stringify(res.data))
uni.showToast({
title: '请求成功',
......@@ -200,16 +196,13 @@
duration: duration
});
this.res = '请求结果 : ' + JSON.stringify(res);
}
},
fail: (err) => {
if (this.pageVisible) {
console.log('request fail', err);
uni.showModal({
content: err.errMsg,
showCancel: false
});
}
},
complete: () => {
uni.hideLoading()
......
......@@ -6,15 +6,8 @@
<page-head :title="title"></page-head>
<view class="uni-padding-wrap uni-common-mt">
<view class="demo">
<image
v-if="imageSrc"
:src="imageSrc"
class="image"
mode="widthFix"
></image>
<text v-else class="uni-hello-addfile" @click="chooseImage"
>+ 选择图片</text
>
<image v-if="imageSrc" :src="imageSrc" class="image" mode="widthFix"></image>
<text v-else class="uni-hello-addfile" @click="chooseImage">+ 选择图片</text>
</view>
</view>
</view>
......@@ -23,28 +16,25 @@
<!-- #endif -->
</template>
<script>
export default {
export default {
data() {
return {
title: 'uploadFile',
imageSrc: '',
task: null as UploadTask | null,
pageVisible: false,
//自动化测试例专用
jest_result:false,
jest_result: false,
}
},
onLoad() {
this.pageVisible = true;
},
onUnload() {
this.imageSrc = '';
this.pageVisible = false;
uni.hideLoading();
this.task?.abort();
},
methods: {
chooseImage: function() {
chooseImage: function () {
uni.chooseImage({
count: 1,
sizeType: ['compressed'],
......@@ -63,7 +53,6 @@ export default {
'user': 'test'
},
success: (res) => {
if (this.pageVisible) {
console.log('uploadImage success, res is:', res)
uni.hideLoading();
uni.showToast({
......@@ -72,17 +61,14 @@ export default {
duration: 1000
})
this.imageSrc = imageSrc
}
},
fail: (err) => {
if (this.pageVisible) {
console.log('uploadImage fail', err);
uni.hideLoading();
uni.showModal({
content: err.errMsg,
showCancel: false
});
}
},
});
},
......@@ -92,7 +78,7 @@ export default {
})
},
//自动化测试例专用
jest_uploadFile(){
jest_uploadFile() {
const imageSrc = "/static/uni.png";
this.task = uni.uploadFile({
url: 'https://unidemo.dcloud.net.cn/upload', //仅为示例,非真实的接口地址
......@@ -110,27 +96,27 @@ export default {
})
}
}
}
}
</script>
<style>
.image {
.image {
width: 100%;
}
}
.demo {
.demo {
background: #fff;
padding: 50rpx;
justify-content: center;
align-items: center;
}
}
.uni-hello-addfile {
.uni-hello-addfile {
text-align: center;
background: #fff;
padding: 50rpx;
margin-top: 10px;
font-size: 38rpx;
color: #808080;
}
}
</style>
\ No newline at end of file
......@@ -7,27 +7,20 @@
<button class="uni-btn-v" type="primary" @click="connect">
连接websocket服务
</button>
<button
class="uni-btn-v"
v-show="connected"
type="primary"
@click="send"
>
<button class="uni-btn-v" v-show="connected" type="primary" @click="send">
发送一条消息
</button>
<button class="uni-btn-v" type="primary" @click="close">
断开websocket服务
</button>
<text class="websocket-tips"
>发送消息后会收到一条服务器返回的消息(与发送的消息内容一致)</text
>
<text class="websocket-tips">发送消息后会收到一条服务器返回的消息(与发送的消息内容一致)</text>
</view>
</view>
</view>
</template>
<script lang="uts">
export default {
export default {
data() {
return {
connected: false,
......@@ -35,11 +28,10 @@ export default {
msg: '',
roomId: '',
platform: '',
pageVisible: false,
}
},
computed: {
showMsg(): string {
showMsg() : string {
if (this.connected) {
if (this.msg.length > 0) {
return '收到消息:' + this.msg
......@@ -53,17 +45,15 @@ export default {
},
onLoad() {
this.platform = uni.getSystemInfoSync().platform
this.pageVisible = true
},
onUnload() {
this.pageVisible = false
uni.closeSocket({
code: 1000,
reason: 'close reason from client',
success:(res: any) => {
success: (res : any) => {
console.log('uni.closeSocket success', res)
},
fail:(err: any) => {
fail: (err : any) => {
console.log('uni.closeSocket fail', err)
},
} as CloseSocketOptions)
......@@ -84,17 +74,16 @@ export default {
})
uni.connectSocket({
url: 'ws://websocket.dcloud.net.cn',
success:(res: any) => {
success: (res : any) => {
// 这里是接口调用成功的回调,不是连接成功的回调,请注意
console.log('uni.connectSocket success', res)
},
fail:(err: any) => {
fail: (err : any) => {
// 这里是接口调用失败的回调,不是连接失败的回调,请注意
console.log('uni.connectSocket fail', err)
},
})
uni.onSocketOpen((res) => {
if (this.pageVisible) {
this.connecting = false
this.connected = true
uni.hideLoading()
......@@ -104,10 +93,8 @@ export default {
title: '连接成功',
})
console.log('onOpen', res)
}
})
uni.onSocketError((err) => {
if (this.pageVisible) {
this.connecting = false
this.connected = false
uni.hideLoading()
......@@ -117,20 +104,15 @@ export default {
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() {
......@@ -140,10 +122,10 @@ export default {
this.platform +
' : ' +
parseInt((Math.random() * 10000).toString()).toString(),
success:(res: any) => {
success: (res : any) => {
console.log(res)
},
fail:(err: any) => {
fail: (err : any) => {
console.log(err)
},
} as SendSocketMessageOptions)
......@@ -152,48 +134,48 @@ export default {
uni.closeSocket({
code: 1000,
reason: 'close reason from client',
success:(res: any) => {
success: (res : any) => {
console.log('uni.closeSocket success', res)
},
fail:(err: any) => {
fail: (err : any) => {
console.log('uni.closeSocket fail', err)
},
} as CloseSocketOptions)
},
},
}
}
</script>
<style>
.uni-btn-v {
.uni-btn-v {
padding: 10rpx 0;
}
}
.uni-btn-v {
.uni-btn-v {
margin: 20rpx 0;
}
}
.websocket-room {
.websocket-room {
height: 40px;
line-height: 40px;
text-align: center;
border-bottom: solid 1px #dddddd;
margin-bottom: 20px;
}
}
.websocket-msg {
.websocket-msg {
padding: 40px 0px;
text-align: center;
font-size: 14px;
line-height: 40px;
color: #666666;
}
}
.websocket-tips {
.websocket-tips {
padding: 40px 0px;
text-align: center;
font-size: 14px;
line-height: 24px;
color: #666666;
}
}
</style>
\ No newline at end of file
......@@ -7,27 +7,20 @@
<button class="uni-btn-v" type="primary" @click="connect">
连接websocket服务
</button>
<button
class="uni-btn-v"
v-show="connected"
type="primary"
@click="send"
>
<button class="uni-btn-v" v-show="connected" type="primary" @click="send">
发送一条消息
</button>
<button class="uni-btn-v" type="primary" @click="close">
断开websocket服务
</button>
<text class="websocket-tips"
>发送消息后会收到一条服务器返回的消息(与发送的消息内容一致)</text
>
<text class="websocket-tips">发送消息后会收到一条服务器返回的消息(与发送的消息内容一致)</text>
</view>
</view>
</view>
</template>
<script lang="uts">
export default {
export default {
data() {
return {
connected: false,
......@@ -35,13 +28,12 @@ export default {
socketTask: null as SocketTask | null,
msg: '',
platform: '',
pageVisible: false,
//自动化测试例专用
jest_result: 0,
}
},
computed: {
showMsg(): string {
showMsg() : string {
if (this.connected) {
if (this.msg.length > 0) {
return '收到消息:' + this.msg
......@@ -55,20 +47,18 @@ export default {
},
onLoad() {
this.platform = uni.getSystemInfoSync().platform
this.pageVisible = true
},
onUnload() {
this.pageVisible = false
uni.hideLoading()
let task = this.socketTask
if (task != null) {
task.close({
code: 1000,
reason: 'close reason from client',
success:(res: any) => {
success: (res : any) => {
console.log('uni.closeSocket success', res)
},
fail:(err: any) =>{
fail: (err : any) => {
console.log('uni.closeSocket fail', err)
},
} as CloseSocketOptions)
......@@ -89,17 +79,16 @@ export default {
})
this.socketTask = uni.connectSocket({
url: 'ws://websocket.dcloud.net.cn',
success:(res: any) =>{
success: (res : any) => {
// 这里是接口调用成功的回调,不是连接成功的回调,请注意
console.log('uni.connectSocket success', res)
},
fail:(err: any) =>{
fail: (err : any) => {
// 这里是接口调用失败的回调,不是连接失败的回调,请注意
console.log('uni.connectSocket fail', err)
},
})
this.socketTask?.onOpen((res: any) => {
if (this.pageVisible) {
this.socketTask?.onOpen((res : any) => {
this.connecting = false
this.connected = true
uni.hideLoading()
......@@ -108,10 +97,8 @@ export default {
title: '连接成功',
})
console.log('onOpen', res)
}
})
this.socketTask?.onError((err: any) => {
if (this.pageVisible) {
this.socketTask?.onError((err : any) => {
this.connecting = false
this.connected = false
uni.hideLoading()
......@@ -120,21 +107,16 @@ export default {
showCancel: false,
})
console.log('onError', err)
}
})
this.socketTask?.onMessage((res: OnSocketMessageCallbackResult) => {
if (this.pageVisible) {
this.socketTask?.onMessage((res : OnSocketMessageCallbackResult) => {
this.msg = res.data as string
console.log('onMessage', res)
}
})
this.socketTask?.onClose((res: any) => {
if (this.pageVisible) {
this.socketTask?.onClose((res : any) => {
this.connected = false
this.socketTask = null
this.msg = ''
console.log('onClose', res)
}
})
},
send() {
......@@ -145,10 +127,10 @@ export default {
parseInt(Math.random() * 10000 + '').toString()
this.socketTask?.send({
data,
success:(res: any) =>{
success: (res : any) => {
console.log(res)
},
fail:(err: any) =>{
fail: (err : any) => {
console.log(err)
},
} as SendSocketMessageOptions)
......@@ -157,22 +139,22 @@ export default {
this.socketTask?.close({
code: 1000,
reason: 'close reason from client',
success:(res: any) =>{
success: (res : any) => {
console.log('uni.closeSocket success', res)
},
fail:(err: any) =>{
fail: (err : any) => {
console.log('uni.closeSocket fail', err)
},
} as CloseSocketOptions)
},
//自动化测试例专用
jest_connectSocket(){
jest_connectSocket() {
this.socketTask = uni.connectSocket({
url: 'ws://websocket.dcloud.net.cn',
success:(_) => {
success: (_) => {
this.jest_result++
},
fail:(_) => {
fail: (_) => {
this.jest_result = 0
},
})
......@@ -184,10 +166,10 @@ export default {
parseInt(Math.random() * 10000 + '').toString()
this.socketTask?.send({
data,
success:(_) =>{
success: (_) => {
this.jest_result++
},
fail:(_) =>{
fail: (_) => {
this.jest_result = 0
},
} as SendSocketMessageOptions)
......@@ -197,31 +179,31 @@ export default {
})
}
},
}
}
</script>
<style>
.uni-btn-v {
.uni-btn-v {
padding: 10rpx 0;
}
}
.uni-btn-v {
.uni-btn-v {
margin: 20rpx 0;
}
}
.websocket-msg {
.websocket-msg {
padding: 40px 0px;
text-align: center;
font-size: 14px;
line-height: 40px;
color: #666666;
}
}
.websocket-tips {
.websocket-tips {
padding: 40px 0px;
text-align: center;
font-size: 14px;
line-height: 24px;
color: #666666;
}
}
</style>
\ No newline at end of file
......@@ -6,7 +6,8 @@
<text class="banner-title">{{ banner.title }}</text>
</list-item>
<sticky-header>
<view style="width: 100%;height:44px;background-color: #f5f5f5;flex-direction: row;justify-content:center;align-items:center;">
<view
style="width: 100%;height:44px;background-color: #f5f5f5;flex-direction: row;justify-content:center;align-items:center;">
<text v-for="(name,index) in th_item" @click="clickTH(index)" style="margin-right: 20px;">
{{name}}
</text>
......@@ -52,16 +53,13 @@
banner: {} as Banner,
listData: [] as Item[],
last_id: '',
pageVisible: false
};
},
onLoad() {
this.pageVisible = true; //设这个变量是为了避免联网结束后页面已经关闭,此时还继续执行回调逻辑的问题。不是必须的
this.getBanner();
this.getList();
},
onUnload() {
this.pageVisible = false;
},
methods: {
getBanner() {
......@@ -72,7 +70,6 @@
url: 'https://unidemo.dcloud.net.cn/api/banner/36kr',
data: data,
success: data => {
if (this.pageVisible) {
this.refresherTriggered = false
if (data.statusCode == 200) {
const result = data.data
......@@ -80,7 +77,6 @@
this.banner = result;
}
}
}
},
fail: (e) => {
console.log('fail', e);
......@@ -100,7 +96,6 @@
url: url,
method: "GET",
success: (res) => {
if (this.pageVisible) {
if (res.statusCode == 200) {
console.log(res);
const result = res.data
......@@ -111,14 +106,11 @@
}
this.refresherTriggered = false;
}
}
},
fail: (res) => {
if (this.pageVisible) {
console.log('fail', res);
this.refresherTriggered = false
}
}
});
},
goDetail(e : Item) {
......@@ -139,20 +131,18 @@
url: '/pages/template/list-news/detail/detail?post_id=' + post_id + "&cover=" + cover + "&title=" + title
});
},
clickTH(index:number){
clickTH(index : number) {
uni.showModal({
content: "点击表头项:" + index,
showCancel: false
});
},
onRefresherrefresh() {
if (this.pageVisible) {
this.refresherTriggered = true
this.getBanner();
this.getList();
}
}
}
};
</script>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册