123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437 |
- <template>
- <view class="u-page">
- <view class="" style="height: 44px;margin-bottom: 88rpx;">
- <u-navbar bgColor="#3c9cff" title="模块测试" @leftClick="leftClick">
- </u-navbar>
- </view>
- <view class="u-demo-block">
- <view class="u-demo-block__content steps">
- <u-steps :current="current1" direction="column">
- <u-steps-item class="steps-item" v-for="item in stepList" :key="item.id" :error="item.error"
- :title="item.title" :desc="item.desc">
- </u-steps-item>
- <!-- <u-steps-item title="测试开门" desc="10:35">
- </u-steps-item>
- <u-steps-item title="测试刷卡" desc="11:40">
- </u-steps-item>
- <u-steps-item title="输入功耗" desc="11:40">
- </u-steps-item> -->
- </u-steps>
- </view>
- </view>
- <view class="upload">
- <u-button :disabled="uploadBtn" type="primary" size="large" @click="uploadTestMsg">完成测试并上传信息</u-button>
- </view>
- <u-popup customStyle="width: 70vw" :round="10" mode="center" :show="show7" @close="close">
- <view class="popupView" style="height: 150px;">
- <view class="power">
- 功耗选择
- </view>
- <view class="inputNum" style="">
- <view class="">
- 功耗:
- </view>
- <u--input placeholder="请输入功耗" border="surround" v-model="powerNum"
- @change="changeInput"></u--input>
- </view>
- <u-radio-group placement="row">
- <u-radio :customStyle="{margin: '15px 30px'}" v-for="(item, index) in radiolist1" :key="index"
- :label="item.value" :name="item.powerRefs" @change="radioChange" iconPlacement="right">
- </u-radio>
- </u-radio-group>
- </view>
- </u-popup>
- </view>
- </template>
- <script>
- export default {
- data() {
- return {
- powerNum: 160,
- subType:null,
- uploadBtn: false,
- uploadMsg: {
- testProjectId: uni.getStorageSync('testProjectId'),
- deviceId: "",
- type: null
-
- },
- radiolist1: [{
- value: '通过',
- disabled: false,
- powerRefs: true
- },
- {
- value: '不通过',
- disabled: false,
- powerRefs: false
- }
- ],
- show7: false,
- flag: 0,
- timer: null,
- signalNum: '',
- gatewayDeviceId: uni.getStorageSync('gatewayDeviceId'),
- show: false,
- current1: null,
- stepList: [{
- id: 0,
- title: '测试信号',
- desc: '测试蓝牙设备信号值是否通过',
- error: false
- }, {
- id: 1,
- title: '蓝牙测试开门',
- desc: '测试蓝牙进行门锁开门',
- error: false
- },
- {
- id: 2,
- title: '测试功率',
- desc: '验证功耗是否通过',
- error: false
- }
- ]
- }
- },
- methods: {
- changeInput(e) {
- console.log(e);
- },
- leftClick() {
- let a = this.stepList.every((item) => {
- return item.error == true
- })
- console.log(a);
- if (a) {
- console.log('模态框');
- uni.hideLoading()
- uni.showModal({
- title: '温馨提示',
- content: '确定取消上传本次测试信息吗?',
- success: res => {
- if (res.confirm) {
- // this.show1 = false
- this.$u.toast(`点击了确定`)
- this.flag = 99
- // console.log(this.flag);
- uni.navigateBack({
- delta: 1
- })
- } else {
- // this.$u.toast(`点击了取消`)
- }
- }
- })
- } else {
- uni.navigateBack({
- delta: 1
- })
- }
- },
- // 测试网关连接
- async testGateway() {
- uni.showLoading({
- mask: true,
- title: '正在测试网关连接',
- icon: 'none'
- })
- const {
- data: res
- } = await uni.$http.get(`/api/v1/test/gateway/connection/${this.gatewayDeviceId}`)
- uni.hideLoading()
- if (res.data.isConnect == true) {
- this.flag = 1
- console.log('网关连接成功');
- } else {
- console.log('网关连接失败');
- this.$u.toast(`网关连接失败`)
- }
- },
- // 测试信号
- async testSignal(obj) {
- uni.showLoading({
- mask: true,
- title: '正在测试信号',
- icon: 'none'
- })
- const {
- data: res
- } = await uni.$http.post('/api/v1/test/bluetooth/checkSignal', obj)
- uni.hideLoading()
- if (res.data.isNormal == true) {
- this.current1 = 1
- this.flag = 2
- console.log('信号测试成功');
- } else {
- this.stepList[0].error = true
- console.log('信号测试失败');
- this.$u.toast(`信号测试失败`)
- }
- },
- // 测试开门
- async openDoor() {
- uni.showLoading({
- mask: true,
- title: '蓝牙开门测试中',
- icon: 'none'
- })
- const {
- data: res
- } = await uni.$http.post('/api/v1/test/bluetooth/openDoor', {
- deviceId: this.uploadMsg.deviceId
- })
- uni.hideLoading()
- if (res.code == 200) {
- this.current1 = 2
- this.flag = 3
- // uni.$u.toast(`开门成功`)
- this.show7 = true
- console.log('开门成功');
- } else {
- this.stepList[1].error = true
- console.log('开门失败');
- }
- },
- radioChange(n) {
- console.log(n);
- if (n) {
- this.current1 = 3
- this.show7 = false
- this.flag = 4
- } else {
- this.stepList[2].error = true
- this.show7 = false
- }
- // this.show7 = false
- },
- async uploadTest() {
- uni.showLoading({
- mask: true,
- title: "正在上传本次测试结果",
- icon: 'none'
- })
- let {
- data: res
- } = await uni.$http.post('/api/v1/test/testResult', this.uploadMsg)
- uni.hideLoading()
- console.log(res);
- if (res.code == 200) {
- uni.$showMsg('上传成功')
- // this.uploadBtn = true
- setTimeout(() => {
- this.resetDevice()
- }, 1500)
-
- // uni.switchTab({
- // url: "/pages/bluetooth/bluetooth"
- // })
- } else {
- uni.$showMsg('上传失败')
- }
- },
- uploadTestMsg() {
- if (this.flag == 1 || this.flag == 0) {
- console.log('失败的案例');
- console.log(this.uploadMsg);
- if(this.subType==1){
- this.$set(this.uploadMsg, 'subType', this.subType)
- }
- this.$set(this.uploadMsg, 'signalNum', this.signalNum)
- this.$set(this.uploadMsg, 'status', 0)
- this.$set(this.uploadMsg, 'signalRes', false)
- this.$set(this.uploadMsg, 'doorOpenRes', false)
- this.$set(this.uploadMsg, 'powerRes', false)
-
-
- this.uploadTest()
- }
- if (this.flag == 2) {
- if(this.subType==1){
- this.$set(this.uploadMsg, 'subType', this.subType)
- }
- this.$set(this.uploadMsg, 'signalNum', this.signalNum)
- this.$set(this.uploadMsg, 'status', 0)
- this.$set(this.uploadMsg, 'signalRes', true)
- this.$set(this.uploadMsg, 'doorOpenRes', false)
- this.$set(this.uploadMsg, 'powerRes', false)
- this.uploadTest()
- }
- if (this.flag == 3) {
- if(this.subType==1){
- this.$set(this.uploadMsg, 'subType', this.subType)
- }
- this.$set(this.uploadMsg, 'signalNum', this.signalNum)
- this.$set(this.uploadMsg, 'status', 0)
- this.$set(this.uploadMsg, 'signalRes', true)
- this.$set(this.uploadMsg, 'doorOpenRes', true)
- this.$set(this.uploadMsg, 'powerRes', false)
- this.uploadTest()
- }
- if (this.flag == 4) {
- if(this.subType==1){
- this.$set(this.uploadMsg, 'subType', this.subType)
- }
- this.$set(this.uploadMsg, 'signalNum', this.signalNum)
- this.$set(this.uploadMsg, 'status', 1)
- this.$set(this.uploadMsg, 'signalRes', true)
- this.$set(this.uploadMsg, 'doorOpenRes', true)
- this.$set(this.uploadMsg, 'powerRes', true)
- this.$set(this.uploadMsg, 'powerNum', this.powerNum)
- console.log(this.uploadMsg);
- this.uploadTest()
- }
- // else {
- // console.log('失败的案例');
- // console.log(this.uploadMsg);
- // this.$set(this.uploadMsg, 'status', 0)
- // this.uploadTest()
- // }
- },
- async resetDevice() {
- uni.showLoading({
- icon: 'none',
- title: '正在重置设备',
- })
- let {
- data: res
- } = await uni.$http.post('/api/v1/test/bluetooth/resetDevice', {
- deviceId: this.uploadMsg.deviceId
- })
- console.log(res);
- uni.hideLoading()
- if (res.code == 200) {
- this.$u.toast(`重置成功`)
- uni.switchTab({
- url:"/pages/bluetooth/bluetooth"
- })
- } else {
- this.$u.toast(`重置失败`)
-
-
- }
- },
- },
- onLoad(option) {
- let item = JSON.parse(option.item)
- console.log(item);
- this.subType=item.subType
- this.signalNum = item.signalNum
- this.uploadMsg.deviceId = item.deviceId
- this.uploadMsg.type = item.type
- // this.room.deviceId = item.deviceId
- const obj = {
- testProjectId: uni.getStorageSync('testProjectId'),
- deviceId: item.deviceId
- }
- this.testGateway().then(() => {
- if (this.flag != 1) {
- return
- }
- this.testSignal(obj).then(() => {
- if (this.flag != 2) {
- return
- }
- this.openDoor().then(() => {
- // if (this.flag != 3) {
- // return
- // }
- })
- })
- })
- },
- }
- </script>
- <style lang="scss">
- .steps {
- display: flex;
- justify-content: center;
- align-items: center;
- .u-steps-item {
- height: 25vh;
- width: calc(100vw - 20px);
- margin: 30px 10px;
- // background-color: red;
- .u-steps-item__line {
- height: 100px !important;
- }
- }
- // .u-steps-item {
- // width: 100vw;
- // height: 25vh;
- // background-color: blue;
- // }
- }
- .upload {
- position: fixed;
- bottom: 0;
- width: 100vw;
- }
- .power {
- text-align: center;
- margin: 13px 0 20px 0;
- }
- .inputNum {
- display: flex;
- justify-content: center;
- align-items: center;
- padding: 0 20rpx;
- }
- .u-radio-group {
- margin-top: 20rpx;
- }
- </style>
- <!-- this.timer = setInterval(() => {
- this.current1++
- console.log(this.current1);
- if (this.current1 === 2) {
- this.btnShow = false
- }
- if (this.current1 === 3) {
- uni.showLoading({
- title: '加载中',
- mask: true
- });
- uni.hideLoading()
- this.stepList[3].error = true
- clearInterval(this.timer)
- }
- }, 3000) -->
|