rlxf_index.js 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. const _my = require("../../../__antmove/api/index.js")(my);
  2. const wx = _my;
  3. const face = require("../../../utils/faceCheck/faceCheck");
  4. const {
  5. getContextByAdminId
  6. } = require("../../../utils/api/api");
  7. const {
  8. throttle
  9. } = require("../../../utils/throttle/throttle");
  10. const date = require("/utils/util/util");
  11. const app = getApp();
  12. import getAuthThree from '/utils/api/auth_api'
  13. import bus from 'iny-bus'
  14. Page({
  15. /**
  16. * 页面的初始数据
  17. */
  18. data() {
  19. return {
  20. // 输入信息
  21. inputName: "",
  22. inputIdcard: "",
  23. phoneNumber: "",
  24. userId: null,
  25. //手机号校验信息
  26. isShowApplet: null,
  27. disabledSubmitScan: false,
  28. eventId: null,
  29. times: 0
  30. }
  31. },
  32. goto() {
  33. this.data.times++
  34. if(this.data.times > 5) {
  35. this.data.times = 0
  36. my.reLaunch({
  37. url: "/pages/index/index"
  38. })
  39. }
  40. },
  41. //查看照片
  42. watch() {
  43. wx.previewImage({
  44. urls: ["https://noise.hz-hanghui.com:8088/yx-fyzd/file/img/instruction.png"]
  45. });
  46. },
  47. authClick: throttle(function () {
  48. if(this.data.disabledSubmitScan) {
  49. return
  50. }
  51. const taskId = `${date.formatTime(Date.now(), "YYYYMMDDHHNNSS")}${parseInt((Math.random() * 9 + 1) * 10000)}`
  52. my.setStorage({
  53. key: 'auth-taskId',
  54. data: taskId
  55. })
  56. my.navigateToMiniProgram({
  57. appId: app.globalData.authAppId, // 16 位
  58. path: 'pages/authorize_three/authorize_three',
  59. query: {
  60. name: '易行智慧通',
  61. notify: null,
  62. token: app.globalData.authAppToken,
  63. taskId
  64. }
  65. })
  66. }, 5000),
  67. // 支付宝验证人脸
  68. async doZFBFaceCheck() {
  69. let {
  70. inputName,
  71. inputIdcard,
  72. phoneNumber,
  73. userId
  74. } = this.data;
  75. let res = await face.getFace_wxrlxf("/api/next/ZFBConfirmFace", "post", {
  76. idNumber: inputIdcard,
  77. phone: phoneNumber,
  78. username: inputName,
  79. userId
  80. })
  81. if (res.data.status === true) {
  82. let userInfo = res.data
  83. userInfo.org = this.data.org
  84. userInfo.orgId = this.data.orgId
  85. userInfo.cardIdEx = this.data.cardIdEx
  86. userInfo.options = this.data.options
  87. app.data.userInfo = userInfo
  88. const that = this
  89. my.alert({
  90. title: '提示',
  91. content: '授权成功',
  92. success() {
  93. that.setCertificationState(true)
  94. }
  95. })
  96. } else {
  97. this.setCertificationState(false)
  98. my.alert({
  99. title: "提示",
  100. content: "未查询到认证结果,请重新认证!"
  101. })
  102. }
  103. },
  104. //获取是否有自定义字段
  105. getContextByAdminId(orgId) {
  106. let that = this;
  107. this.data.isShowApplet = null;
  108. wx.showLoading({
  109. title: "检查账号配置中.."
  110. });
  111. return getContextByAdminId(orgId).then(res => {
  112. that.data.isShowApplet = res.data;
  113. }).finally(() => {
  114. wx.hideLoading();
  115. });
  116. },
  117. //跳转页面 (是否缓存进入)
  118. changePage(showModal) {
  119. if (this.data.isShowApplet) {
  120. wx.navigateTo({
  121. url: "/pages/wx_airport/rlxf_userMsg/index?orgId=" + this.data.orgId + "&org=" + this.data.org + "&showModal=" + showModal
  122. });
  123. } else {
  124. wx.reLaunch({
  125. url: "/pages/wx_airport/rlxf_pass/rlxf_pass?orgId=" + this.data.orgId + "&org=" + this.data.org + "&showModal=" + showModal
  126. });
  127. }
  128. },
  129. goProblem() {
  130. wx.navigateTo({
  131. url: "/pages/wx_airport/problem_report/index?adminId=" + this.data.orgId
  132. });
  133. },
  134. onAppShowHandler(options) {
  135. console.log(options);
  136. if(options && options.referrerInfo) {
  137. // 从三要素认证返回
  138. if(options.referrerInfo.appId === app.globalData.authAppId && options.referrerInfo.extraData) {
  139. const authStatus = options.referrerInfo.extraData.authStatus
  140. if(authStatus) {
  141. const authTaskId = my.getStorageSync({ key: 'auth-taskId' })
  142. my.removeStorage({ key: 'auth-taskId' })
  143. if(authTaskId && authTaskId.data) {
  144. bus.emit('appShowHandler', authTaskId.data)
  145. }
  146. } else {
  147. my.alert({
  148. title: '提示',
  149. content: '授权失败'
  150. })
  151. }
  152. }
  153. }
  154. },
  155. async zfbAuthCallback(authTaskId) {
  156. my.showLoading({
  157. content: "加载中..."
  158. })
  159. const result = await getAuthThree({taskId: authTaskId, token: app.globalData.authAppToken})
  160. /**
  161. * certNo 身份证号
  162. * certName 姓名
  163. * phone 手机号
  164. */
  165. if(result.errcode) {
  166. my.alert({
  167. title: "提示",
  168. content: "未查询到认证结果,请重新认证!"
  169. })
  170. return
  171. }
  172. if(!result.data || !result.data.token) {
  173. my.alert({
  174. title: "提示",
  175. content: result.msg
  176. })
  177. return
  178. }
  179. this.setData({
  180. inputName: result.data.certName,
  181. inputIdcard: result.data.certNo,
  182. phoneNumber: result.data.phone,
  183. userId: result.data.userId
  184. })
  185. this.doZFBFaceCheck()
  186. my.hideLoading()
  187. },
  188. // 设置授权状态
  189. setCertificationState(isSuccess) {
  190. if(isSuccess) {
  191. wx.setStorageSync("userInfo", app.data.userInfo)
  192. this.changePage(true)
  193. } else {
  194. app.data.userInfo = null
  195. }
  196. },
  197. /**
  198. * 生命周期函数--监听页面加载
  199. */
  200. onLoad: async function (options) {
  201. my.onAppShow(this.onAppShowHandler)
  202. this.data.eventId = bus.on('appShowHandler', (res) => {
  203. this.zfbAuthCallback(res)
  204. })
  205. let launchOptions = my.getLaunchOptionsSync()
  206. if(!launchOptions.query) {
  207. launchOptions = my.getEnterOptionsSync()
  208. }
  209. let json = {};
  210. if (!options.isJump) {
  211. // var url = decodeURIComponent(options.q);
  212. // json = verify.GetQueryJson(url);
  213. json = launchOptions.query || {}
  214. } else {
  215. json = options;
  216. }
  217. // 测试用
  218. json = {
  219. orgId: 54,
  220. org: '公司测试',
  221. type: 0,
  222. // disinfectAreaId: 5
  223. };
  224. let moduleContent = {
  225. msg: "未检测到区域码,请扫正确的二维码进入小程序哦~",
  226. show: false
  227. };
  228. if (!("orgId" in json)) {
  229. moduleContent.show = true;
  230. }
  231. if (json.orgId == "" || String(json.orgId) == "null" || String(json.orgId) == "undefined") {
  232. moduleContent.show = true;
  233. moduleContent.msg = "区域码数据已失效,请联系管理员更新二维码";
  234. }
  235. if (moduleContent.show) {
  236. my.alert({
  237. title: "提示",
  238. content: moduleContent.msg
  239. });
  240. this.setData({
  241. disabledSubmitScan: true
  242. });
  243. return;
  244. }
  245. //保留二维码的参数
  246. let urlString = "";
  247. for (let i in json) {
  248. urlString += `${i}=${json[i]}&`;
  249. }
  250. this.data.options = urlString;
  251. this.data.orgId = json.orgId;
  252. this.data.org = json.org;
  253. app.data.type = json.type ? json.type : null;
  254. await this.getContextByAdminId(json.orgId);
  255. // 判断缓存
  256. var userInfo = wx.getStorageSync("userInfo");
  257. if (userInfo) {
  258. if (userInfo.orgId != json.orgId) {
  259. userInfo.createTime = "";
  260. }
  261. userInfo.orgId = json.orgId;
  262. userInfo.org = json.org;
  263. userInfo.options = urlString;
  264. wx.setStorageSync("userInfo", userInfo);
  265. this.changePage(false);
  266. }
  267. if ("disinfectAreaId" in json) {
  268. app.data.disinfectAreaId = json.disinfectAreaId;
  269. }
  270. },
  271. /**
  272. * 生命周期函数--监听页面初次渲染完成
  273. */
  274. onReady: function () {},
  275. /**
  276. * 生命周期函数--监听页面显示
  277. */
  278. onShow: function () {
  279. // setTimeout(() => {
  280. // this.zfbAuthCallback('2023061316041384222')
  281. // }, 3000)
  282. },
  283. /**
  284. * 生命周期函数--监听页面隐藏
  285. */
  286. onHide: function () {},
  287. /**
  288. * 生命周期函数--监听页面卸载
  289. */
  290. onUnload: function () {
  291. bus.remove('appShowHandler', this.data.eventId)
  292. my.offAppShow(this.onAppShowHandler)
  293. },
  294. /**
  295. * 页面相关事件处理函数--监听用户下拉动作
  296. */
  297. onPullDownRefresh: function () {},
  298. /**
  299. * 页面上拉触底事件的处理函数
  300. */
  301. onReachBottom: function () {},
  302. /**
  303. * 用户点击右上角分享
  304. */
  305. onShareAppMessage: function () {},
  306. antmoveAction: function () {
  307. //执行时动态赋值,请勿删除
  308. }
  309. });