Skip to content

Commit 1a142cf

Browse files
committed
Enhance Gist functionality by adding public visibility option. Updated Gist interface to include 'public' property, modified CreateGistModal to allow users to toggle visibility, and adjusted GistList to support public attribute in editing. Default visibility set to true.
1 parent 7cf9a24 commit 1a142cf

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

src/api/gist.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ if(token.value){
4747

4848
export interface Gist {
4949
id: string
50+
public: boolean
5051
description: string
5152
url: string
5253
html_url: string

src/components/CreateGistModal.vue

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@
99
<a-form-item label="描述">
1010
<a-input v-model="gistForm.description" placeholder="请输入 Gist 描述" />
1111
</a-form-item>
12+
<a-form-item label="公开">
13+
<a-switch
14+
v-model="gistForm.public"
15+
:default-checked="true"
16+
:disabled="isEdit"
17+
/>
18+
</a-form-item>
1219
<div v-for="(file, index) in gistForm.files" :key="index" class="file-item">
1320
<div class="file-header">
1421
<h4>{{ file.filename.length > 0 ? file.filename : '文件 ' + (index + 1) }}</h4>
@@ -60,6 +67,7 @@ interface Props {
6067
editGist?: {
6168
id: string
6269
description: string
70+
public?: boolean
6371
files: Record<string, { content: string; filename?: string }>
6472
}
6573
}
@@ -69,12 +77,13 @@ const props = withDefaults(defineProps<Props>(), {
6977
editGist: undefined
7078
})
7179
72-
const isEdit = computed(() => props.editMode && props.editGist)
80+
const isEdit = computed(() => props.editMode && props.editGist !== undefined )
7381
7482
// 监听编辑模式的 Gist 数据变化
7583
watch(() => props.editGist, (newGist) => {
7684
if (newGist) {
7785
gistForm.description = newGist.description
86+
gistForm.public = newGist.public ?? true
7887
gistForm.files = Object.entries(newGist.files).map(([filename, file]) => ({
7988
filename,
8089
content: file.content,
@@ -131,6 +140,7 @@ const getLanguageFromFilename = (filename: string): string => {
131140
132141
const gistForm = reactive({
133142
description: '',
143+
public: true,
134144
files: [
135145
{
136146
filename: '',
@@ -151,6 +161,7 @@ const handleCancel = () => {
151161
152162
const resetForm = () => {
153163
gistForm.description = ''
164+
gistForm.public = true
154165
gistForm.files = [{
155166
filename: '',
156167
content: '',
@@ -187,7 +198,7 @@ const handleCreate = async () => {
187198
188199
await gistApi.createGist({
189200
description: gistForm.description,
190-
public: true,
201+
public: gistForm.public,
191202
files
192203
})
193204
Message.success('创建成功')

src/components/GistList.vue

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ const expandedKeys = ref<string[]>([])
114114
const editingGist = ref<{
115115
id: string
116116
description: string
117+
public: boolean
117118
files: Record<string, { content: string; filename?: string }>
118119
} | undefined>(undefined)
119120
@@ -239,6 +240,7 @@ const showEditModal = async (gist: Gist) => {
239240
240241
editingGist.value = {
241242
id: gist.id,
243+
public: gist.public,
242244
description: gist.description,
243245
files
244246
}

0 commit comments

Comments
 (0)