| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- // pages/index/index.js
- import cloudApi from "../../apis/cloudApi"
- import {
- wxSetSessionKey,
- } from "../../utils/wxUtils"
- import {
- postApi
- } from "../../apis/api"
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- },
- go() {
- if (wx.getStorageSync('userId')) {
- wx.navigateTo({
- url: '/pages/takePhoto/takePhoto',
- })
- } else {
- this.getOpenid()
- }
- },
- async getOpenid() {
- let res = await cloudApi("getOpenId")
- let {
- openId
- } = res.result
- wx.setStorageSync('openId', openId)
- let res1 = await postApi("/user/wx/login", {
- openId
- })
- if (res1.data.status == 0) {
- let data = {
- ...res1.data.result.userInfo,
- ...res1.data.result.shipInfo,
- }
- Object.keys(data).forEach(function (key) {
- wx.setStorageSync(key, data[key])
- })
- wx.navigateTo({
- url: '/pages/takePhoto/takePhoto',
- })
- } else {
- let session_key = wx.getStorageSync('session_key')
- let openId = wx.getStorageSync('openId')
- wx.navigateTo({
- url: '/pages/takePhoto/takePhoto',
- })
- wx.clearStorage({
- success: (res) => {
- wx.setStorageSync('session_key', session_key)
- wx.setStorageSync('openId', openId)
- },
- })
- }
- },
- onLoad: function (options) {
- this.getOpenid()
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
- }
- })
|