杨磊
2024-05-11 89f05ceabb90fa1e17d051c9d90149e08ee54663
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"
@@ -10,8 +10,12 @@
    <div class="filterBox font-family">
      <div class="searchBox">
        <input type="text" placeholder="输入姓名/别名/朝代" />
        <button>搜索</button>
        <input
          v-model="keywords"
          type="text"
          placeholder="输入姓名/别名/朝代"
        />
        <button @click="getData">搜索</button>
      </div>
      <div class="dynasty">
        <div style="font-weight: 700; line-height: 0.25rem">筛选朝代</div>
@@ -54,6 +58,7 @@
</template>
<script>
import * as echarts from "echarts";
import { inheritMedicalList, getDynastyAll } from "@/api/index.js";
export default {
  data() {
    return {
@@ -102,17 +107,48 @@
          isColor: true,
        },
      ],
      nodeData: [],
      keywords: "",
    };
  },
  onLoad(options) {
    this.idIndex = options.id;
    console.log("optionsoptionsoptions", options.id);
    getDynasty()
  },
  mounted() {
    // 初始化 echarts
    this.initBarChart();
    this.getData();
    this.getDynasty()
  },
  methods: {
    getDynasty() {
      getDynastyAll().then((res) => {
        console.log(res, "getDynastyAll");
      });
    },
    getData() {
      inheritMedicalList({
        keywords: this.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 进行挂载
@@ -157,10 +193,10 @@
        series: [
          {
            type: "graph",
            layout: "none",
            symbolSize: SymbolSize + 20,
            layout: "force",
            symbolSize: 120,
            //是否允许用户拖动图片
            roam: false,
            roam: true,
            label: {
              show: true,
              color: "black", // 设置节点文字颜色为黑色
@@ -168,7 +204,6 @@
            },
            edgeSymbol: ["circle", "arrow"],
            edgeSymbolSize: [4, 10],
            edgeLabel: {
              show: true,
              fontSize: FontSize, //更改两者关系的字体
@@ -179,128 +214,42 @@
              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,
            },
            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?id=" +
            params.data.identifier +
            "&name=" +
            encodeURIComponent(params.data.name),
        });
      });
    },
    // 返回按钮
    goBack() {
      // uuni.redirectTo();
      uni.redirectTo({
        url: "/pages/index/index",
      });
      this.$router.go(-1);
    },
  },
};