Masters.vue
4.42 KB
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
<template>
<div class="masters-container">
<!-- 一行一个 Item(单列) -->
<section class="single-list">
<div
class="item-card"
v-for="(item, i) in singleItems"
:key="`single-${i}`"
@click="goDetail(item)"
>
<div class="item-image">
<img :src="item.image" :alt="item.name" />
</div>
<div class="item-caption">
<div class="item-role">{{ item.role }}</div>
<div class="item-name" v-html="formatNameWithSuperscript(item.name)"></div>
</div>
</div>
</section>
<!-- 一行两个 Item(双列) -->
<section class="grid-two">
<div
class="item-card small"
v-for="(item, i) in gridItems"
:key="`grid-${i}`"
@click="goDetail(item)"
>
<div class="item-image">
<img :src="item.image" :alt="item.name" />
</div>
<div class="item-caption">
<div class="item-role">{{ item.role }}</div>
<div class="item-name small" v-html="formatNameWithSuperscript(item.name)"></div>
</div>
</div>
</section>
</div>
</template>
<script setup>
import { ref, onMounted } from 'vue'
import { useRouter } from 'vue-router'
import { useTitle } from '@vueuse/core';
// 导入接口
import { getSSQZAPI } from '@/api/index.js'
const router = useRouter()
useTitle('三師七證')
// 三师
const singleItems = ref([])
// 七证
const gridItems = ref([])
const goDetail = (item) => {
router.push(`/masters/${item.id}`)
}
/**
* 为name字段的第一个文字添加上标效果
* @param {string} name - 原始姓名
* @returns {string} - 带上标的HTML字符串
*/
const formatNameWithSuperscript = (name) => {
if (!name || name.length === 0) return name
const firstChar = name.charAt(0)
const restChars = name.slice(1)
return `<sup style="font-size: 0.6rem;">上</sup>${firstChar}<sup style="font-size: 0.6rem;">下</sup>${restChars}`
}
const pid = ref(router.currentRoute.value.query.pid)
onMounted(async () => {
// 调用接口获取三师七证数据
const { code, list } = await getSSQZAPI({ pid: pid.value });
if (code) {
const singleItemsData = list[0].list;
const gridItemsData = list[1].list;
singleItems.value = singleItemsData.map(item => ({
id: item.id,
role: item.post_excerpt,
name: item.post_title,
image: item.photo + '?imageMogr2/thumbnail/400x/strip/quality/70'
}))
gridItems.value = gridItemsData.map(item => ({
id: item.id,
role: item.post_excerpt,
name: item.post_title,
image: item.photo + '?imageMogr2/thumbnail/400x/strip/quality/70'
}))
}
})
</script>
<style scoped>
/* 页面容器 */
.masters-container {
padding: 1.5rem;
background: #F2EBDB;
}
/* 单列列表区 */
.single-list {
display: flex;
flex-direction: column;
gap: 1rem;
margin-bottom: 1rem;
}
/* 双列网格区 */
.grid-two {
display: grid;
grid-template-columns: repeat(2, 1fr);
gap: 0.75rem;
}
/* 卡片 */
.item-card {
position: relative;
border: 2px solid #6B4102;
overflow: hidden;
transition: transform 0.2s ease;
padding: 0.5rem;
}
.item-card:hover {
transform: translateY(-0.125rem);
}
.item-card.small {
/* 双列卡片视觉上更紧凑 */
border: 1px solid rgba(107, 65, 2, 0.8);
}
/* 图片区域 - 采用固定纵向比例 */
.item-image {
width: 100%;
aspect-ratio: 3 / 4;
background: #f5f5f5;
}
.item-image img {
width: 100%;
height: 100%;
object-fit: cover;
display: block;
}
/* 底部说明条 */
.item-caption {
position: absolute;
left: 0;
right: 0;
bottom: 0;
background: rgba(107, 65, 2, 0.8);
color: #fff;
padding: 0.75rem;
text-align: center;
}
.item-role {
font-size: 0.75rem;
opacity: 0.95;
}
.item-name {
font-size: 1.5rem;
font-weight: 600;
margin-top: 0.25rem;
}
.item-name.small {
font-size: 1.25rem;
}
/* 响应式调整 */
@media (max-width: 48rem) {
.item-caption {
padding: 0.625rem;
margin: 0.5rem;
}
}
@media (max-width: 30rem) {
.masters-container {
padding: 0.75rem;
}
.item-caption {
padding: 0.5rem;
margin: 0.5rem;
}
.item-name {
font-size: 1.25rem;
}
.item-name.small {
font-size: 1rem;
}
}
@media (max-width: 20rem) {
.grid-two {
gap: 0.5rem;
}
.item-caption {
padding: 0.375rem;
margin: 0.5rem;
}
.item-name {
font-size: 1rem;
}
.item-name.small {
font-size: 0.875rem;
}
}
</style>