index.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. wx.navigateTo({
  17. url: '/pages/takePhoto/takePhoto',
  18. })
  19. },
  20. async getOpenid() {
  21. let res = await cloudApi("getOpenId")
  22. let {
  23. openId
  24. } = res.result
  25. wx.setStorageSync('openId', openId)
  26. let res1 = await postApi("/user/wx/login", {
  27. openId
  28. })
  29. console.log(res1)
  30. if (res1.data.status == 0) {
  31. let data = {
  32. ...res1.data.result.userInfo,
  33. ...res1.data.result.shipInfo,
  34. }
  35. Object.keys(data).forEach(function (key) {
  36. wx.setStorageSync(key, data[key])
  37. })
  38. wx.navigateTo({
  39. url: '/pages/takePhoto/takePhoto',
  40. })
  41. } else {
  42. let session_key = wx.getStorageSync('session_key')
  43. let openId = wx.getStorageSync('openId')
  44. wx.clearStorage({
  45. success: (res) => {
  46. wx.setStorageSync('session_key', session_key)
  47. wx.setStorageSync('openId', openId)
  48. },
  49. })
  50. }
  51. },
  52. onLoad: function (options) {
  53. this.getOpenid()
  54. },
  55. /**
  56. * 用户点击右上角分享
  57. */
  58. onShareAppMessage: function () {
  59. }
  60. })