index.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. loginStatus: false
  15. },
  16. goToExperience() {
  17. wx.redirectTo({
  18. url: `${this.data.loginStatus?'/pages/takePhoto/takePhoto':'/pages/newCachePage/newCachePage'}`,
  19. })
  20. },
  21. async login() {
  22. wxSetSessionKey()
  23. let res1 = await postApi("/user/wx/openId/login", {
  24. openId: wx.getStorageSync('openId')
  25. })
  26. if (res1.data.status == 0) {
  27. let data = {
  28. ...res1.data.result.userInfo,
  29. ...res1.data.result.shipInfo,
  30. }
  31. Object.keys(data).forEach(function (key) {
  32. wx.setStorageSync(key, data[key])
  33. })
  34. wx.navigateTo({
  35. url: '/pages/takePhoto/takePhoto',
  36. })
  37. } else {
  38. let session_key = wx.getStorageSync('session_key')
  39. let openId = wx.getStorageSync('openId')
  40. wx.navigateTo({
  41. url: '/pages/takePhoto/takePhoto',
  42. })
  43. wx.clearStorage({
  44. success: (res) => {
  45. wx.setStorageSync('session_key', session_key)
  46. wx.setStorageSync('openId', openId)
  47. },
  48. })
  49. }
  50. },
  51. onLoad: function (options) {
  52. if (wx.getStorageSync('userId') && wx.getStorageSync('shipName')) {
  53. this.setData({
  54. loginStatus: true
  55. })
  56. }
  57. },
  58. onShow() {
  59. let v = wx.getAccountInfoSync()
  60. if (v.miniProgram.envVersion != "release") {
  61. wx.showToast({
  62. title: `当前环境:${v.miniProgram.envVersion=="develop"?'开发版':'体验版'}`,
  63. icon: 'none',
  64. duration: 1000
  65. })
  66. }
  67. },
  68. /**
  69. * 用户点击右上角分享
  70. */
  71. onShareAppMessage: function () {
  72. }
  73. })