Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add page watermark #526

Merged
merged 1 commit into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"lint-staged": "^13.1.2",
"markdown-it": "^13.0.1",
"markdown-it-link-attributes": "^4.0.1",
"naive-ui": "^2.38.1",
"naive-ui": "^2.38.2",
"npm-run-all": "^4.1.5",
"pinia": "^2.0.33",
"postcss": "^8.4.35",
Expand Down
8 changes: 4 additions & 4 deletions pnpm-lock.yaml

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

3 changes: 3 additions & 0 deletions service/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,7 @@ router.post('/session', async (req, res) => {
title: config.siteConfig.siteTitle,
chatModels,
allChatModels: chatModelOptions,
showWatermark: config.siteConfig?.showWatermark,
},
})
return
Expand Down Expand Up @@ -699,6 +700,7 @@ router.post('/session', async (req, res) => {
chatModels,
allChatModels: chatModelOptions,
usageCountLimit: config.siteConfig?.usageCountLimit,
showWatermark: config.siteConfig?.showWatermark,
userInfo,
},
})
Expand All @@ -716,6 +718,7 @@ router.post('/session', async (req, res) => {
title: config.siteConfig.siteTitle,
chatModels: chatModelOptions, // if userId is null which means in nologin mode, open all model options, otherwise user can only choose gpt-3.5-turbo
allChatModels: chatModelOptions,
showWatermark: config.siteConfig?.showWatermark,
userInfo,
},
})
Expand Down
1 change: 1 addition & 0 deletions service/src/storage/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ export class SiteConfig {
public chatModels?: string,
public globalAmount?: number,
public usageCountLimit?: boolean,
public showWatermark?: boolean,
) { }
}

Expand Down
10 changes: 10 additions & 0 deletions src/components/common/Setting/Site.vue
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,16 @@ onMounted(() => {
/>
</div>
</div>
<div class="flex items-center space-x-4">
<span class="flex-shrink-0 w-[100px]">{{ $t('setting.showWatermark') }}</span>
<div class="flex-1">
<NSwitch
:round="false"
:value="config && config.showWatermark"
@update:value="(val) => { if (config) config.showWatermark = val }"
/>
</div>
</div>
<div class="flex items-center space-x-4">
<span class="flex-shrink-0 w-[100px]" />
<NButton :loading="saving" type="primary" @click="updateSiteInfo(config)">
Expand Down
1 change: 1 addition & 0 deletions src/components/common/Setting/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export class SiteConfig {
chatModels?: string
globalAmount?: number
usageCountLimit?: boolean
showWatermark?: boolean
}

export class MailConfig {
Expand Down
27 changes: 27 additions & 0 deletions src/components/common/Watermark/index.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<script setup lang="ts">
import { NWatermark } from 'naive-ui'
import { computed } from 'vue'
import { useUserStore } from '@/store'

const userStore = useUserStore()
const content = computed(() => `${document.title}\n\n\n${userStore.userInfo.name}`)
</script>

<template>
<NWatermark
:content="content"
cross
fullscreen
:font-size="16"
:line-height="16"
font-family="monospace"
font-color="rgba(128, 128, 128, .15)"
:width="384"
:height="384"
:x-offset="12"
:y-offset="65"
:rotate="-15"
:z-index="3000"
text-align="center"
/>
</template>
3 changes: 2 additions & 1 deletion src/components/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ import SvgIcon from './SvgIcon/index.vue'
import UserAvatar from './UserAvatar/index.vue'
import Setting from './Setting/index.vue'
import PromptStore from './PromptStore/index.vue'
import Watermark from './Watermark/index.vue'

export { HoverButton, NaiveProvider, SvgIcon, UserAvatar, Setting, PromptStore, GithubSite }
export { HoverButton, NaiveProvider, SvgIcon, UserAvatar, Setting, PromptStore, GithubSite, Watermark }
1 change: 1 addition & 0 deletions src/locales/en-US.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ export default {
globalAmount: 'Global Usage Amount for New User',
limit_switch: 'Open Usage Limitation',
usageCountLimit: 'Enable Usage Count Limit',
showWatermark: 'Show Watermark',
redeemCardNo: 'Redeem CardNo',
useAmount: 'No. of questions',
setting: 'Setting',
Expand Down
1 change: 1 addition & 0 deletions src/locales/zh-CN.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ export default {
globalAmount: '新用户全局次数设置',
limit_switch: '打开次数限制',
usageCountLimit: '使用次数限制',
showWatermark: '显示水印',
redeemCardNo: '兑换码卡号',
useAmount: '可提问次数',
setting: '设置',
Expand Down
1 change: 1 addition & 0 deletions src/store/modules/auth/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ interface SessionResponse {
value: string
}[]
usageCountLimit: boolean
showWatermark: boolean
userInfo: { name: string; description: string; avatar: string; userId: string; root: boolean; config: UserConfig }
}

Expand Down
3 changes: 2 additions & 1 deletion src/views/chat/layout/sider/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import List from './List.vue'
import Footer from './Footer.vue'
import { useAppStore, useAuthStore, useChatStore } from '@/store'
import { useBasicLayout } from '@/hooks/useBasicLayout'
import { GithubSite, PromptStore } from '@/components/common'
import { GithubSite, PromptStore, Watermark } from '@/components/common'
import { fetchAnnouncement } from '@/api'
import { AnnounceConfig } from '@/components/common/Setting/model'

Expand Down Expand Up @@ -156,6 +156,7 @@ onMounted(async () => {
</div>
</div>
</NModal>
<Watermark v-if="authStore.session?.showWatermark" />
</template>

<style scoped>
Expand Down
Loading