app.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547
  1. import {
  2. tracking,
  3. snConfig,
  4. getVisitDeviceUser,
  5. publicInterface
  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 publicInterface({
  291. prop: 'fkjCodeSignOutUrl',
  292. defaultProp: '/visitorCodeSignOut',
  293. data: data,
  294. method: 'post',
  295. errorTip: ''
  296. })
  297. this.data.signOffMsg = res.data
  298. setTimeout(()=>{
  299. closeSecondaryScreen()
  300. this.data.cycleIntervalSwitch = false
  301. }, 1000)
  302. my.reLaunch({
  303. url: '/pages/resultPage/index?result=签离成功'
  304. });
  305. } catch (error) {
  306. console.log(error);
  307. my.showToast({
  308. content: error.msg || '扫码签离api请求失败',
  309. duration: 2000
  310. });
  311. }
  312. } else {
  313. my.showToast({
  314. content: '扫码失败,请重试',
  315. duration: 2000
  316. });
  317. }
  318. })
  319. },
  320. // 小程序二维码登记
  321. async getVisitDeviceUser(data) {
  322. let data1 = {
  323. userId: data.serId,
  324. timestamp: data.timestamp,
  325. }
  326. try {
  327. let res = await getVisitDeviceUser(data1)
  328. console.log('小程序二维码登记', res)
  329. this.data.userInfo.avatar = res.data.avatar
  330. this.data.userInfo.idCardPhoto = res.data.avatar
  331. this.data.userInfo.xm = res.data.username
  332. this.data.userInfo.sfzh = res.data.idNumber
  333. this.data.userInfo.phone = res.data.phone
  334. this.data.userInfo.visitorUnit = res.data.workPlace
  335. this.data.userInfo.carnum = res.data.carNumber
  336. this.data.userInfo.verifyType = 6; // 二维码
  337. this.data.userInfo.certContent = res.data; // 身份证阅读器返回全部
  338. let reminderAuth = this.globalData.snDisposition.reminderAuth;
  339. // 是否跳转到提示页
  340. if (reminderAuth) {
  341. my.reLaunch({
  342. url: '/pages/tipsPage/index'
  343. })
  344. } else {
  345. // 是否启用副屏处理中页面
  346. let processingPageSwitch = this.globalData.snDisposition.processingPageSwitch;
  347. if (this.data.isSecondaryScreenState && processingPageSwitch) {
  348. console.log('打开副屏', this.data.isSecondaryScreenState);
  349. closeSecondaryScreen()
  350. this.data.cycleIntervalSwitch = false
  351. openSecondaryScreen(this.globalData.snDisposition.processingPageImage || '')
  352. }
  353. my.reLaunch({
  354. url: '/pages/interviewee/index'
  355. })
  356. }
  357. } catch (error) {
  358. console.log(error);
  359. this.data.isOkQrCodeSignIn = false
  360. setTimeout(()=>{
  361. closeSecondaryScreen()
  362. this.data.cycleIntervalSwitch = false
  363. }, 1000)
  364. my.reLaunch({
  365. url: '/pages/resultPage/index?result=结果页超时&&timer=' + this.globalData.snDisposition.resultPageTimeout,
  366. })
  367. }
  368. },
  369. globalData: {
  370. isPortraitScreen: null,// 是否为竖屏:true竖屏 false横屏
  371. // 13CD002006700011 137D002002300009 118D002000500012 136D002002300012
  372. sn: '',
  373. appVersion: '', //app版本号
  374. // 获取访客机配置token
  375. FKJConfiguration: '01f8624317168a4a52fd89f673a3ccbc',
  376. // 所修改内容的类型 0:修改基本设置 1:修改高级设置 2:超时时长设置 3:语音设置 4:密码设置
  377. modifyType: [0, 1, 2, 3, 4],
  378. //访客机配置
  379. snDisposition: {
  380. mode: null,
  381. sn: null,
  382. status: null,
  383. useAlipayFace: true,
  384. useIdcard: true,
  385. usePersonCard: true,
  386. voiceVolume: 80,
  387. mpassword: "117521",
  388. purchaserId: null,
  389. applicationTypeId: null,
  390. deviceModelHardwareId: null,
  391. deviceModelEnvironmentId: null,
  392. systemTypeCode: null,
  393. noIdcardRegister: false,
  394. noIdcardInputPhone: true,
  395. wxScanRegister: false,
  396. zfbScanRegister: false,
  397. wxQrcodeUrl: "https://tx.hz-hanghui.com:8088/yx-fyzd/faceCheckVisitor?type=2",
  398. zfbQrcodeUrl: "https://tx.hz-hanghui.com:8088/yx-fyzd/faceCheckVisitor?type=2",
  399. visiteeUrl: "https://tx.hz-hanghui.com:8088/yx-fyzd/api/v1/fkj/visitee/list",
  400. areaUrl: "https://tx.hz-hanghui.com:8088/yx-fyzd/api/v1/fkj/area/info",
  401. fkjCodeSignOutUrl: "https://tx.hz-hanghui.com:8088/yx-fyzd/visitorCodeSignOut", //扫码签离
  402. fkjHistoryRecordUrl: "https://tx.hz-hanghui.com:8088/yx-fyzd/history", // 历史拜访查询
  403. fkjRecordUrl: "https://tx.hz-hanghui.com:8088/yx-fyzd/visitorReportPageList", //访客记录接口
  404. fkjSignOutUrl: "https://tx.hz-hanghui.com:8088/yx-fyzd/visitorSignOut", //手动签离
  405. transitPushSwitch: true, // 启用进出记录推送 默认值:true
  406. transitPushUrl: "https://tx.hz-hanghui.com:8088/yx-fyzd/visitorReport",
  407. printVisitorList: false,
  408. signOut: true,
  409. riskCheck: false,
  410. hiddenButton: false,
  411. reminderAuth: false, // 是否启用注意事项提示语
  412. reminder: '', // 注意事项提示图片
  413. reminderPlayText: '', // 提示标语播报文本
  414. confirmCountdownSwitch: true, // 是否启用确定倒计时
  415. confirmCountdownTime: 15,
  416. secondaryPageSwitch: true, // 是否启用副屏轮播图
  417. secondaryPageImages: [], // 副屏轮播图(0/5)
  418. processingPageSwitch: true, // 是否启用副屏处理中页面
  419. processingPageImage: '', // 副屏处理中页面图
  420. generalQrcode: true,
  421. generalQrcodeTitle: "",
  422. ethQrcode: true,
  423. ethQrcodeTitle: "梯控二维码",
  424. ethQrcodeUrl: "https://tx.hz-hanghui.com:8088/yx-fyzd/api/v1/fkj/visitor/eth/qrCode",
  425. chooseVisiteeTimeout: 90,
  426. readIdcardTimeout: 15,
  427. inputIdcardTimeout: 30,
  428. inputPhoneTimeout: 30,
  429. singOutTimeout: 15,
  430. resultPageTimeout: 5,
  431. successVoice: "比对成功",
  432. failVoice: "比对失败,请重试,或刷身份证",
  433. registerSuccessVoice: "正在打印访客单",
  434. readIdcardVoice: "请刷身份证",
  435. inputIdcardVoice: "请输入身份证号",
  436. inputPhoneVoice: "请输入手机号",
  437. connectSearchVoice: "正在联网查询信息,请耐心等待",
  438. singOutVoice: "请将二维码对准设备的扫码窗",
  439. notDesensitizedColumn: [],
  440. registerNotDesensitizedColumn: [],
  441. faceTimeout: 40,
  442. oneToOneTimeout: 40,
  443. connectSearchTimeout: 40,
  444. faceFailHandInput: false,
  445. visitReason: '', // 拜访事由选项
  446. expirationDate: null, // 使用时间期限
  447. },
  448. // 设备信息
  449. deviceInformation: {},
  450. // 获取三要素在线配置接口
  451. serviceAddress: '',
  452. // 获取用户信息
  453. appId: '3292340fd1d913395fe32f781399604a',
  454. appKey: 'hhLOhU8Wb5x',
  455. appSecret: '3ade6850270e2964bb7499492493e464ceccf937',
  456. privateKey: 'wxuoukkrts68aqwv',
  457. // ⾃然⼈⻛险评分查询
  458. appIdRisk: 'be454b553daa209177e8d51883e828d2',
  459. appKeyRisk: 'hh0SLerEB5E',
  460. appSecretRisk: '2ec80e28fa7c98936fd053c9b72aa81692bb5ec5',
  461. privateKeyRisk: 'yfxrbbnnmsyuteaj',
  462. // ⾃然⼈⻛险评分查询结果 1:正常2:逃犯3:其他
  463. riskResult: 1,
  464. expirationDateTodayOpen: false, // 今天是否已经到期提醒
  465. },
  466. /*globalDataWatchers: {},
  467. /!**
  468. * 初始化递归监听
  469. *!/
  470. initGlobalDataWatcher() {
  471. this.observe(this.globalData);
  472. },
  473. /!**
  474. * 递归监听对象
  475. * @param {Object} obj 要监听的对象
  476. * @param {String} parentKey 父路径
  477. *!/
  478. observe(obj, parentKey = '') {
  479. const watchers = this.globalDataWatchers;
  480. Object.keys(obj).forEach(key => {
  481. let value = obj[key];
  482. const fullPath = parentKey ? `${parentKey}.${key}` : key; // 完整路径
  483. // 如果是对象,递归监听其子属性
  484. if (value && typeof value === 'object') {
  485. this.observe(value, fullPath);
  486. }
  487. // 定义 getter 和 setter
  488. Object.defineProperty(obj, key, {
  489. configurable: true,
  490. enumerable: true,
  491. get() {
  492. return value;
  493. },
  494. set: newValue => {
  495. if (newValue !== value) {
  496. value = newValue;
  497. console.log(`${fullPath} 被更新为:`, newValue);
  498. // 触发监听器
  499. if (watchers[fullPath]) {
  500. watchers[fullPath].forEach(callback => callback(newValue));
  501. }
  502. // 如果新值是对象,递归监听其子属性
  503. if (newValue && typeof newValue === 'object') {
  504. this.observe(newValue, fullPath);
  505. }
  506. }
  507. },
  508. });
  509. });
  510. },
  511. /!**
  512. * 添加监听器
  513. * @param {String} path 属性路径
  514. * @param {Function} callback 回调函数
  515. *!/
  516. watchGlobalData(path, callback) {
  517. if (!this.globalDataWatchers[path]) {
  518. this.globalDataWatchers[path] = [];
  519. }
  520. this.globalDataWatchers[path].push(callback);
  521. },
  522. /!**
  523. * 移除监听器
  524. * @param path 属性路径
  525. * @param callback 回调函数
  526. *!/
  527. unwatchGlobalData(path, callback) {
  528. const watchers = this.globalDataWatchers[path];
  529. if (watchers) {
  530. this.globalDataWatchers[path] = watchers.filter(cb => cb !== callback);
  531. }
  532. },*/
  533. });