YM
2024-04-30 f4c14c24cb6cf1ed1c09cab760f6b9c8381df557
src/pages/inherit/index.vue
@@ -1,7 +1,7 @@
<template>
  <view class="">
    <headNav
      :idIndex="idIndex"
      idIndex="2"
      :searchBg="false"
      text="中医世医传承数据库"
      bg="/static/image/topBg1.png"
@@ -54,6 +54,7 @@
</template>
<script>
import * as echarts from "echarts";
import { inheritMedicalList } from "@/api/index.js";
export default {
  data() {
    return {
@@ -64,44 +65,45 @@
        {
          name: "唐",
          number: "4910",
          isColor: false,
          isColor: false
        },
        {
          name: "五代",
          number: "494",
          isColor: true,
          isColor: true
        },
        {
          name: "宋",
          number: "51273",
          isColor: false,
          isColor: false
        },
        {
          name: "北宋",
          number: "15",
          isColor: true,
          isColor: true
        },
        {
          name: "南宋",
          number: "4910",
          isColor: false,
          isColor: false
        },
        {
          name: "元",
          number: "299",
          isColor: true,
          isColor: true
        },
        {
          name: "明",
          number: "1830",
          isColor: false,
          isColor: false
        },
        {
          name: "清",
          number: "1000",
          isColor: true,
        },
          isColor: true
        }
      ],
      nodeData: []
    };
  },
  onLoad(options) {
@@ -109,10 +111,31 @@
    console.log("optionsoptionsoptions", options.id);
  },
  mounted() {
    // 初始化 echarts
    this.initBarChart();
    this.getData();
  },
  methods: {
    getData() {
      inheritMedicalList({
        keywords: "",
        dynastyId: "",
        searchType: "KEYWORD",
        path: ""
      }).then((res) => {
        console.log(res);
        this.nodeData = res.object.nodeList.map((item) => {
          return {
            ...item,
            itemStyle: {
              color: "#F8E2D7",
              borderColor: "#F3AA78",
              borderWidth: "3"
            }
          };
        });
        // 初始化 echarts
        this.initBarChart();
      });
    },
    initBarChart() {
      // WMBg
      //通过 $ref 进行挂载
@@ -142,14 +165,14 @@
      let option = {
        title: {
          text: [""],
          text: [""]
        },
        backgroundColor: {
          type: "image",
          image: "/static/image/WMBg.png",
          repeat: "repeat-x", // 是否平铺,可以是 'repeat-x', 'repeat-y', 'no-repeat'
          size: "100% 100%", // 背景图片的尺寸,可以是百分比或者像素
          position: "center center", // 背景图片的位置,可以是 top, bottom, middle 或者百分比
          position: "center center" // 背景图片的位置,可以是 top, bottom, middle 或者百分比
        },
        tooltip: {},
        animationDurationUpdate: 1500,
@@ -157,18 +180,17 @@
        series: [
          {
            type: "graph",
            layout: "none",
            symbolSize: SymbolSize + 20,
            layout: "force",
            symbolSize: 120,
            //是否允许用户拖动图片
            roam: false,
            roam: true,
            label: {
              show: true,
              color: "black", // 设置节点文字颜色为黑色
              fontSize: FontSize, // 设置文字大小
              fontSize: FontSize // 设置文字大小
            },
            edgeSymbol: ["circle", "arrow"],
            edgeSymbolSize: [4, 10],
            edgeLabel: {
              show: true,
              fontSize: FontSize, //更改两者关系的字体
@@ -179,132 +201,44 @@
              formatter: function (params) {
                // params.data 是边的数据对象,你可以在这里定义关系名
                // 例如,你可以根据 source 和 target 的名称来定义关系名
                return params.data.relationName || "父子"; // 如果定义了 relationName 则显示它,否则显示“父子”
              },
                return params.data.relationName; // 如果定义了 relationName 则显示它,否则显示“父子”
              }
            },
            //各个节点
            data: [
              {
                name: "薛雪",
                itemStyle: {
                  color: "#F8E2D7",
                  borderColor: "#F3AA78",
                  borderWidth: "3",
                },
              },
              {
                name: "邵登瀛",
                x: 400,
                y: 300,
                itemStyle: {
                  color: "#F8E2D7",
                  borderColor: "#F3AA78",
                  borderWidth: "3",
                },
              },
              {
                name: "邵鲁瞻",
                x: 500,
                y: 300,
                itemStyle: {
                  color: "#F8E2D7",
                  borderColor: "#F3AA78",
                  borderWidth: "3",
                },
              },
              {
                name: "邵春泉",
                x: 600,
                y: 300,
                itemStyle: {
                  color: "#F8E2D7",
                  borderColor: "#F3AA78",
                  borderWidth: "3",
                },
              },
              {
                name: "徐锦",
                x: 650,
                y: 400,
                itemStyle: {
                  color: "#DCE7EB",
                  borderColor: "#5F81A4",
                  borderWidth: "3",
                },
              },
              {
                name: "邵丙扬",
                x: 700,
                y: 300,
                itemStyle: {
                  color: "#F8E2D7",
                  borderColor: "#F3AA78",
                  borderWidth: "3",
                },
              },
              {
                name: "冯桂芬",
                x: 720,
                y: 400,
                itemStyle: {
                  color: "#DCE7EB",
                  borderColor: "#5F81A4",
                  borderWidth: "3",
                },
              },
              {
                name: "李鸿章",
                x: 740,
                y: 500,
                itemStyle: {
                  color: "#E1E1E1",
                  borderColor: "#888888",
                  borderWidth: "3",
                },
              },
              {
                name: "邵景尧",
                x: 800,
                y: 200,
                itemStyle: {
                  color: "#F8E2D7",
                  borderColor: "#F3AA78",
                  borderWidth: "3",
                },
              },
              {
                name: "邵景康",
                x: 800,
                y: 400,
                itemStyle: {
                  color: "#F8E2D7",
                  borderColor: "#F3AA78",
                  borderWidth: "3",
                },
              },
            ],
            data: this.nodeData,
            lineStyle: {
              color: "#000000",
              opacity: 0.9,
              width: 2,
              curveness: 0,
              curveness: 0
            },
          },
        ],
            force: {
              // initLayout: 'circular',
              // gravity: 0
              friction: 0.1,
              repulsion: 500,
              edgeLength: 6
            }
          }
        ]
      };
      //进行渲染
      myChart.setOption(option);
      myChart.on("click", (params) => {
        uni.navigateTo({
        url: "/pages/inherit/list"
      });
          url:
            "/pages/inherit/list?id=" +
            params.data.identifier +
            "&name=" +
            encodeURIComponent(params.data.name)
        });
      });
    },
    // 返回按钮
    goBack() {
      this.$router.go(-1);
    },
  },
    }
  }
};
</script>
<style scoped>