From 41b707ed4cc0a0c8af869b753b8c1be35b7564bb Mon Sep 17 00:00:00 2001 From: chengpeipei <472799208@qq.com> Date: Wed, 13 Nov 2024 17:41:07 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9F=BA=E6=9C=AC=E8=AE=BE=E7=BD=AE=E4=B8=AD?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=8C=BF=E5=90=8D=E8=AF=84=E8=AE=BA=E6=97=B6?= =?UTF-8?q?=E6=98=B5=E7=A7=B0=E3=80=81=E7=94=B5=E5=AD=90=E9=82=AE=E4=BB=B6?= =?UTF-8?q?=E3=80=81=E7=BD=91=E7=AB=99=E7=9A=84=E8=BE=93=E5=85=A5=E6=8F=90?= =?UTF-8?q?=E7=A4=BA=E9=85=8D=E7=BD=AE=EF=BC=8C=E5=8F=AF=E4=BB=A5=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E8=AF=84=E8=AE=BA=E6=97=B6=E5=AF=B9=E5=BA=94=E8=BE=93?= =?UTF-8?q?=E5=85=A5=E6=A1=86=E7=9A=84=E6=8F=90=E7=A4=BA=E6=96=87=E5=AD=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/comment-widget/src/base-form.ts | 21 +++++++++++++--- packages/comment-widget/src/comment-widget.ts | 15 ++++++++++++ packages/comment-widget/src/context/index.ts | 3 +++ packages/widget/src/index.ts | 6 +++++ .../comment/widget/DefaultCommentWidget.java | 6 +++++ .../comment/widget/SettingConfigGetter.java | 3 +++ src/main/resources/extensions/settings.yaml | 24 +++++++++++++++++++ 7 files changed, 75 insertions(+), 3 deletions(-) diff --git a/packages/comment-widget/src/base-form.ts b/packages/comment-widget/src/base-form.ts index 460b92a..41fa6ce 100644 --- a/packages/comment-widget/src/base-form.ts +++ b/packages/comment-widget/src/base-form.ts @@ -13,6 +13,9 @@ import { kindContext, nameContext, toastContext, + nicknamePlaceholderContext, + emailPlaceholderContext, + websitePlaceholderContext, } from './context'; import './emoji-button'; import './icons/icon-loading'; @@ -60,6 +63,18 @@ export class BaseForm extends LitElement { @state() toastManager: ToastManager | undefined; + @consume({ context: nicknamePlaceholderContext, subscribe: true }) + @state() + nicknamePlaceholder = ''; + + @consume({ context: emailPlaceholderContext, subscribe: true }) + @state() + emailPlaceholder = ''; + + @consume({ context: websitePlaceholderContext, subscribe: true }) + @state() + websitePlaceholder = ''; + textareaRef: Ref = createRef(); get customAccount() { @@ -182,21 +197,21 @@ export class BaseForm extends LitElement { name="displayName" value=${this.customAccount.displayName} type="text" - placeholder="昵称" + placeholder=${this.nicknamePlaceholder} required /> (或登录账号) ` diff --git a/packages/comment-widget/src/comment-widget.ts b/packages/comment-widget/src/comment-widget.ts index 2f92f13..d4e36e5 100644 --- a/packages/comment-widget/src/comment-widget.ts +++ b/packages/comment-widget/src/comment-widget.ts @@ -31,6 +31,9 @@ import { useAvatarProviderContext, versionContext, withRepliesContext, + nicknamePlaceholderContext, + emailPlaceholderContext, + websitePlaceholderContext, } from './context'; import { ToastManager } from './lit-toast'; import baseStyles from './styles/base'; @@ -71,6 +74,18 @@ export class CommentWidget extends LitElement { @property({ type: Number, attribute: 'with-reply-size' }) withReplySize = 10; + @provide({ context: nicknamePlaceholderContext }) + @property({ type: String, attribute: 'nickname-placeholder' }) + nicknamePlaceholder = ''; + + @provide({ context: emailPlaceholderContext }) + @property({ type: String, attribute: 'email-placeholder' }) + emailPlaceholder = ''; + + @provide({ context: websitePlaceholderContext }) + @property({ type: String, attribute: 'website-placeholder' }) + websitePlaceholder = ''; + @provide({ context: useAvatarProviderContext }) @property({ type: Boolean, attribute: 'use-avatar-provider' }) useAvatarProvider = false; diff --git a/packages/comment-widget/src/context/index.ts b/packages/comment-widget/src/context/index.ts index d35c564..e55056c 100644 --- a/packages/comment-widget/src/context/index.ts +++ b/packages/comment-widget/src/context/index.ts @@ -13,6 +13,9 @@ export const useAvatarProviderContext = createContext(Symbol('useAvatar export const avatarProviderContext = createContext(Symbol('avatarProvider')); export const avatarProviderMirrorContext = createContext(Symbol('avatarProviderMirror')); export const avatarPolicyContext = createContext(Symbol('avatarPolicy')); +export const nicknamePlaceholderContext = createContext(Symbol('nicknamePlaceholder')); +export const emailPlaceholderContext = createContext(Symbol('emailPlaceholder')); +export const websitePlaceholderContext = createContext(Symbol('websitePlaceholder')); export const allowAnonymousCommentsContext = createContext( Symbol('allowAnonymousComments') diff --git a/packages/widget/src/index.ts b/packages/widget/src/index.ts index 4aa74f8..f6dff79 100644 --- a/packages/widget/src/index.ts +++ b/packages/widget/src/index.ts @@ -16,6 +16,9 @@ interface Props { avatarProviderMirror?: string; avatarPolicy?: string; captchaEnabled: boolean; + nicknamePlaceholder?: string; + emailPlaceholder?: string; + websitePlaceholder?: string; } export function init(el: string, props: Props) { @@ -44,6 +47,9 @@ export function init(el: string, props: Props) { commentWidget.avatarProviderMirror = props.avatarProviderMirror || ''; commentWidget.avatarPolicy = props.avatarPolicy || ''; commentWidget.captchaEnabled = props.captchaEnabled || false; + commentWidget.nicknamePlaceholder = props.nicknamePlaceholder || ''; + commentWidget.emailPlaceholder = props.emailPlaceholder || ''; + commentWidget.websitePlaceholder = props.websitePlaceholder || ''; const observer = new IntersectionObserver((entries) => { entries.forEach((entry) => { diff --git a/src/main/java/run/halo/comment/widget/DefaultCommentWidget.java b/src/main/java/run/halo/comment/widget/DefaultCommentWidget.java index de8f4f5..8a00169 100644 --- a/src/main/java/run/halo/comment/widget/DefaultCommentWidget.java +++ b/src/main/java/run/halo/comment/widget/DefaultCommentWidget.java @@ -67,6 +67,9 @@ private String commentHtml(IAttribute groupAttribute, IAttribute kindAttribute, properties.setProperty("replySize", String.valueOf(basicConfig.getReplySize())); properties.setProperty("withReplies", String.valueOf(basicConfig.isWithReplies())); properties.setProperty("withReplySize", String.valueOf(basicConfig.getWithReplySize())); + properties.setProperty("nicknamePlaceholder", String.valueOf(basicConfig.getNicknamePlaceholder())); + properties.setProperty("emailPlaceholder", String.valueOf(basicConfig.getEmailPlaceholder())); + properties.setProperty("websitePlaceholder", String.valueOf(basicConfig.getWebsitePlaceholder())); var avatarConfig = settingConfigGetter.getAvatarConfig().blockOptional().orElseThrow(); properties.setProperty("useAvatarProvider", String.valueOf(avatarConfig.isEnable())); @@ -100,6 +103,9 @@ private String commentHtml(IAttribute groupAttribute, IAttribute kindAttribute, avatarProviderMirror: "${avatarProviderMirror}", avatarPolicy: "${avatarPolicy}", captchaEnabled: ${captchaEnabled}, + nicknamePlaceholder: "${nicknamePlaceholder}", + emailPlaceholder: "${emailPlaceholder}", + websitePlaceholder: "${websitePlaceholder}", } ); diff --git a/src/main/java/run/halo/comment/widget/SettingConfigGetter.java b/src/main/java/run/halo/comment/widget/SettingConfigGetter.java index 257bcc6..298b734 100644 --- a/src/main/java/run/halo/comment/widget/SettingConfigGetter.java +++ b/src/main/java/run/halo/comment/widget/SettingConfigGetter.java @@ -69,6 +69,9 @@ class BasicConfig { private int replySize; private boolean withReplies; private int withReplySize; + private String nicknamePlaceholder; + private String emailPlaceholder; + private String websitePlaceholder; } @Data diff --git a/src/main/resources/extensions/settings.yaml b/src/main/resources/extensions/settings.yaml index b812553..56b57d0 100644 --- a/src/main/resources/extensions/settings.yaml +++ b/src/main/resources/extensions/settings.yaml @@ -31,6 +31,30 @@ spec: key: withReplySize validation: required value: 5 + - $formkit: text + label: 昵称输入提示 + name: nicknamePlaceholder + id: nicknamePlaceholder + key: nicknamePlaceholder + value: "昵称" + help: 匿名评论时昵称输入栏的提示信息 + validation: required + - $formkit: text + label: 电子邮件输入提示 + name: emailPlaceholder + id: emailPlaceholder + key: emailPlaceholder + value: "电子邮件" + help: 匿名评论时电子邮件输入栏的提示信息 + validation: required + - $formkit: text + label: 网站输入提示 + name: websitePlaceholder + id: websitePlaceholder + key: websitePlaceholder + value: "网站" + help: 匿名评论时网站输入栏的提示信息 + validation: required - group: security label: 安全设置 formSchema: