Skip to content

Commit 3ceb168

Browse files
committed
feat: enhance snippets API and UI interactions
- Updated the `getGroups` method in the snippets API to support pagination. - Improved the `SnippetCard` component by adding double-click functionality to open snippet URLs in a new tab. - Refined the `SnippetMetaForm` component by removing unnecessary class for better styling. - Adjusted the snippet list handling to correctly map data from the API response. These changes improve the usability and functionality of the snippets feature in the application. Signed-off-by: Innei <tukon479@gmail.com>
1 parent dd6e472 commit 3ceb168

5 files changed

Lines changed: 23 additions & 9 deletions

File tree

src/api/snippets.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ export const snippetsApi = {
5656
delete: (id: string) => request.delete<void>(`/snippets/${id}`),
5757

5858
// 获取分组列表
59-
getGroups: (params?: { size?: number }) =>
60-
request.get<SnippetGroup[]>('/snippets/group', { params }),
59+
getGroups: (params?: { page?: number; size?: number }) =>
60+
request.get<PaginateResult<SnippetGroup>>('/snippets/group', { params }),
6161

6262
// 获取分组下的片段
6363
getGroupSnippets: (reference: string) =>

src/layouts/setup-view.vue

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<script lang="ts">
2+
import { defineComponent, onMounted, ref } from 'vue'
3+
24
import { bgUrl } from '~/constants/env'
35
46
export default defineComponent({

src/views/extra-features/snippets/components/snippet-card.tsx

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,17 +85,25 @@ export const SnippetCard = defineComponent({
8585

8686
const snippetUrl = computed(() => {
8787
const s = props.snippet
88-
const base =
89-
API_URL +
90-
(s.type === SnippetType.Function ? '/fn/' : '/snippets/') +
91-
s.reference
92-
return `${base}/${s.name}${s.private ? `?token=${getToken()}` : ''}`
88+
const path =
89+
s.type === SnippetType.Function
90+
? `/serverless/${s.reference}/${s.name}`
91+
: `/${s.reference}/${s.name}`
92+
return `${API_URL}${path}${s.private ? `?token=${getToken()}` : ''}`
9393
})
9494

9595
const handleClick = () => {
9696
props.onSelect?.(props.snippet)
9797
}
9898

99+
const handleDoubleClick = (e: MouseEvent) => {
100+
// Avoid triggering when double-clicking interactive controls inside the card
101+
const target = e.target as HTMLElement | null
102+
if (target?.closest('button, a, input, textarea, [role="button"]')) return
103+
104+
window.open(snippetUrl.value, '_blank')
105+
}
106+
99107
const handleExternalLink = (e: MouseEvent) => {
100108
e.stopPropagation()
101109
window.open(snippetUrl.value, '_blank')
@@ -119,6 +127,8 @@ export const SnippetCard = defineComponent({
119127
selected && 'bg-neutral-100 dark:bg-neutral-800',
120128
]}
121129
onClick={handleClick}
130+
onDblclick={handleDoubleClick}
131+
title="双击打开访问地址"
122132
>
123133
{(() => {
124134
const Icon = typeIcon.value
@@ -178,6 +188,8 @@ export const SnippetCard = defineComponent({
178188
selected && 'bg-neutral-100 dark:bg-neutral-800/80',
179189
]}
180190
onClick={handleClick}
191+
onDblclick={handleDoubleClick}
192+
title="双击打开访问地址"
181193
>
182194
{/* Row 1: Name + Icons */}
183195
<div class="flex items-center gap-1.5">

src/views/extra-features/snippets/components/snippet-meta-form.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ export const SnippetMetaForm = defineComponent({
227227
)}
228228

229229
{/* 开关选项 */}
230-
<div class="space-y-3 rounded-md bg-neutral-50 p-3 dark:bg-neutral-800/30">
230+
<div class="space-y-3 rounded-md bg-neutral-50 dark:bg-neutral-800/30">
231231
<SwitchRow
232232
value={!props.data.private}
233233
label="公开访问"

src/views/extra-features/snippets/composables/use-snippet-list.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export function useSnippetList() {
2424
groupsWithSnippets.value.map((g) => [g.reference, g.expanded]),
2525
)
2626

27-
groupsWithSnippets.value = data.map((group) => ({
27+
groupsWithSnippets.value = data.data.map((group) => ({
2828
...group,
2929
snippets: [],
3030
expanded: existingExpandedState.get(group.reference) ?? false,

0 commit comments

Comments
 (0)