"use strict";
const common_vendor = require("../../common/vendor.js");
const api_request = require("../../api/request.js");
const _sfc_main = {
  __name: "login",
  setup(__props) {
    common_vendor.onMounted(() => {
      getFonts();
    });
    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.header["Set-Cookie"]);
      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;
      }
    };
    const getFonts = () => {
      common_vendor.index.loadFontFace({
        family: "FangZhengXiaoZhuan",
        source: `url("https://carbon2.obs.cn-north-4.myhuaweicloud.com/fonts/FangZhengXiaoZhuan.ttf")`,
        success: (res) => {
          console.log("success", res);
        },
        fail: (err) => {
          console.log("err", err);
        }
      });
      common_vendor.index.loadFontFace({
        family: "FangZhengFonts",
        source: `url("https://carbon2.obs.cn-north-4.myhuaweicloud.com/fonts/FangZhengFonts.TTF")`,
        success: (res) => {
          console.log("success", res);
        },
        fail: (err) => {
          console.log("err", err);
        }
      });
    };
    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);
