<template>
  <div id="homeIndex">
    <el-row>
      <el-col :span="24" class="main animate__animated animate__backInRight" v-loading="loading">
        <el-col :span="24" class="one">
          <el-button type="primary" v-for="i in list" :key="i._id" @click="toPath(i)">{{ i.name }}</el-button>
        </el-col>
      </el-col>
    </el-row>
  </div>
</template>

<script setup lang="ts">
// 基础
import type { Ref } from 'vue';
import { ElMessage } from 'element-plus';
import { onMounted, ref } from 'vue';
import { useRouter } from 'vue-router';
// 接口
import { ModuleStore } from '@common/src/stores/system/module';
import { MenusStore } from '@common/src/stores/system/menus';
import type { IQueryResult } from '@/util/types.util'; //
const moduleAxios = ModuleStore();
const menusAxios = MenusStore();

// 路由
const router = useRouter();
// 加载中
const loading: Ref<any> = ref(false);

const list: Ref<any> = ref([]);

// 请求
onMounted(async () => {
  loading.value = true;
  await search();
  loading.value = false;
});
const search = async () => {
  let name = import.meta.env.VITE_APP_ROUTER;
  const res: IQueryResult = await moduleAxios.query({ name: name, is_use: '0' });
  if (res && res.errcode == '0') {
    if (res.total > 0) {
      let moduleInfo = res.data[0];
      let menusInfo: IQueryResult = await menusAxios.query({ module_id: moduleInfo._id });
      if (res.errcode == '0') list.value = menusInfo.data;
    }
  } else {
    ElMessage({ message: `${res.errmsg}`, type: 'error' });
  }
};
const toPath = (e) => {
  router.push({ path: `${e.path}` });
};
</script>
<style scoped lang="scss"></style>
