| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- // pages/index/index.js
- import { wxSetSessionKey } from "../../utils/wxUtils";
- import { postApi } from "../../apis/api";
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- loginStatus: false,
- },
- async login() {
- if (!wx.getStorageSync("openId")) {
- wx.showToast({
- title: "正在初始化登录信息...",
- icon: "none",
- duration: 1500,
- });
- wxSetSessionKey();
- return;
- }
- wx.showLoading({
- title: "正在登录...",
- });
- let { data } = await postApi("/login/openid", {
- openId: wx.getStorageSync("openId"),
- });
- if (data.status == 0) {
- let obj = {
- ...data.result.userInfo,
- ...data.result.shipInfo,
- };
- Object.keys(obj).forEach(function (key) {
- wx.setStorageSync(key, obj[key]);
- });
- wx.setStorageSync("accessToken", data.result.tokenInfo.tokenValue);
- } else {
- wx.showToast({
- title: data.msg,
- icon: "none",
- duration: 1500,
- });
- }
- setTimeout(() => {
- wx.hideLoading();
- wx.switchTab({
- url: "/pages/takePhoto/takePhoto",
- });
- }, 1000);
- },
- onLoad: function (options) {
- if (wx.getStorageSync("userId") && wx.getStorageSync("shipName")) {
- this.setData({
- loginStatus: true,
- });
- }
- },
- onShow() {
- let v = wx.getAccountInfoSync();
- if (v.miniProgram.envVersion != "release") {
- wx.showToast({
- title: `当前环境:${
- v.miniProgram.envVersion == "develop" ? "开发版" : "体验版"
- }`,
- icon: "none",
- duration: 1000,
- });
- }
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {},
- });
|