Skip to content

Commit 832744e

Browse files
committed
feat: 微信二维码弹窗
1 parent 5ef95cb commit 832744e

2 files changed

Lines changed: 171 additions & 0 deletions

File tree

quartz/components/PersonalIntro.tsx

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import { QuartzComponent, QuartzComponentConstructor, QuartzComponentProps } from "./types"
2+
// @ts-ignore
3+
import wechatScript from "./scripts/wechat.inline"
24
import { classNames } from "../util/lang"
35

46
const PersonalIntro: QuartzComponent = ({ displayClass }: QuartzComponentProps) => {
@@ -27,6 +29,33 @@ const PersonalIntro: QuartzComponent = ({ displayClass }: QuartzComponentProps)
2729
</svg>
2830
</a>
2931

32+
<button
33+
class="social-link wechat-trigger"
34+
title="微信"
35+
>
36+
<svg class="social-icon" viewBox="0 0 24 24" fill="currentColor">
37+
<g transform="scale(1.5)">
38+
<path d="M11.176 14.429c-2.665 0-4.826-1.8-4.826-4.018
39+
0-2.22 2.159-4.02 4.824-4.02S16 8.191 16 10.411
40+
c0 1.21-.65 2.301-1.666 3.036a.32.32 0 0 0-.12.366l.218.81
41+
a.6.6 0 0 1 .029.117.166.166 0 0 1-.162.162.2.2 0 0 1-.092-.03
42+
l-1.057-.61a.5.5 0 0 0-.256-.074.5.5 0 0 0-.142.021
43+
5.7 5.7 0 0 1-1.576.22M9.064 9.542a.647.647 0 1 0
44+
.557-1 .645.645 0 0 0-.646.647.6.6 0 0 0 .09.353Zm3.232.001
45+
a.646.646 0 1 0 .546-1 .645.645 0 0 0-.644.644.63.63 0 0 0
46+
.098.356"/>
47+
<path d="M0 6.826c0 1.455.781 2.765 2.001 3.656a.385.385 0 0 1
48+
.143.439l-.161.6-.1.373a.5.5 0 0 0-.032.14.19.19 0 0 0
49+
.193.193q.06 0 .111-.029l1.268-.733a.6.6 0 0 1
50+
.308-.088q.088 0 .171.025a6.8 6.8 0 0 0 1.625.26
51+
4.5 4.5 0 0 1-.177-1.251c0-2.936 2.785-5.02 5.824-5.02l.15.002
52+
C10.587 3.429 8.392 2 5.796 2 2.596 2 0 4.16 0 6.826m4.632-1.555
53+
a.77.77 0 1 1-1.54 0 .77.77 0 0 1 1.54 0m3.875 0a.77.77 0 1 1
54+
-1.54 0 .77.77 0 0 1 1.54 0"/>
55+
</g>
56+
</svg>
57+
</button>
58+
3059
{/* <a href="https://www.linkedin.com/in/ainightcoder" target="_blank" rel="noopener noreferrer" class="social-link" title="LinkedIn">
3160
<svg class="social-icon" viewBox="0 0 24 24" fill="currentColor">
3261
<path d="M20.447 20.452h-3.554v-5.569c0-1.328-.027-3.037-1.852-3.037-1.853 0-2.136 1.445-2.136 2.939v5.667H9.351V9h3.414v1.561h.046c.477-.9 1.637-1.85 3.37-1.85 3.601 0 4.267 2.37 4.267 5.455v6.286zM5.337 7.433c-1.144 0-2.063-.926-2.063-2.065 0-1.138.92-2.063 2.063-2.063 1.14 0 2.064.925 2.064 2.063 0 1.139-.925 2.065-2.064 2.065zm1.782 13.019H3.555V9h3.564v11.452zM22.225 0H1.771C.792 0 0 .774 0 1.729v20.542C0 23.227.792 24 1.771 24h20.451C23.2 24 24 23.227 24 22.271V1.729C24 .774 23.2 0 22.222 0h.003z"/>
@@ -51,6 +80,23 @@ const PersonalIntro: QuartzComponent = ({ displayClass }: QuartzComponentProps)
5180
</svg>
5281
</a> */}
5382
</div>
83+
84+
{/* 微信二维码弹窗 */}
85+
<div
86+
id="wechat-modal"
87+
class="wechat-modal"
88+
>
89+
<div class="wechat-modal-content">
90+
<button
91+
class="wechat-close"
92+
>
93+
×
94+
</button>
95+
<h3>微信联系</h3>
96+
<img src="/static/wechat_qrcode.png" alt="微信二维码" class="wechat-qr" />
97+
<p>扫描二维码添加微信</p>
98+
</div>
99+
</div>
54100
</div>
55101
)
56102
}
@@ -130,6 +176,8 @@ PersonalIntro.css = `
130176
text-decoration: none;
131177
transition: all 0.2s ease;
132178
position: relative;
179+
border: none;
180+
cursor: pointer;
133181
}
134182
135183
.social-link:hover {
@@ -145,6 +193,66 @@ PersonalIntro.css = `
145193
fill: currentColor;
146194
}
147195
196+
/* 微信弹窗样式 */
197+
.wechat-modal {
198+
display: none;
199+
position: fixed;
200+
top: 0;
201+
left: 0;
202+
width: 100%;
203+
height: 100%;
204+
background: rgba(0, 0, 0, 0.5);
205+
z-index: 1000;
206+
align-items: center;
207+
justify-content: center;
208+
}
209+
210+
.wechat-modal-content {
211+
background: var(--light);
212+
border-radius: 12px;
213+
padding: 2rem;
214+
text-align: center;
215+
position: relative;
216+
max-width: 300px;
217+
width: 90%;
218+
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
219+
}
220+
221+
.wechat-close {
222+
position: absolute;
223+
top: 10px;
224+
right: 15px;
225+
background: none;
226+
border: none;
227+
font-size: 1.5rem;
228+
cursor: pointer;
229+
color: var(--darkgray);
230+
transition: color 0.2s ease;
231+
}
232+
233+
.wechat-close:hover {
234+
color: var(--dark);
235+
}
236+
237+
.wechat-modal-content h3 {
238+
margin: 0 0 1rem 0;
239+
color: var(--dark);
240+
font-size: 1.2rem;
241+
}
242+
243+
.wechat-qr {
244+
width: 200px;
245+
height: 200px;
246+
margin: 1rem 0;
247+
border-radius: 8px;
248+
}
249+
250+
.wechat-modal-content p {
251+
margin: 1rem 0 0 0;
252+
color: var(--darkgray);
253+
font-size: 0.9rem;
254+
}
255+
148256
/* 暗色主题优化 */
149257
:root[saved-theme="dark"] .intro-title {
150258
color: var(--light);
@@ -172,6 +280,27 @@ PersonalIntro.css = `
172280
color: var(--light);
173281
}
174282
283+
/* 暗色主题微信弹窗样式 */
284+
:root[saved-theme="dark"] .wechat-modal-content {
285+
background: var(--darkgray);
286+
}
287+
288+
:root[saved-theme="dark"] .wechat-modal-content h3 {
289+
color: var(--light);
290+
}
291+
292+
:root[saved-theme="dark"] .wechat-close {
293+
color: var(--lightgray);
294+
}
295+
296+
:root[saved-theme="dark"] .wechat-close:hover {
297+
color: var(--light);
298+
}
299+
300+
:root[saved-theme="dark"] .wechat-modal-content p {
301+
color: var(--lightgray);
302+
}
303+
175304
/* 响应式优化 */
176305
@media (max-width: 600px) {
177306
.personal-intro {
@@ -210,4 +339,6 @@ PersonalIntro.css = `
210339
}
211340
`
212341

342+
PersonalIntro.afterDOMLoaded = wechatScript
343+
213344
export default (() => PersonalIntro) satisfies QuartzComponentConstructor
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
document.addEventListener("nav", () => {
2+
const wechatTrigger = document.querySelector(".wechat-trigger") as HTMLButtonElement
3+
const wechatModal = document.getElementById("wechat-modal") as HTMLElement
4+
const wechatClose = document.querySelector(".wechat-close") as HTMLButtonElement
5+
6+
if (!wechatTrigger || !wechatModal || !wechatClose) {
7+
return
8+
}
9+
10+
// 显示微信弹窗
11+
const showWechatModal = (e: Event) => {
12+
e.preventDefault()
13+
wechatModal.style.display = "flex"
14+
}
15+
16+
// 隐藏微信弹窗
17+
const hideWechatModal = (e: Event) => {
18+
e.preventDefault()
19+
wechatModal.style.display = "none"
20+
}
21+
22+
// 点击空白处关闭弹窗
23+
const handleModalClick = (e: Event) => {
24+
if (e.target === wechatModal) {
25+
hideWechatModal(e)
26+
}
27+
}
28+
29+
// 绑定事件监听器
30+
wechatTrigger.addEventListener("click", showWechatModal)
31+
wechatClose.addEventListener("click", hideWechatModal)
32+
wechatModal.addEventListener("click", handleModalClick)
33+
34+
// 清理函数
35+
window.addCleanup(() => {
36+
wechatTrigger.removeEventListener("click", showWechatModal)
37+
wechatClose.removeEventListener("click", hideWechatModal)
38+
wechatModal.removeEventListener("click", handleModalClick)
39+
})
40+
})

0 commit comments

Comments
 (0)