command-detail.vue 3.76 KB
<template>
	<view class="command-detail">
		<view class="detail-top">{{ commandDetail.deviceName }}</view>
		<view class="detail">
			<view class="detail-item">
				<view class="detail-label">{{ $t('device.deviceType') }}</view>
				<view class="detail-value">{{ $t(deviceType) }}</view>
			</view>
			<u-line length="90%" margin="0 auto"></u-line>
			<view class="detail-item">
				<view class="detail-label">{{$t('device.deviceNumber')}}</view>
				<view class="detail-value">{{ commandDetail.deviceSn }}</view>
			</view>
			<u-line length="90%" margin="0 auto"></u-line>
			<view class="detail-item">s
				<view class="detail-label">{{ $t('common.belongingOrganization') }}</view>
				<view class="detail-value">{{ commandDetail.organizationName }}</view>
			</view>
			<u-line length="90%" margin="0 auto"></u-line>
			<view class="detail-item">
				<view class="detail-label">{{ $t('device.commandTime') }}</view>
				<view class="detail-value">{{ format(commandDetail.createTime) }}</view>
			</view>
			<u-line length="90%" margin="0 auto"></u-line>
			<view class="detail-item">
				<view class="detail-label">{{ $t('device.commandType') }}</view>
				<view class="detail-value">{{ commandDetail.additionalInfo.cmdType===1?$t('device.service'):$t('common.customText') }}</view>
			</view>
			<u-line length="90%" margin="0 auto" v-if="commandDetail.additionalInfo.cmdType"></u-line>
			<view class="detail-item">
				<view class="detail-label">{{ $t('device.responseType') }}</view>
				<view class="detail-value">{{ commandDetail.request.oneway ? $t('device.oneWay') : $t('device.twoWay') }}</view>
			</view>
			<u-line length="90%" margin="0 auto"></u-line>
			<view class="detail-item">
				<view class="detail-label">{{ $t('device.commandStatus') }}</view>
				<view class="detail-value">{{ commandDetail.statusName }}</view>
			</view>
			<u-line length="90%" margin="0 auto"></u-line>
			<view class="detail-item" v-if="!commandDetail.request.oneway">
				<view class="detail-label">{{ $t('device.responseResults') }}</view>
				<view class="detail-value">{{ commandDetail.response?JSON.stringify(commandDetail.response):$t('common.noText') }}
				</view>
			</view>
		</view>
		<view class="command">{{ $t('device.commandContent') }}</view>
		<u-textarea :value="formatValue(commandDetail.request.body)" disabled></u-textarea>
		<view style="height: 50rpx;"></view>
	</view>
</template>

<script>
	import {
		formatToDate
	} from '@/plugins/utils.js';
	export default {
		data() {
			return {
				commandDetail: {},
				failContent: ""
			};
		},
		computed: {
			deviceType() {
				
				return this.commandDetail.deviceType === 'DIRECT_CONNECTION' ?
					'common.directlyDevice' :
					this.commandDetail.deviceType === 'GATEWAY' ?
					'common.gatewayDevice' :
					this.commandDetail.deviceType === 'SENSOR' ?
					'common.sensorDevice' :
					'';
			}
		},
		methods: {
			format(date) {
				return formatToDate(date, 'YYYY-MM-DD HH:mm:ss');
			},
			formatValue(value) {
				try {
					const val = JSON.parse(value['params']);
					//微信小程序端object无法显示,格式化为字符串
					const stringifyVal = JSON.stringify(val['params'])
					const formatVal = stringifyVal
						.replace(/\\"/g, '"')
						.replace(/]"/g, ']')
						.replace(/"\[/g, '[');
					return formatVal
				} catch (e) {
					return value['params']
				}
			}
		},
		onShow(){
			this.$nextTick(()=>{
				uni.setNavigationBarTitle({
					title:this.$t('menu.commandDetail')
				})
			})	
		},
		onLoad(options) {
			const { data } = options;
			this.commandDetail = JSON.parse(decodeURIComponent(data));
			if (this.commandDetail.response.status === 'SUCCESS') return
			this.failContent = JSON.stringify(this.commandDetail.response.error)
		}
	};
</script>

<style lang="scss" scoped>
	@import "../static/command-detail.scss";
</style>