<template>
  <div id="home">
    <home1 v-if="type == '1'"></home1>
    <home2 v-else-if="type == '2'"></home2>
    <!--  <home3 v-else-if="type == '3'"></home3> -->
  </div>
</template>

<script setup lang="ts">
// 组件

import store from '@/stores/counter';
import home1 from './home-1.vue';
import home2 from './home-2.vue';
// import home3 from './home-3.vue';
import type { Ref } from 'vue';
import { ref, onMounted } from 'vue';
import { ElMessage } from 'element-plus';

// 接口
import { ModuleStore } from '@common/src/stores/admin/module'; //模块
import { RoleStore } from '@common/src/stores/admin/role'; //模块
import type { IQueryResult } from '@/util/types.util'; //
const module = ModuleStore();
const role = RoleStore();
// 默认值
let type: Ref<string> = ref('');

onMounted(async () => {
  let e = store.state.user;
  let name = import.meta.env.VITE_APP_ROUTER;
  const res: IQueryResult = await module.query({ name: name, is_use: 'Y' });
  if (res && res.errcode == '0') {
    if (res.total > 0) {
      let moduleInfo = res.data[0];
      let roleInfo = await role.um();
      if (roleInfo.errcode == '0') {
        if (roleInfo.data) {
          let menus = roleInfo.data[moduleInfo._id];
          if (menus && menus.length > 0) {
            if (e && e.role_type == '1') type.value = '1';
            else if ((e && e.role_type == '2') || (e && e.role_type == '3')) type.value = '2';
            localStorage.setItem('is_role', 'true');
          } else {
            type.value = '2';
            localStorage.setItem('is_role', 'false');
          }
        }
      }
    }
  } else {
    ElMessage({ message: `${res.errmsg}`, type: 'error' });
  }
});
</script>

<style scoped lang="scss"></style>
