app.js 16 KB

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