233 lines
9.6 KiB
HTML
233 lines
9.6 KiB
HTML
{{ if .AskClosedMessage }}
|
||
<div>
|
||
<div uk-alert class="uk-text-center">
|
||
<p>{{ .AskClosedMessage }}</p>
|
||
{{ if .AskNextOpenAtStr }}
|
||
<p class="uk-text-small uk-text-muted">{{t .LangCode "ask.nextOpenAt" .AskNextOpenAtStr}}</p>
|
||
{{ end }}
|
||
{{ if .AskLastCloseAtStr }}
|
||
<p class="uk-text-small uk-text-muted">{{t .LangCode "ask.lastCloseAt" .AskLastCloseAtStr}}</p>
|
||
{{ end }}
|
||
</div>
|
||
|
||
<!-- 提问功能关闭但私聊开启:保留独立私聊入口(提问与私聊是独立功能) -->
|
||
{{ if .AllowChat }}
|
||
<div class="uk-margin-top">
|
||
{{ if .LoggedUser }}
|
||
<form method="post" action="/_/{{.PageUser.Domain}}" id="chat-only-form" enctype="multipart/form-data">
|
||
{{ .CSRFTokenHTML }}
|
||
{{ if .PageUser.AskPassword }}
|
||
<input type="hidden" name="ask_password" id="ask_password_input" value="">
|
||
{{ end }}
|
||
<input type="hidden" name="start_chat_val" value="true">
|
||
<input type="hidden" name="g-recaptcha-response" id="chat-g-recaptcha-response" value="">
|
||
<div class="uk-margin uk-text-center">
|
||
<textarea name="content" class="uk-textarea" rows="4" placeholder="{{t .LangCode "ask.chatPlaceholder"}}" maxlength="{{ .Limits.ChatMessageLen }}"></textarea>
|
||
</div>
|
||
<div class="uk-margin uk-text-center">
|
||
{{ if eq .CaptchaType "math" }}
|
||
<button type="button" class="uk-button uk-button-secondary math-captcha-trigger" id="chat-only-submit-btn">{{t .LangCode "ask.chat"}}</button>
|
||
{{ else }}
|
||
<button type="submit" class="uk-button uk-button-secondary g-recaptcha"
|
||
data-sitekey="{{.RecaptchaSiteKey}}" data-callback="onChatOnlySubmit"
|
||
id="chat-only-submit-btn">{{t .LangCode "ask.chat"}}</button>
|
||
{{ end }}
|
||
<div class="uk-text-meta">{{t .LangCode "ask.chatLimit" .PageUser.ChatMaxMessages}}</div>
|
||
</div>
|
||
</form>
|
||
{{ else }}
|
||
<!-- 未登录:私聊需登录 -->
|
||
<div class="uk-text-center uk-margin">
|
||
<p class="uk-text-small uk-text-muted">{{t .LangCode "ask.loginRequiredChat"}}</p>
|
||
<a class="uk-button uk-button-secondary uk-button-small" href="/login?to={{.CurrentURI}}">{{t .LangCode "ask.goLogin"}}</a>
|
||
</div>
|
||
{{ end }}
|
||
</div>
|
||
{{ end }}
|
||
|
||
{{ if and .AllowChat .LoggedUser }}
|
||
{{ if ne .CaptchaType "math" }}
|
||
<!-- 独立私聊表单的验证码回调(提问表单的 onSubmit 只提交 #form) -->
|
||
<script>
|
||
function onChatOnlySubmit(token) {
|
||
var form = document.getElementById('chat-only-form');
|
||
if (!form) return;
|
||
var btn = document.getElementById('chat-only-submit-btn');
|
||
if (btn) { btn.disabled = true; btn.innerText = '{{t .LangCode "common.verifying"}}'; }
|
||
var needPassword = {{ if .PageUser.AskPassword }}true{{ else }}false{{ end }};
|
||
if (needPassword) {
|
||
UIkit.modal.prompt('{{t .LangCode "ask.needPassword"}}', '', 'password')
|
||
.then(function(password) {
|
||
if (password) {
|
||
var pw = form.querySelector('#ask_password_input');
|
||
if (pw) pw.value = password;
|
||
form.submit();
|
||
} else {
|
||
if (btn) { btn.disabled = false; btn.innerText = '{{t .LangCode "ask.chat"}}'; }
|
||
}
|
||
});
|
||
} else {
|
||
form.submit();
|
||
}
|
||
}
|
||
</script>
|
||
{{ end }}
|
||
{{ end }}
|
||
</div>
|
||
{{ else if not .CanAsk }}
|
||
<div>
|
||
<div uk-alert class="uk-text-center">
|
||
<p>{{t .LangCode "ask.needLogin"}}</p>
|
||
</div>
|
||
<div class="uk-margin uk-text-center">
|
||
<a class="uk-button uk-button-primary" href="/login?to={{.CurrentURI}}">{{t .LangCode "ask.goLogin"}}</a>
|
||
</div>
|
||
</div>
|
||
{{ else }}
|
||
<form method="post" action="/_/{{.PageUser.Domain}}" enctype="multipart/form-data" id="form">
|
||
{{ .CSRFTokenHTML }}
|
||
|
||
{{if .PageUser.AskPassword}}
|
||
<input type="hidden" name="ask_password" id="ask_password_input" value="">
|
||
{{end}}
|
||
|
||
<input type="hidden" name="start_chat_val" id="start_chat_val" value="false">
|
||
<input type="hidden" name="g-recaptcha-response" id="g-recaptcha-response" value="">
|
||
|
||
<div class="uk-margin uk-text-center">
|
||
<textarea name="content" class="uk-textarea" rows="5" placeholder="{{t .LangCode "ask.placeholder"}}"
|
||
maxlength="{{ .Limits.QuestionContentLen }}">{{.content}}</textarea>
|
||
<div x-data="{ files: null }" style="width: 100%; background-color: #f8f8f8; display: flex; padding-top: 5px; padding-bottom: 5px; align-items: center; justify-content: start;gap: 5px">
|
||
<div uk-form-custom>
|
||
<a href="#" class="uk-icon-link" uk-icon="image" style="margin-left: 10px"></a>
|
||
<span style="font-size: 12px" x-text="files ? files[0].name : '{{t .LangCode "ask.addImage"}}'"></span>
|
||
<input id="uploader" name="images" type="file" accept="image/*" x-on:change="files = Object.values($event.target.files)">
|
||
</div>
|
||
<button x-show="files" type="button" class="uk-icon-link" uk-icon="close" style="margin-left: 10px;"
|
||
@click="files = null"></button>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="uk-margin uk-grid-small">
|
||
<label class="uk-text-small">
|
||
<input name="private" class="uk-checkbox" type="checkbox"> {{t .LangCode "ask.private"}}
|
||
</label>
|
||
<label class="uk-text-small">
|
||
<input name="receive_reply_via_email" id="notify-checkbox" class="uk-checkbox" type="checkbox"> {{t .LangCode "ask.notify"}}
|
||
</label>
|
||
<div id="email-container" style="width: 100%; display: none;" class="uk-margin-small-top">
|
||
<input class="uk-input uk-form-small" type="email" name="receive_reply_email" id="email-input" placeholder="{{t .LangCode "ask.emailPlaceholder"}}">
|
||
</div>
|
||
</div>
|
||
|
||
<div class="uk-margin uk-text-center">
|
||
<div class="uk-grid-small uk-flex-center" uk-grid>
|
||
<div>
|
||
{{ if eq .CaptchaType "math" }}
|
||
<button type="button" class="uk-button uk-button-primary math-captcha-trigger" id="normal-submit-btn">{{t .LangCode "ask.submit"}}</button>
|
||
{{ else }}
|
||
<button type="submit" class="uk-button uk-button-primary g-recaptcha"
|
||
data-sitekey="{{.RecaptchaSiteKey}}" data-callback="onSubmit"
|
||
id="normal-submit-btn">{{t .LangCode "ask.submit"}}</button>
|
||
{{ end }}
|
||
</div>
|
||
{{ if not .AllowChat }}
|
||
<div>
|
||
<button type="button" class="uk-button uk-button-secondary" disabled
|
||
uk-tooltip="{{t .LangCode "ask.chatDisabled"}}">{{t .LangCode "ask.chat"}}</button>
|
||
</div>
|
||
{{ else if .LoggedUser }}
|
||
<div>
|
||
<button type="button" class="uk-button uk-button-secondary" id="chat-submit-btn">{{t .LangCode "ask.chat"}}</button>
|
||
<div class="uk-text-meta">{{t .LangCode "ask.chatLimit" .PageUser.ChatMaxMessages}}</div>
|
||
</div>
|
||
{{ else }}
|
||
<div>
|
||
<button type="button" class="uk-button uk-button-secondary" id="chat-submit-btn">{{t .LangCode "ask.chat"}}</button>
|
||
</div>
|
||
{{ end }}
|
||
</div>
|
||
</div>
|
||
</form>
|
||
|
||
<script>
|
||
// 邮箱显隐与验证逻辑
|
||
var notifyCheckbox = document.getElementById('notify-checkbox');
|
||
var emailContainer = document.getElementById('email-container');
|
||
var emailInput = document.getElementById('email-input');
|
||
|
||
if (notifyCheckbox && emailContainer && emailInput) {
|
||
notifyCheckbox.addEventListener('change', function() {
|
||
if (this.checked) {
|
||
emailContainer.style.display = 'block';
|
||
emailInput.setAttribute('required', 'required');
|
||
} else {
|
||
emailContainer.style.display = 'none';
|
||
emailInput.removeAttribute('required');
|
||
emailInput.value = '';
|
||
}
|
||
});
|
||
}
|
||
|
||
// 私聊按钮:设置标识后触发验证弹窗
|
||
var chatBtn = document.getElementById('chat-submit-btn');
|
||
if (chatBtn) {
|
||
chatBtn.addEventListener('click', function() {
|
||
var isLogged = {{ if .LoggedUser }}true{{ else }}false{{ end }};
|
||
if (!isLogged) {
|
||
var currentURI = '{{.CurrentURI}}';
|
||
UIkit.modal.dialog(
|
||
'<div class="uk-text-center uk-padding" style="min-height: 150px; display: flex; flex-direction: column; justify-content: center;">' +
|
||
'<h3 class="uk-modal-title uk-margin-small-bottom">{{t .LangCode "ask.loginRequired"}}</h3>' +
|
||
'<p class="uk-text-muted uk-margin-small-bottom">{{t .LangCode "ask.loginRequiredChat"}}</p>' +
|
||
'<a href="/login?to=' + encodeURIComponent(currentURI) + '" class="uk-button uk-button-primary">{{t .LangCode "ask.goLogin"}}</a>' +
|
||
'</div>',
|
||
{width: '400px'}
|
||
);
|
||
return;
|
||
}
|
||
document.getElementById('start_chat_val').value = 'true';
|
||
{{ if eq .CaptchaType "math" }}
|
||
var submitBtn = document.getElementById('normal-submit-btn');
|
||
if (submitBtn) submitBtn.click();
|
||
{{ else }}
|
||
document.getElementById('normal-submit-btn').click();
|
||
{{ end }}
|
||
});
|
||
}
|
||
|
||
{{ if ne .CaptchaType "math" }}
|
||
function onSubmit(token) {
|
||
var btn = document.querySelector('.g-recaptcha');
|
||
var originalText = btn.innerText;
|
||
|
||
if (notifyCheckbox && notifyCheckbox.checked && emailInput && emailInput.value.trim() === '') {
|
||
alert(CAPTCHA_I18N.needEmail);
|
||
grecaptcha.reset();
|
||
return;
|
||
}
|
||
|
||
btn.disabled = true;
|
||
btn.innerText = '{{t .LangCode "common.verifying"}}';
|
||
|
||
var needPassword = {{if .PageUser.AskPassword}}true{{else}}false{{end}};
|
||
if (needPassword) {
|
||
UIkit.modal.prompt(CAPTCHA_I18N.needPassword, '', 'password')
|
||
.then(function(password) {
|
||
if (password) {
|
||
document.getElementById('ask_password_input').value = password;
|
||
document.getElementById('form').submit();
|
||
} else {
|
||
btn.disabled = false;
|
||
btn.innerText = originalText;
|
||
grecaptcha.reset();
|
||
}
|
||
});
|
||
} else {
|
||
document.getElementById('form').submit();
|
||
}
|
||
}
|
||
{{ end }}
|
||
</script>
|
||
{{ end }}
|