mh-two-thousand-and-two
2024-03-29 d27fbd63d7840787d7f3ca5333b6e24dc3a860d4
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
<template>
    <view>
        <headNav />
        <!-- 高级搜索 -->
        <view style="margin: .35rem 0 .16rem 0; ">
            <advancedSearch />
        </view>
        <!-- 热门搜索 -->
        <view class="flex flex-center" style="font-size: .1rem;color: #2C2C2C;">
            热门搜索:
            <ul class="flex" style="margin-right: 10rpx;">
                <li v-for="item in hot" :key="item.id"
                    style="color: #244A7B; margin: 0 .1rem;color: #5879a4;font-size: .12rem;">
                    {{item.name}}
                </li>
            </ul>
        </view>
        <!-- 关系表地图 -->
        <view id="relation" style="margin-top: .2rem; height: 70vh;width: 100%;"></view>
        <!-- 朝代 -->
        <view class="flex flex-center" style="width: 100%; position: fixed;bottom: .33rem;left: 0;">
            <ul class="flex">
                <li style="" v-for="(item,index) in dynasty" :key="item.id">
                    <view class="flex flex-center" style="height: .35rem; background-color: #fff; color:#244A7B ;">
                        {{item.coord}}
                    </view>
                    <view class="flex flex-center font-family"
                        :style="{'marginRight': index === dynasty.length - 1 ? '0' : '0.03rem'}"
                        style="padding: .05rem .19rem; color: #fff; font-size: .14rem; margin-top: .03rem;margin-right: .03rem;background-color: #597AA5;">
                        {{item.name}}
                    </view>
                </li>
            </ul>
        </view>
    </view>
</template>
 
<script>
    import * as echarts from 'echarts';
    export default {
        data() {
            return {
                // 朝代
                dynasty: [{
                    name: '夏朝',
                    coord: '2070BC',
                    id: 1
                }, {
                    name: '商朝',
                    id: 2,
                    coord: '1600BC',
                }, {
                    name: '西周',
                    id: 3,
                    coord: '1600BC'
                }, {
                    name: '春秋战国',
                    id: 4,
                    coord: '770BC'
                }, {
                    name: '秦朝',
                    id: 4,
                    coord: '221BC'
                }, {
                    name: '汉朝',
                    id: 5,
                    coord: '202BC'
                }, {
                    name: '三国两晋南北朝',
                    id: 6,
                    coord: '184'
                }, {
                    name: '隋朝',
                    id: 7,
                    coord: '581'
                }, {
                    name: '唐朝',
                    id: 8,
                    coord: '618'
                }, {
                    name: '五代十国',
                    id: 9,
                    coord: '907'
                }, {
                    name: '辽夏金',
                    id: 10,
                    coord: '907'
                }, {
                    name: '宋朝',
                    id: 11,
                    coord: '960'
                }, {
                    name: '元朝',
                    id: 12,
                    coord: '1271'
                }, {
                    name: '明朝',
                    id: 13,
                    coord: '1368'
                }, {
                    name: '清朝',
                    id: 14,
                    coord: '1636'
                }],
                // 热门搜索
                hot: [{
                    id: 1,
                    name: '李时珍',
                    bgColor: false
                }, {
                    id: 2,
                    name: '李时珍2',
                    bgColor: false
                }, {
                    id: 3,
                    name: '李时珍3',
                    bgColor: false
                }, ],
            }
        },
        methods: {
            // 关系图谱
            relation() {
                var chartDom = document.getElementById('relation');
                var myChart = echarts.init(chartDom);
                // 假设您有节点名称和它们之间的关系数据
                var nodes = ['李时珍', '成就', '传承', '亲友', '著作'];
                var relationships = [{
                        source: '李时珍',
                        target: '成就',
                        relation: '好友'
                    },
                    {
                        source: '李时珍',
                        target: '传承',
                        relation: '好1友'
                    },
                    {
                        source: '李时珍',
                        target: '亲友',
                        relation: '好2友'
                    },
                    {
                        source: '李时珍',
                        target: '著作',
                        relation: '好2友'
                    },
                    // 其他关系...
                ];
 
                // 根据关系数据生成连接线
                var links = [];
                relationships.forEach(function(relationship) {
                    var sourceIndex = nodes.indexOf(relationship.source);
                    var targetIndex = nodes.indexOf(relationship.target);
                    console.log(sourceIndex, targetIndex);
                    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;
                                }, // 设置关系标签内容为"Child-Parent"
                                color: '#2C2C2C',
                                fontSize: 12,
                                backgroundColor: 'rgba(255, 255, 255, 1)',
                                padding: [3, 8],
                                borderRadius: 30,
                                position: 'middle', // 设置标签文本在线的中间位置上居中显示
                                bottom: -10,
                                z: 10, // 设置标签的z轴高度,使其比连接线更高
                                // offset: [0, 15] ,// 往下移动 10 像素
                                distance: -12, // 将标签放置在连接线上
                            }
                        });
                    }
 
                });
                console.log(links);
                // 根据nodes动态生成节点数据
                var nodeData = nodes.map(function(node, index) {
                    return {
                        name: node,
                        x: Math.random() * 1000, // 设置随机x坐标位置
                        y: Math.random() * 600, // 设置随机y坐标位置
                        itemStyle: {
                            color: getColorByIndex(index), // 可以根据索引设置不同的颜色
                            borderWidth: 2,
                            borderColor: getColorByIndex(index + 1)
                        }
                    };
                });
                // 设置颜色
                function getColorByIndex(index) {
                    var colors = ['#ecf4ff', '#dd9795', '#f1edbe', '#ecf4ff', '#c5dbd8']; // 可以根据实际情况设置颜色数组
                    return colors[index % colors.length];
                }
                var option;
                option = {
                    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: {},
                    animationDurationUpdate: 1500,
                    animationEasingUpdate: 'quinticInOut',
                    series: [{
                        type: 'graph',
                        layout: 'none',
                        symbolSize: 40, // 调整节点大小
                        label: {
                            show: true,
                            color: 'black', // 设置节点文字颜色为黑色
 
                        },
                        edgeSymbol: ['circle'],
                        edgeSymbolSize: [4, 10],
                        data: nodeData,
                        links: links,
                        lineStyle: {
                            opacity: 0.9,
                            width: 2,
                            curveness: 0.3
                        }
                    }]
                };
 
                // 将生成的连接线添加到echarts图表的option中
                option.series[0].links = links;
                option && myChart.setOption(option);
            },
        },
        mounted() {
            // 关系图谱
            this.relation()
        }
    }
</script>
 
<style>
 
</style>