Skip to content

Commit 891bb7a

Browse files
committed
chore: 优化弹窗最新列表中设置已读的逻辑
1 parent 2d7c4c0 commit 891bb7a

4 files changed

Lines changed: 65 additions & 59 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
- chore: 优化编辑器插入 Obsidian Callouts 后新增默认换行
1+
- chore: 优化编辑器插入 Obsidian Callouts 后新增默认换行
2+
- chore: 优化弹窗最新列表中设置已读的逻辑

entrypoints/DialogComponents/components/HotPosts.vue

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
<template>
22
<ul class="list" v-if="this.list.length > 0">
3-
<li v-for="item in list" :key="item.id">
3+
<li v-for="item in list" :key="item.id" class="news-item hot">
44
<div class="news-content">
55
<a
66
:href="'https://linux.do/t/topic/' + item.id"
77
@click="handleLinkClick($event, item.id)"
8-
class="news-link"
9-
>
8+
class="news-link">
109
{{ item.title }}
1110
</a>
11+
</div>
12+
<div class="news-meta">
1213
<em>{{ item.highest_post_number }}</em>
1314
</div>
1415
</li>
@@ -18,8 +19,8 @@
1819

1920
<script>
2021
export default {
21-
props: ["list"],
22-
emits: ["remove-item"],
22+
props: ['list'],
23+
emits: ['remove-item'],
2324
data() {
2425
return {};
2526
},
@@ -32,7 +33,7 @@ export default {
3233
const targetUrl = `https://linux.do/t/topic/${itemId}`;
3334
3435
try {
35-
const browserAPI = typeof browser !== "undefined" ? browser : chrome;
36+
const browserAPI = typeof browser !== 'undefined' ? browser : chrome;
3637
3738
// 查询当前活动的标签页
3839
const tabs = await new Promise((resolve) => {
@@ -43,7 +44,7 @@ export default {
4344
const currentTab = tabs[0];
4445
4546
// 检查当前活动标签页是否为 linux.do
46-
if (currentTab.url && currentTab.url.includes("linux.do")) {
47+
if (currentTab.url && currentTab.url.includes('linux.do')) {
4748
// 如果当前标签页是 linux.do,直接在当前标签页跳转
4849
browserAPI.tabs.update(currentTab.id, { url: targetUrl });
4950
} else {
@@ -55,14 +56,14 @@ export default {
5556
browserAPI.tabs.create({ url: targetUrl });
5657
}
5758
} catch (error) {
58-
console.error("处理链接跳转失败:", error);
59+
console.error('处理链接跳转失败:', error);
5960
// 出错时回退到新标签页打开
60-
window.open(targetUrl, "_blank");
61+
window.open(targetUrl, '_blank');
6162
}
6263
6364
// 向父组件发送移除事件
64-
this.$emit("remove-item", itemId);
65-
},
66-
},
65+
this.$emit('remove-item', itemId);
66+
}
67+
}
6768
};
6869
</script>

entrypoints/DialogComponents/components/NewsPosts.vue

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,16 @@
55
<a
66
:href="'https://linux.do/t/topic/' + item.id"
77
@click="handleLinkClick($event, item.id)"
8-
class="news-link"
9-
>
8+
class="news-link">
109
{{ item.title }}
1110
</a>
11+
</div>
12+
<div class="news-meta">
1213
<em>{{ item.highest_post_number }}</em>
13-
<button class="preview-btn" @click="previewPost(item.id)" title="设为已读">
14+
<button
15+
class="preview-btn"
16+
@click="previewPost(item.id)"
17+
title="设为已读">
1418
<svg
1519
xmlns="http://www.w3.org/2000/svg"
1620
width="16"
@@ -20,8 +24,7 @@
2024
stroke="currentColor"
2125
stroke-width="2"
2226
stroke-linecap="round"
23-
stroke-linejoin="round"
24-
>
27+
stroke-linejoin="round">
2528
<path d="M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z" />
2629
<circle cx="12" cy="12" r="3" />
2730
<path d="M12 1v6m0 6v6" />
@@ -35,12 +38,10 @@
3538

3639
<script>
3740
export default {
38-
props: ["list"],
39-
emits: ["remove-item"],
41+
props: ['list'],
42+
emits: ['remove-item'],
4043
data() {
41-
return {
42-
43-
};
44+
return {};
4445
},
4546
methods: {
4647
async handleLinkClick(event, itemId) {
@@ -51,7 +52,7 @@ export default {
5152
const targetUrl = `https://linux.do/t/topic/${itemId}`;
5253
5354
try {
54-
const browserAPI = typeof browser !== "undefined" ? browser : chrome;
55+
const browserAPI = typeof browser !== 'undefined' ? browser : chrome;
5556
5657
// 查询当前活动的标签页
5758
const tabs = await new Promise((resolve) => {
@@ -80,32 +81,32 @@ export default {
8081
}
8182
8283
// 向父组件发送移除事件
83-
this.$emit("remove-item", itemId);
84+
this.$emit('remove-item', itemId);
8485
},
8586
8687
previewPost(itemId) {
8788
// 后台预览帖子,保持用户登录状态
88-
console.log("开始后台预览帖子:", itemId);
89+
console.log('开始后台预览帖子:', itemId);
8990
this.loadPostInBackground(`https://linux.do/t/topic/${itemId}`);
9091
// 预览后也移除这条目
91-
this.$emit("remove-item", itemId);
92-
this.$message.success('设为已读!')
92+
this.$emit('remove-item', itemId);
93+
this.$message.success('设为已读!');
9394
},
9495
9596
loadPostInBackground(url) {
9697
// 创建隐藏的 iframe 来加载页面,保持用户登录状态
97-
const iframe = document.createElement("iframe");
98-
iframe.style.display = "none";
99-
iframe.style.width = "0";
100-
iframe.style.height = "0";
101-
iframe.style.border = "none";
102-
iframe.style.position = "absolute";
103-
iframe.style.left = "-9999px";
98+
const iframe = document.createElement('iframe');
99+
iframe.style.display = 'none';
100+
iframe.style.width = '0';
101+
iframe.style.height = '0';
102+
iframe.style.border = 'none';
103+
iframe.style.position = 'absolute';
104+
iframe.style.left = '-9999px';
104105
iframe.src = url;
105106
106107
// 监听加载完成
107108
iframe.onload = () => {
108-
console.log("后台预览完成:", url);
109+
console.log('后台预览完成:', url);
109110
// 延迟移除 iframe,确保页面完全加载
110111
setTimeout(() => {
111112
if (iframe.parentNode) {
@@ -116,16 +117,15 @@ export default {
116117
117118
// 错误处理
118119
iframe.onerror = () => {
119-
console.error("后台预览失败:", url);
120+
console.error('后台预览失败:', url);
120121
if (iframe.parentNode) {
121122
document.body.removeChild(iframe);
122123
}
123124
};
124125
125126
// 添加到页面
126127
document.body.appendChild(iframe);
127-
},
128-
129-
},
128+
}
129+
}
130130
};
131131
</script>

entrypoints/DialogComponents/style.less

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -106,35 +106,27 @@ a {
106106
padding: 2px 0;
107107
border-bottom: 1px solid #eee;
108108
display: flex;
109-
align-items: center;
109+
align-items: flex-start;
110110
position: relative;
111-
padding-right: 40px;
112111

113112
a {
114113
text-decoration: none;
115114
padding: 5px 0;
116115
border-radius: 3px;
117116
position: relative;
118-
// display: -webkit-box;
119-
// -webkit-box-orient: vertical;
120-
// -webkit-line-clamp: 1;
121-
// overflow: hidden;
122117

123118
&:hover {
124119
text-decoration: underline;
125120
}
126121

127-
128122
}
129123

130124
em {
131125
font-style: normal;
132-
position: absolute;
133-
top: 10px;
134-
right: 0;
135126
border-radius: 30px;
136127
height: 20px;
137128
background-color: var(--color-neutral-3);
129+
color: var(--color-neutral-8);
138130
display: inline-flex;
139131
align-items: center;
140132
justify-content: center;
@@ -188,10 +180,9 @@ a {
188180
gap: 6px;
189181
padding: 2px 0;
190182
min-height: 20px;
191-
/* 固定最小行高 */
192183
width: 100%;
193184
overflow: hidden;
194-
/* 防止内容溢出 */
185+
flex: 1;
195186
}
196187

197188
.preview-btn {
@@ -205,10 +196,9 @@ a {
205196
justify-content: center;
206197
transition: all 0.2s;
207198
flex-shrink: 0;
208-
min-width: 30px;
209-
position: absolute;
210-
top: 6px;
211-
right: 0;
199+
200+
width: 100%;
201+
height: 100%;
212202
}
213203

214204
.preview-btn:hover {
@@ -220,10 +210,24 @@ a {
220210
height: 14px;
221211
}
222212

223-
.news-item:hover .preview-btn {
213+
.news-meta {
214+
width: 36px;
215+
height: 36px;
224216
display: flex;
217+
align-items: center;
218+
justify-content: center;
219+
220+
&:hover {
221+
em {
222+
display: none;
223+
}
224+
225+
.preview-btn {
226+
display: flex;
227+
}
228+
}
225229
}
226230

227-
.news-item:hover em {
228-
display: none;
231+
.news-item.hot .news-meta em {
232+
display: inline-flex;
229233
}

0 commit comments

Comments
 (0)