cat-eye-test.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459
  1. <template>
  2. <view class="u-page">
  3. <view class="" style="height: 44px;margin-bottom: 88rpx;">
  4. <u-navbar bgColor="#3c9cff" title="猫眼测试" @leftClick="leftClick">
  5. </u-navbar>
  6. </view>
  7. <view class="u-demo-block">
  8. <view class="u-demo-block__content steps">
  9. <u-steps :current="current1" direction="column">
  10. <u-steps-item class="steps-item" v-for="item in stepList" :key="item.id" :error="item.error"
  11. :title="item.title" :desc="item.desc">
  12. </u-steps-item>
  13. <!-- <u-steps-item title="测试开门" desc="10:35">
  14. </u-steps-item>
  15. <u-steps-item title="测试刷卡" desc="11:40">
  16. </u-steps-item>
  17. <u-steps-item title="输入功耗" desc="11:40">
  18. </u-steps-item> -->
  19. </u-steps>
  20. </view>
  21. </view>
  22. <view class="upload" style="width: 100vw;">
  23. <u-button :disabled="uploadBtn" type="primary" size="large" @click="uploadTestMsg">完成测试并上传信息</u-button>
  24. </view>
  25. <u-modal :show="show1" :title="title" :content='content1' @confirm="confirm" :asyncClose="true">
  26. <u-button @click=pass slot="confirmButton" type="primary" text="通过" shape="circle"></u-button>
  27. <u-button @click="noPass" slot="confirmButton" type="error" text="不通过" shape="circle"></u-button>
  28. </u-modal>
  29. <u-popup customStyle="width: 70vw" :round="10" mode="center" :show="show7" @close="close">
  30. <view class="popupView" style="height: 150px;">
  31. <view class="power">
  32. 功耗选择
  33. </view>
  34. <view class="inputNum" style="">
  35. <view class="">
  36. 功耗:
  37. </view>
  38. <u--input placeholder="请输入功耗" border="surround" v-model="powerNum" @change="changeInput"></u--input>
  39. </view>
  40. <u-radio-group placement="row">
  41. <u-radio :customStyle="{margin: '15px 30px'}" v-for="(item, index) in radiolist1" :key="index"
  42. :label="item.value" :name="item.powerRefs" @change="radioChange" iconPlacement="right">
  43. </u-radio>
  44. </u-radio-group>
  45. </view>
  46. </u-popup>
  47. </view>
  48. </template>
  49. <script>
  50. export default {
  51. data() {
  52. return {
  53. signalNum: '',
  54. uploadBtn: false,
  55. powerNum: 160,
  56. uploadMsg: {
  57. testProjectId: uni.getStorageSync('testProjectId'),
  58. deviceId: "",
  59. type: null
  60. },
  61. radiolist1: [{
  62. value: '通过',
  63. disabled: false,
  64. powerRefs: true
  65. },
  66. {
  67. value: '不通过',
  68. disabled: false,
  69. powerRefs: false
  70. }
  71. ],
  72. show7: false,
  73. flag: 0,
  74. gatewayDeviceId: uni.getStorageSync('gatewayDeviceId'),
  75. show1: false,
  76. title: '温馨提示',
  77. content1: '系统已成功植入您的人脸,请问您的人脸验证是否通过',
  78. obj: {
  79. testProjectId: uni.getStorageSync('testProjectId'),
  80. deviceId: ""
  81. },
  82. show: false,
  83. current1: null,
  84. timer: null,
  85. stepList: [{
  86. id: 0,
  87. title: '测试信号',
  88. desc: '测试网关信号',
  89. error: false
  90. }, {
  91. id: 1,
  92. title: '测试人脸开门',
  93. desc: '测试人脸是否开门正常',
  94. error: false
  95. },
  96. {
  97. id: 2,
  98. title: '功耗输入',
  99. desc: '测试功耗',
  100. error: false
  101. }
  102. ]
  103. }
  104. },
  105. methods: {
  106. changeInput(e) {
  107. console.log('change', e);
  108. },
  109. radioChange(n) {
  110. console.log(n);
  111. if (n) {
  112. this.current1 = 3
  113. this.show7 = false
  114. this.flag = 6
  115. } else {
  116. this.stepList[2].error = true
  117. this.show7 = false
  118. }
  119. this.show7 = false
  120. },
  121. pass() {
  122. this.current1 = 2
  123. this.show1 = false
  124. this.flag = 5
  125. this.show7 = true
  126. },
  127. noPass() {
  128. this.show1 = false
  129. this.stepList[1].error = true
  130. },
  131. async uploadTest() {
  132. uni.showLoading({
  133. mask: true,
  134. title: "正在上传本次测试结果",
  135. icon: 'none'
  136. })
  137. let {
  138. data: res
  139. } = await uni.$http.post('/api/v1/test/testResult', this.uploadMsg)
  140. uni.hideLoading()
  141. console.log(res);
  142. if (res.code == 200) {
  143. uni.$showMsg('上传成功')
  144. // this.uploadBtn = true
  145. setTimeout(() => {
  146. this.resetDevice()
  147. }, 1500)
  148. } else {
  149. uni.$showMsg('上传失败')
  150. }
  151. },
  152. // 重置设备
  153. async resetDevice() {
  154. uni.showLoading({
  155. mask: true,
  156. icon: 'none',
  157. title: '正在重置设备',
  158. })
  159. let {
  160. data: res
  161. } = await uni.$http.post('/api/v1/test/bluetooth/resetDevice', {
  162. deviceId: this.uploadMsg.deviceId
  163. })
  164. console.log(res);
  165. uni.hideLoading()
  166. if (res.code == 200) {
  167. this.$u.toast(`重置成功`)
  168. uni.switchTab({
  169. url:"/pages/bluetooth/bluetooth"
  170. })
  171. } else {
  172. this.$u.toast(`重置失败`)
  173. }
  174. },
  175. uploadTestMsg() {
  176. console.log(this.uploadMsg);
  177. if (this.flag == 0 || this.flag == 1 || this.flag == 2) {
  178. this.$set(this.uploadMsg, 'signalNum', this.signalNum)
  179. this.$set(this.uploadMsg, 'status', 0)
  180. // this.$set(this.uploadMsg, 'faceOpenRes', true)
  181. this.$set(this.uploadMsg, 'signalRes', false)
  182. this.$set(this.uploadMsg, 'faceOpenRes', false)
  183. this.$set(this.uploadMsg, 'powerRes', false)
  184. this.uploadTest()
  185. }
  186. if (this.flag == 3 || this.flag == 4) {
  187. this.$set(this.uploadMsg, 'signalNum', this.signalNum)
  188. this.$set(this.uploadMsg, 'status', 0)
  189. this.$set(this.uploadMsg, 'signalRes', true)
  190. this.$set(this.uploadMsg, 'faceOpenRes', false)
  191. this.$set(this.uploadMsg, 'powerRes', false)
  192. this.uploadTest()
  193. }
  194. if (this.flag == 5) {
  195. this.$set(this.uploadMsg, 'signalNum', this.signalNum)
  196. this.$set(this.uploadMsg, 'status', 0)
  197. this.$set(this.uploadMsg, 'signalRes', true)
  198. this.$set(this.uploadMsg, 'faceOpenRes', true)
  199. this.$set(this.uploadMsg, 'powerRes', false)
  200. this.$set(this.uploadMsg, 'powerNum', this.powerNum)
  201. console.log(this.uploadMsg);
  202. this.uploadTest()
  203. }
  204. if (this.flag == 6) {
  205. this.$set(this.uploadMsg, 'signalNum', this.signalNum)
  206. this.$set(this.uploadMsg, 'status', 1)
  207. this.$set(this.uploadMsg, 'signalRes', true)
  208. this.$set(this.uploadMsg, 'faceOpenRes', true)
  209. this.$set(this.uploadMsg, 'powerRes', true)
  210. this.$set(this.uploadMsg, 'powerNum', this.powerNum)
  211. console.log(this.uploadMsg);
  212. this.uploadTest()
  213. }
  214. },
  215. leftClick() {
  216. let a = this.stepList.every((item) => {
  217. return item.error == true
  218. })
  219. console.log(a);
  220. if (a) {
  221. console.log('模态框');
  222. uni.hideLoading()
  223. uni.showModal({
  224. title: '温馨提示',
  225. content: '确定取消上传本次测试信息吗?',
  226. success: res => {
  227. if (res.confirm) {
  228. // this.show1 = false
  229. this.$u.toast(`点击了确定`)
  230. this.flag = 99
  231. // console.log(this.flag);
  232. uni.navigateBack({
  233. delta: 1
  234. })
  235. } else {
  236. // this.$u.toast(`点击了取消`)
  237. }
  238. }
  239. })
  240. } else {
  241. uni.navigateBack({
  242. delta: 1
  243. })
  244. }
  245. },
  246. // 测试网关连接
  247. async testGateway() {
  248. uni.showLoading({
  249. title: '正在测试网关连接',
  250. icon: 'none'
  251. })
  252. const {
  253. data: res
  254. } = await uni.$http.get(`/api/v1/test/gateway/connection/${this.gatewayDeviceId}`)
  255. uni.hideLoading()
  256. if (res.data.isConnect == true) {
  257. this.flag = 1
  258. console.log('网关连接成功');
  259. } else {
  260. console.log('网关连接失败');
  261. this.$u.toast(`网关连接失败`)
  262. }
  263. },
  264. // 测试信号
  265. async testSignal() {
  266. uni.showLoading({
  267. mask: true,
  268. title: '信号测试中',
  269. icon: 'none'
  270. })
  271. const {
  272. data: res
  273. } = await uni.$http.post('/api/v1/test/bluetooth/checkSignal', this.obj)
  274. uni.hideLoading()
  275. if (res.data.isNormal == true) {
  276. this.current1 = 1
  277. this.flag = 3
  278. console.log('信号测试成功')
  279. } else {
  280. this.$u.toast(`信号测试失败`)
  281. }
  282. },
  283. // 检测人脸是否上传
  284. async faceHas() {
  285. uni.showLoading({
  286. mask: true,
  287. title: '检测人脸是否上传',
  288. icon: 'none'
  289. })
  290. let {
  291. data: res
  292. } = await uni.$http.get(`/api/v1/test/user/${uni.getStorageSync('userId')}/hasUploadFace`)
  293. uni.hideLoading()
  294. if (res.data.hasUploadFace === true) {
  295. console.log('人脸已上传');
  296. this.flag = 2
  297. } else {
  298. this.$u.toast(`人脸未上传,请去我的页面上传人脸`)
  299. }
  300. },
  301. // confirm() {
  302. // setTimeout(() => {
  303. // // 3秒后自动关闭
  304. // this.show = false;
  305. // uni.switchTab({
  306. // url: "/pages/mine/mine"
  307. // })
  308. // }, 2000)
  309. // },
  310. // 猫眼植入特征值
  311. async uploadFace() {
  312. uni.showLoading({
  313. mask: true,
  314. title: '下发人脸',
  315. icon: 'none'
  316. })
  317. let {
  318. data: res
  319. } =
  320. await uni.$http.post('/api/v1/test/bluetooth/addTestFaceToCam', {
  321. userId: uni.getStorageSync('userId'),
  322. deviceId: this.obj.deviceId
  323. })
  324. // console.log(res);
  325. uni.hideLoading()
  326. if (res.code === 200) {
  327. this.show1 = true
  328. console.log('植入成功');
  329. uni.showToast({
  330. duration: 1500,
  331. title: '人脸植入成功',
  332. icon: 'none'
  333. })
  334. this.show1 = true
  335. this.flag = 4
  336. } else {
  337. this.$u.toast(`人脸植入失败`)
  338. console.log('人脸上传失败');
  339. this.stepList[1].error = true
  340. }
  341. }
  342. },
  343. onLoad(option) {
  344. console.log(111);
  345. let item = JSON.parse(option.item)
  346. console.log(item);
  347. this.signalNum = item.signalNum
  348. this.obj.deviceId = item.deviceId
  349. this.uploadMsg.deviceId = item.deviceId
  350. this.uploadMsg.type = item.type
  351. this.testGateway().then(() => {
  352. if (this.flag != 1) {
  353. return
  354. }
  355. this.faceHas().then(() => {
  356. if (this.flag != 2) {
  357. return
  358. }
  359. this.testSignal().then(() => {
  360. if (this.flag != 3) {
  361. return
  362. }
  363. this.uploadFace()
  364. })
  365. })
  366. })
  367. }
  368. }
  369. </script>
  370. <style lang="scss">
  371. .steps {
  372. display: flex;
  373. justify-content: center;
  374. align-items: center;
  375. .u-steps-item {
  376. height: 25vh;
  377. width: calc(100vw - 20px);
  378. margin: 30px 10px;
  379. // background-color: red;
  380. .u-steps-item__line {
  381. height: 100px !important;
  382. }
  383. }
  384. // .u-steps-item {
  385. // width: 100vw;
  386. // height: 25vh;
  387. // background-color: blue;
  388. // }
  389. }
  390. .u-modal__button-group--confirm-button {
  391. flex-direction: row !important;
  392. }
  393. .u-modal .u-button {
  394. width: 180rpx !important;
  395. }
  396. .upload {
  397. position: fixed;
  398. bottom: 0;
  399. width: 100vw;
  400. }
  401. .power {
  402. text-align: center;
  403. margin: 13px 0 20px 0;
  404. }
  405. .inputNum {
  406. display: flex;
  407. justify-content: center;
  408. align-items: center;
  409. padding: 0 20rpx;
  410. }
  411. .u-radio-group {
  412. margin-top: 20rpx;
  413. }
  414. </style>