index.ts 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. // pages/entry/index.ts
  2. const app = getApp<IAppOption>();
  3. import { compareVersion } from "../../utils/util";
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. nickName: "",
  10. phoneNumber: "",
  11. school: "",
  12. schoolList: [],
  13. inputed: false
  14. },
  15. phoneinput(e: WechatMiniprogram.CustomEvent) {
  16. this.setData({
  17. phoneNumber: e.detail.value
  18. })
  19. },
  20. bindKeyInput(e: WechatMiniprogram.CustomEvent) {
  21. this.setData({
  22. nickName: e.detail.value
  23. })
  24. },
  25. toFace() {
  26. if (!this.data.phoneNumber) {
  27. return wx.showToast({
  28. "icon": "none",
  29. "title": "未获取手机号",
  30. duration: 2000
  31. })
  32. }
  33. app.seaveUserData({
  34. data: {
  35. name: this.data.nickName,
  36. phone: this.data.phoneNumber,
  37. organization: this.data.school || undefined
  38. },
  39. method: "POST",
  40. success: () => {
  41. // 进入人脸识别
  42. let url = "/pages/faceRecognition/index";
  43. const version: string = app.globalData.SystemInfo?.SDKVersion || "";
  44. if (compareVersion(version, "2.25.0") !== -1) url = "/pages/faceRecognitionVK/index"
  45. wx.navigateTo({ url })
  46. }
  47. })
  48. },
  49. getPhoneNumber(e: WechatMiniprogram.CustomEvent) {
  50. if (!e.detail.code) {
  51. wx.showToast({
  52. title: "请升级最新版微信。"
  53. })
  54. return
  55. }
  56. app.getPhone({
  57. data: {
  58. code: e.detail.code
  59. },
  60. header: {},
  61. success: (res: any) => {
  62. if (!res.purePhoneNumber) {
  63. app.globalData.phone = "";
  64. wx.setStorageSync("userphone", "");
  65. wx.showToast({
  66. icon: "none",
  67. title: "未获取手机号,请手动输入",
  68. duration: 2000
  69. })
  70. return;
  71. }
  72. app.globalData.phone = res.purePhoneNumber;
  73. this.setData({
  74. phoneNumber: res.purePhoneNumber
  75. })
  76. wx.setStorageSync("userphone", res.purePhoneNumber);
  77. this.setData({
  78. inputed: true
  79. })
  80. }
  81. })
  82. },
  83. bindchange(e:WechatMiniprogram.CustomEvent){
  84. this.setData({
  85. school: this.data.schoolList[e.detail.value] || ""
  86. })
  87. },
  88. /**
  89. * 生命周期函数--监听页面加载
  90. */
  91. onLoad() {
  92. if (app.globalData.phone) {
  93. this.setData({
  94. phoneNumber: app.globalData.phone,
  95. inputed: true
  96. })
  97. }
  98. app.getSchoolList({
  99. data: {},
  100. method: "GET",
  101. success: (res: any) => {
  102. this.setData({
  103. schoolList: (res || []).map((v:any) => v.organization),
  104. school: (res || [])[0]?.organization
  105. })
  106. }
  107. })
  108. },
  109. /**
  110. * 生命周期函数--监听页面初次渲染完成
  111. */
  112. onReady() {
  113. },
  114. /**
  115. * 生命周期函数--监听页面显示
  116. */
  117. onShow() {
  118. },
  119. /**
  120. * 生命周期函数--监听页面隐藏
  121. */
  122. onHide() {
  123. },
  124. /**
  125. * 生命周期函数--监听页面卸载
  126. */
  127. onUnload() {
  128. },
  129. /**
  130. * 页面相关事件处理函数--监听用户下拉动作
  131. */
  132. onPullDownRefresh() {
  133. },
  134. /**
  135. * 页面上拉触底事件的处理函数
  136. */
  137. onReachBottom() {
  138. },
  139. /**
  140. * 用户点击右上角分享
  141. */
  142. onShareAppMessage() {
  143. }
  144. })
  145. export { }