socket
This commit is contained in:
parent
49e5ed4b5c
commit
736ff85457
|
|
@ -57,13 +57,18 @@ class webSocketUtils {
|
|||
// 监听连接失败,这里代码我注释掉的原因是因为如果服务器关闭后,和下面的onclose方法一起发起重连操作,这样会导致重复连接
|
||||
uni.onSocketError((res) => {
|
||||
console.log('网络断开,请检查!');
|
||||
// this.socketTask = null;
|
||||
// this.is_open_socket = false;
|
||||
this.Close()
|
||||
this.socketTask = null;
|
||||
this.is_open_socket = false;
|
||||
// this.Close()
|
||||
this.canReconnect = true;
|
||||
clearInterval(this.heartbeatInterval);
|
||||
clearInterval(this.reconnectTimeOut);
|
||||
if (this.connectNum <= 10) {
|
||||
// uni.showLoading({
|
||||
// title: `网络连接失败,正尝试第${this.connectNum}次连接`,
|
||||
// mask: true
|
||||
// })
|
||||
uni.$emit('message', 1) //进行重连
|
||||
uni.showToast({
|
||||
title: `网络连接失败,正尝试第${this.connectNum}次连接`,
|
||||
icon: 'none',
|
||||
|
|
@ -78,6 +83,13 @@ class webSocketUtils {
|
|||
});
|
||||
this.connectNum = 1;
|
||||
this.canReconnect = false;
|
||||
this.Close()
|
||||
setTimeout(res => {
|
||||
uni.switchTab({
|
||||
url: '/pages/index/index'
|
||||
})
|
||||
uni.hideLoading()
|
||||
}, 1000)
|
||||
}
|
||||
});
|
||||
// 这里仅是事件监听【如果socket关闭了会执行】
|
||||
|
|
@ -134,10 +146,6 @@ class webSocketUtils {
|
|||
clearInterval(this.heartbeatInterval);
|
||||
//如果不是人为关闭的话,进行重连
|
||||
if (!this.is_open_socket) {
|
||||
uni.showLoading({
|
||||
title: '加载中',
|
||||
mask: true
|
||||
})
|
||||
console.log('进行重连');
|
||||
this.canReconnect = true;
|
||||
this.reconnectTimeOut = setInterval(() => {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,41 @@
|
|||
# 测试发现h5不支持
|
||||
## 如何使用
|
||||
```
|
||||
<template>
|
||||
<view class="barrage-test">
|
||||
<vastwu-barrage width="750rpx" height="1300rpx" ref="vBarrage"></vastwu-barrage>
|
||||
</view>
|
||||
</template>
|
||||
<script>
|
||||
const list = ['模拟弹幕效果','宽度如要修改请留意动画是从750rpx到-100%','高度默认100%','随机颜色','随机速度','图标可设置','图标大小可控','可自定义高度轨道','高度轨道数组多长,一屏幕就能播多少列','高度不够不会显示','欢迎使用','不会重叠']
|
||||
import vastwuBarrage from '@/components/vastwu-barrage/vastwu-barrage.vue'
|
||||
export default {
|
||||
components:{vastwuBarrage},
|
||||
data() {
|
||||
return {}
|
||||
},
|
||||
onLoad() {
|
||||
this.$refs.vBarrage.init(list)
|
||||
},
|
||||
methods: {}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.barrage-test{
|
||||
background-color: #C0C0C0
|
||||
}
|
||||
</style>
|
||||
```
|
||||
|
||||
## 参数说明
|
||||
|参数|类型|默认|说明|
|
||||
|:-|:-:|-:|-:|
|
||||
|trackList|Array|[0,100,200,300,400,500,600,700,800,900,1000]|自定义弹幕轨道,值为距离容器顶部的距离,可根据图标高度自行调整|
|
||||
|icon|String||默认图标|
|
||||
|iconWidth|String|62rpx|图标宽度|
|
||||
|iconHeight|String|'86rpx'|图标高度|
|
||||
|minTime|Number|7|最短过渡时间|
|
||||
|maxTime|Number|10|最长过渡时间|
|
||||
|width|String|'100%'|容器宽度|
|
||||
|height|String|'100%'|容器高度|
|
||||
|
|
@ -44,6 +44,19 @@ function requestrequest(options) {
|
|||
}
|
||||
|
||||
async function request(options) {
|
||||
let networkType = ''
|
||||
uni.getNetworkType({
|
||||
success: (res) => {
|
||||
networkType = res.networkType
|
||||
}
|
||||
});
|
||||
if (networkType == 'none') {
|
||||
uni.showToast({
|
||||
title: '网络异常,请检查网络',
|
||||
icon: 'none'
|
||||
})
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
if (options.toast) {
|
||||
// #ifdef MP-WEIXIN || APP-PLUS
|
||||
|
|
|
|||
|
|
@ -274,26 +274,35 @@
|
|||
// });
|
||||
// return;
|
||||
// }
|
||||
let res = await this.api.loginapplogin({
|
||||
username: this.form.loginName,
|
||||
password: this.form.password,
|
||||
code: this.form.code
|
||||
});
|
||||
console.log(res);
|
||||
if (res.code == 0) {
|
||||
uni.cache.set('token', res.data.token);
|
||||
uni.cache.set('miniAppOpenId', res.data.userInfo
|
||||
.miniAppOpenId)
|
||||
uni.cache.set('userInfo', res.data.userInfo);
|
||||
if (uni.cache.get('types') == 'types') {
|
||||
uni.reLaunch({
|
||||
url: '/pages/order_food/order_food'
|
||||
// #ifdef MP-WEIXIN
|
||||
uni.login({
|
||||
provider: 'weixin',
|
||||
success: async (data) => {
|
||||
let res = await this.api.loginapplogin({
|
||||
username: this.form.loginName,
|
||||
password: this.form.password,
|
||||
code: this.form.code,
|
||||
opencode: data.code
|
||||
});
|
||||
} else {
|
||||
uni.pro.switchTab('index/index')
|
||||
}
|
||||
console.log(res);
|
||||
if (res.code == 0) {
|
||||
uni.cache.set('token', res.data.token);
|
||||
uni.cache.set('miniAppOpenId', res.data.userInfo
|
||||
.miniAppOpenId)
|
||||
uni.cache.set('userInfo', res.data.userInfo);
|
||||
if (uni.cache.get('types') == 'types') {
|
||||
uni.reLaunch({
|
||||
url: '/pages/order_food/order_food'
|
||||
});
|
||||
} else {
|
||||
uni.pro.switchTab('index/index')
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
});
|
||||
// #endif
|
||||
|
||||
}
|
||||
|
||||
},
|
||||
// async getPhoneNumber(res) { // 获取手机号
|
||||
|
|
|
|||
|
|
@ -65,7 +65,8 @@
|
|||
空
|
||||
</view>
|
||||
<view class="shop-item" v-for="(item1,index1) in item.products" :key="item1.id">
|
||||
<view class="cover langcover" style="width:180rpx; height: 180rpx;" @click.stop="clickspecifications(item1,index,index1)">
|
||||
<view class="cover langcover" style="width:180rpx; height: 180rpx;"
|
||||
@click.stop="clickspecifications(item1,index,index1)">
|
||||
<c-image style="position: absolute;z-index:2;"
|
||||
:src="`${item1.coverImg}?x-oss-process=image/resize,m_lfit,w_90,h_90`" width="180"
|
||||
height="180"></c-image>
|
||||
|
|
@ -229,12 +230,7 @@
|
|||
</view>
|
||||
</view>
|
||||
</u-popup>
|
||||
<u-popup :show="popupshowInfo" :round="20" mode="center" @close="popupshowInfo = false"
|
||||
:safeAreaInsetBottom='false'>
|
||||
<view class="showInfo">
|
||||
|
||||
</view>
|
||||
</u-popup>
|
||||
<!-- <vastwu-barrage width="750rpx" height="1300rpx" ref="vBarrage"></vastwu-barrage> -->
|
||||
</view>
|
||||
</template>
|
||||
|
||||
|
|
@ -242,7 +238,9 @@
|
|||
import _ from 'lodash';
|
||||
import navbar from '../../uni_modules/uview-ui/libs/config/props/navbar';
|
||||
import webSocketUtils from '@/common/js/websocket.js'
|
||||
// import vastwuBarrage from '@/components/vastwu-barrage/vastwu-barrage.vue'
|
||||
export default {
|
||||
// components:{vastwuBarrage},
|
||||
data() {
|
||||
return {
|
||||
// #ifndef MP-WEIXIN
|
||||
|
|
@ -257,7 +255,6 @@
|
|||
shopList: {}, //数据类型
|
||||
active: 0,
|
||||
showShopInfo: false,
|
||||
popupshowInfo: false,
|
||||
showShopsku: false,
|
||||
titleTopNumIndex: 0,
|
||||
titleTopNums: [],
|
||||
|
|
@ -299,6 +296,7 @@
|
|||
this.$nextTick(() => {
|
||||
this.countTitleTopNum(); //导航栏
|
||||
});
|
||||
// this.$refs.vBarrage.init([123])
|
||||
},
|
||||
onUnload() {
|
||||
this.socketTicket.Close()
|
||||
|
|
@ -349,6 +347,11 @@
|
|||
// })
|
||||
// }
|
||||
// });
|
||||
if (msg == 1) { // 网络在连接
|
||||
this.fixedtrue = true
|
||||
return false
|
||||
}
|
||||
this.fixedtrue = false
|
||||
if (msg.status != 'success') {
|
||||
uni.showToast({
|
||||
title: msg.msg,
|
||||
|
|
@ -429,8 +432,12 @@
|
|||
},
|
||||
// 数据处理
|
||||
socketSendMsg(data) {
|
||||
console.log(data, 1111)
|
||||
if (this.socketTicket) {
|
||||
console.log(222)
|
||||
this.socketTicket.send(data);
|
||||
} else {
|
||||
console.log(333)
|
||||
}
|
||||
},
|
||||
getQueryString(url, name) { //解码
|
||||
|
|
@ -471,9 +478,6 @@
|
|||
})
|
||||
if (res.code == 0) {
|
||||
this.shopList = res.data
|
||||
setTimeout(() => {
|
||||
this.fixedtrue = false
|
||||
}, 1000)
|
||||
this.$nextTick(() => {
|
||||
this.countTitleTopNum();
|
||||
});
|
||||
|
|
@ -515,6 +519,8 @@
|
|||
this.hodgepodge(item, 2)
|
||||
},
|
||||
async hodgepodge(item, a, c) { //此接口去获取商品id !!!赋值库存 数量 价格等
|
||||
console.log(11111)
|
||||
|
||||
try {
|
||||
let res = await this.api.productqueryProductSku({
|
||||
shopId: uni.cache.get('shopUser'),
|
||||
|
|
@ -1158,12 +1164,6 @@
|
|||
}
|
||||
}
|
||||
|
||||
.showInfo {
|
||||
width: 100%;
|
||||
border-radius: 20rpx;
|
||||
background: #fff;
|
||||
max-height: 70vh;
|
||||
}
|
||||
|
||||
.shop-info-wrap {
|
||||
.info-wrap {
|
||||
|
|
|
|||
Loading…
Reference in New Issue