index.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575
  1. <template>
  2. <view class="content">
  3. <!-- <view class="first-line">
  4. <button class="first-btn">一层</button>
  5. <button class="second-btn">二层</button>
  6. </view> -->
  7. <view class="second-content">
  8. <view class="sec-first">
  9. <!-- <view class="sec-first-one">配送中心</view>
  10. <view class="sec-first-two">盥洗室</view> -->
  11. 一层档口监测图
  12. </view>
  13. <view class="sec-second">
  14. <view class="first-col">
  15. <view class="shop-text" v-for="(name,i) in shopName">
  16. {{shopNum[i]}} {{name}}
  17. </view>
  18. </view>
  19. <view class="second-col">
  20. <view class="second-col-line">
  21. <view class="shop-btn" :class="{'color1':rank[i] == 1,'color2':rank[i] == 2}"
  22. v-for="(shop,i) in shopNum1">
  23. <!-- <view class="shop-btn" :class="{'color1':rank[i] == 1,'color2':rank[i] == 2}"
  24. v-for="(shop,i) in shopNum1" @click="getInfo(i)"> -->
  25. <view class="">
  26. {{shop}}
  27. </view>
  28. <view class="">
  29. {{peopleNum[i]}}人
  30. </view>
  31. </view>
  32. </view>
  33. <view class="second-col-item">
  34. <view class="col-item" v-for="(shop,i) in shopNum1"></view>
  35. </view>
  36. <view class="second-col-line">
  37. <view class="shop-btn" :class="{'color1':rank[19-i] == 1,'color2':rank[19-i] == 2}"
  38. v-for="(shop,i) in shopNum2">
  39. <!-- <view class="shop-btn" :class="{'color1':rank[19-i] == 1,'color2':rank[19-i] == 2}"
  40. v-for="(shop,i) in shopNum2" @click="getInfo(19-i)"> -->
  41. <view class="">
  42. {{shop}}
  43. </view>
  44. <view class="">
  45. {{peopleNum[19-i]}}人
  46. </view>
  47. </view>
  48. </view>
  49. </view>
  50. </view>
  51. <!-- <view class="sec-third">
  52. <view class="sec-third-one">黄焖鸡米饭</view>
  53. <view class="sec-third-two">包子铺</view>
  54. </view> -->
  55. </view>
  56. <view class="third-note">
  57. <view class="third-first">
  58. <span style="color: #FF0000;">*</span>
  59. 注:点击对应食堂窗口查看实时人数
  60. </view>
  61. <view class="third-second">
  62. <view class="one-line">
  63. <view class="one-block"></view>
  64. <view class="third-text">
  65. 窗口人数低于{{minNum}}人
  66. </view>
  67. </view>
  68. <view class="tow-line">
  69. <view class="two-block"></view>
  70. <view class="third-text">
  71. 窗口人数高于{{minNum}}人且小于{{maxNum}}人
  72. </view>
  73. </view>
  74. <view class="three-line">
  75. <view class="three-block"></view>
  76. <view class="third-text">
  77. 窗口人数高于{{maxNum}}人
  78. </view>
  79. </view>
  80. </view>
  81. </view>
  82. </view>
  83. </template>
  84. <script>
  85. import sha256 from "../../static/index.js"
  86. import demo from '../../static/demo.js'
  87. export default {
  88. data() {
  89. return {
  90. rank: [],
  91. minNum: 0,
  92. maxNum: 12,
  93. shopNum1: [],
  94. shopNum2: [],
  95. shopNum: ['①', '②', '③', '④', '⑤', '⑥', '⑦', '⑧', '⑨', '⑩', '⑪', '⑫', '⑬', '⑭', '⑮', '⑯', '⑰', '⑱', '⑲',
  96. '⑳'
  97. ],
  98. // peopleNum: [6, 12, 6, 14, 5, 4, 17, 6, 9, 13, 6, 1, 4, 9, 5, 14, 5, 3, 0, -10],
  99. peopleNum: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
  100. shopName: ['奶茶店', '晏阿婆米线', '犀米家', '港式套餐饭', '小东北麻辣烫', '小芸家食速快餐', '后来的粥', '思艳鲜包', '荷叶蒸饭', '老南昌米粉', '食尚快餐',
  101. '五谷渔粉', '柚米套餐饭', '北方饼店', '宴阿婆自选水饺', '贵州花溪牛肉', '小木屋', '麻辣香锅', '土耳其烤肉饭', '兰州拉面'
  102. ],
  103. status_code: '',
  104. response: '',
  105. nonce: '290208a68afdc9aca4b454da8fc22acd3f88a178c32e4128c0a00e7ff13fbdc7',
  106. opaque: 'null',
  107. uri: '/API/Web/Login',
  108. algorithm: 'SHA-256',
  109. username: 'admin',
  110. password: 'Chuanghai-2021',
  111. realm: 'device',
  112. qop: 'auth',
  113. nc: '00000001',
  114. cnonce: '247fe9fd623c1c42',
  115. token: '',
  116. lap_number: '',
  117. reader_id: '',
  118. sequence: '',
  119. heat_alarm: '',
  120. heartResult: '',
  121. flag: 1,
  122. chan: '',
  123. store: [7, 3, 18, 5, 15, 14, 8, 19, 11, 20, 9, 13, 10, 1, 4, 6, 17, 12, 2, 16],
  124. }
  125. },
  126. watch: {
  127. // status_code: { //深度监听,可监听到对象、数组的变化
  128. // handler(val, oldVal) {
  129. // if (val != 200) {
  130. // clearInterval(this.timer)
  131. // this.flag = 0
  132. // } else if (val == 200) {
  133. // this.flag = 1
  134. // this.timer = setInterval(() => {
  135. // this.heartBeat()
  136. // }, 25000)
  137. // this.checkInfoFirst()
  138. // }
  139. // },
  140. // deep: true
  141. // },
  142. // heartResult: {
  143. // handler(val, oldVal) {
  144. // if (val != 'success') {
  145. // clearInterval(this.timer)
  146. // this.flag = 0
  147. // }
  148. // },
  149. // deep: true
  150. // },
  151. peopleNum: {
  152. handler(val, oldVal) {
  153. this.getShopNum()
  154. this.getRank()
  155. },
  156. deep: true
  157. }
  158. },
  159. onLoad() {
  160. this.getShopNum()
  161. this.getRank()
  162. this.getNumInfo()
  163. this.timer = setInterval(() => {
  164. this.getNumInfo()
  165. }, 8000)
  166. // this.getSha256()
  167. // this.login()
  168. // this.loginRange()
  169. },
  170. onUnload() {
  171. clearInterval(this.timer)
  172. },
  173. methods: {
  174. loginRange() {
  175. uni.request({
  176. url: '/camera/Login/Range',
  177. method: 'POST',
  178. header: {
  179. "Content-Type": "application/json; charset=UTF-8",
  180. },
  181. success: res => {
  182. console.log(res)
  183. },
  184. });
  185. },
  186. async login() {
  187. // console.log(this.nonce)
  188. const res = await uni.request({
  189. url: '/camera/Web/Login',
  190. method: 'POST',
  191. header: {
  192. "Content-Type": "application/json",
  193. 'Authorization': 'Digest username="' + this.username + '",realm="' + this
  194. .realm + '",nonce=' + this.nonce + ',uri="' + this.uri + '",algorithm="' +
  195. this.algorithm + '",qop=auth,nc=' + this.nc + ',cnonce="' + this.cnonce +
  196. '",response="' + this.response + '"',
  197. },
  198. });
  199. this.result = res[1]
  200. this.status_code = this.result.statusCode
  201. this.headers = this.result.header['www-authenticate']
  202. if (this.status_code == 401) {
  203. let headers = this.result.header['www-authenticate']
  204. let pattern = new RegExp('".*?"', "g"); // 正则匹配URL
  205. let matcher = headers.match(pattern);
  206. // this.realm = matcher[0]
  207. this.nonce = matcher[1].substring(1, matcher[1].length - 1)
  208. // console.log(this.headers)
  209. // console.log(this.nonce)
  210. this.getSha256()
  211. this.login()
  212. } else if (this.status_code == 200) {
  213. // console.log(res[1].header['x-csrftoken'])
  214. this.token = res[1].header['x-csrftoken']
  215. console.log('登录成功')
  216. uni.showToast({
  217. icon: 'success',
  218. title: '登录成功',
  219. duration: 2000
  220. });
  221. } else {
  222. console.log('登录失败!!!!!!')
  223. this.showLoding()
  224. clearInterval(this.timer)
  225. setTimeout(() => {
  226. location.reload();
  227. }, 5000);
  228. }
  229. },
  230. showLoding() {
  231. uni.showLoading({
  232. title: '重新加载中'
  233. });
  234. setTimeout(function() {
  235. uni.hideLoading();
  236. }, 3000);
  237. },
  238. async heartBeat() {
  239. // console.log(this.flag)
  240. const res = await uni.request({
  241. url: '/camera/Login/Heartbeat',
  242. method: 'POST',
  243. header: {
  244. "Content-Type": "application/json",
  245. "X-csrftoken": this.token
  246. },
  247. });
  248. // console.log(res)
  249. // console.log(res[1].data.error_code)
  250. this.heartResult = res[1].data.result
  251. if (this.heartResult == 'success') {
  252. console.log('保活成功')
  253. uni.showToast({
  254. icon: 'success',
  255. title: '保活成功',
  256. duration: 2000
  257. });
  258. } else {
  259. console.log('保活失败!!!!!!')
  260. clearInterval(this.timer)
  261. }
  262. },
  263. checkInfoFirst() {
  264. uni.request({
  265. url: '/camera/Event/Check',
  266. method: 'POST',
  267. header: {
  268. "X-csrftoken": this.token,
  269. "Content-Type": "application/json",
  270. },
  271. success: res => {
  272. // console.log(res.data.data)
  273. console.log('首次推送成功')
  274. this.lap_number = res.data.data.lap_number
  275. this.reader_id = res.data.data.reader_id
  276. this.sequence = res.data.data.sequence
  277. if (this.reader_id != '') {
  278. this.checkInfo()
  279. }
  280. },
  281. fail: (err) => {
  282. console.log('首次推送失败!!!!!!', err)
  283. },
  284. });
  285. },
  286. checkInfo() {
  287. // console.log(this.flag)
  288. this.heat_alarm = ''
  289. uni.request({
  290. url: '/camera/Event/Check',
  291. method: 'POST',
  292. header: {
  293. "X-csrftoken": this.token,
  294. "Content-Type": "application/json",
  295. },
  296. data: {
  297. "data": {
  298. "lap_number": this.lap_number,
  299. "reader_id": this.reader_id,
  300. "sequence": this.sequence,
  301. "subscribe_ai_metadata": true,
  302. "subscribe_intelligence": true,
  303. }
  304. },
  305. success: res => {
  306. // console.log(res.data.data)
  307. // console.log(res.data.result)
  308. if (res.data.result == 'success') {
  309. this.lap_number = res.data.data.lap_number
  310. this.reader_id = res.data.data.reader_id
  311. this.sequence = res.data.data.sequence
  312. this.heat_alarm = res.data.data.heat_alarm
  313. if (this.heat_alarm != 'HeatAlarm') {
  314. // console.log(res.data.data)
  315. for (let j = 0; j < res.data.data.alarm_list.length; j++) {
  316. if ('realtime_data_report' in res.data.data.alarm_list[j]) {
  317. // console.log(res.data.data.alarm_list[j].realtime_data_report)
  318. var objs = res.data.data.alarm_list[j].realtime_data_report
  319. for (let i = 0; i < objs.length; i++) {
  320. if ('realtime_data_type' in objs[i]) {
  321. if (objs[i].realtime_data_type == 'queue_length') {
  322. var chanNum = objs[i].channel.substring(2) - 1
  323. var storeNum = this.store[chanNum] - 1
  324. console.log('当前通道为:', objs[i].channel, ',当前档口为:', this
  325. .store[chanNum], ',当前档口人数为:', objs[i]
  326. .shoulder_count)
  327. this.peopleNum.splice(storeNum, 1, objs[i].shoulder_count)
  328. }
  329. } else {
  330. console.log('realtime_data_type不存在!!!!!!')
  331. }
  332. }
  333. } else {
  334. // console.log('realtime_data_report 不存在!!!!!!')
  335. }
  336. }
  337. }
  338. if (this.flag == 1) {
  339. setTimeout(() => {
  340. console.log('推送请求成功')
  341. uni.showToast({
  342. icon: 'success',
  343. title: '推送成功',
  344. duration: 2000
  345. });
  346. this.checkInfo()
  347. }, 5000);
  348. } else {
  349. console.log('推送请求失败!!!!!!')
  350. }
  351. } else {
  352. console.log('返回参数不存在,正在重新推送请求')
  353. setTimeout(() => {
  354. location.reload();
  355. }, 3000);
  356. }
  357. },
  358. fail: (err) => {
  359. this.checkInfoFirst()
  360. console.log('推送失败!!!!!!', err)
  361. },
  362. });
  363. },
  364. getSha256() {
  365. let A1 = mycrypto.sha256.create()
  366. let A2 = mycrypto.sha256.create()
  367. let Response = mycrypto.sha256.create()
  368. let sha1 = this.username + ':' + this.realm + ':' + this.password
  369. let sha2 = 'POST' + ':' + this.uri
  370. A1.update(sha1)
  371. var HA1 = A1.digest().toHex()
  372. A2.update(sha2)
  373. var HA2 = A2.digest().toHex()
  374. var ResponseText = HA1 + ':' + this.nonce + ':' + this.nc + ':' + this.cnonce + ':' + this.qop + ':' + HA2
  375. Response.update(ResponseText)
  376. this.response = Response.digest().toHex()
  377. // console.log('response:', this.response)
  378. // console.log('Authorization:Digest username="', this.username, '",realm="', this
  379. // .realm, '",nonce="', this.nonce, '",uri="', this.uri, '",algorithm="',
  380. // this.algorithm, '",qop=auth,nc=', this.nc, ',cnonce="', this.cnonce, '",response="', this.response,
  381. // '"')
  382. },
  383. getNumInfo() {
  384. uni.request({
  385. url: 'camera/loginquery.action',
  386. method: 'POST',
  387. header: {
  388. "Content-Type": "application/json; charset=UTF-8",
  389. },
  390. success: res => {
  391. // console.log(res)
  392. this.info = JSON.parse(res.data.message)
  393. console.log(this.info)
  394. if ('error_code' in this.info) {
  395. this.showLoding()
  396. } else {
  397. if (this.info.result = 'success') {
  398. if (this.info.data.heat_alarm != 'HeatAlarm') {
  399. for (let j = 0; j < this.info.data.alarm_list.length; j++) {
  400. if ('realtime_data_report' in this.info.data.alarm_list[j]) {
  401. // console.log(this.info.data.alarm_list[j].realtime_data_report)
  402. var objs = this.info.data.alarm_list[j].realtime_data_report
  403. for (let i = 0; i < objs.length; i++) {
  404. if ('realtime_data_type' in objs[i]) {
  405. if (objs[i].realtime_data_type == 'queue_length') {
  406. var chanNum = objs[i].channel.substring(2) - 1
  407. var storeNum = this.store[chanNum] - 1
  408. // if (objs[i].shoulder_count != 0) {
  409. console.log('当前通道为:', objs[i].channel, ',当前档口为:',
  410. this
  411. .store[chanNum], ',当前档口人数为:', objs[i]
  412. .shoulder_count)
  413. this.peopleNum.splice(storeNum, 1, objs[i]
  414. .shoulder_count)
  415. // }
  416. }
  417. } else {
  418. console.log('realtime_data_type不存在!!!!!!')
  419. }
  420. }
  421. } else {
  422. // console.log('realtime_data_report 不存在!!!!!!')
  423. }
  424. }
  425. } else {
  426. this.peopleNum = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
  427. console.log('等待中……')
  428. }
  429. }
  430. }
  431. },
  432. fail: (err) => {
  433. console.log('推送失败!!!!!!', err)
  434. // this.checkFirst()
  435. },
  436. });
  437. },
  438. // checkFirst() {
  439. // uni.request({
  440. // url: '/camera/loginfirst.action',
  441. // method: 'POST',
  442. // header: {
  443. // "Content-Type": "application/json; charset=UTF-8",
  444. // },
  445. // success: res => {
  446. // console.log('重新激活成功')
  447. // },
  448. // });
  449. // },
  450. getShopNum() {
  451. this.shopNum1 = this.shopNum.slice(0, 10)
  452. this.shopNum2 = this.shopNum.slice(10, 20).reverse()
  453. // var i = 1
  454. // while (i <= 20) {
  455. // var name = '窗口名称' + i
  456. // // console.log(name)
  457. // i = i + 1
  458. // this.shopName.push(name)
  459. // }
  460. // console.log(this.shopName)
  461. },
  462. getRank() {
  463. const self = this
  464. var i = 0
  465. self.rank = []
  466. var tmp = []
  467. while (i < self.peopleNum.length) {
  468. // console.log(this.peopleNum[i])
  469. if (self.peopleNum[i] > self.minNum && self.peopleNum[i] <= self.maxNum) {
  470. tmp.push(1)
  471. } else if (self.peopleNum[i] > self.maxNum) {
  472. tmp.push(2)
  473. } else if (self.peopleNum[i] <= self.minNum && self.peopleNum[i] >= 0) {
  474. tmp.push(0)
  475. } else {
  476. console.log('num is error')
  477. }
  478. setTimeout(() => {
  479. self.rank = tmp
  480. self.$forceUpdate()
  481. }, 300);
  482. i += 1
  483. }
  484. // console.log(this.rank)
  485. },
  486. getInfo(e) {
  487. // console.log(e)
  488. if (this.peopleNum[e] >= 0) {
  489. uni.showToast({
  490. icon: 'none',
  491. title: e + 1 + '号窗口实时人数:' + this.peopleNum[e],
  492. duration: 2000
  493. });
  494. } else if (this.peopleNum[e] == undefined) {
  495. uni.showToast({
  496. icon: 'none',
  497. title: 'empty',
  498. duration: 2000
  499. });
  500. } else {
  501. uni.showToast({
  502. icon: 'none',
  503. title: 'error',
  504. duration: 2000
  505. });
  506. }
  507. },
  508. //跳转
  509. navigatorToSec() {
  510. uni.navigateTo({
  511. url: '/pages/second/second',
  512. });
  513. },
  514. getTime() {
  515. var date = new Date(),
  516. year = date.getFullYear(),
  517. month = date.getMonth() + 1,
  518. day = date.getDate(),
  519. hour = date.getHours() < 10 ? "0" + date.getHours() : date.getHours(),
  520. minute = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes(),
  521. second = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
  522. month >= 1 && month <= 9 ? (month = "0" + month) : "";
  523. day >= 0 && day <= 9 ? (day = "0" + day) : "";
  524. var timer = year + '-' + month + '-' + day + ' ' + hour + ':' + minute + ':' + second;
  525. return timer;
  526. },
  527. }
  528. }
  529. </script>
  530. <style>
  531. @import url("index.css");
  532. </style>