邃芒智像相册
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 

192 行
3.4 KiB

  1. const app = getApp()
  2. import request from '../../utils/request'
  3. import Dialog from '@vant/weapp/dialog/dialog';
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. isAgree: false,
  10. tmpUserId: ""
  11. },
  12. /**
  13. * 生命周期函数--监听页面加载
  14. */
  15. onLoad(options) {
  16. console.log(options, 'options');
  17. wx.hideHomeButton()
  18. if (options.scene) {
  19. this.setData({
  20. tmpUserId: options.scene
  21. })
  22. }
  23. app.tokenCallBack = token => {
  24. if (token) {
  25. this.bindUser()
  26. } else {
  27. }
  28. }
  29. },
  30. /**
  31. * 生命周期函数--监听页面显示
  32. */
  33. onShow() {
  34. },
  35. getPhoneNumber(e) {
  36. const that = this
  37. if (e.detail.iv) {
  38. const openId = wx.getStorageSync('openId')
  39. const appId = request.appId
  40. const iv = e.detail.iv
  41. const encryptedData = e.detail.encryptedData
  42. const data = {
  43. openId,
  44. appId,
  45. encryptedData,
  46. iv
  47. }
  48. that.loginWithPhone(data)
  49. } else {
  50. that.getPhoneNumberFail()
  51. wx.showToast({
  52. title: '授权失败',
  53. icon: "error"
  54. })
  55. }
  56. },
  57. checkUserPro() {
  58. if (!this.data.isAgree) {
  59. Dialog.confirm({
  60. title: '提示',
  61. message: '同意智像相机用户使用协议?',
  62. })
  63. .then(() => {
  64. this.setData({
  65. isAgree: true
  66. })
  67. })
  68. .catch(() => {
  69. // on cancel
  70. });
  71. }
  72. },
  73. // 用户协议状态变更
  74. checkboxChange(e) {
  75. if (e.detail.value[0]) {
  76. this.setData({
  77. isAgree: true
  78. })
  79. } else {
  80. this.setData({
  81. isAgree: false
  82. })
  83. }
  84. },
  85. // 查看用户协议
  86. goPro() {
  87. wx.navigateTo({
  88. url: '/pages/userProtocol/userProtocol',
  89. })
  90. },
  91. loginWithPhone(data) {
  92. const that = this
  93. request.post({
  94. url: '/api/miniApp/loginPhone',
  95. data
  96. }).then(res => {
  97. // 获取手机号之后,绑定用户与机器
  98. if (res.data.token) {
  99. wx.setStorageSync('token', res.data.token)
  100. request.setHead(res.data.token)
  101. }
  102. that.bindUser()
  103. }).catch(err => {
  104. console.log(err, 'err');
  105. })
  106. },
  107. // 绑定用户与机器
  108. bindUser() {
  109. const openId = wx.getStorageSync('openId')
  110. const tmpUserId = this.data.tmpUserId
  111. const data = {
  112. openId,
  113. tmpUserId
  114. }
  115. request.post({
  116. url: '/api/miniApp/bindUser',
  117. data
  118. }).then(res => {
  119. console.log(res, 'res');
  120. wx.showToast({
  121. title: '登录成功!',
  122. icon: "success",
  123. duration: 1500,
  124. complete: () => {
  125. setTimeout(() => {
  126. if (tmpUserId) {
  127. wx.setStorageSync('isPay', false)
  128. wx.redirectTo({
  129. url: `/pages/index/index?machineQrcodeId=${tmpUserId}`,
  130. })
  131. } else {
  132. wx.redirectTo({
  133. url: `/pages/index/index`,
  134. })
  135. }
  136. }, 1500);
  137. }
  138. })
  139. }).catch(err => {
  140. console.log(err, 'err');
  141. wx.showToast({
  142. title: '服务器异常,请稍后再试',
  143. icon: "none"
  144. })
  145. })
  146. },
  147. getPhoneNumberFail() {
  148. },
  149. /**
  150. * 页面相关事件处理函数--监听用户下拉动作
  151. */
  152. onPullDownRefresh() {
  153. },
  154. /**
  155. * 页面上拉触底事件的处理函数
  156. */
  157. onReachBottom() {
  158. },
  159. /**
  160. * 用户点击右上角分享
  161. */
  162. onShareAppMessage() {
  163. }
  164. })