"use strict";
const common_vendor = require("../common/vendor.js");
const stores_user = require("../stores/user.js");
const stores_permission = require("../stores/permission.js");
require("../utils/storage.js");
require("../utils/constant.js");
require("../utils/auth.js");
require("../utils/request.js");
require("../config.js");
require("../utils/errorCode.js");
require("../utils/common.js");
if (!Array) {
  const _easycom_u_checkbox2 = common_vendor.resolveComponent("u-checkbox");
  const _easycom_u_checkbox_group2 = common_vendor.resolveComponent("u-checkbox-group");
  (_easycom_u_checkbox2 + _easycom_u_checkbox_group2)();
}
const _easycom_u_checkbox = () => "../node-modules/uview-plus/components/u-checkbox/u-checkbox.js";
const _easycom_u_checkbox_group = () => "../node-modules/uview-plus/components/u-checkbox-group/u-checkbox-group.js";
if (!Math) {
  (_easycom_u_checkbox + _easycom_u_checkbox_group)();
}
const _sfc_main = {
  __name: "login",
  setup(__props) {
    const userStore = stores_user.useUserStore();
    const permissionStore = stores_permission.usePermissionStore();
    const { proxy } = common_vendor.getCurrentInstance();
    const data = common_vendor.reactive({
      loginForm: {
        username: "",
        password: "",
        code: "",
        uuid: ""
      },
      isRemember: []
    });
    const {
      loginForm,
      isRemember
    } = common_vendor.toRefs(data);
    common_vendor.onMounted(() => {
      if (common_vendor.index.getStorageSync("account")) {
        isRemember.value = ["1"];
        let account = JSON.parse(common_vendor.index.getStorageSync("account"));
        loginForm.value.username = account.username;
        loginForm.value.password = account.password;
      }
    });
    function remember(e) {
      isRemember.value = e;
    }
    function handleLogin() {
      if (!loginForm.value.username) {
        proxy.$modal.msg("请输入账号~");
        return;
      }
      if (!loginForm.value.password) {
        proxy.$modal.msg("请输入密码~");
        return;
      }
      pwdLogin();
    }
    async function pwdLogin(params) {
      if (isRemember.value.length > 0 && isRemember.value[0]) {
        let account = {
          username: loginForm.value.username,
          password: loginForm.value.password
        };
        common_vendor.index.setStorageSync("account", JSON.stringify(account));
      } else {
        common_vendor.index.setStorageSync("account", "");
      }
      await userStore.Login(loginForm.value);
      await permissionStore.GetPermis();
      console.log("permissionStore.permissions_menu=================", permissionStore.permissions_menu);
      if (permissionStore.permissions_menu && permissionStore.permissions_menu != "[]") {
        proxy.$tab.reLaunch("/pages/globalPages/home");
      } else {
        proxy.$modal.msg("该用户无权限~");
      }
    }
    return (_ctx, _cache) => {
      return {
        a: common_vendor.unref(loginForm).username,
        b: common_vendor.o(($event) => common_vendor.unref(loginForm).username = $event.detail.value),
        c: common_vendor.unref(loginForm).password,
        d: common_vendor.o(($event) => common_vendor.unref(loginForm).password = $event.detail.value),
        e: common_vendor.p({
          size: "16",
          labelSize: "12",
          labelColor: "#666",
          name: "1",
          label: "记住密码"
        }),
        f: common_vendor.o(remember),
        g: common_vendor.o(($event) => common_vendor.isRef(isRemember) ? isRemember.value = $event : null),
        h: common_vendor.p({
          modelValue: common_vendor.unref(isRemember)
        }),
        i: common_vendor.o(handleLogin)
      };
    };
  }
};
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-236737c1"], ["__file", "F:/兴元/开门柜项目/平台端管理系统小程序/src/pages/login.vue"]]);
wx.createPage(MiniProgramPage);
