index.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import Dialg from "../../miniprogram_npm/@vant/weapp/dialog/dialog";
  2. const app = getApp();
  3. Page({
  4. data: {
  5. CustomBar: app.globalData.CustomBar,
  6. },
  7. // 登录
  8. async getphonenumber (e) {
  9. try {
  10. if (!e.detail.hasOwnProperty('iv')) return false;
  11. let { encryptedData, iv } = e.detail, { appId: appid } = app.globalData.mustArg, { openid } = app.globalData.user;
  12. let res = await wx.$request({ url: "/account/wxbind/", data: { appid, openid, encryptedData, iv }, method: "post" });
  13. let { face, name, tel, token, type, user_id } = res.data;
  14. wx.setStorageSync("token", token ? 'JWT ' + token : '');
  15. app.globalData.user = { ...app.globalData.user, face, name, tel, token, type, user_id };
  16. this.onShow();
  17. } catch (err) { wx.$err(err) }
  18. },
  19. onLoad: function (options) {
  20. options.data && this.setData({ value: options.data });
  21. },
  22. onReady: function () {
  23. },
  24. onShow: function () {
  25. if (!app.globalData._initState) {
  26. wx.navigateTo({
  27. url: '/pages/index/index',
  28. });
  29. return false;
  30. }
  31. !wx.getStorageSync('token') &&
  32. Dialg.confirm({ message: "您尚未登录,不能操作该功能!", confirmButtonText: '微信快捷登录', confirmButtonOpenType: "getPhoneNumber" }).then(res => {
  33. }).catch(() => { wx.navigateBack({ delta: 1 }) })
  34. ;
  35. },
  36. onHide: function () {
  37. },
  38. onUnload: function () {
  39. },
  40. onPullDownRefresh: function () {
  41. },
  42. onReachBottom: function () {
  43. },
  44. })