Skip to content

Commit

Permalink
feat: add copy text
Browse files Browse the repository at this point in the history
  • Loading branch information
YunYouJun committed Feb 9, 2024
1 parent c8b799d commit f4971ec
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 1 deletion.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ Powered by [DeepSeek 开发平台](https://platform.deepseek.com/).
cp .env.example .env

# .env
# Use DeepSeek
AI_SERVICE_URL='https://api.deepseek.com/v1'
MODEL_NAME='deepseek-chat'
# you can get free tokens from https://platform.deepseek.com/
OPENAI_API_KEY=your_deepseek_api_key
```
Expand Down
68 changes: 67 additions & 1 deletion components/SpringFestivalCouplets.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { copyBlobToClipboard } from 'copy-image-clipboard'
import { useClipboard } from '@vueuse/core'
import { suggestedCoupletsFilename } from '~/config'
import type { SprintFestivalCouplets } from '~/packages/ai/src'
import pkg from '~/package.json'
defineProps<{
coupletsData: SprintFestivalCouplets
Expand Down Expand Up @@ -57,6 +58,67 @@ async function shareLink() {
alert('已复制链接')
}
}
/**
* 复制春联文字
*/
async function copyText() {
const { 上联 } = app.coupletsData
const minWidth = app.coupletsData['横批'].length + 3 * 2
// const txt = `
// *
// * *
// * *
// * ${app.coupletsData['总结']} *
// * *
// * *
// *
// `
const fuLines = [
'',
'口 口',
// eslint-disable-next-line no-irregular-whitespace, vue/no-irregular-whitespace
`口 ${app.coupletsData['总结']} 口`,
'口 口',
'',
]
function getFuChar(row: number) {
// const fuLine = txt.split('\n')[row] || ''
const fuLine = fuLines[row] || ' '
// 填充空格
// eslint-disable-next-line no-irregular-whitespace, vue/no-irregular-whitespace
// " " 全角空格 U+3000
const halfWidth = (minWidth - fuLine.length) / 2
return ' '.repeat(halfWidth) + fuLine + ' '.repeat(halfWidth)
}
const lines = []
const halfWidth = (minWidth - app.coupletsData['横批'].length) / 2 + 1
const halfSpace = ' '.repeat(halfWidth)
lines.push(`${halfSpace}${app.coupletsData['横批']}${halfSpace}`)
lines.push('')
// fu start
const fuStartLine = Math.floor(上联.length <= 5 ? 0 : (上联.length - 5) / 2)
const cLen = app.coupletsData['上联'].length
for (let i = 0; i < cLen; i++)
lines.push(`${app.coupletsData['上联'][i]} ${getFuChar(i - fuStartLine)} ${app.coupletsData['下联'][i]}`)
// app.coupletsData['上联']
lines.push('')
lines.push(`春联生成自:${pkg.homepage}`)
const txt = lines.join('\n')
await copy(txt)
if (copied.value) {
// eslint-disable-next-line no-alert
alert(txt)
}
}
</script>

<template>
Expand Down Expand Up @@ -151,7 +213,11 @@ async function shareLink() {

<div class="font-zmx mt-2 flex" text="black" gap="2">
<SfcButton icon="i-ri-link" @click="shareLink">
分享春联链接
分享链接
</SfcButton>

<SfcButton icon="i-ri-file-copy-line" @click="copyText">
复制春联
</SfcButton>
</div>
</template>
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "0.0.1",
"private": true,
"packageManager": "pnpm@8.15.1",
"homepage": "https://ai-sfc.yunyoujun.cn",
"repository": {
"url": "https://github.com/YunYouJun/ai-sfc"
},
Expand Down

0 comments on commit f4971ec

Please sign in to comment.