Browse Source

bug 修复

lilei 4 years ago
parent
commit
e6f282603a
4 changed files with 58 additions and 11 deletions
  1. 2 2
      App.vue
  2. 2 0
      pages/getOrder/getOrder.vue
  3. 34 6
      pages/work/index/index.vue
  4. 20 3
      store/index.js

+ 2 - 2
App.vue

@@ -1,6 +1,6 @@
 <script>
-	const uat_URL = 'https://carwash.test.zyucgj.com/cw-wechat/' // 预发布
-	// const uat_URL = 'http://192.168.16.103:8103/cw-wechat/' // 本地
+	// const uat_URL = 'https://carwash.test.zyucgj.com/cw-wechat/' // 预发布
+	const uat_URL = 'http://192.168.16.103:8103/cw-wechat/' // 本地
 	const pro_URL = 'https://carwash.zyucgj.com/saas/clz/'  // 生产
 	const buildType = 0 // 打包环境对应类型,1 生产 0 预发布
 	const buildURL = buildType ? pro_URL : uat_URL // 打包后实际对应的url

+ 2 - 0
pages/getOrder/getOrder.vue

@@ -417,6 +417,8 @@
 			// 付款成功后
 			paySuccess(){
 				this.$store.state.vuex_orderInfo.orderStatus = 'PAID'
+				this.$store.state.orderDjs = 0
+				this.$store.state.loadingDjs = 0
 				// 付款成功后开始洗车
 				uni.redirectTo({
 					url: `/pages/work/index/index`

+ 34 - 6
pages/work/index/index.vue

@@ -36,6 +36,7 @@
 				<view class="work-dtime" v-if="status=='start'">
 					距离订单强制完成还剩
 					<u-count-down
+					    v-if="timestamp>0"
 						@end="endDtime"
 						separator="zh"
 						font-size="36"
@@ -110,7 +111,7 @@
 export default {
 	data() {
 		return {
-			timestamp: 300, // 初始情况下5分钟后自动结束
+			timestamp: 0, // 初始情况下5分钟后自动结束
 			rdeg: -135, // 进度条初始角度
 			ldeg: -135, /// 进度条初始角度
 			step: 0, // 进度条增值,共60步
@@ -124,20 +125,45 @@ export default {
 			orderNo: '',// 订单编号
 		};
 	},
+	onShow() {
+		console.log("onShow")
+		// 计算当前倒计时
+		let od = this.$store.state.orderDjs
+		if(od!=0){
+			let d = new Date().getTime() - od
+			this.timestamp = 300 - d/1000
+		}
+		// 计算当前进度条步数
+		let ld = this.$store.state.loadingDjs
+		let serverTime = this.washDuration / 60 * 1000
+		if(ld!=0){
+			let lod = new Date().getTime() - ld
+			this.step = this.step + Math.floor(lod/serverTime)
+		}
+	},
 	onLoad(options) {
+		console.log("onLoad")
 		// 创建websocket
 		this.$store.commit('$webSocket')
+		
 		// 获取用户及订单信息
 		let orderInfo = this.$store.state.vuex_orderInfo
 		this.washCarType = orderInfo.itemCode
 		this.orderNo = orderInfo.orderNo
 		this.washDuration = orderInfo.duration
-		
+		// 记录当前的时间
+		this.$store.state.orderDjs = new Date().getTime()
 		// 监听消息
 		uni.$on('wsMessage',(e)=>{
-			console.log(e.data.level,e.data.msgCode,e.data.msgCodeInfo)
-			console.log("--------------------------------------------")
-			if(e.type == 'xcz'){
+			if(typeof e == 'string'){
+				// 连接成功
+				if(e=='connected'){
+					
+				}
+			}
+			if(typeof e == 'object' && e.type == 'xcz'){
+				console.log(e.data.level,e.data.msgCode,e.data.msgCodeInfo)
+				console.log("--------------------------------------------")
 				// 进度消息
 				if(e.data.level == 'C'&&this.status!="reseting"){
 					 // 启动成功
@@ -245,7 +271,9 @@ export default {
 				this.curWorkStutesText='设备已启动';
 				this.showStart = false;
 				this.step = 0;
-				let serverTime = 0.5
+				let serverTime = this.washDuration / 60; // 转换成分钟
+				// 记录当前的开始时间
+				this.$store.state.loadingDjs = new Date().getTime()
 				this.interId = setInterval(()=>{
 					// 小于60时说明洗车机正在工作中
 					if(this.step<=60){

+ 20 - 3
store/index.js

@@ -12,7 +12,18 @@ try{
 }
 
 // 需要永久存储,且下次APP启动需要取出的,在state中的变量名
-let saveStateKeys = ['vuex_user', 'vuex_token', 'vuex_userData','vuex_payType','vuex_payStatus','vuex_storeLabel','vuex_orderInfo','vuex_workStatus'];
+let saveStateKeys = [
+	'vuex_user', 
+	'vuex_token', 
+	'vuex_userData',
+	'vuex_payType',
+	'vuex_payStatus',
+	'vuex_storeLabel',
+	'vuex_orderInfo',
+	'vuex_workStatus',
+	'orderDjs',
+	'loadingDjs',
+];
 
 // 保存变量到本地存储中
 const saveLifeData = function(key, value){
@@ -52,7 +63,10 @@ const store = new Vuex.Store({
 			duration: 0, // 不同服务的机器运行时间
 			orderNo: '',// 订单编号
 			orderStatus: '' // 订单状态
-		}
+		},
+		// 设备运行页面的计时器
+		orderDjs: 0, // 订单完成倒计时
+		loadingDjs: 0 // 进度条倒计时
 	},
 	mutations: {
 		$uStore(state, payload) {
@@ -104,11 +118,14 @@ const store = new Vuex.Store({
 			})
 			// 接受消息
 			state.vuex_socket.onMessage(function(e){
-				if (e.data != 'pong'){
+				if (typeof(e.data) == 'object'){
 				  let ret = JSON.parse(e.data)
 				  console.log('ws接收消息!', ret)
 				  uni.$emit('wsMessage',ret)
 				}
+				if(typeof(e.data) == 'string'){
+					uni.$emit('wsMessage',e.data)
+				}
 			})
 			// 发送心跳包
 			state.vuex_heartInterId = setInterval(function () {