<template>
  <el-container>
    <div class="p_container">
      <!-- 左 -->
      <div class="grid-content1">
        <div class="left_top">
          <div class="title">统一门户</div>
          <div class="small_title">
            <img src="../../../../../assets/img/unified-resources/小标题.png" alt />
            <span>热点应用</span>
            <div>
              <span v-for="item in hotUse" :key="item" class="num_bg">{{ item }}</span>
            </div>
          </div>
          <div class="use_content">
            <div class="use_count">
              <div class="use_count_item">
                <img src="../../../../../assets/img/unified-resources/非信创应用.png" alt />
                <div>
                  <div class="use_count_item_title">非信创应用</div>
                  <div class="use_count_item_num">20</div>
                </div>
              </div>
              <div class="use_count_item">
                <img src="../../../../../assets/img/unified-resources/信创应用.png" alt />
                <div>
                  <div class="use_count_item_title">信创应用</div>
                  <div class="use_count_item_num">15</div>
                </div>
              </div>
            </div>
            <div class="use_chart" ref="hot_chart">
              <!-- <div  ></div> -->
            </div>
          </div>
          <div class="small_title">
            <img src="../../../../../assets/img/unified-resources/小标题.png" alt />
            <span>常用浏览器</span>
            <!-- <div>
                <span v-for="item in hotUse" :key="item" class="num_bg">{{ item }}</span>
            </div>-->
          </div>
          <div class="use_content">
            <div class="use_count">
              <div class="use_count_item">
                <img src="../../../../../assets/img/unified-resources/浏览器.png" alt />
                <div>
                  <div class="use_count_item_num">80%</div>
                  <div class="use_count_item_title">8:00-19:00</div>
                </div>
              </div>
              <div class="use_count_item">
                <img src="../../../../../assets/img/unified-resources/浏览器.png" alt />
                <div>
                  <div class="use_count_item_num">20%</div>
                  <div class="use_count_item_title">19:00-8:00</div>
                </div>
              </div>
            </div>
            <div class="use_chart" ref="browser_chart">
              <!-- <div  ></div> -->
            </div>
          </div>
        </div>
        <div class="left_center">
          <div class="title">统一用户</div>
          <el-table :data="userTableData" stripe style="width: 100%" max-height="200">
            <el-table-column prop="date" label></el-table-column>
            <el-table-column prop="name" label="用户总数" width="120"></el-table-column>
          </el-table>
        </div>
        <div class="left_bottom">
          <div class="title">接入</div>
        </div>
      </div>

      <!-- 右 -->
      <div class="grid-content2">
        <div class="grid-content2_top">
          <div class="title">统一接入</div>
          <div class="grid-content2_top_box1">
            <div class="grid-content2_top_item1">
              <div class="grid-content2_top_item1_title">今日API接入总量</div>
              <div>
                <div>接口数量</div>
                <div>169</div>
              </div>
              <div>
                <div>转发数量</div>
                <div>55/23</div>
              </div>
            </div>
            <div class="grid-content2_top_item1">
              <div class="grid-content2_top_item1_title">库表接入总量</div>
              <div>
                <div>接口数量</div>
                <div>169</div>
              </div>
              <div>
                <div>转发数量</div>
                <div>55/23</div>
              </div>
            </div>
            <div class="grid-content2_top_item1">
              <div class="grid-content2_top_item1_title">Kafka topic总量</div>
              <div>
                <div>接口数量</div>
                <div>169</div>
              </div>
              <div>
                <div>转发数量</div>
                <div>55/23</div>
              </div>
            </div>
            <div class="grid-content2_top_item1">
              <div class="grid-content2_top_item1_title">文件</div>
              <div>
                <div>接口数量</div>
                <div>169</div>
              </div>
              <div>
                <div>转发数量</div>
                <div>55/23</div>
              </div>
            </div>
          </div>
          <div class="grid-content2_top_box2">
            <div class="grid-content2_top_item2">
              <div class="grid-content2_top_item2_img">
                <img src="../../../../../assets/img/unified-resources/异常.png" alt />
                <div>
                  <div>接口数量</div>
                  <div>169</div>
                </div>
              </div>
              <div class="grid-content2_top_item2_status_danger"></div>
            </div>

            <div class="grid-content2_top_item2">
              <div class="grid-content2_top_item2_img">
                <img src="../../../../../assets/img/unified-resources/最高.png" alt />
                <div>
                  <div>接口数量</div>
                  <div>169</div>
                </div>
              </div>
              <div class="grid-content2_top_item2_status_success"></div>
            </div>
            <div class="grid-content2_top_item2">
              <div class="grid-content2_top_item2_img">
                <img src="../../../../../assets/img/unified-resources/平均.png" alt />
                <div>
                  <div>接口数量</div>
                  <div>169</div>
                </div>
              </div>
              <div class="grid-content2_top_item2_status_primary"></div>
            </div>
            <div class="grid-content2_top_item2">
              <div class="grid-content2_top_item2_img">
                <img src="../../../../../assets/img/unified-resources/最低.png" alt />
                <div>
                  <div>接口数量</div>
                  <div>169</div>
                </div>
              </div>
              <div class="grid-content2_top_item2_status_warning"></div>
            </div>
          </div>
        </div>
        <div class="grid-content2_bottom">
          <div class="title">统一资源</div>
          <div class="grid-content2_bottom_content">
            <!--  -->
            <div class="count_box">
              <div class="title_box">
                <div v-for="item in titleData" :key="item">{{ item.title }}</div>
              </div>
              <div class="num_box">
                <div class="num_box_top">
                  <div>
                    <div>数据目录</div>
                    <div>
                      <span v-for="item in hotUse" :key="item" class="num_bg">{{ item }}</span>
                    </div>
                  </div>
                </div>
                <div class="num_box_bottom"></div>
              </div>
              <div class="bar_chart"></div>
            </div>
            <!-- 表格 -->
            <div>
              <div class="small_title">
                <img src="../../../../../assets/img/unified-resources/小标题.png" alt />
                <span>统一接口监控状态监听</span>
              </div>
              <div style="tab_table">
                <div class="tab_img" :class="{tab_active:''}">存储空间</div>
                <div class="tab_img" :class="{tab_active:''}">监控预警</div>
              </div>
              <el-table :data="userTableData" stripe style="width: 100%" max-height="200">
                <el-table-column type="index" width="50"></el-table-column>
                <el-table-column prop="name" label="接口"></el-table-column>
                <el-table-column prop="name" label="状态" width=""></el-table-column>
              </el-table>
            </div>
          </div>
        </div>
      </div>
    </div>
  </el-container>
</template>

<script>
import * as echarts from "echarts";
export default {
  data() {
    return {
      hotUse: [3, 5],
      // 热点应用
      hotChartData: [
        { name: "OA", success: 33, fail: 1 },
        { name: "lims", success: 30, fail: 1 },
        { name: "grp", success: 22, fail: 1 },
        { name: "应急系统", success: 19, fail: 1 },
        { name: "产品管理", success: 15, fail: 1 }
      ],
      browserChartData: [
        { name: "IE", value: 11 },
        { name: "Firefox", value: 5.6 },
        { name: "Chrome", value: 8 },
        { name: "Safari", value: 9 }
      ],
      userTableData: [
        {
          date: "2016-05-02",
          name: "王小虎",
          address: "上海市普陀区金沙江路 1518 弄"
        },
        {
          date: "2016-05-04",
          name: "王小虎",
          address: "上海市普陀区金沙江路 1517 弄"
        },
        {
          date: "2016-05-01",
          name: "王小虎",
          address: "上海市普陀区金沙江路 1519 弄"
        },
        {
          date: "2016-05-03",
          name: "王小虎",
          address: "上海市普陀区金沙江路 1516 弄"
        }
      ],
      titleData: [
        { title: "上链" },
        { title: "数据归集" },
        { title: "数据共享" },
        { title: "数据目录" }
      ],
      tabData: [{ title: "存储空间" }, { title: "监控预警" }]
    };
  },
  mounted() {
    this.initHotChart();
    this.initBrowserChart();
  },
  methods: {
    initHotChart() {
      const chart = echarts.init(this.$refs.hot_chart);
      const data = this.hotChartData;

      // 计算每个项目的总和并进行归一化
      const totalData = data.map(item => item.success + item.fail);
      const normalizedData = data.map((item, index) => ({
        name: item.name,
        success: item.success / totalData[index], // 归一化成功比例
        fail: item.fail / totalData[index] // 归一化失败比例
      }));

      const option = {
        title: {
          text: "热点应用名称", // 主标题
          left: "left", // 标题居中
          top: "0%", // 设置标题距离顶部5%的位置
          textStyle: {
            fontSize: 12, // 字体大小
            fontWeight: "500", // 字体加粗
            color: "#333" // 字体颜色
          }
        },
        graphic: [
          {
            type: "text",
            right: "3%", // 将文字定位到右上角
            top: "5%",
            style: {
              text: "登录次数 成功/失败", // 显示的文本
              font: "10px sans-serif",
              fill: "#333"
            }
          }
        ],
        tooltip: {
          trigger: "item",
          // 格式化显示原始数据量，而非归一化后的比例
          formatter: params => {
            const currentData = data[params.dataIndex];
            return `登录次数 ${params.name}: 成功 ${currentData.success} / 失败 ${currentData.fail}`;
          }
        },
        grid: {
          left: "5%",
          right: "20%",
          top: "15%",
          bottom: "10%",
          containLabel: true
        },
        xAxis: {
          type: "value",
          splitLine: { show: false },
          axisLine: { show: false },
          axisTick: { show: false },
          axisLabel: { show: false }
        },
        yAxis: {
          type: "category",
          data: data.map(item => item.name),
          axisLine: { show: false },
          axisTick: { show: false },
          axisLabel: { show: true, textStyle: { color: "#333" } }
        },
        series: [
          {
            name: "成功",
            type: "bar",
            stack: "总量",
            data: normalizedData.map(item => item.success), // 使用归一化后的数据
            itemStyle: {
              // 使用线性渐变，调整渐变颜色
              color: params => {
                const isEven = params.dataIndex % 2 === 0; // 判断是否为偶数索引
                return new echarts.graphic.LinearGradient(0, 0, 1, 0, [
                  {
                    offset: 0,
                    color: isEven ? "#d2ebfb" : "#fbf0e4" // 蓝色和黄色交替
                  },
                  {
                    offset: 1,
                    color: isEven ? "#0b91e9" : "#fe8e08" // 蓝色和黄色交替
                  }
                ]);
              }
            },
            label: {
              show: false,
              //   position: 'insideRight', // 标签显示在柱体右侧
              //   formatter: '{c}', // 显示归一化后的数值
              color: "#fff" // 标签字体颜色
            }
          },
          {
            name: "失败",
            type: "bar",
            stack: "总量",
            data: normalizedData.map(item => item.fail), // 使用归一化后的数据
            itemStyle: {
              color: "#daebff" // 蓝灰色表示失败
            },
            label: {
              show: true,
              position: "insideRight", // 标签显示在柱体右侧
              formatter: params => {
                const currentData = data[params.dataIndex];
                return ` ${currentData.success} / ${currentData.fail}`;
              },
              color: "#000", // 标签字体颜色
              offset: [50, 0] // 调整标签位置，向右偏移
            }
          }
        ]
      };

      chart.setOption(option);
    },
    initBrowserChart() {
      const chart = echarts.init(this.$refs.browser_chart);
      const data = this.browserChartData;

      const option = {
        tooltip: {
          trigger: "item",
          formatter: "{b}: {c} ({d}%)"
        },
        legend: {
          orient: "vertical",
          left: "right",
          data: data.map(item => item.name),
          textStyle: {
            color: "#333"
          }
        },
        series: [
          {
            name: "浏览器市场份额",
            type: "pie",
            radius: ["40%", "70%"], // 设置环形图的内外半径
            color: ["#fe8f02", "#0a7cff", "#2cb68c", "#e23636"],
            labelLine: {
              show: true // 显示标签连线
            },
            label: {
              formatter: "{b}: {c}" // 格式化显示名称和数值
            },
            data: data.map(item => ({
              value: item.value,
              name: item.name
            }))
            // itemStyle: {
            //   // 设置每个部分的颜色
            //   color: params => {
            //     // const colorList = ["#FF9F00", "#FF6F61", "#3E9D45", "#E74C3C"]; // 自定义颜色列表
            //     const colorList = ["#fe8f02", "#0a7cff", "#2cb68c", "#e23636"]; // 自定义颜色列表
            //     return colorList[params.dataIndex];
            //   }
            // }
          }
        ]
      };

      chart.setOption(option);
    }
  }
};
</script>

<style lang="scss" scoped>
* {
  box-sizing: border-box;
}
.el-container {
  width: 100%;
  box-sizing: border-box;
  padding: 20px;
  // padding: 20px 20px 0 0px;
  height: calc(100vh - 90px);
  background-color: #edf4fa;
}
.p_container {
  width: 100%;
  display: flex;
}
.title {
  padding-left: 30px;
  width: 340px;
  height: 38px;
  line-height: 38px;
  background: url(../../../../../assets/img/unified-resources/标题背景.png)
    no-repeat;
  background-size: 100% 100%;
}

.small_title {
  //   height: 40px;
  display: flex;
  align-items: center;

  > span {
    font-family: Alibaba PuHuiTi;
    font-weight: 500;
    font-size: 16px;
    color: #333333;
    margin: 0 10px;
  }

  > div {
    // height: 40px;
    display: flex;
    align-items: center;

    .num_bg {
      width: 25px;
      height: 31px;
      margin-right: 5px;
      background: url(../../../../../assets/img/unified-resources/数字背景.png)
        no-repeat;
      background-size: 100% 100%;
      color: #269cfd;
      text-align: center;
      line-height: 31px;
    }
  }
}

.grid-content1 {
  width: 574px;
  //   height: 500px;
  // height: calc(100vh - 80px);
  height: 100%;
  margin-right: 20px;

  .left_top {
    box-sizing: border-box;
    width: 574px;
    height: 420px;
    background: rgba(255, 255, 255, 0.7);
    box-shadow: 0px 2px 15px 1px rgba(0, 26, 52, 0.08);
    padding: 20px;

    .use_content {
      //   height: 200px;
      width: 100%;
      display: flex;

      .use_count {
        // width: 110px;
        // height: 100px;

        .use_count_item {
          display: flex;
          margin: 10px 0;

          > img {
            width: 60px;
            height: 50px;
          }

          > div {
            .use_count_item_title {
              min-width: 140px;
              font-family: Alibaba PuHuiTi;
              font-weight: 500;
              font-size: 16px;
              color: #333333;
            }

            .use_count_item_num {
              font-family: DIN;
              font-weight: 500;
              font-size: 20px;
              color: #008ce6;
              text-shadow: 0px 3px 0px rgba(174, 218, 255, 0.53);
              background: linear-gradient(0deg, #0787ff 0%, #45bcf9 100%);
              -webkit-background-clip: text;
              -webkit-text-fill-color: transparent;
            }
          }
        }
      }

      .use_chart {
        width: 360px;
        height: 140px;
      }
    }
  }
  .left_center {
    background: rgba(255, 255, 255, 0.7);
    box-shadow: 0px 2px 15px 1px rgba(0, 26, 52, 0.08);
    padding: 20px;
    box-sizing: border-box;
    margin: 20px 0;
  }
  .left_bottom {
    background: rgba(255, 255, 255, 0.7);
    box-shadow: 0px 2px 15px 1px rgba(0, 26, 52, 0.08);
    padding: 20px;
    box-sizing: border-box;
  }
}

.grid-content2 {
  width: 100%;
  height: 100%;
  flex: 1;
  display: flex;
  flex-direction: column;
  .grid-content2_top {
    width: 100%;
    height: 30%;
    background: rgba(255, 255, 255, 0.7);
    box-shadow: 0px 2px 15px 1px rgba(0, 26, 52, 0.08);
    padding: 20px;
    box-sizing: border-box;
    margin-bottom: 20px;
    .grid-content2_top_box1 {
      display: flex;
      justify-content: space-between;
      align-items: center;
      // gap: 20px;
      .grid-content2_top_item1 {
        flex: 1;
        position: relative;

        .grid-content2_top_item1_title {
          position: absolute;
          top: 15px;
          left: 30px;
        }
        // padding: 0px 30px 10px;
        display: flex;
        justify-content: space-around;
        align-items: center;
        // width: 292px;
        width: 25%;
        height: 120px;
        border: 1px solid #ffffff;
        background: url(../../../../../assets/img/unified-resources/框.png)
          no-repeat;
        background-size: 100% 100%;
      }
    }
    .grid-content2_top_box2 {
      display: flex;
      justify-content: space-between;
      align-items: center;
      .grid-content2_top_item2 {
        flex: 1;
        padding: 0 40px;
        height: 100px;
        display: flex;
        align-items: center;
        justify-content: space-between;
        background: url(../../../../../assets/img/unified-resources/面板.png)
          no-repeat;
        background-size: 100% 100%;
        .grid-content2_top_item2_img {
          display: flex;
          align-items: center;
          // margin-left: 40px;
          > img {
            margin-right: 20px;
          }
        }
        .grid-content2_top_item2_status_danger {
          height: 30px;
          width: 2px;
          border-right: 5px solid #f98a8c;
          border-radius: 5px;
        }
        .grid-content2_top_item2_status_success {
          height: 30px;
          width: 2px;
          border-right: 5px solid #60daa8;
          border-radius: 5px;
        }
        .grid-content2_top_item2_status_primary {
          height: 30px;
          width: 2px;
          border-right: 5px solid #8bc7f9;
          border-radius: 5px;
        }
        .grid-content2_top_item2_status_warning {
          height: 30px;
          width: 2px;
          border-right: 5px solid #fdd58c;
          border-radius: 5px;
        }
      }
    }
  }
  .grid-content2_bottom {
    flex: 1;
    background: rgba(255, 255, 255, 0.7);
    box-shadow: 0px 2px 15px 1px rgba(0, 26, 52, 0.08);
    padding: 20px;
    box-sizing: border-box;
    .count_box {
      width: 100%;
    }
    .title_box {
      > div {
        width: 163px;
        height: 40px;
        background: url(../../../../../assets/img/unified-resources/三角箭头.png)
          no-repeat;
        background-size: 100% 100%;
        line-height: 40px;
        text-align: center;
        margin-top: 10px;
      }
    }
  }
}

// 数字背景
.num_bg {
  width: 25px;
  height: 31px;
  margin-right: 5px;
  background: url(../../../../../assets/img/unified-resources/数字背景.png)
    no-repeat;
  background-size: 100% 100%;
  color: #269cfd;
  text-align: center;
  line-height: 31px;
}
</style>