-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathindex.html
More file actions
587 lines (510 loc) · 20.4 KB
/
index.html
File metadata and controls
587 lines (510 loc) · 20.4 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
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
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>ATProto 动态</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: -apple-system, BlinkMacSystemFont, 'PingFang SC', 'Helvetica Neue', Arial, sans-serif;
background-color: #f5f5f5;
color: #333;
line-height: 1.6;
}
.timeline {
max-width: 600px;
margin: 0 auto;
background-color: #fff;
padding-bottom: 80px;
}
.header {
position: sticky;
top: 0;
background-color: #fff;
z-index: 100;
padding: 10px 16px;
border-bottom: 1px solid #e0e0e0;
text-align: center;
font-size: 18px;
font-weight: 600;
}
.post {
padding: 12px 16px;
border-bottom: 8px solid #f5f5f5;
}
.post-header {
display: flex;
align-items: center;
margin-bottom: 10px;
}
.avatar {
width: 42px;
height: 42px;
border-radius: 50%;
background-color: #e0e0e0;
margin-right: 12px;
overflow: hidden;
}
.avatar img {
width: 100%;
height: 100%;
object-fit: cover;
}
.user-info {
flex: 1;
}
.username {
font-size: 15px;
font-weight: 600;
margin-bottom: 2px;
}
.post-time {
font-size: 12px;
color: #8e8e93;
}
.post-content {
font-size: 15px;
line-height: 1.6;
margin-bottom: 10px;
word-break: break-word;
}
.post-images {
margin-bottom: 10px;
}
.image-grid {
display: grid;
gap: 4px;
}
.image-grid-1 {
grid-template-columns: 1fr;
}
.image-grid-2,
.image-grid-3 {
grid-template-columns: repeat(2, 1fr);
}
.image-grid-3 > div:nth-child(3n) {
grid-column: span 2;
}
.image-grid-4,
.image-grid-5,
.image-grid-6 {
grid-template-columns: repeat(3, 1fr);
}
.image-container {
aspect-ratio: 1;
overflow: hidden;
background-color: #f5f5f5;
}
.image-container img {
width: 100%;
height: 100%;
object-fit: cover;
transition: transform 0.3s ease;
}
.post-actions {
display: flex;
justify-content: space-between;
padding-top: 8px;
border-top: 1px solid #e0e0e0;
}
.action-btn {
display: flex;
align-items: center;
color: #8e8e93;
font-size: 14px;
padding: 4px 0;
}
.action-btn svg {
width: 20px;
height: 20px;
margin-right: 6px;
}
.like-comment-section {
margin-top: 10px;
padding: 8px 0;
}
.likes {
background-color: #f5f5f5;
padding: 8px 12px;
border-radius: 4px;
margin-bottom: 8px;
font-size: 14px;
color: #555;
}
.comments {
font-size: 14px;
}
.comment {
margin-bottom: 8px;
}
.comment-author {
font-weight: 600;
margin-right: 4px;
}
.comment-content {
color: #333;
}
.comment-form {
display: flex;
align-items: center;
margin-top: 8px;
padding: 8px;
background-color: #f5f5f5;
border-radius: 20px;
}
.comment-input {
flex: 1;
background: transparent;
border: none;
outline: none;
font-size: 14px;
}
.comment-submit {
background: transparent;
border: none;
color: #07c160;
font-size: 14px;
font-weight: 600;
cursor: pointer;
}
/* 添加更多朋友圈特有样式 */
.location-tag {
display: inline-flex;
align-items: center;
font-size: 13px;
color: #3478f6;
margin-right: 12px;
margin-top: 6px;
}
.location-tag svg {
width: 14px;
height: 14px;
margin-right: 4px;
}
.post-more {
width: 20px;
height: 20px;
display: flex;
align-items: center;
justify-content: center;
}
.post-more svg {
width: 16px;
height: 16px;
color: #8e8e93;
}
/* 适配不同屏幕 */
@media (max-width: 600px) {
.timeline {
max-width: 100%;
}
}
/* 错误状态样式 */
.error-state {
padding: 40px 20px;
text-align: center;
color: #8e8e93;
}
.error-state .icon {
font-size: 48px;
margin-bottom: 16px;
}
.error-state .message {
font-size: 16px;
margin-bottom: 16px;
}
.error-state .retry-btn {
background-color: #07c160;
color: white;
border: none;
padding: 8px 16px;
border-radius: 20px;
font-size: 14px;
cursor: pointer;
}
/* 加载状态样式 */
.loading-state {
padding: 40px 20px;
text-align: center;
color: #8e8e93;
}
.loading-state .spinner {
width: 30px;
height: 30px;
border: 3px solid #f3f3f3;
border-top: 3px solid #07c160;
border-radius: 50%;
animation: spin 1s linear infinite;
margin: 0 auto 16px;
}
@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
</style>
</head>
<body>
<div class="timeline">
<div class="header">ATProto 动态</div>
<!-- 动态将通过JavaScript动态加载 -->
<div id="posts-container"></div>
<!-- 错误状态(初始隐藏) -->
<div id="error-state" class="error-state" style="display: none;">
<div class="icon">⚠️</div>
<div class="message">加载动态失败,请重试</div>
<button class="retry-btn">重试</button>
</div>
<!-- 加载状态(初始显示) -->
<div id="loading-state" class="loading-state">
<div class="spinner"></div>
<div>加载中...</div>
</div>
</div>
<script>
document.addEventListener('DOMContentLoaded', function() {
const postsContainer = document.getElementById('posts-container');
const errorState = document.getElementById('error-state');
const loadingState = document.getElementById('loading-state');
const retryBtn = document.querySelector('.retry-btn');
// 固定的repo参数
const REPO = 'did:plc:2g5otsgova72cgqr6zglnys5';
// 示例postIds列表,实际应用中可能需要从另一个API获取
const POST_IDS = ['3lzxlka3aas2v', '3lzxlka3aas2w', '3lzxlka3aas2x'];
// 从atproto API获取单条动态
async function fetchPost(postId) {
try {
const url = `https://public.api.bsky.app/xrpc/com.atproto.repo.getRecord?repo=${REPO}&collection=app.bsky.feed.post&rkey=${postId}`;
const response = await fetch(url);
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const data = await response.json();
return data.value;
} catch (error) {
console.error('获取动态失败:', error);
throw error;
}
}
// 格式化时间
function formatDate(dateString) {
const date = new Date(dateString);
const now = new Date();
const diff = now - date;
const minutes = Math.floor(diff / 60000);
const hours = Math.floor(diff / 3600000);
const days = Math.floor(diff / 86400000);
if (minutes < 60) {
return `${minutes}分钟前`;
} else if (hours < 24) {
return `${hours}小时前`;
} else if (days < 7) {
return `${days}天前`;
} else {
return date.toLocaleDateString('zh-CN');
}
}
// 创建图片网格
function createImageGrid(images) {
if (!images || images.length === 0) {
return '';
}
const count = Math.min(images.length, 6);
let gridClass = '';
if (count === 1) gridClass = 'image-grid-1';
else if (count <= 3) gridClass = 'image-grid-3';
else gridClass = 'image-grid-6';
let html = `<div class="post-images"><div class="image-grid ${gridClass}">`;
for (let i = 0; i < count; i++) {
// 使用picsum作为图片占位符,实际应用中应使用动态中的图片URL
const imgUrl = `https://picsum.photos/id/${1000 + i}/600/600`;
html += `<div class="image-container"><img src="${imgUrl}" alt="图片"></div>`;
}
html += '</div></div>';
return html;
}
// 渲染单条动态
function renderPost(post, postId) {
// 模拟数据,实际应用中应从API响应中提取
const username = post.displayName || '用户';
const avatarUrl = `https://picsum.photos/id/${Math.floor(Math.random() * 100)}/200/200`;
const content = post.text || '这条动态没有文字内容';
const createdAt = formatDate(post.createdAt || new Date().toISOString());
// 生成随机的点赞数和评论
const likeCount = Math.floor(Math.random() * 20) + 1;
const commentCount = Math.floor(Math.random() * 5);
let commentsHtml = '';
for (let i = 0; i < commentCount; i++) {
commentsHtml += `
<div class="comment">
<span class="comment-author">用户${i+1}</span>
<span class="comment-content">这是一条评论</span>
</div>
`;
}
// 创建位置标签(如果有)
const locationTag = post.location ? `
<div class="location-tag">
<svg viewBox="0 0 24 24" fill="currentColor">
<path d="M12 2C8.13 2 5 5.13 5 9c0 5.25 7 13 7 13s7-7.75 7-13c0-3.87-3.13-7-7-7zm0 9.5c-1.38 0-2.5-1.12-2.5-2.5s1.12-2.5 2.5-2.5 2.5 1.12 2.5 2.5-1.12 2.5-2.5 2.5z"></path>
</svg>
${post.location}
</div>
` : '';
// 生成随机图片
const imagesCount = Math.floor(Math.random() * 7); // 0-6张图片
const images = imagesCount > 0 ? Array.from({length: imagesCount}) : [];
const imageGridHtml = createImageGrid(images);
const postHtml = `
<div class="post" data-post-id="${postId}">
<div class="post-header">
<div class="avatar"><img src="${avatarUrl}" alt="头像"></div>
<div class="user-info">
<div class="username">${username}</div>
<div class="post-time">${createdAt}</div>
</div>
<div class="post-more">
<svg viewBox="0 0 24 24" fill="none">
<circle cx="6" cy="12" r="1.5"></circle>
<circle cx="12" cy="12" r="1.5"></circle>
<circle cx="18" cy="12" r="1.5"></circle>
</svg>
</div>
</div>
<div class="post-content">
${content}
</div>
${imageGridHtml}
${locationTag}
<div class="post-actions">
<div class="action-btn">
<svg viewBox="0 0 24 24" fill="none">
<path d="M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12 19 6.41z"></path>
</svg>
赞
</div>
<div class="action-btn">
<svg viewBox="0 0 24 24" fill="none">
<path d="M21 6h-2v9H6v2c0 .55.45 1 1 1h11l4 4V7c0-.55-.45-1-1-1zm-4 6V3c0-.55-.45-1-1-1H3c-.55 0-1 .45-1 1v14l4-4h10c.55 0 1-.45 1-1z"></path>
</svg>
评论
</div>
<div class="action-btn">
<svg viewBox="0 0 24 24" fill="none">
<path d="M2.01 21L23 12 2.01 3 2 10l15 2-15 2z"></path>
</svg>
分享
</div>
</div>
<div class="like-comment-section">
<div class="likes">
<span class="like-icon">❤️</span> ${likeCount}人赞了这条动态
</div>
<div class="comments">
${commentsHtml}
</div>
<div class="comment-form">
<input type="text" class="comment-input" placeholder="评论...">
<button class="comment-submit">发送</button>
</div>
</div>
</div>
`;
postsContainer.insertAdjacentHTML('beforeend', postHtml);
}
// 加载所有动态
async function loadPosts() {
postsContainer.innerHTML = '';
loadingState.style.display = 'block';
errorState.style.display = 'none';
try {
// 模拟API调用延迟
await new Promise(resolve => setTimeout(resolve, 1000));
// 模拟从API获取数据
const mockPosts = POST_IDS.map((id, index) => ({
text: index === 0 ? '今天天气真好,出来晒太阳啦!☀️' :
index === 1 ? '自己做的晚餐,味道还不错!🍳' :
'新入手的相机,拍了一组照片,大家觉得怎么样?📷',
displayName: index === 0 ? '张小明' :
index === 1 ? '李小华' : '王小红',
createdAt: new Date(Date.now() - index * 86400000).toISOString(),
location: index === 0 ? '城市中央公园' :
index === 2 ? '滨江大道' : null
}));
// 渲染所有动态
POST_IDS.forEach((postId, index) => {
renderPost(mockPosts[index], postId);
});
// 绑定事件
bindEvents();
} catch (error) {
console.error('加载动态失败:', error);
loadingState.style.display = 'none';
errorState.style.display = 'block';
} finally {
loadingState.style.display = 'none';
}
}
// 绑定交互事件
function bindEvents() {
// 点赞功能
const likeButtons = document.querySelectorAll('.action-btn:nth-child(1)');
likeButtons.forEach(button => {
button.addEventListener('click', function() {
const likeIcon = this.querySelector('svg');
if (likeIcon.style.fill === 'red') {
likeIcon.style.fill = 'none';
} else {
likeIcon.style.fill = 'red';
}
});
});
// 评论提交功能
const commentForms = document.querySelectorAll('.comment-form');
commentForms.forEach(form => {
const input = form.querySelector('.comment-input');
const submitBtn = form.querySelector('.comment-submit');
const commentsContainer = form.parentElement.querySelector('.comments');
submitBtn.addEventListener('click', function() {
const commentText = input.value.trim();
if (commentText) {
const newComment = document.createElement('div');
newComment.className = 'comment';
newComment.innerHTML = `
<span class="comment-author">我</span>
<span class="comment-content">${commentText}</span>
`;
commentsContainer.appendChild(newComment);
input.value = '';
}
});
input.addEventListener('keypress', function(e) {
if (e.key === 'Enter') {
submitBtn.click();
}
});
});
// 图片点击放大预览
const images = document.querySelectorAll('.image-container img');
images.forEach(img => {
img.addEventListener('click', function() {
if (this.style.transform === 'scale(1.05)') {
this.style.transform = 'scale(1)';
} else {
this.style.transform = 'scale(1.05)';
}
});
});
}
// 初始化
loadPosts();
// 重试按钮事件
retryBtn.addEventListener('click', loadPosts);
});
</script>
</body>
</html>