系统设置(2/3)

系统设置页前端实现
This commit is contained in:
Chenx221 2024-03-30 14:48:55 +08:00
parent e10f119811
commit 243a0a4b9c
Signed by: chenx221
GPG Key ID: D7A9EC07024C3021
2 changed files with 65 additions and 9 deletions

View File

@ -1,17 +1,48 @@
<?php
use yii\helpers\Html;
use yii\web\JqueryAsset;
use yii\web\View;
use yii\widgets\ActiveForm;
/* @var $this yii\web\View */
use app\models\SiteConfig;
use yii\bootstrap5\Html;
/* @var $siteConfig app\models\SiteConfig */
JqueryAsset::register($this);
$this->title = '系统设置';
$siteConfig = new SiteConfig();
$siteConfig->loadFromEnv();
?>
<div class="admin-system">
<div class="admin-system">
<h1><?= Html::encode($this->title) ?></h1>
<h1><?= Html::encode($this->title) ?></h1>
<br>
</div>
<?php $form = ActiveForm::begin(); ?>
<table>
<?php
$attributes = array_keys(get_object_vars($siteConfig));
foreach ($attributes as $attribute) {
echo '<tr id="tr-'.$attribute.'">';
echo '<th style="width: 200px"><p>' . $siteConfig->attributeLabels()[$attribute] . '</p></th>';
if ($attribute == 'registrationEnabled' || $attribute == 'enableIpinfo') {
echo '<td>' . $form->field($siteConfig, $attribute)->checkbox(['class' => 'form-check-input'], false)->label(false) . '</td>';
} elseif ($attribute == 'verifyProvider') {
echo '<td>' . $form->field($siteConfig, $attribute)->dropDownList(['None' => 'None', 'reCAPTCHA' => 'reCAPTCHA', 'hCaptcha' => 'hCaptcha', 'Turnstile' => 'Turnstile'], ['class' => 'form-select form-select-sm', 'style' => 'width:25em'])->label(false) . '</td>';
} else {
echo '<td>' . $form->field($siteConfig, $attribute)->textInput(['class' => 'form-control form-control-sm', 'style' => 'width:25em'])->label(false) . '</td>';
}
echo '</tr>';
}
?>
</table>
<div class="form-group">
<?= Html::submitButton('保存', ['class' => 'btn btn-success']) ?>
</div>
<?php ActiveForm::end(); ?>
</div>
<?php
$this->registerJsFile('@web/js/admin-system.js', ['depends' => [JqueryAsset::class], 'position' => View::POS_END]);
?>

25
web/js/admin-system.js Normal file
View File

@ -0,0 +1,25 @@
$(document).ready(function () {
updateTableRowVisibility();
$('#siteconfig-verifyprovider').change(function () {
updateTableRowVisibility();
});
$('#siteconfig-enableipinfo').change(function () {
updateTableRowVisibility();
});
});
function updateTableRowVisibility() {
let currentValue = $('#siteconfig-verifyprovider').val();
let ipinfoEnable = $('#siteconfig-enableipinfo').prop('checked');
$('#tr-recaptchaSiteKey, #tr-recaptchaSecret, #tr-hcaptchaSiteKey, #tr-hcaptchaSecret, #tr-turnstileSiteKey, #tr-turnstileSecret,#tr-ipinfoToken').hide();
if (currentValue === 'reCAPTCHA') {
$('#tr-recaptchaSiteKey, #tr-recaptchaSecret').show();
} else if (currentValue === 'hCaptcha') {
$('#tr-hcaptchaSiteKey, #tr-hcaptchaSecret').show();
} else if (currentValue === 'Turnstile') {
$('#tr-turnstileSiteKey, #tr-turnstileSecret').show();
}
if (ipinfoEnable) {
$('#tr-ipinfoToken').show();
}
}