123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570 |
- <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 {
- subType: null,
- signalNum: '',
- interrupt: false,
- powerNum: 160,
- 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,
- cardPass: false,
- room: {
- deviceId: "",
- hotelId: 3,
- building: 2,
- floor: 7,
- room: "7728"
- },
- 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
- },
- {
- id: 3,
- 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.interrupt = true
- // console.log(this.flag);
- uni.navigateBack({
- delta: 1
- })
- } else {
- // this.interrupt = true
- // this.$u.toast(`点击了取消`)
- }
- }
- })
- } else {
- // this.flag = 99
- uni.hideLoading()
- this.interrupt = true
- uni.reLaunch({
- url: "/pages/bluetooth/bluetooth"
- })
- }
- },
- // 测试网关连接
- async testGateway() {
- uni.showLoading({
- 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({
- title: '正在测试信号',
- icon: 'none'
- })
- const {
- data: res
- } = await uni.$http.post('/api/v1/test/bluetooth/checkSignal', obj)
- console.log(res);
- 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 updataTime() {
- uni.showLoading({
- icon: 'none',
- title: "正在下发房间号"
- })
- const {
- data: res
- } = await uni.$http.post('/api/v1/test/bluetooth/setRoom', this.room)
- uni.hideLoading()
- if (res.code == 200) {
- this.flag = 4
- console.log('时间更新成功');
- } else {
- this.$u.toast(`时间更新失败`)
- console.log('时间更新失败');
- }
- },
- // 测试开门
- async openDoor() {
- uni.showLoading({
- title: '蓝牙开门测试中',
- icon: 'none'
- })
- const {
- data: res
- } = await uni.$http.post('/api/v1/test/bluetooth/openDoor', {
- deviceId: this.room.deviceId
- })
- uni.hideLoading()
- if (res.code == 200) {
- this.current1 = 2
- this.flag = 3
- // uni.$u.toast(`开门成功`)
- console.log('开门成功');
- } else {
- this.stepList[1].error = true
- console.log('开门失败');
- // this.stepList[2].error = true
- }
- },
- // 测试刷卡
- async swipe() {
- const {
- data: res
- } = await uni.$http.post('/api/v1/test/bluetooth/queryOpenDoorRes', {
- deviceId: this.room.deviceId,
- type: 5,
- })
- // console.log(res);
- if (res.data.cardOpenDoorRes === true) {
- // this.current1 = 3
- this.cardPass = true
- this.flag = 5
- console.log('开门记录');
- // uni.$u.toast(`刷卡开门成功`)
- } else {
- // this.stepList[2].error = true
- }
- },
- radioChange(n) {
- console.log(n);
- if (n) {
- this.current1 = 4
- this.show7 = false
- this.flag = 6
- } else {
- this.stepList[3].error = true
- this.show7 = false
- }
- // this.show7 = false
- },
- async uploadTest() {
- uni.showLoading({
- 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.showToast({
- // icon: 'none',
- // title: '上传成功',
- // duration: 2000
- // })
- this.$u.toast(`上传成功`)
- // this.uploadBtn = true
- setTimeout(() => {
- this.resetDevice()
- }, 2000)
- // uni.switchTab({
- // url: "/pages/bluetooth/bluetooth"
- // })
- } else {
- uni.$showMsg('上传失败')
- }
- },
- // 重置设备
- 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(`重置成功`)
- } else {
- this.$u.toast(`重置失败`)
- uni.showModal({
- title: '提示',
- content: '设备重置失败,点击确定继续重置',
- success: function(res) {
- if (res.confirm) {
- this.resetDevice()
- } else if (res.cancel) {
- console.log('用户点击取消');
- }
- }
- });
- }
- },
- uploadTestMsg() {
- if (this.flag == 1 || this.flag == 0) {
- console.log('失败的案例');
- console.log(this.uploadMsg);
- if (this.subType == 0 || this.subType == null) {
- this.$set(this.uploadMsg, 'subType', 0)
- }
- 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.$set(this.uploadMsg, 'cardOpenRes', false)
- this.$set(this.uploadMsg, 'signalNum', this.signalNum)
- this.uploadTest()
- }
- if (this.flag == 2) {
- if (this.subType == 0 || this.subType == null) {
- this.$set(this.uploadMsg, 'subType', 0)
- }
- this.$set(this.uploadMsg, 'status', 0)
- this.$set(this.uploadMsg, 'signalRes', true)
- this.$set(this.uploadMsg, 'signalNum', this.signalNum)
- this.$set(this.uploadMsg, 'doorOpenRes', false)
- this.$set(this.uploadMsg, 'powerRes', false)
- this.$set(this.uploadMsg, 'cardOpenRes', false)
- this.uploadTest()
- }
- if (this.flag == 3 || this.flag == 4) {
- if (this.subType == 0 || this.subType == null) {
- this.$set(this.uploadMsg, 'subType', 0)
- }
- this.$set(this.uploadMsg, 'status', 0)
- this.$set(this.uploadMsg, 'signalRes', true)
- this.$set(this.uploadMsg, 'doorOpenRes', true)
- this.$set(this.uploadMsg, 'signalNum', this.signalNum)
- this.$set(this.uploadMsg, 'powerRes', false)
- this.$set(this.uploadMsg, 'cardOpenRes', false)
- this.uploadTest()
- }
- if (this.flag == 5) {
- if (this.subType == 0 || this.subType == null) {
- this.$set(this.uploadMsg, 'subType', 0)
- }
- 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.$set(this.uploadMsg, 'cardOpenRes', true)
- console.log(this.uploadMsg);
- this.uploadTest()
- }
- if (this.flag == 6) {
- if (this.subType == 0 || this.subType == null) {
- this.$set(this.uploadMsg, 'subType', 0)
- }
- this.$set(this.uploadMsg, 'status', 1)
- this.$set(this.uploadMsg, 'signlRes', true)
- this.$set(this.uploadMsg, 'doorOpenRes', true)
- this.$set(this.uploadMsg, 'powerRes', true)
- this.$set(this.uploadMsg, 'cardOpenRes', 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()
- // }
- },
- doorCard() {
- uni.showLoading({
- title: "请刷卡",
- icon: "none"
- })
- this.swipe()
- let counter = 0
- this.timer = setInterval(() => {
- if (this.interrupt) {
- clearInterval(this.timer)
- return
- }
- console.log(counter);
- // 一分钟之后不再自动调取接口
- if (counter == 11) {
- uni.hideLoading()
- clearInterval(this.timer)
- this.$u.toast(`检测到未刷卡`)
- this.stepList[2].error = true
- return
- }
- if (this.cardPass == true) {
- uni.hideLoading()
- this.current1 = 3
- this.show7 = true
- clearInterval(this.timer)
- return
- }
- counter++
- this.swipe()
- }, 5000)
- }
- },
- onUnload() {
- console.log('我是页面卸载函数');
- this.flag = 22
- },
- onLoad(option) {
- console.log(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 || this.interrupt) {
- return
- }
- this.testSignal(obj).then(() => {
- if (this.flag != 2 || this.interrupt) {
- return
- }
- this.openDoor().then(() => {
- if (this.flag != 3 || this.interrupt) {
- return
- }
- this.updataTime().then(() => {
- if (this.flag != 4 || this.interrupt) {
- return
- }
- this.doorCard()
- })
- })
- })
- })
- },
- }
- </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) -->
|