index.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. switch (options.type) {
  21. case 'watch':
  22. this.setData({ title: '查看填报', value: options.data || '', type: options.type });
  23. break;
  24. case 'draftsupdate':
  25. this.setData({ title: "修改草稿", value: options.data || '', type: options.type });
  26. break;
  27. case 'providedupdate':
  28. this.setData({ title: "修改已填报", value: options.data || '', type: options.type });
  29. break;
  30. default:
  31. this.setData({ type: options.type, value: options.data || '', title: "新增填报" })
  32. }
  33. },
  34. onReady: function () {
  35. },
  36. onShow: function () {
  37. if (!app.globalData._initState) {
  38. wx.navigateTo({
  39. url: '/pages/index/index',
  40. });
  41. return false;
  42. }
  43. !wx.getStorageSync('token') &&
  44. Dialg.confirm({ message: "您尚未登录,不能操作该功能!", confirmButtonText: '微信快捷登录', confirmButtonOpenType: "getPhoneNumber" }).then(res => {
  45. }).catch(() => { wx.navigateBack({ delta: 1 }) })
  46. ;
  47. },
  48. onHide: function () {
  49. },
  50. onUnload: function () {
  51. },
  52. onPullDownRefresh: function () {
  53. },
  54. onReachBottom: function () {
  55. },
  56. })