Skip to content

Commit

Permalink
feat: 移除 @nuxt/prisma 包 - build-and-deploy
Browse files Browse the repository at this point in the history
  • Loading branch information
nonhana committed Nov 21, 2024
1 parent 83cfa62 commit 608c165
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 55 deletions.
2 changes: 0 additions & 2 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
NODE_ENV = "development"

HANA_DATABASE_URL = "postgresql://your_username:your_password@localhost:5432/grey_flowers?schema=public"
4 changes: 0 additions & 4 deletions nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,6 @@ export default defineNuxtConfig({
preload: true,
download: true,
},
prisma: {
installStudio: false,
},
modules: [
'@nuxtjs/tailwindcss',
'@nuxtjs/i18n',
Expand All @@ -92,7 +89,6 @@ export default defineNuxtConfig({
'@nuxtjs/seo',
'@vueuse/nuxt',
'@pinia/nuxt',
'@prisma/nuxt',
],
plugins: ['~/plugins/directives.ts'],
devtools: { enabled: true },
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
"@nuxtjs/tailwindcss": "^6.12.1",
"@pinia/nuxt": "^0.6.1",
"@prisma/client": "^5.22.0",
"@prisma/nuxt": "^0.0.35",
"@tailwindcss/forms": "^0.5.9",
"@tailwindcss/typography": "^0.5.15",
"@types/node": "^22.7.4",
Expand Down
79 changes: 54 additions & 25 deletions pages/articles/archives/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,45 +6,74 @@ definePageMeta({
const route = useRoute()
const router = useRouter()
// 文章总数
const { data: count } = await useAsyncData('article-count', () => $fetch('/api/articles/count'))
// 文章日期,key 为年份,value 为该年份下的月份数组
const { data: dateMap } = await useAsyncData('articles-by-publishedAt', () => $fetch('/api/articles/dates'))
const yearList = computed(() => dateMap.value ? (Object.keys(dateMap.value)).sort((a, b) => Number(b) - Number(a)) : [])
const curYear = ref<string>(route.query.year as string || yearList.value[0])
const yearList = computed(() =>
dateMap.value ? Object.keys(dateMap.value).sort((a, b) => Number(b) - Number(a)) : [],
)
const curYear = ref<string | null>(null)
const monthList = computed(() => dateMap.value ? [...dateMap.value[curYear.value]].sort((a, b) => Number(b) - Number(a)) : [])
const curMonth = ref<string>(route.query.month as string || monthList.value[0])
const monthList = computed(() =>
curYear.value && dateMap.value && dateMap.value[curYear.value]
? [...dateMap.value[curYear.value]].sort((a, b) => Number(b) - Number(a))
: [],
)
const curMonth = ref<string | null>(null)
function toggleYear(year: string) {
curYear.value = year
function syncQueryToState() {
const yearFromQuery = route.query.year as string
const monthFromQuery = route.query.month as string
// 如果查询参数不存在,拿到最新的年份和月份
const defaultYear = yearList.value[0] || null
const defaultMonth = monthList.value[0] || null
curYear.value = yearFromQuery || defaultYear
curMonth.value = monthFromQuery || defaultMonth
// 更新到最新的查询参数
if (!yearFromQuery || !monthFromQuery) {
updateQuery({ year: curYear.value!, month: curMonth.value! })
}
}
function toggleMonth(month: string) {
curMonth.value = month
// 更新查询参数
function updateQuery(params: { year?: string, month?: string }) {
const newQuery = { ...route.query, ...params }
if (JSON.stringify(route.query) !== JSON.stringify(newQuery)) {
router.replace({ query: newQuery })
}
}
watch(curYear, (newYear) => {
router.replace({ query: { ...route.query, year: newYear, month: dateMap.value![newYear][0] } })
}, { immediate: true })
watch(
() => route.query,
() => { syncQueryToState() },
{ immediate: true },
)
watch(() => route.query.year, (yearQuery) => {
const newYear = yearQuery as string || yearList.value[0]
if (newYear !== curYear.value) {
curYear.value = newYear
watch(curYear, (newYear) => {
if (newYear) {
updateQuery({ year: newYear, month: monthList.value[0] })
}
})
watch(curMonth, (newMonth) => {
router.replace({ query: { ...route.query, month: newMonth } })
})
watch(() => route.query.month, (monthQuery) => {
const newMonth = monthQuery as string || monthList.value[0]
if (newMonth !== curMonth.value) {
curMonth.value = newMonth
if (newMonth) {
updateQuery({ month: newMonth })
}
})
syncQueryToState()
function toggleYear(year: string) {
curYear.value = year
}
function toggleMonth(month: string) {
curMonth.value = month
}
</script>

<template>
Expand All @@ -64,7 +93,7 @@ watch(() => route.query.month, (monthQuery) => {
<span>{{ year }}</span>
</div>
</div>
<div class="hana-card flex gap-2 overflow-auto">
<div v-if="monthList.length" class="hana-card flex gap-2 overflow-auto">
<div
v-for="month in monthList"
:key="month"
Expand Down
23 changes: 0 additions & 23 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 608c165

Please sign in to comment.