Skip to content

Commit cc65f39

Browse files
authored
feat: add page watermark (#526)
Signed-off-by: Bob Du <i@bobdu.cc>
1 parent fad1a75 commit cc65f39

File tree

12 files changed

+54
-7
lines changed

12 files changed

+54
-7
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
"lint-staged": "^13.1.2",
5050
"markdown-it": "^13.0.1",
5151
"markdown-it-link-attributes": "^4.0.1",
52-
"naive-ui": "^2.38.1",
52+
"naive-ui": "^2.38.2",
5353
"npm-run-all": "^4.1.5",
5454
"pinia": "^2.0.33",
5555
"postcss": "^8.4.35",

pnpm-lock.yaml

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

service/src/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -645,6 +645,7 @@ router.post('/session', async (req, res) => {
645645
title: config.siteConfig.siteTitle,
646646
chatModels,
647647
allChatModels: chatModelOptions,
648+
showWatermark: config.siteConfig?.showWatermark,
648649
},
649650
})
650651
return
@@ -699,6 +700,7 @@ router.post('/session', async (req, res) => {
699700
chatModels,
700701
allChatModels: chatModelOptions,
701702
usageCountLimit: config.siteConfig?.usageCountLimit,
703+
showWatermark: config.siteConfig?.showWatermark,
702704
userInfo,
703705
},
704706
})
@@ -716,6 +718,7 @@ router.post('/session', async (req, res) => {
716718
title: config.siteConfig.siteTitle,
717719
chatModels: chatModelOptions, // if userId is null which means in nologin mode, open all model options, otherwise user can only choose gpt-3.5-turbo
718720
allChatModels: chatModelOptions,
721+
showWatermark: config.siteConfig?.showWatermark,
719722
userInfo,
720723
},
721724
})

service/src/storage/model.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ export class SiteConfig {
205205
public chatModels?: string,
206206
public globalAmount?: number,
207207
public usageCountLimit?: boolean,
208+
public showWatermark?: boolean,
208209
) { }
209210
}
210211

src/components/common/Setting/Site.vue

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,16 @@ onMounted(() => {
147147
/>
148148
</div>
149149
</div>
150+
<div class="flex items-center space-x-4">
151+
<span class="flex-shrink-0 w-[100px]">{{ $t('setting.showWatermark') }}</span>
152+
<div class="flex-1">
153+
<NSwitch
154+
:round="false"
155+
:value="config && config.showWatermark"
156+
@update:value="(val) => { if (config) config.showWatermark = val }"
157+
/>
158+
</div>
159+
</div>
150160
<div class="flex items-center space-x-4">
151161
<span class="flex-shrink-0 w-[100px]" />
152162
<NButton :loading="saving" type="primary" @click="updateSiteInfo(config)">

src/components/common/Setting/model.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export class SiteConfig {
3232
chatModels?: string
3333
globalAmount?: number
3434
usageCountLimit?: boolean
35+
showWatermark?: boolean
3536
}
3637

3738
export class MailConfig {
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<script setup lang="ts">
2+
import { NWatermark } from 'naive-ui'
3+
import { computed } from 'vue'
4+
import { useUserStore } from '@/store'
5+
6+
const userStore = useUserStore()
7+
const content = computed(() => `${document.title}\n\n\n${userStore.userInfo.name}`)
8+
</script>
9+
10+
<template>
11+
<NWatermark
12+
:content="content"
13+
cross
14+
fullscreen
15+
:font-size="16"
16+
:line-height="16"
17+
font-family="monospace"
18+
font-color="rgba(128, 128, 128, .15)"
19+
:width="384"
20+
:height="384"
21+
:x-offset="12"
22+
:y-offset="65"
23+
:rotate="-15"
24+
:z-index="3000"
25+
text-align="center"
26+
/>
27+
</template>

src/components/common/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@ import SvgIcon from './SvgIcon/index.vue'
55
import UserAvatar from './UserAvatar/index.vue'
66
import Setting from './Setting/index.vue'
77
import PromptStore from './PromptStore/index.vue'
8+
import Watermark from './Watermark/index.vue'
89

9-
export { HoverButton, NaiveProvider, SvgIcon, UserAvatar, Setting, PromptStore, GithubSite }
10+
export { HoverButton, NaiveProvider, SvgIcon, UserAvatar, Setting, PromptStore, GithubSite, Watermark }

src/locales/en-US.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ export default {
8888
globalAmount: 'Global Usage Amount for New User',
8989
limit_switch: 'Open Usage Limitation',
9090
usageCountLimit: 'Enable Usage Count Limit',
91+
showWatermark: 'Show Watermark',
9192
redeemCardNo: 'Redeem CardNo',
9293
useAmount: 'No. of questions',
9394
setting: 'Setting',

src/locales/zh-CN.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ export default {
8888
globalAmount: '新用户全局次数设置',
8989
limit_switch: '打开次数限制',
9090
usageCountLimit: '使用次数限制',
91+
showWatermark: '显示水印',
9192
redeemCardNo: '兑换码卡号',
9293
useAmount: '可提问次数',
9394
setting: '设置',

0 commit comments

Comments
 (0)