<template>
  <h1>DocumentAI</h1>

  <h3>build version</h3>
  <p class="italic">{{ version }}</p>

  <h3>build tag</h3>
  <p class="italic">{{ build_tag }}</p>


  <h3>模型信息</h3>
  <p>模型个数：{{ model_num }}</p>
  <el-table :data="model_data" style="width: 100%">
    <el-table-column prop="key" label="Key" width="auto" />
    <el-table-column prop="type" label="Type" width="auto" />
    <el-table-column prop="subtype" label="Subtype" width="auto" />
    <el-table-column prop="format" label="Format" width="auto" />
    <el-table-column prop="version" label="Version" width="auto" />
  </el-table>
</template>

<script setup lang="ts">
import { onMounted, ref } from "vue";
import { GetBuildTag, GetModelInfo } from '../../../api/api'
import { storeToRefs } from 'pinia'
import { useVersionStore } from '../../../store/Version';

const vr = useVersionStore();
const { build_tag, model_info, version } = storeToRefs(vr);

let model_num = ref(0)
let model_data: any = ref([])

onMounted(async () => {
  if (build_tag.value == "") {
    GetBuildTag("/v1/buildTag").then(res => {
      build_tag.value = res;
    })
  }
  if (model_info.value == "") {
    GetModelInfo("/v1/modelInfo").then(res => {
      model_info.value = res;
      const model = JSON.parse(model_info.value)
      model_num.value = model['model_num']
      console.log(model['model_num'])
      console.log(model['model_keys'])
      const model_array = model['model_keys']
      for (let i = 0; i < model_array.length; i++) {
        model_data.value.push({
          key: model_array[i]['model_key'],
          type: model_array[i]['model_type'],
          subtype: model_array[i]['model_sub_type'],
          format: model_array[i]['model_format'],
          version: model_array[i]['model_version'],
        })
      }
    })
  }
  const model = JSON.parse(model_info.value)
  model_num.value = model['model_num']
  console.log(model['model_num'])
  console.log(model['model_keys'])
  const model_array = model['model_keys']
  for (let i = 0; i < model_array.length; i++) {
    model_data.value.push({
      key: model_array[i]['model_key'],
      type: model_array[i]['model_type'],
      subtype: model_array[i]['model_sub_type'],
      format: model_array[i]['model_format'],
      version: model_array[i]['model_version'],
    })
  }
})
</script>

<style scoped lang="less">
.italic {
  font-style: italic;
}
</style>