杨磊
2025-04-07 ce9ff4af4cf7ccc87d3ef94a849942baf112b811
src/views/directory/index.vue
@@ -1,9 +1,541 @@
<template>
  <div>学生名录</div>
  <div class="page">
    <div class="page-header">
      <p>王永炎院士学生目录</p>
    </div>
    <div class="page-main-title">
      <p @click="changeTab('chart')" :class="[activeTabs == 'chart' ? 'active-tab' : '']">
        <img :src="[activeTabs == 'chart' ? chartIcon : noChartIcon]" alt="">
        <span>图表显示</span>
      </p>
      <p @click="changeTab('list')" :class="[activeTabs == 'list' ? 'active-tab' : '']">
        <img :src="[activeTabs == 'list' ? listIcon : noListIcon]" alt="">
        <span>列表显示</span>
      </p>
    </div>
    <!-- 图表显示 -->
    <div class="charts-main" v-if="activeTabs == 'chart'">
      <div class="radial-tree-container">
        <div ref="chart" style="width: 100%; height: 600px"></div>
      </div>
    </div>
    <!-- 列表显示 -->
    <div class="page-main" v-if="activeTabs == 'list'">
      <div v-for="(item, index) in universityList" :key="index">
        <div
          class="table-title"
          v-if="item.studentList && item.studentList.length > 0"
        >
          <div class="table-title-left">
            <p class="table-title-name">{{ item.name }}</p>
            <p class="table-title-degree">{{ item.degree }}</p>
            <p class="table-title-number">{{ item.studentList.length }}人</p>
          </div>
          <div class="table-title-right" @click="item.isShow = !item.isShow"><img
              :src="[item.isShow ? topIcon : bottomIcon]" alt=""></div>
        </div>
        <table
          cellpadding="100"
          v-if="item.studentList && item.studentList.length > 0 && item.isShow"
        >
          <tr class="table-heading">
            <th>姓名</th>
            <th>性别</th>
            <th>学习时间</th>
            <th>工作单位(到二级单位全称)</th>
            <th>职务</th>
            <th>职称</th>
          </tr>
          <tr v-for="(citem, cindex) in item.studentList" :key="cindex">
            <td>
              {{ citem.studentName }}
            </td>
            <td>
              {{ citem.gender }}
            </td>
            <td>{{ citem.studyTime }}</td>
            <td>{{ citem.workUnit }}</td>
            <td>{{ citem.position }}</td>
            <td>{{ citem.title }}</td>
          </tr>
        </table>
      </div>
    </div>
  </div>
</template>
<script>
export default {};
import * as echarts from "echarts";
import axios from "axios";
export default {
  data() {
    return {
      chartIcon: require("@/assets/images/directory/chartIcon.png"),
      noChartIcon: require("@/assets/images/directory/noChartIcon.png"),
      listIcon: require("@/assets/images/directory/listIcon.png"),
      noListIcon: require("@/assets/images/directory/noListIcon.png"),
      topIcon: require("@/assets/images/directory/topIcon.png"),
      bottomIcon: require("@/assets/images/directory/bottomIcon.png"),
      activeTabs: "chart",
      universityList: [
        {
          name: "北京中医药大学",
          degree: "硕士",
          isShow: "true",
          studentList: [
            {
              studentName: "王玉来",
              gender: "男",
              studyTime: "1985.09-1988.07",
              workUnit: "北京中医药大学东方学院",
              position: "原院长",
              title: "主任医师、教授",
            },
            {
              studentName: "王玉来",
              gender: "男",
              studyTime: "1985.09-1988.07",
              workUnit: "北京中医药大学东方学院",
              position: "原院长",
              title: "主任医师、教授",
            },
            {
              studentName: "王玉来",
              gender: "男",
              studyTime: "1985.09-1988.07",
              workUnit: "北京中医药大学东方学院",
              position: "原院长",
              title: "主任医师、教授",
            },
          ],
        },
        {
          name: "北京中医药大学",
          degree: "硕士",
          isShow: "true",
          studentList: [
            {
              studentName: "王玉来",
              gender: "男",
              studyTime: "1985.09-1988.07",
              workUnit: "北京中医药大学东方学院",
              position: "原院长",
              title: "主任医师、教授",
            },
            {
              studentName: "王玉来",
              gender: "男",
              studyTime: "1985.09-1988.07",
              workUnit: "北京中医药大学东方学院",
              position: "原院长",
              title: "主任医师、教授",
            },
            {
              studentName: "王玉来",
              gender: "男",
              studyTime: "1985.09-1988.07",
              workUnit: "北京中医药大学东方学院",
              position: "原院长",
              title: "主任医师、教授",
            },
          ],
        },
        {
          name: "北京中医药大学",
          degree: "硕士",
          isShow: "true",
          studentList: [
            {
              studentName: "王玉来",
              gender: "男",
              studyTime: "1985.09-1988.07",
              workUnit: "北京中医药大学东方学院",
              position: "原院长",
              title: "主任医师、教授",
            },
            {
              studentName: "王玉来",
              gender: "男",
              studyTime: "1985.09-1988.07",
              workUnit: "北京中医药大学东方学院",
              position: "原院长",
              title: "主任医师、教授",
            },
            {
              studentName: "王玉来",
              gender: "男",
              studyTime: "1985.09-1988.07",
              workUnit: "北京中医药大学东方学院",
              position: "原院长",
              title: "主任医师、教授",
            },
          ],
        },
        {
          name: "北京中医药大学",
          degree: "硕士",
          isShow: "true",
          studentList: [],
        },
        {
          name: "北京中医药大学",
          degree: "硕士",
          isShow: "true",
          studentList: [
            {
              studentName: "王玉来",
              gender: "男",
              studyTime: "1985.09-1988.07",
              workUnit: "北京中医药大学东方学院",
              position: "原院长",
              title: "主任医师、教授",
            },
            {
              studentName: "王玉来",
              gender: "男",
              studyTime: "1985.09-1988.07",
              workUnit: "北京中医药大学东方学院",
              position: "原院长",
              title: "主任医师、教授",
            },
            {
              studentName: "王玉来",
              gender: "男",
              studyTime: "1985.09-1988.07",
              workUnit: "北京中医药大学东方学院",
              position: "原院长",
              title: "主任医师、教授",
            },
          ],
        },
        {
          name: "北京中医药大学",
          degree: "硕士",
          isShow: "true",
          studentList: [],
        },
        {
          name: "北京中医药大学",
          degree: "硕士",
          isShow: "true",
          studentList: [
            {
              studentName: "王玉来",
              gender: "男",
              studyTime: "1985.09-1988.07",
              workUnit: "北京中医药大学东方学院",
              position: "原院长",
              title: "主任医师、教授",
            },
            {
              studentName: "王玉来",
              gender: "男",
              studyTime: "1985.09-1988.07",
              workUnit: "北京中医药大学东方学院",
              position: "原院长",
              title: "主任医师、教授",
            },
            {
              studentName: "王玉来",
              gender: "男",
              studyTime: "1985.09-1988.07",
              workUnit: "北京中医药大学东方学院",
              position: "原院长",
              title: "主任医师、教授",
            },
          ],
        },
      ],
      chart: null,
      chartData: {
        name: "Root",
        children: [
          {
            name: "Node 1",
            children: [
              { name: "Leaf 1-1" },
              { name: "Leaf 1-2" },
              { name: "Leaf 1-3" },
            ],
          },
          {
            name: "Node 2",
            children: [
              {
                name: "Node 2-1",
                children: [{ name: "Leaf 2-1-1" }, { name: "Leaf 2-1-2" }],
              },
              { name: "Leaf 2-2" },
            ],
          },
          {
            name: "Node 3",
            children: [{ name: "Leaf 3-1" }, { name: "Leaf 3-2" }],
          },
        ],
      },
    };
  },
  mounted() {
    this.initChart();
    window.addEventListener("resize", this.handleResize);
  },
  beforeDestroy() {
    window.removeEventListener("resize", this.handleResize);
    if (this.chart) {
      this.chart.dispose();
    }
  },
  methods: {
    changeTab(key) {
      this.activeTabs = key;
      console.log(this.activeTabs, "activeTabs");
    },
    initChart() {
      this.chart = echarts.init(this.$refs.chart);
      const option = {
        tooltip: {
          trigger: "item",
          triggerOn: "mousemove",
          formatter: (params) => {
            const data = params.data;
            return `
              <div style="
                padding: 10px;
                background: #fff;
                border-radius: 5px;
                box-shadow: 0 2px 10px rgba(0,0,0,0.1);
                max-width: 300px;
              ">
                <div style="
                  border-bottom: 1px solid #eee;
                  padding-bottom: 5px;
                  margin-bottom: 5px;
                ">
                  <span style="
                    font-size: 16px;
                    color: #333;
                    font-weight: bold;
                  ">${data.name}</span>
                  ${
                    data.customInfo
                      ? `<span style="
                    background: #ffeb3b;
                    padding: 2px 5px;
                    border-radius: 3px;
                    margin-left: 8px;
                    font-size: 12px;
                  ">${data.customInfo}</span>`
                      : ""
                  }
                </div>
                <div style="margin-top: 8px;">
                  <div>节点值: <span style="color: #4f8ff7;">${
                    data.value || 0
                  }</span></div>
                  <div>描述: ${data.description || "暂无描述"}</div>
                </div>
              </div>
            `;
          },
        },
        series: [
          {
            type: "tree",
            data: [this.chartData],
            layout: "radial",
            symbol: "emptyCircle",
            symbolSize: 7,
            initialTreeDepth: -1, // 展开所有节点
            animationDurationUpdate: 750,
            emphasis: {
              focus: "descendant",
            },
            label: {
              position: "left",
              verticalAlign: "middle",
              align: "right",
              fontSize: 12,
              rotate: 0,
            },
            leaves: {
              label: {
                position: "right",
                verticalAlign: "middle",
                align: "left",
              },
            },
            expandAndCollapse: true,
            lineStyle: {
              color: "#ccc",
              width: 1,
            },
            itemStyle: {
              color: "#4f8ff7",
              borderColor: "#4f8ff7",
            },
            roam: true,
            center: ["10%", "15%"], // 微调垂直居中
            radius: "60%", // 增大半径占比
            nodePadding: 20,
          },
        ],
      };
      this.chart.setOption(option);
    },
    handleResize() {
      if (this.chart) {
        this.chart.resize();
      }
    },
  },
};
</script>
<style></style>
<style lang="less" scoped>
.page {
  width: 100%;
  height: 100%;
  box-sizing: border-box;
  background-color: #e9e1d4;
  overflow: auto;
}
.page-header {
  height: 102px;
  width: 100%;
  text-align: left;
  margin-bottom: 8px;
  border-bottom: 2px solid #937950;
  p {
    padding: 35px 0 34px 0;
    font-family: Alimama DongFangDaKai;
    font-size: 30px;
    text-indent: 1em;
    border-bottom: 1px solid #937950;
  }
}
.page-main-title {
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  margin-bottom: 75px;
  color: #9e9e9e;
  p {
    display: flex;
    align-items: center;
    padding: 15.5px 20px;
    border-bottom: 2px solid #9e9e9e;
  }
  img {
    width: 24px;
    height: auto;
    margin-right: 10px;
  }
  span {
    font-family: Source Han Sans;
    font-size: 24px;
    font-weight: bold;
  }
}
.active-tab {
  color: #937950 !important;
  border-bottom: 2px solid #937950 !important;
}
.page-main {
  width: 1313px;
  margin: 0 auto;
  overflow: hidden;
  margin-bottom: 100px;
  table {
    width: 100%;
    border-collapse: collapse;
  }
  tr {
    background-color: #fff;
    background-clip: padding-box;
    border-bottom: 2px solid transparent;
  }
  th {
    font-family: Source Han Serif CN;
    font-size: 14px;
    font-weight: bold;
    padding: 4px 41px;
  }
  td {
    font-family: Source Han Serif CN;
    font-size: 14px;
    padding: 6px 41px;
    text-align: center;
  }
  tr:last-child td {
    border-bottom: none;
    /* 移除最后一行的下边框 */
  }
}
.charts-main {
  // background-color: #000;
}
.table-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 28px;
  background-color: #d8cbb6;
  margin-bottom: 4px;
  margin-top: 2px;
  .table-title-left {
    display: flex;
    align-items: center;
  }
  .table-title-name {
    width: 200px;
    overflow: hidden;
    font-family: Source Han Serif CN;
    font-size: 18px;
    font-weight: bold;
  }
  .table-title-degree {
    font-family: Source Han Serif CN;
    font-size: 14px;
    font-weight: bold;
    margin-right: 40px;
  }
  .table-title-number {
    font-family: Source Han Serif CN;
    font-size: 14px;
    font-weight: bold;
  }
  .table-title-right {
    cursor: pointer;
  }
  img {
    width: 20px;
    height: auto;
  }
}
</style>