Skip to content

Commit 87f3414

Browse files
committed
feat: migrate pull requests and update galgame
1 parent 0e22649 commit 87f3414

33 files changed

Lines changed: 638 additions & 550 deletions

components/edit/galgame/pr/Alias.vue

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,9 @@ watch(
7272
</script>
7373

7474
<template>
75-
<div class="relative">
76-
<div class="space-y-2">
77-
<h2 class="text-xl">游戏别名</h2>
78-
<p class="text-default-500">
79-
别名最多 17 个, 可以输入别名按下回车创建别名
80-
</p>
81-
</div>
75+
<div class="relative space-y-2">
76+
<h2 class="text-xl">游戏别名</h2>
77+
<p class="text-default-500">别名最多 17 个, 可以输入别名按下回车创建别名</p>
8278

8379
<div
8480
class="ring-default-500 bg-default/10 min-h-[44px] w-full rounded-lg px-6 py-3 shadow transition-all focus-within:ring-1"

components/edit/galgame/pr/Footer.vue

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,33 @@
11
<script setup lang="ts">
2-
import { checkGalgamePR } from '../../utils/checkGalgamePR'
2+
import { updateGalgameSchema } from '~/validations/galgame'
33
44
const { galgamePR } = storeToRefs(useTempGalgamePRStore())
55
66
const isPublishing = ref(false)
77
88
const handlePublishGalgamePR = async () => {
9-
const pullRequest = {
10-
gid: galgamePR.value[0].id,
11-
name: galgamePR.value[0].name,
12-
introduction: galgamePR.value[0].introduction,
13-
contentLimit: galgamePR.value[0].contentLimit,
14-
alias: galgamePR.value[0].alias
9+
const galgame = galgamePR.value[0]
10+
const data: Record<string, number | string | string[]> = {
11+
vndbId: galgame.vndbId,
12+
name_en_us: galgame.name['en-us'],
13+
name_ja_jp: galgame.name['ja-jp'],
14+
name_zh_cn: galgame.name['zh-cn'],
15+
name_zh_tw: galgame.name['zh-tw'],
16+
intro_en_us: galgame.introduction['en-us'],
17+
intro_ja_jp: galgame.introduction['ja-jp'],
18+
intro_zh_cn: galgame.introduction['zh-cn'],
19+
intro_zh_tw: galgame.introduction['zh-tw'],
20+
contentLimit: galgame.contentLimit,
21+
aliases: String(galgame.alias)
1522
}
1623
17-
if (!checkGalgamePR(pullRequest)) {
24+
const result = updateGalgameSchema.safeParse(data)
25+
if (!result.success) {
26+
const message = JSON.parse(result.error.message)[0]
27+
useMessage(
28+
`位置: ${message.path[0]} - 错误提示: ${message.message}`,
29+
'warn'
30+
)
1831
return
1932
}
2033
const res = await useComponentMessageStore().alert(
@@ -30,17 +43,17 @@ const handlePublishGalgamePR = async () => {
3043
isPublishing.value = true
3144
}
3245
33-
const result = await $fetch(`/api/galgame/${pullRequest.gid}/pr`, {
46+
const response = await $fetch(`/api/galgame/${galgame.id}/pr`, {
3447
method: 'POST',
35-
body: pullRequest,
48+
body: data,
3649
watch: false,
3750
...kungalgameResponseHandler
3851
})
3952
isPublishing.value = false
4053
41-
if (result) {
54+
if (response) {
4255
useKunLoliInfo('创建更新请求成功', 5)
43-
await navigateTo(`/galgame/${pullRequest.gid}`, {
56+
await navigateTo(`/galgame/${galgame.id}`, {
4457
replace: true
4558
})
4659
}

components/edit/galgame/pr/PullRequest.vue

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import { languageItems } from '~/constants/edit'
33
44
const introductionLanguage = ref<Language>('zh-cn')
5+
const { galgamePR } = storeToRefs(useTempGalgamePRStore())
56
</script>
67

78
<template>
@@ -15,19 +16,29 @@ const introductionLanguage = ref<Language>('zh-cn')
1516

1617
<EditGalgamePrTitle />
1718

18-
<EditGalgameContentLimit type="rewrite" />
19+
<div>
20+
<h2 class="text-xl">VNDB 编号</h2>
21+
<div class="my-2 flex items-center justify-center gap-2">
22+
<KunInput v-model="galgamePR[0].vndbId" placeholder="例如: v19658" />
23+
</div>
24+
</div>
1925

20-
<KunTab
21-
:items="languageItems"
22-
v-model="introductionLanguage"
23-
variant="underlined"
24-
color="primary"
25-
size="sm"
26-
/>
27-
<EditGalgameEditor :lang="introductionLanguage" type="rewrite" />
26+
<div class="space-y-2">
27+
<h2 class="text-xl">游戏介绍</h2>
28+
<KunTab
29+
:items="languageItems"
30+
v-model="introductionLanguage"
31+
variant="underlined"
32+
color="primary"
33+
size="sm"
34+
/>
35+
<EditGalgameEditor :lang="introductionLanguage" type="rewrite" />
36+
</div>
2837

2938
<EditGalgamePrAlias type="rewrite" />
3039

40+
<EditGalgameContentLimit type="rewrite" />
41+
3142
<EditGalgamePrFooter />
3243
</KunCard>
3344
</ClientOnly>

components/galgame/Galgame.vue

Lines changed: 21 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,62 @@
11
<script setup lang="ts">
2-
import {
3-
galgameDetailSectionTabs,
4-
type GalgameDetailSectionTabType
5-
} from '~/constants/galgame'
62
import type { GalgameDetail } from '~/types/api/galgame'
73
84
const props = defineProps<{
95
galgame: GalgameDetail
106
}>()
117
128
provide<GalgameDetail>('galgame', props.galgame)
13-
14-
const activeTab = ref<GalgameDetailSectionTabType>('comment')
159
</script>
1610

1711
<template>
1812
<div class="space-y-3">
1913
<GalgameHeader :galgame="galgame" />
2014

2115
<div class="grid grid-cols-1 gap-3 md:grid-cols-3">
22-
<KunCard
23-
:is-hoverable="false"
24-
:is-transparent="false"
25-
content-class="space-y-6 relative"
26-
class-name="w-full h-full md:col-span-2"
27-
>
28-
<GalgameIntroduction :introduction="galgame.introduction" />
16+
<div class="md:col-span-2">
17+
<KunCard
18+
:is-hoverable="false"
19+
:is-transparent="false"
20+
content-class="space-y-6 relative"
21+
>
22+
<GalgameIntroduction :introduction="galgame.introduction" />
2923

30-
<KunDivider />
24+
<KunDivider />
3125

32-
<GalgameResource />
26+
<GalgameResource />
3327

34-
<GalgameSeries v-if="galgame.series" />
28+
<GalgameSeries v-if="galgame.series" />
3529

36-
<KunTab
37-
:items="galgameDetailSectionTabs"
38-
v-model="activeTab"
39-
variant="underlined"
40-
size="sm"
41-
/>
42-
<KunCard :is-hoverable="false">
4330
<GalgameCommentContainer
44-
v-if="activeTab === 'comment'"
4531
:user-data="galgame.contributor"
4632
:target-user="galgame.user"
4733
/>
48-
<GalgameHistory v-if="activeTab === 'history'" />
49-
<GalgameLink v-if="activeTab === 'link'" />
50-
<GalgamePrContainer v-if="activeTab === 'pr'" />
5134
</KunCard>
52-
</KunCard>
35+
</div>
5336

5437
<div class="space-y-3 md:col-span-1">
5538
<GalgameInfo :galgame="galgame" />
5639

40+
<KunCard :is-hoverable="false" :is-transparent="false">
41+
<GalgameLink />
42+
</KunCard>
43+
5744
<KunCard :is-hoverable="false" :is-transparent="false">
5845
<GalgameHistory />
5946
</KunCard>
6047

48+
<KunCard :is-hoverable="false" :is-transparent="false">
49+
<GalgamePrContainer />
50+
</KunCard>
51+
6152
<KunCard :is-hoverable="false" :is-transparent="false">
6253
<KunHeader
6354
name="贡献者"
64-
description="本游戏项目的贡献者, 计 Galgame 资源贡献"
55+
description="本游戏项目的贡献者, 计 Galgame 资源发布贡献"
6556
scale="h3"
6657
:is-show-divider="false"
6758
/>
68-
<div class="flex items-center gap-1">
59+
<div class="flex flex-wrap items-center gap-1">
6960
<KunTooltip
7061
v-for="(user, index) in galgame.contributor"
7162
:key="index"

components/galgame/Introduction.vue

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,8 @@ defineProps<{
3333
暂无对应翻译, 为您找到最近似的语言, 欢迎贡献翻译
3434
</div>
3535

36-
<KunCard :is-hoverable="false">
37-
<KunContent
38-
:content="getPreferredLanguageText(introduction, introductionLanguage)"
39-
/>
40-
</KunCard>
36+
<KunContent
37+
:content="getPreferredLanguageText(introduction, introductionLanguage)"
38+
/>
4139
</div>
4240
</template>

components/galgame/Rewrite.vue

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ const handleRewriteGalgame = async (galgame: GalgameDetail) => {
1111
const { introduction, markdown, series, ...rest } = galgame
1212
galgamePR.value[0] = {
1313
introduction: markdown,
14-
series: [],
1514
...rest
1615
}
1716
await navigateTo('/edit/galgame/rewrite')

components/galgame/card/Nav.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ watch(
6969
<KunSelect
7070
:options="kunGalgameSortFieldOptions"
7171
:model-value="sortField"
72-
@set="(value) => (sortField = value as 'time' | 'views' | 'created')"
72+
@set="(value) => (sortField = value as 'time' | 'view' | 'created')"
7373
>
7474
<span>{{ KUN_GALGAME_RESOURCE_SORT_FIELD_MAP[sortField] }}</span>
7575
</KunSelect>

components/galgame/link/Link.vue

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,15 @@ const handleDeleteLink = async (gid: number, glid: number) => {
7272
:is-show-divider="false"
7373
name="相关链接"
7474
description="这里可以添加任何与该游戏有关的链接, 例如论坛话题, 其它网络文章, 视频链接, 媒体链接等等"
75-
scale="h2"
75+
scale="h3"
7676
>
77-
<template #headerEndContent>
78-
<KunButton class-name="shrink-0" @click="isShowEdit = !isShowEdit">
77+
<template #endContent>
78+
<KunButton
79+
size="sm"
80+
variant="flat"
81+
class-name="shrink-0"
82+
@click="isShowEdit = !isShowEdit"
83+
>
7984
添加相关链接
8085
</KunButton>
8186
</template>

components/galgame/pr/Container.vue

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ const gid = computed(() => {
66
77
const pageData = reactive({
88
page: 1,
9-
limit: 7
9+
limit: 10,
10+
galgameId: gid.value
1011
})
1112
1213
const { data, status, refresh } = await useFetch(
@@ -25,7 +26,7 @@ const { data, status, refresh } = await useFetch(
2526
<KunHeader
2627
name="更新请求"
2728
description="蓝色代表增加, 红色代表删减, 游戏发布者或管理员可以合并或拒绝请求, 您可以自己合并自己为自己创建的游戏提出的更新请求"
28-
scale="h2"
29+
scale="h3"
2930
/>
3031

3132
<KunLoading v-if="status === 'pending'" />
@@ -35,14 +36,15 @@ const { data, status, refresh } = await useFetch(
3536
<GalgamePrInfo
3637
v-for="(pr, index) in data.prs"
3738
:key="index"
38-
:gid="gid"
39+
:galgame-id="gid"
3940
:pr="pr"
4041
:status="status"
4142
:refresh="refresh"
4243
/>
4344
</div>
4445

4546
<KunPagination
47+
v-if="data.totalCount > 10 || data.totalCount === 10"
4648
v-model:current-page="pageData.page"
4749
:total-page="Math.ceil(data.totalCount / pageData.limit)"
4850
:is-loading="status === 'pending'"

components/galgame/pr/Details.vue

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,14 @@ const props = defineProps<{
1111
}>()
1212
const galgame = inject<GalgameDetail>('galgame')
1313
14-
const { uid, roles } = usePersistUserStore()
15-
const isShowButton = computed(() => galgame?.user.uid === uid || roles >= 2)
14+
const { id, role } = usePersistUserStore()
15+
const isShowButton = computed(() => galgame?.user.id === id || role >= 2)
1616
const isFetching = ref(false)
1717
const isShowReasonInput = ref(false)
1818
const declineInput = ref('')
1919
2020
const diff = computed(() => {
21-
if (!galgame || !props.details.galgame) {
22-
return []
23-
}
24-
return diffGalgame(galgame, props.details.galgame)
21+
return diffGalgame(toRaw(props.details.oldData), toRaw(props.details.newData))
2522
})
2623
2724
const handleDeclineRequest = async () => {
@@ -38,12 +35,15 @@ const handleDeclineRequest = async () => {
3835
}
3936
4037
isFetching.value = true
41-
const result = await $fetch(`/api/galgame/${props.details.gid}/pr/decline`, {
42-
method: 'PUT',
43-
body: { gprid: props.details.gprid, note: declineInput.value.trim() },
44-
watch: false,
45-
...kungalgameResponseHandler
46-
})
38+
const result = await $fetch(
39+
`/api/galgame/${props.details.galgameId}/pr/decline`,
40+
{
41+
method: 'PUT',
42+
body: { galgamePrId: props.details.id, note: declineInput.value.trim() },
43+
watch: false,
44+
...kungalgameResponseHandler
45+
}
46+
)
4747
isFetching.value = false
4848
4949
if (result) {
@@ -62,12 +62,15 @@ const handleMergeRequest = async () => {
6262
}
6363
6464
isFetching.value = true
65-
const result = await $fetch(`/api/galgame/${props.details.gid}/pr/merge`, {
66-
method: 'PUT',
67-
body: { gprid: props.details.gprid },
68-
watch: false,
69-
...kungalgameResponseHandler
70-
})
65+
const result = await $fetch(
66+
`/api/galgame/${props.details.galgameId}/pr/merge`,
67+
{
68+
method: 'PUT',
69+
body: { galgamePrId: props.details.id },
70+
watch: false,
71+
...kungalgameResponseHandler
72+
}
73+
)
7174
isFetching.value = false
7275
7376
if (result) {

0 commit comments

Comments
 (0)