From f4971ecd3970f502227fee114678240df91c6496 Mon Sep 17 00:00:00 2001 From: YunYouJun Date: Fri, 9 Feb 2024 21:27:13 +0800 Subject: [PATCH] feat: add copy text --- README.md | 3 ++ components/SpringFestivalCouplets.vue | 68 ++++++++++++++++++++++++++- package.json | 1 + 3 files changed, 71 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 2e4dc2e..06e8a0e 100644 --- a/README.md +++ b/README.md @@ -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 ``` diff --git a/components/SpringFestivalCouplets.vue b/components/SpringFestivalCouplets.vue index eaf0cf6..307b44d 100644 --- a/components/SpringFestivalCouplets.vue +++ b/components/SpringFestivalCouplets.vue @@ -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 @@ -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) + } +} diff --git a/package.json b/package.json index ee5079a..fa76889 100644 --- a/package.json +++ b/package.json @@ -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" },