index.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. // pages/index/index.js
  2. import cloudApi from "../../apis/cloudApi"
  3. import {
  4. wxSetSessionKey,
  5. } from "../../utils/wxUtils"
  6. import {
  7. postApi
  8. } from "../../apis/api"
  9. Page({
  10. /**
  11. * 页面的初始数据
  12. */
  13. data: {
  14. },
  15. go() {
  16. if (wx.getStorageSync('userId')) {
  17. wx.navigateTo({
  18. url: '/pages/takePhoto/takePhoto',
  19. })
  20. } else {
  21. this.getOpenid()
  22. }
  23. },
  24. async getOpenid() {
  25. let res = await cloudApi("getOpenId")
  26. let {
  27. openId
  28. } = res.result
  29. wx.setStorageSync('openId', openId)
  30. let res1 = await postApi("/user/wx/login", {
  31. openId
  32. })
  33. if (res1.data.status == 0) {
  34. let data = {
  35. ...res1.data.result.userInfo,
  36. ...res1.data.result.shipInfo,
  37. }
  38. Object.keys(data).forEach(function (key) {
  39. wx.setStorageSync(key, data[key])
  40. })
  41. wx.navigateTo({
  42. url: '/pages/takePhoto/takePhoto',
  43. })
  44. } else {
  45. let session_key = wx.getStorageSync('session_key')
  46. let openId = wx.getStorageSync('openId')
  47. wx.clearStorage({
  48. success: (res) => {
  49. wx.setStorageSync('session_key', session_key)
  50. wx.setStorageSync('openId', openId)
  51. },
  52. })
  53. }
  54. },
  55. onLoad: function (options) {
  56. this.getOpenid()
  57. },
  58. /**
  59. * 用户点击右上角分享
  60. */
  61. onShareAppMessage: function () {
  62. }
  63. })