register.js 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. const util = require("../../utils/tool");
  2. const App = getApp();
  3. // import common from "/utils/tool.js";
  4. Page({
  5. data: {
  6. appAssetsUrl: App.appAssetsUrl,
  7. apiRoot: App.apiRoot,
  8. isCheck: false,
  9. mobile: "",
  10. inviteCode: "",
  11. // App.apiRoot+'auth/captcha.jpg?t='+ new Date().getTime()
  12. captcha: "",
  13. imgCode: "",
  14. code: "",
  15. time: 60,
  16. word: "获取验证码",
  17. isDjs: false,
  18. clear: null,
  19. openid: "",
  20. meetId: "",
  21. expertId: "",
  22. memberId: "",
  23. disabled: false,
  24. },
  25. onLoad: function (options) {
  26. // inviteCode
  27. console.log(options, options.inviteCode, "inviteCode");
  28. this.setData({
  29. inviteCode: options.inviteCode,
  30. openid: options.openid,
  31. });
  32. // this.getCaptcha()
  33. this.getYzcode();
  34. if (options.meetId != "") {
  35. this.setData({
  36. meetId: options.meetId,
  37. expertId: options.expertId,
  38. memberId: options.memberId,
  39. });
  40. }
  41. },
  42. getYzcode() {
  43. App._get(
  44. `auth/base64/captcha`, {
  45. openid: this.data.openid,
  46. },
  47. (res) => {
  48. if (res.code === 0) {
  49. this.setData({
  50. captcha: res.data,
  51. });
  52. }
  53. }
  54. );
  55. },
  56. // getPhoneNumber(e) {
  57. // if (e.detail.errMsg == 'getPhoneNumber:ok') {
  58. // // 用户允许获取手机号
  59. // this.setData({
  60. // code: e.detail.code
  61. // })
  62. // this.getKey(e.detail.code);
  63. // }
  64. // },
  65. // getKey(code) {
  66. // let that = this;
  67. // App._post_form('auth/getAppletPhone', "application/json", code, res => {
  68. // console.log(res, 222222)
  69. // if (res.code == 0) {
  70. // that.setData({
  71. // telInput: res.msg
  72. // })
  73. // }
  74. // }, fail => {
  75. // console.log(fail);
  76. // })
  77. // },
  78. getPhoneNumber(e) {
  79. const that = this;
  80. if (e.detail.errMsg != "getPhoneNumber:ok") {
  81. return;
  82. }
  83. var params = {
  84. encryptedData: e.detail.encryptedData,
  85. iv: e.detail.iv,
  86. sessionKey: wx.getStorageSync("session_key"),
  87. };
  88. App._post_form(
  89. "member/decodeUserInfo?encryptedData=" +
  90. params.encryptedData +
  91. "&iv=" +
  92. params.iv +
  93. "&sessionKey=" +
  94. params.sessionKey,
  95. "application/json;charset=UTF-8",
  96. params,
  97. function (data) {
  98. if (data.code == 0) {
  99. that.setData({
  100. mobile: data.msg,
  101. disabled: true
  102. });
  103. }
  104. },
  105. function (err) {
  106. wx.showToast({
  107. title: "请求失败",
  108. icon: "none",
  109. duration: 3500,
  110. });
  111. return;
  112. }
  113. );
  114. // wx.checkSession({
  115. // success (res) {
  116. // console.log(res, 111)
  117. // if(res.errMsg=="checkSession:ok"){
  118. // }
  119. // },
  120. // fail () {
  121. // // session_key 已经失效,需要重新执行登录流程
  122. // util.alert('微信登录已过期');
  123. // setTimeout(() => {
  124. // wx.navigateBack({
  125. // delta: 1
  126. // });
  127. // },2500)
  128. // }
  129. // })
  130. },
  131. // 获取图形验证码
  132. getCaptcha() {
  133. this.setData({
  134. captcha: "",
  135. });
  136. if (this.data.captcha === "") {
  137. setTimeout(() => {
  138. this.setData({
  139. captcha: this.data.apiRoot +
  140. "auth/captcha.jpg?openid=" +
  141. this.data.openid +
  142. "&t=" +
  143. new Date().getTime(),
  144. });
  145. }, 300);
  146. }
  147. // console.log('dddddddddddddd')
  148. // this.setData({
  149. // captcha: this.data.apiRoot + 'auth/captcha.jpg?openid=' + this.data.openid + '&t=' + new Date().getTime()
  150. // })
  151. // console.log(this.data.captcha,'11111111111111')
  152. },
  153. // changeCode() {
  154. // this.setData({
  155. // captcha: ''
  156. // })
  157. // this.getCaptcha()
  158. // },
  159. codeDetail(e) {
  160. console.log(e);
  161. },
  162. change(e) {
  163. if (e.detail.value.length > 0) {
  164. this.setData({
  165. isCheck: true,
  166. });
  167. } else {
  168. this.setData({
  169. isCheck: false,
  170. });
  171. }
  172. },
  173. //倒计时
  174. countDown() {
  175. var that = this;
  176. if (that.data.time <= 0) {
  177. this.setData({
  178. isDjs: false,
  179. time: 60,
  180. });
  181. clearInterval(that.data.clear);
  182. } else {
  183. --that.data.time;
  184. this.setData({
  185. isDjs: true,
  186. time: that.data.time,
  187. });
  188. }
  189. },
  190. getCode() {
  191. let that = this;
  192. if (!this.data.mobile) {
  193. return util.alert("请先获取手机号");
  194. }
  195. if (!this.data.isDjs) {
  196. this.setData({
  197. isDjs: true,
  198. clear: setInterval(that.countDown, 1000),
  199. });
  200. App._get(
  201. "auth/sendCode", {
  202. mobile: this.data.mobile,
  203. },
  204. (res) => {
  205. if (res.code === 0) {
  206. wx.showToast({
  207. title: "发送成功",
  208. });
  209. }
  210. }
  211. );
  212. // this.data.clear = setInterval(this.countDown, 1000);
  213. }
  214. // this.setData({
  215. // word: this.data.time
  216. // })
  217. // this.data.word = this.data.time
  218. console.log("dffddf");
  219. console.log(this.data.isDjs);
  220. },
  221. toPrivacy() {
  222. wx.navigateTo({
  223. url: "/pages/privacy/privacy",
  224. });
  225. },
  226. reg() {
  227. if (!this.data.mobile) {
  228. return util.alert("请获取手机号");
  229. }
  230. if (!this.data.imgCode) {
  231. return util.alert("请输入图形验证码");
  232. }
  233. if (!this.data.code && !this.data.disabled) {
  234. return util.alert("请输入短信证码");
  235. }
  236. if (!this.data.isCheck) {
  237. return util.alert("请勾选隐私协议");
  238. }
  239. let userInfo = wx.getStorageSync("userInfo");
  240. let form = {
  241. captcha: this.data.imgCode,
  242. inviteCode: this.data.inviteCode,
  243. memberPhoto: userInfo.avatarUrl,
  244. mobile: this.data.mobile,
  245. name: userInfo.nickName,
  246. openid: wx.getStorageSync("openid"),
  247. shortMessageCode: this.data.code,
  248. };
  249. App._post_form(
  250. "auth/appletsRegistered",
  251. "application/json;charset=UTF-8",
  252. form,
  253. (res) => {
  254. if (res.code === 0) {
  255. wx.setStorageSync("USER", res.memberinfo);
  256. console.log(this.data.meetId, 11111111)
  257. if (this.data.meetId != "") {
  258. wx.reLaunch({
  259. url: `/meet/meet/addmeet?meetId=${this.data.meetId}&expertId=${this.data.expertId}&memberId=${this.data.memberId}`,
  260. });
  261. } else {
  262. wx.reLaunch({
  263. url: "/pages/home/index/index?login=1",
  264. });
  265. }
  266. }
  267. }
  268. );
  269. },
  270. onUnload: function () {
  271. clearInterval(this.data.clear);
  272. console.log("卸载");
  273. },
  274. });