app.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538
  1. import {
  2. tracking,
  3. snConfig,
  4. getVisitDeviceUser,
  5. visitorCodeSignOut
  6. } from './utils/api/api'
  7. import {
  8. getForm,
  9. getDate,
  10. formatTime
  11. } from './utils/index/index'
  12. import {
  13. closeSecondaryScreen, openCycleSecondaryScreen, openSecondaryScreen
  14. } from './utils/index/callAmpe'
  15. App({
  16. data: {
  17. // 用户输入身份证号
  18. inputIdCard: '',
  19. // 用户输入手机号
  20. inputPhone: '',
  21. //设备上报心跳
  22. TIME_COUNT: 60,
  23. timer: null,
  24. //用户信息
  25. userInfo: {
  26. avatar: '',
  27. idCardPhoto: '',
  28. xm: '',
  29. sfzh: '',
  30. phone: '',
  31. workPlace: '',
  32. carNumber: '',
  33. // xm: '张佳燕',
  34. // sfzh: '331082199910045826',
  35. // phone: '15888632412',
  36. },
  37. // 刷证获取到的用户信息
  38. brushingCardUserIInfo: {},
  39. // 拜访成功数据信息
  40. visitoMsgData: {},
  41. // 签离成功的用户信息
  42. signOffMsg: {},
  43. // 刷身份证是否开始
  44. isOkBrushingCard: false,
  45. // 扫码登记是否开始
  46. isOkQrCodeSignIn: false,
  47. // 刷脸是否开始
  48. isokFaceScan: false,
  49. // 刷脸初始化是否成功
  50. isFaceScanInitialize: false, // 是否捕获到联网查询错误
  51. isNetworkQueryError: true,
  52. clickRetryNum: 0, //获取用户信息重试次数
  53. isSecondaryScreenState: true, // 是否能加载到副屏
  54. cycleIntervalId: null, // 副屏展示定时器
  55. cycleIntervalSwitch: false, // 副屏展示是否开启
  56. secondaryPageImagesIndex: 0,
  57. },
  58. onLaunch(options) {
  59. // this.initGlobalDataWatcher();
  60. let snDisposition = my.getStorageSync({
  61. key: 'snDisposition'
  62. }).data;
  63. if (snDisposition) {
  64. this.globalData.snDisposition = snDisposition
  65. }
  66. this.globalData.snDisposition.id = null
  67. this.globalData.expirationDateTodayOpen = false
  68. this.getSecondaryScreenState()
  69. this.getSystemInfo()
  70. this.getSystemInfoSync()
  71. this.getDeviceInformation()
  72. this.initialize()
  73. this.brushingCard()
  74. this.scanCode()
  75. // this.snConfig()
  76. },
  77. onShow(options) {
  78. // 从后台被 scheme 重新打开
  79. },
  80. // 初始化
  81. initialize() {
  82. // 刷脸初始化
  83. let params = {
  84. "action": "initFace",
  85. "event": "open",
  86. "taskId": "2",
  87. "params": {
  88. "scope": "auth_user,order_service"
  89. }
  90. }
  91. console.log('刷脸初始化开始');
  92. my.call("ampeHHCommunication", params, res => {
  93. console.log(res, '刷脸初始化结束')
  94. if (res.success) {
  95. this.data.isFaceScanInitialize = true
  96. }
  97. });
  98. },
  99. initSecondaryScreen() {
  100. // 启用首页副屏
  101. console.log(this.data.isSecondaryScreenState && this.globalData.snDisposition.secondaryPageSwitch)
  102. if (this.data.isSecondaryScreenState && this.globalData.snDisposition.secondaryPageSwitch) {
  103. console.log('打开副屏轮播', this.data.isSecondaryScreenState);
  104. openCycleSecondaryScreen()
  105. }
  106. // console.log('关闭副屏', app.data.isSecondaryScreenState)
  107. // if (app.data.isSecondaryScreenState && app.globalData.snDisposition.secondaryPageSwitch) {
  108. // // closeSecondaryScreen()
  109. // closeCycleSecondaryScreen()
  110. // }
  111. },
  112. // 获取副屏状态
  113. getSecondaryScreenState() {
  114. let params = {
  115. "action": "getSecondaryScreenState",
  116. "event": "open",
  117. "taskId": "10",
  118. }
  119. try {
  120. my.call("ampeHHCommunication", params, res => {
  121. console.log(res, '获取副屏状态')
  122. this.data.cycleIntervalId && clearInterval(this.data.cycleIntervalId);
  123. this.data.isSecondaryScreenState = false
  124. this.data.secondaryPageImagesIndex = 0
  125. if (res.success) {
  126. // 副屏展示状态 显示1 关闭 0 暂不支持 -1(没加载到副屏)
  127. let screenState = res.data.getSecondaryScreenState;
  128. this.data.isSecondaryScreenState = true
  129. if (screenState == -1) {
  130. this.data.cycleIntervalSwitch = false
  131. } else if (screenState == 1) {
  132. closeSecondaryScreen()
  133. }
  134. this.initSecondaryScreen()
  135. console.log('ampeHHCommunication', res);
  136. console.log(this.data.isSecondaryScreenState)
  137. } else {
  138. this.data.cycleIntervalSwitch = false
  139. }
  140. })
  141. } catch (error) {
  142. console.log(error);
  143. }
  144. },
  145. //设备上报心跳的接口 60秒调一次
  146. trackingInterval() {
  147. let {
  148. TIME_COUNT,
  149. timer,
  150. count
  151. } = this.data
  152. if (!timer) {
  153. count = TIME_COUNT;
  154. timer = setInterval(async () => {
  155. if (count > 0 && count <= TIME_COUNT) {
  156. count--;
  157. } else {
  158. clearInterval(timer);
  159. this.data.timer = null;
  160. await this.tracking()
  161. this.trackingInterval()
  162. }
  163. }, 60 * 1000)
  164. }
  165. },
  166. async tracking() {
  167. let form = {
  168. sn: this.globalData.sn
  169. }
  170. try {
  171. let res = await tracking(form)
  172. } catch (error) {
  173. console.log(error);
  174. }
  175. },
  176. // 获取设备信息
  177. getDeviceInformation() {
  178. let params = {
  179. "action": "getDeviceInfo",
  180. "event": "open",
  181. "taskId": "4"
  182. }
  183. let that = this
  184. try {
  185. my.call('ampeHHCommunication', params, res => {
  186. console.log(res, '获取设备信息');
  187. if (res.data) {
  188. that.globalData.deviceInformation = res.data
  189. that.globalData.sn = res.data.sn
  190. that.snConfig()
  191. that.tracking()
  192. that.trackingInterval()
  193. }
  194. });
  195. } catch (error) {
  196. console.log(error);
  197. }
  198. },
  199. getSystemInfo() {
  200. // 利用callback回调 解决页面异步调取 数据的问题 todo
  201. my.getSystemInfo({
  202. success: (res) => {
  203. // 通过宽高比例判断屏幕类型
  204. if (res.screenWidth / res.screenHeight > 1) {
  205. this.globalData.isPortraitScreen = false
  206. console.log('getSystemInfo====>横屏模式');
  207. } else {
  208. this.globalData.isPortraitScreen = true
  209. console.log('getSystemInfo====>竖屏模式');
  210. }
  211. },
  212. fail: (err) => {
  213. console.log(err);
  214. }
  215. });
  216. },
  217. // 获取版本号
  218. getSystemInfoSync() {
  219. const accountInfo = my.getAccountInfoSync();
  220. this.globalData.appVersion = accountInfo.miniProgram.version
  221. },
  222. // 获取设备配置
  223. async snConfig() {
  224. let data = {
  225. "token": this.globalData.FKJConfiguration,
  226. "sn": this.globalData.sn
  227. }
  228. try {
  229. let res = await snConfig(data)
  230. this.globalData.snDisposition = res.data
  231. my.setStorageSync({
  232. data: res.data,
  233. key: 'snDisposition'
  234. });
  235. } catch (error) {
  236. console.log(error);
  237. }
  238. },
  239. // 刷身份证监听
  240. brushingCard() {
  241. my.on('initIDCardListener', res => {
  242. console.log("刷身份证监听", this.data.isOkBrushingCard, res.data)
  243. if (!this.data.isOkBrushingCard && !this.data.isokFaceScan) {
  244. if (res.data) {
  245. this.data.isOkBrushingCard = true
  246. this.data.brushingCardUserIInfo = res.data
  247. this.data.brushingCardUserIInfo.name = this.data.brushingCardUserIInfo.name.replace(/\s*/g, "")
  248. setTimeout(()=>{
  249. closeSecondaryScreen()
  250. this.data.cycleIntervalSwitch = false
  251. }, 1000)
  252. this.data.userInfo.idCardPhoto = res.data.photoBase64
  253. my.reLaunch({
  254. url: '/pages/resultPage/index?result=首页刷证',
  255. })
  256. } else {
  257. my.showToast({
  258. content: '刷证失败,请重试',
  259. duration: 2000
  260. });
  261. }
  262. } else {
  263. return
  264. }
  265. })
  266. },
  267. //开启⼆维码监听
  268. scanCode() {
  269. my.on('initQRListener', async res => {
  270. console.log('⼆维码监听 ', res.data)
  271. // 扫码登记
  272. if (res.data && res.data.qrCode && res.data.qrCode.indexOf('HHFKJ') > -1) {
  273. if (!this.data.isOkQrCodeSignIn) {
  274. this.data.isOkQrCodeSignIn = true
  275. let data = getForm(res.data.qrCode)
  276. this.getVisitDeviceUser(data)
  277. }
  278. } else if (res.data && res.data.qrCode) {
  279. if (res.data.qrCode.indexOf('\\000026') > -1 || res.data.qrCode.indexOf('\\000029') > -1) {
  280. res.data.qrCode = res.data.qrCode.slice(7)
  281. }
  282. console.log(res.data.qrCode);
  283. // 扫码签离
  284. let data = {
  285. sn: this.globalData.sn,
  286. code: res.data.qrCode
  287. }
  288. console.log(data);
  289. try {
  290. let res = await visitorCodeSignOut(data)
  291. console.log(res.data);
  292. this.data.signOffMsg = res.data
  293. setTimeout(()=>{
  294. closeSecondaryScreen()
  295. this.data.cycleIntervalSwitch = false
  296. }, 1000)
  297. my.reLaunch({
  298. url: '/pages/resultPage/index?result=签离成功'
  299. });
  300. } catch (error) {
  301. console.log(error);
  302. my.showToast({
  303. content: error.msg || '扫码失败,请重试',
  304. duration: 2000
  305. });
  306. }
  307. } else {
  308. my.showToast({
  309. content: '扫码失败,请重试',
  310. duration: 2000
  311. });
  312. }
  313. })
  314. },
  315. // 小程序二维码登记
  316. async getVisitDeviceUser(data) {
  317. let data1 = {
  318. userId: data.serId,
  319. timestamp: data.timestamp,
  320. }
  321. try {
  322. let res = await getVisitDeviceUser(data1)
  323. console.log('小程序二维码登记', res)
  324. this.data.userInfo.avatar = res.data.avatar
  325. this.data.userInfo.idCardPhoto = res.data.avatar
  326. this.data.userInfo.xm = res.data.username
  327. this.data.userInfo.sfzh = res.data.idNumber
  328. this.data.userInfo.phone = res.data.phone
  329. this.data.userInfo.visitorUnit = res.data.workPlace
  330. this.data.userInfo.carnum = res.data.carNumber
  331. this.data.userInfo.verifyType = 6; // 二维码
  332. this.data.userInfo.certContent = res.data; // 身份证阅读器返回全部
  333. let reminderAuth = this.globalData.snDisposition.reminderAuth;
  334. // 是否跳转到提示页
  335. if (reminderAuth) {
  336. my.reLaunch({
  337. url: '/pages/tipsPage/index'
  338. })
  339. } else {
  340. // 是否启用副屏处理中页面
  341. let processingPageSwitch = this.globalData.snDisposition.processingPageSwitch;
  342. if (this.data.isSecondaryScreenState && processingPageSwitch) {
  343. console.log('打开副屏', this.data.isSecondaryScreenState);
  344. closeSecondaryScreen()
  345. this.data.cycleIntervalSwitch = false
  346. openSecondaryScreen(this.globalData.snDisposition.processingPageImage || '')
  347. }
  348. my.reLaunch({
  349. url: '/pages/interviewee/index'
  350. })
  351. }
  352. } catch (error) {
  353. console.log(error);
  354. this.data.isOkQrCodeSignIn = false
  355. setTimeout(()=>{
  356. closeSecondaryScreen()
  357. this.data.cycleIntervalSwitch = false
  358. }, 1000)
  359. my.reLaunch({
  360. url: '/pages/resultPage/index?result=结果页超时&&timer=' + this.globalData.snDisposition.resultPageTimeout,
  361. })
  362. }
  363. },
  364. globalData: {
  365. isPortraitScreen: null,// 是否为竖屏:true竖屏 false横屏
  366. // 13CD002006700011 137D002002300009 118D002000500012 136D002002300012
  367. sn: '',
  368. appVersion: '', //app版本号
  369. // 获取访客机配置token
  370. FKJConfiguration: '01f8624317168a4a52fd89f673a3ccbc',
  371. // 所修改内容的类型 0:修改基本设置 1:修改高级设置 2:超时时长设置 3:语音设置 4:密码设置
  372. modifyType: [0, 1, 2, 3, 4],
  373. //访客机配置
  374. snDisposition: {
  375. mode: null,
  376. sn: null,
  377. status: null,
  378. useAlipayFace: true,
  379. useIdcard: true,
  380. usePersonCard: true,
  381. voiceVolume: 80,
  382. mpassword: "117521",
  383. purchaserId: null,
  384. applicationTypeId: null,
  385. deviceModelHardwareId: null,
  386. deviceModelEnvironmentId: null,
  387. systemTypeCode: null,
  388. noIdcardRegister: false,
  389. noIdcardInputPhone: true,
  390. wxScanRegister: false,
  391. zfbScanRegister: false,
  392. wxQrcodeUrl: "https://tx.hz-hanghui.com:8088/yx-fyzd/faceCheckVisitor?type=2",
  393. zfbQrcodeUrl: "https://tx.hz-hanghui.com:8088/yx-fyzd/faceCheckVisitor?type=2",
  394. visiteeUrl: "https://tx.hz-hanghui.com:8088/yx-fyzd/api/v1/fkj/visitee/list",
  395. areaUrl: "https://tx.hz-hanghui.com:8088/yx-fyzd/api/v1/fkj/area/info",
  396. transitPushSwitch: true, // 启用进出记录推送 默认值:true
  397. transitPushUrl: "https://tx.hz-hanghui.com:8088/yx-fyzd/visitorReport",
  398. printVisitorList: false,
  399. signOut: true,
  400. riskCheck: false,
  401. hiddenButton: false,
  402. reminderAuth: false, // 是否启用注意事项提示语
  403. reminder: '', // 注意事项提示图片
  404. reminderPlayText: '', // 提示标语播报文本
  405. confirmCountdownSwitch: true, // 是否启用确定倒计时
  406. confirmCountdownTime: 15,
  407. secondaryPageSwitch: true, // 是否启用副屏轮播图
  408. secondaryPageImages: [], // 副屏轮播图(0/5)
  409. processingPageSwitch: true, // 是否启用副屏处理中页面
  410. processingPageImage: '', // 副屏处理中页面图
  411. generalQrcode: true,
  412. generalQrcodeTitle: "",
  413. ethQrcode: true,
  414. ethQrcodeTitle: "梯控二维码",
  415. ethQrcodeUrl: "https://tx.hz-hanghui.com:8088/yx-fyzd/api/v1/fkj/visitor/eth/qrCode",
  416. chooseVisiteeTimeout: 90,
  417. readIdcardTimeout: 15,
  418. inputIdcardTimeout: 30,
  419. inputPhoneTimeout: 30,
  420. singOutTimeout: 15,
  421. resultPageTimeout: 5,
  422. successVoice: "比对成功",
  423. failVoice: "比对失败,请重试,或刷身份证",
  424. registerSuccessVoice: "正在打印访客单",
  425. readIdcardVoice: "请刷身份证",
  426. inputIdcardVoice: "请输入身份证号",
  427. inputPhoneVoice: "请输入手机号",
  428. connectSearchVoice: "正在联网查询信息,请耐心等待",
  429. singOutVoice: "请将二维码对准设备的扫码窗",
  430. notDesensitizedColumn: [],
  431. registerNotDesensitizedColumn: [],
  432. faceTimeout: 40,
  433. oneToOneTimeout: 40,
  434. connectSearchTimeout: 40,
  435. faceFailHandInput: false,
  436. visitReason: '', // 拜访事由选项
  437. expirationDate: null, // 使用时间期限
  438. },
  439. // 设备信息
  440. deviceInformation: {},
  441. // 获取三要素在线配置接口
  442. serviceAddress: '',
  443. // 获取用户信息
  444. appId: '3292340fd1d913395fe32f781399604a',
  445. appKey: 'hhLOhU8Wb5x',
  446. appSecret: '3ade6850270e2964bb7499492493e464ceccf937',
  447. privateKey: 'wxuoukkrts68aqwv',
  448. // ⾃然⼈⻛险评分查询
  449. appIdRisk: 'be454b553daa209177e8d51883e828d2',
  450. appKeyRisk: 'hh0SLerEB5E',
  451. appSecretRisk: '2ec80e28fa7c98936fd053c9b72aa81692bb5ec5',
  452. privateKeyRisk: 'yfxrbbnnmsyuteaj',
  453. // ⾃然⼈⻛险评分查询结果 1:正常2:逃犯3:其他
  454. riskResult: 1,
  455. expirationDateTodayOpen: false, // 今天是否已经到期提醒
  456. },
  457. /*globalDataWatchers: {},
  458. /!**
  459. * 初始化递归监听
  460. *!/
  461. initGlobalDataWatcher() {
  462. this.observe(this.globalData);
  463. },
  464. /!**
  465. * 递归监听对象
  466. * @param {Object} obj 要监听的对象
  467. * @param {String} parentKey 父路径
  468. *!/
  469. observe(obj, parentKey = '') {
  470. const watchers = this.globalDataWatchers;
  471. Object.keys(obj).forEach(key => {
  472. let value = obj[key];
  473. const fullPath = parentKey ? `${parentKey}.${key}` : key; // 完整路径
  474. // 如果是对象,递归监听其子属性
  475. if (value && typeof value === 'object') {
  476. this.observe(value, fullPath);
  477. }
  478. // 定义 getter 和 setter
  479. Object.defineProperty(obj, key, {
  480. configurable: true,
  481. enumerable: true,
  482. get() {
  483. return value;
  484. },
  485. set: newValue => {
  486. if (newValue !== value) {
  487. value = newValue;
  488. console.log(`${fullPath} 被更新为:`, newValue);
  489. // 触发监听器
  490. if (watchers[fullPath]) {
  491. watchers[fullPath].forEach(callback => callback(newValue));
  492. }
  493. // 如果新值是对象,递归监听其子属性
  494. if (newValue && typeof newValue === 'object') {
  495. this.observe(newValue, fullPath);
  496. }
  497. }
  498. },
  499. });
  500. });
  501. },
  502. /!**
  503. * 添加监听器
  504. * @param {String} path 属性路径
  505. * @param {Function} callback 回调函数
  506. *!/
  507. watchGlobalData(path, callback) {
  508. if (!this.globalDataWatchers[path]) {
  509. this.globalDataWatchers[path] = [];
  510. }
  511. this.globalDataWatchers[path].push(callback);
  512. },
  513. /!**
  514. * 移除监听器
  515. * @param path 属性路径
  516. * @param callback 回调函数
  517. *!/
  518. unwatchGlobalData(path, callback) {
  519. const watchers = this.globalDataWatchers[path];
  520. if (watchers) {
  521. this.globalDataWatchers[path] = watchers.filter(cb => cb !== callback);
  522. }
  523. },*/
  524. });