"use strict";
const common_vendor = require("../../common/vendor.js");
const api_request = require("../../api/request.js");
const _sfc_main = {
  __name: "login",
  setup(__props) {
    const login = () => {
      common_vendor.index.login({
        provider: "weixin",
        //使用微信登录
        success: function(loginRes) {
          if (loginRes.code !== null) {
            console.log("获取code:" + loginRes.code);
            loginUser(loginRes.code);
          } else {
            console.log("code为空");
          }
        }
      });
    };
    const loginUser = async (code) => {
      const res = await common_vendor.index.request({
        url: api_request.baseUrl + "/user/login/wx_open",
        method: "GET",
        data: {
          code
        }
      });
      console.log("loginUser后台返回的==>", res);
      common_vendor.index.removeStorageSync("cookie");
      common_vendor.index.setStorageSync("cookie", res.header["Set-Cookie"]);
      if (res.data.code == 1) {
        common_vendor.index.showToast({
          title: "登录成功",
          duration: 2e3
          //提示两秒
        });
        common_vendor.index.setStorageSync("userInfo", res.data.data);
        common_vendor.index.switchTab({
          url: "/pages/home/home"
        });
      } else {
        common_vendor.index.showToast({
          icon: "error",
          title: "登录失败，请重试"
        });
        return;
      }
    };
    return (_ctx, _cache) => {
      return {
        a: common_vendor.o(login)
      };
    };
  }
};
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-e4e4508d"], ["__file", "D:/jiangchengfeiyi-xiaochengxu/pages/login/login.vue"]]);
wx.createPage(MiniProgramPage);
