Skip to content

Commit

Permalink
refactor: extract button & add enter key watch
Browse files Browse the repository at this point in the history
  • Loading branch information
YunYouJun committed Feb 4, 2024
1 parent ab45f60 commit 641a394
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 7 deletions.
12 changes: 12 additions & 0 deletions components/AiPrompt.vue
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
<script lang="ts" setup>
import consola from 'consola'
import { useMagicKeys } from '@vueuse/core'
const app = useAppStore()
/**
* generate sfc 春联
*/
async function generate() {
if (app.loading)
return
app.loading = true
const data = await $fetch('/api/generate', {
query: {
Expand All @@ -17,6 +22,13 @@ async function generate() {
app.setCoupletsData(data)
app.loading = false
}
// Ctrl + Enter / Cmd + Enter to generate
const { Ctrl_enter, Cmd_enter } = useMagicKeys()
watch(() => [Cmd_enter.value, Ctrl_enter.value], (v) => {
if (v)
generate()
})
</script>

<template>
Expand Down
12 changes: 12 additions & 0 deletions components/SfcButton.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<script lang="ts" setup>
defineProps<{
icon: string
}>()
</script>

<template>
<button flex items-center justify-center class="w-full btn" text="black">
<div :class="icon" mr-1 />
<slot />
</button>
</template>
14 changes: 7 additions & 7 deletions components/SpringFestivalCouplets.vue
Original file line number Diff line number Diff line change
Expand Up @@ -104,18 +104,18 @@ async function shareLink() {
</div>

<div class="font-zmx mt-4 flex" text="black" gap="2">
<button class="w-full btn" text="black" @click="download">
<SfcButton icon="i-ri-download-line" @click="download">
下载图片
</button>
<button class="w-full btn" text="black" @click="copyImg">
</SfcButton>
<SfcButton icon="i-ri-clipboard-line" @click="copyImg">
拷贝图片
</button>
</SfcButton>
</div>

<div class="font-zmx mt-2 flex" text="black" gap="2">
<button flex items-center justify-center class="w-full btn" text="black" @click="shareLink">
分享春联链接 <div class="ml-1" i-ri-link />
</button>
<SfcButton icon="i-ri-link" @click="shareLink">
分享春联链接
</SfcButton>
</div>
</template>

Expand Down

0 comments on commit 641a394

Please sign in to comment.