index.js 1.7 KB

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