1
QYF-GitLab1
2024-07-18 a4a5b8dc84e9f9c2e1890f7d2c9e91f548840084
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
<template>
  <view
    style="width: 100%; height: 100%; display: flex; flex-direction: column"
  >
    <headNav :idIndex="'6'" text="学术流派" />
    <!-- 高级搜索 -->
    <view style="margin-top: 0.1rem">
      <advancedSearch
        @onSearch="onSearch"
        @onSubmit="onSubmit"
        :from="From"
        placehold="请输入关键字"
        :keyword="searchKey"
        :advancedSearchBack="advancedSearchBack"
      />
    </view>
    <!-- 热门搜索 -->
    <view class="flex flex-center hotSearch">
      热门搜索:
      <ul class="flex" style="margin-right: 10rpx">
        <li
          @click="onSearch({ text: item }, index)"
          :class="{ cursor: true, active: hotAciveIndex === index }"
          v-for="(item, index) in hotKeyList"
          :key="item"
        >
          {{ item }}
        </li>
      </ul>
    </view>
    <!-- 关系表地图 -->
    <div
      id="relation"
      style="margin-top: 0.1rem; flex: 1; width: 100%; position: relative"
    >
      <div
        v-if="!loading && relationships.length == 0"
        style="
          position: absolute;
          top: 30%;
          left: 0;
          right: 0;
          text-align: center;
          font-size: 0.2rem;
          color: #666;
        "
      >
        暂无相关数据
      </div>
    </div>
  </view>
</template>
 
<script>
import {
  getPersonData,
  getHotSearch,
  getPDataStatistics,
} from "@/api/index.js";
import * as echarts from "echarts";
export default {
  data() {
    return {
      loading: true,
      hotAciveIndex: "",
      currentId: 21682,
      // echarts数据
      nodes: [],
      // echarts两者的关系
      relationships: [],
      // 高级搜索
      From: {
        from: [
          {
            type: "input",
            label: "姓名",
            name: "name",
            value: "",
          },
          {
            type: "input",
            label: "别名",
            name: "alias",
            value: "",
          },
          {
            type: "input",
            label: "籍贯",
            name: "location",
            value: "",
          },
          {
            type: "select",
            label: "职业",
            name: "sdId",
            value: "",
            options: [
              {
                label: "未指明",
                value: "UNKNOWN",
              },
            ],
          },
          {
            type: "input",
            label: "官职",
            name: "office",
            value: "",
          },
          {
            type: "select",
            label: "性别",
            value: "",
            name: "genderTypeEO",
            options: [
              {
                label: "未指明",
                value: "UNKNOWN",
              },
              {
                label: "男",
                value: "MALE",
              },
              {
                label: "女",
                value: "WOMAN",
              },
            ],
          },
          {
            type: "input",
            label: "时期",
            name: "period",
            value: "",
          },
          {
            type: "input",
            label: "机构",
            name: "inst",
            value: "",
          },
          {
            type: "number",
            label: "页码",
            name: "page",
            value: "",
          },
          {
            type: "number",
            label: "页大小",
            name: "pageSize",
            value: "",
          },
        ],
      },
      // 下面的朝代1
      dynastyColor: 1,
      // 朝代
      dynasty: [
        {
          name: "夏朝",
          coord: "2070BC",
          id: 1,
        },
        {
          name: "商朝",
          id: 2,
          coord: "1600BC",
        },
        {
          name: "西周",
          id: 3,
          coord: "1600BC",
        },
        {
          name: "春秋战国",
          id: 4,
          coord: "770BC",
        },
        {
          name: "秦朝",
          id: 5,
          coord: "221BC",
        },
        {
          name: "汉朝",
          id: 6,
          coord: "202BC",
        },
        {
          name: "三国两晋南北朝",
          id: 7,
          coord: "184",
        },
        {
          name: "隋朝",
          id: 8,
          coord: "581",
        },
        {
          name: "唐朝",
          id: 9,
          coord: "618",
        },
        {
          name: "五代十国",
          id: 10,
          coord: "907",
        },
        {
          name: "辽夏金",
          id: 11,
          coord: "907",
        },
        {
          name: "宋朝",
          id: 12,
          coord: "960",
        },
        {
          name: "元朝",
          id: 13,
          coord: "1271",
        },
 
        {
          name: "明朝",
          id: 14,
          coord: "1368",
        },
        {
          name: "清朝",
          id: 15,
          coord: "1636",
        },
      ],
      // 热门搜索
      hotKeyList: [],
      searchKey: "",
 
      // 分类
      categories: [],
      // 人物信息
      infoOfPersons: [],
      // 学术流派
      infoOfSchools:[],
      // 当前人物信息
      ownInfo: null,
    };
  },
  mounted() {
    this.getData();
    // this.echartsArr();
    this.hotSearch();
    // 监听窗口大小变化
    window.addEventListener("resize", this.relation);
    this.innt();
  },
  onLoad(options) {
    this.searchKey = options.keyword;
  },
  methods: {
    // 获取人物关系
    getPersonInfo(arr, str, newArr, order, type, parent) {
      for (let i = 0; i < arr.length; i++) {
        const ele = arr[i];
        const personInfo = this.infoOfPersons.find(
          (item) => item.id == ele.personId
        );
        const obj = {
          personId: ele.personId,
          parentId: parent.id,
          id2: personInfo.id,
          relationTypeId: ele.relationTypeId,
          relationTypeName: ele.relationTypeName,
          parentName: parent?.NAME[0]?.content1 ?? parent.parentName,
          name2: personInfo?.NAME[0]?.content1,
          category: type,
        };
        if (str == "literatureList") {
          obj.relationTypeName = ele.literatureName;
        }
        if (str == "schoolList") {
          const nameData = this.infoOfSchools?.find(i=>i.schoolId == ele.schoolId)
          obj.relationTypeName = nameData?.name[0];
        }
        if (str == "placeList") {
          obj.relationTypeName = ele.ancientName ?? ele.currentName;
        }
        newArr.push(obj);
        if (ele[str] && ele[str]?.length) {
          order++;
          this.getPersonInfo(ele[str], str, newArr, order, type, personInfo);
        }
      }
    },
 
    // 处理数据
    changeLiterature(arr, str) {
      for (let i = 0; i < arr.length; i++) {
        const ele = arr[i];
        if (!ele.personId && ele.personList?.length) {
          ele.literatureList = [];
          ele.personId = this.ownInfo.id;
          if (ele[str] && ele[str]?.length) {
            for (let j = 0; j < ele.personList.length; j++) {
              const item = ele.personList[j];
              const data = item[str]?.map((e) => {
                return {
                  ...e,
                  personId: item.personId,
                };
              });
              if (data?.length) {
                ele[str].push(...data);
              }
            }
          }
        }
      }
      return arr;
    },
 
    //数组去重
    deduplicateArray(arr, idKey) {
      // 使用一个辅助对象来跟踪已经见过的ID
      const seen = {};
      // 使用filter方法过滤数组
      const deduplicatedArray = arr.filter((item) => {
        // 获取当前对象的ID
        const id = item[idKey];
        // 如果ID在辅助对象中不存在,则将其添加到对象并返回true
        if (!seen[id]) {
          seen[id] = true;
          return true;
        }
        // 如果ID已经存在,返回false
        return false;
      });
 
      return deduplicatedArray;
    },
 
    // 查询详情
    getData() {
      this.loading = true;
      getPersonData(this.currentId).then((res) => {
        this.nodes = [];
        this.relationships = [];
        let kinData = [];
        let teacher = [];
        let literature = [];
        let social = [];
        let place = [];
        let school = [];
        if (res && res.success && res.object) {
          console.log(res.object);
          this.infoOfPersons = res.object?.infoOfPersons;
          this.infoOfSchools = res.object?.infoOfSchools;
          if (res.object?.personChain) {
            this.ownInfo = this.infoOfPersons.find(
              (item) => item.id == res.object?.personChain.personId
            );
            const obj = res.object?.personChain;
            if (obj.kinList?.length) {
              let newArr = [];
              this.categories.push({ name: "亲属关系" });
              this.getPersonInfo(
                obj.kinList,
                "kinList",
                newArr,
                1,
                0,
                this.ownInfo
              );
              kinData = [...newArr];
            }
            if (obj.teacherStudentList?.length) {
              this.categories.push({ name: "师承关系" });
              let newArr = [];
              this.getPersonInfo(
                obj.teacherStudentList,
                "teacherStudentList",
                newArr,
                1,
                1,
                this.ownInfo
              );
              teacher = [...newArr];
            }
            if (obj.literatureList?.length) {
              this.categories.push({ name: "文献作品" });
              let newArr = [];
              const data = this.changeLiterature(
                obj.literatureList,
                "literatureList"
              );
              this.getPersonInfo(
                data,
                "literatureList",
                newArr,
                1,
                2,
                this.ownInfo
              );
              literature = [...newArr];
            }
            if (obj.socialList?.length) {
              let newArr = [];
              this.categories.push({ name: "社会关系" });
              const data = this.changeLiterature(obj.socialList, "socialList");
              this.getPersonInfo(
                data,
                "socialList",
                newArr,
                1,
                3,
                this.ownInfo
              );
              social = [...newArr];
            }
            if (obj.placeList?.length) {
              this.categories.push({ name: "活动地" });
              let newArr = [];
              const data = this.changeLiterature(obj.placeList, "placeList");
              this.getPersonInfo(data, "placeList", newArr, 1, 4, this.ownInfo);
              place = [...newArr];
              // console.log(place, "placeList");
            }
            if (obj.schoolList?.length) {
              this.categories.push({ name: "学术流派" });
              let newArr = [];
              const data = this.changeLiterature(obj.schoolList, "schoolList");
              this.getPersonInfo(
                data,
                "schoolList",
                newArr,
                1,
                3,
                this.ownInfo
              );
              school = [...newArr];
              // console.log(school, "schoolList");
            }
          }
          const personData = [
            ...kinData,
            ...teacher,
            ...literature,
            ...social,
            ...place,
            ...school,
          ];
          // console.log(personData)
          personData.forEach((item) => {
            let exists1 = this.nodes.some(
              (node) =>
                node.id === item.parentId && node.name === item.parentName
            );
            let exists2 = this.nodes.some(
              (node) => node.id === item.parentId && node.name === item.name2
            );
            // 证明不存在
            if (item.name1 && exists1 !== true) {
              this.nodes.push({
                name: item.parentName,
                id: item.parentId,
                ...item,
              });
            }
            if (item.name2 && exists2 !== true) {
              this.nodes.push({
                name: item.name2,
                id: item.id2,
                ...item,
              });
            }
            let obj = {
              source: item.parentName,
              target: item.name2,
              relation: item.relationTypeName || "", // 如果存在 relationName 字段则使用,否则为空字符串
            };
            this.relationships.push(obj);
          });
        }
        this.loading = false;
        this.relation();
      });
    },
    // 关系图谱
    relation() {
      var chartDom = document.getElementById("relation");
      var myChart = echarts.init(chartDom);
      // 假设您有节点名称和它们之间的关系数据
      var nodes = this.deduplicateArray(this.nodes, "id");
      var relationships = this.relationships;
 
      let FontSize = 12; // 字体大小
      let BorderWidth = 2; // 边框大小
      let SymbolSize = 80; // 尺寸距离
      let Distance = 10;
      // 不同尺寸下修改echarts的字体
      if (window.innerWidth > 2560 && window.innerWidth <= 3840) {
        FontSize = 20;
        BorderWidth = 5;
        SymbolSize = 90;
        Distance = 33;
      } else if (window.innerWidth > 1920 && window.innerWidth <= 2560) {
        FontSize = 18;
        BorderWidth = 4;
        SymbolSize = 80;
        Distance = 22;
      } else if (window.innerWidth >= 1366 && window.innerWidth <= 1920) {
        FontSize = 14;
        BorderWidth = 4;
        SymbolSize = 70;
        Distance = 22;
      }
      // 根据关系数据生成连接线
      var links = [];
      relationships.forEach((relationship, i) => {
        var sourceIndex = nodes.findIndex(
          (node) => node.name === relationship.source
        );
        var targetIndex = nodes.findIndex(
          (node) => node.name === relationship.target
        );
        if (relationship.relation) {
          if (sourceIndex !== -1 && targetIndex !== -1) {
            links.push({
              source: sourceIndex,
              target: targetIndex,
              label: {
                show: true,
                formatter: function (params) {
                  // 使用函数动态生成标签内容
                  // return relationships.find(rel => rel.source === nodes[params.data
                  //         .source] && rel.target === nodes[params.data.target])
                  //     .relation;
                  return relationship.relation;
                }, // 设置关系标签内容为"Child-Parent"
                color: "#2C2C2C",
                fontSize: FontSize - 2,
                backgroundColor: "rgba(255, 255, 255, 1)",
                padding: [3, 8],
                borderRadius: 30,
                position: "middle", // 设置标签文本在线的中间位置上居中显示
                // z: -1, // 设置标签的z轴高度,使其比连接线更高
                distance: -10, // 将标签放置在连接线上
              },
            });
          }
        }
      });
      // 根据nodes动态生成节点数据
      var nodeData = nodes;
      var option;
      option = {
        title: {
          text: "学术流派",
          // subtext: '',
          left: "center",
          top: FontSize + 10,
          textStyle: {
            fontSize: FontSize, // 设置标题文字大小为 18px
          },
          subtextStyle: {
            fontSize: FontSize, // 设置副标题文字大小为 14px
            color: "#2C2C2C",
          },
        },
        backgroundColor: {
          type: "image",
          image: "/static/image/characterRelationBg.png",
          // repeat: 'repeat-x', // 是否平铺,可以是 'repeat-x', 'repeat-y', 'no-repeat'
          size: "100% 100%", // 背景图片的尺寸,可以是百分比或者像素
          position: "center center", // 背景图片的位置,可以是 top, bottom, middle 或者百分比
        },
        tooltip: {},
        legend: [
          {
            // selectedMode: 'single',
            data: this.categories.map(function (a) {
              return a.name;
            }),
          },
        ],
        animationDurationUpdate: 1500,
        animationEasingUpdate: "quinticInOut",
        series: [
          {
            type: "graph",
            legendHoverLink: false,
            layout: "force",
            data: nodeData,
            links: links,
            categories: this.categories,
            roam: true,
            label: {
              position: "right",
              formatter: "{b}",
            },
            lineStyle: {
              color: "source",
              curveness: 0.3,
            },
            emphasis: {
              focus: "adjacency",
              lineStyle: {
                width: 10,
              },
            },
          },
        ],
      };
      // 将生成的连接线添加到echarts图表的option中
      // option.series[0].links = links;
      // 设置点击事件监听
      myChart.off("click");
      myChart.on("click", (params) => {
        if (params.dataType === "node") {
          this.spaceTimeArr(params.data.id);
        }
      });
      console.log(option, "option");
      myChart.setOption(option);
    },
    // 基础搜索
    onSearch(val, index) {
      if (index !== undefined) {
        this.searchKey = "";
        this.hotAciveIndex = index;
      } else {
        this.hotAciveIndex = "";
      }
      // this.searchKey = val.text;
      this.getData(val.text);
    },
    // 高级搜索
    onSubmit(val) {
      getAdvanceSearch({
        ...val,
        page: 1,
        pageSize: 100,
      }).then((res) => {
        console.log(res, "res");
      });
    },
    advancedSearchBack() {
      uni.navigateTo({
        url: "/pages/knowledgeBase/knowledgeBase",
      });
    },
    // 点击下面的朝代按钮
    dynastyBottomClick(item) {
      this.dynastyColor = item.id;
      this.onSearch({
        text: item.name,
      });
    },
    // 关系图 点击里面的元素
    spaceTimeArr(id) {
      // 关系图的数据
      uni.navigateTo({
        url: "/pages/character/detail?id=" + id,
      });
    },
    // 获取朝代echarts的数据
    echartsArr() {
      getDataStatistics().then((res) => {
        res.object.dynastyStatistic.details.map((item, index) => {
          // this.dynasty.id = item.dynastyId
          // this.dynasty.name = item.dynastyName
          // this.dynasty.coord = item.count
          this.dynasty[index].id = item.dynastyId;
          this.dynasty[index].name = item.dynastyName;
          this.dynasty[index].coord = item.count;
        });
      });
    },
    // 热门搜索
    hotSearch() {
      getHotSearch().then((res) => {
        const indexList = Object.keys(res.object);
        indexList.sort((a, b) => parseInt(b) - parseInt(a));
        this.hotKeyList = indexList.map((item) => {
          return res.object[item];
        });
      });
    },
 
    // 高级搜索里面职业的下拉菜单
    innt() {
      getPDataStatistics().then((res) => {
        const professionIndex = this.From.from.findIndex(
          (field) => field.label === "职业"
        );
        // 如果找到了职业字段
        if (professionIndex !== -1) {
          // 将 profession.list 转换为 options 格式
          const options = res.object.occupationStatistic.details.map(
            (item) => ({
              label: item.tagName,
              value: item.tagId.toString(), // 将 id 转换为字符串,确保与 value 类型一致
            })
          );
          // 更新职业字段的 options 属性
          this.$set(this.From.from[professionIndex], "options", options);
        }
      });
    },
  },
};
</script>
 
<style>
#relatio {
  width: 100%;
  height: 100%;
}
@media screen and (min-width: 2560px) and (max-width: 3840px) {
}
 
@media screen and (min-width: 1366px) and (max-width: 1920px) {
}
 
::v-deep .uni-input-placeholder {
  line-height: 1;
  font-size: 0.12rem;
}
 
::v-deep .ffff {
  border-radius: 0.5rem;
}
 
::v-deep .widget_button {
  border-radius: 0.5rem;
  margin: 0.02rem;
}
 
.hotSearch {
  font-size: 0.12rem;
  color: #2c2c2c;
 
  li {
    color: #244a7b;
    margin: 0 0.1rem;
    color: #244a7b;
    &.active {
      color: #027edc;
      font-weight: bold;
    }
  }
}
</style>