mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-23 11:27:24 +08:00
save settings add validation
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
<template>
|
||||
<el-form :model="formData" :rules="rules" ref="formRef" label-width="250px" class="formData" size="mini">
|
||||
<el-form :model="formData" :rules="rules" ref="formRef" label-width="250px" class="formData" size="mini" :v-loading="loading">
|
||||
<el-form-item label="Enabled" prop="backup.enabled">
|
||||
<el-radio v-model="formData.backup.enabled" label="yes">Yes</el-radio>
|
||||
<el-radio v-model="formData.backup.enabled" label="no">No</el-radio>
|
||||
@@ -94,6 +94,7 @@ export default {
|
||||
const router = useRouter()
|
||||
const { id } = route.query
|
||||
const state = reactive({
|
||||
loading: false,
|
||||
token: localGet('token') || '',
|
||||
id: id,
|
||||
allClasses: [],
|
||||
@@ -113,6 +114,7 @@ export default {
|
||||
'backup.enabled': [{ required: 'true', }],
|
||||
},
|
||||
})
|
||||
|
||||
onMounted( () => {
|
||||
|
||||
})
|
||||
@@ -138,9 +140,12 @@ export default {
|
||||
}
|
||||
}
|
||||
const listSetting = async () => {
|
||||
//not work....
|
||||
state.loading = true
|
||||
let res = await api.listSetting({prefix: "backup"})
|
||||
console.log("listSetting", res)
|
||||
state.formData = res.data
|
||||
state.loading = false
|
||||
}
|
||||
return {
|
||||
...toRefs(state),
|
||||
|
||||
@@ -27,10 +27,12 @@ export default {
|
||||
const backup = ref(null)
|
||||
const hr = ref(null)
|
||||
const state = useTable()
|
||||
let activeTabIndex = 0
|
||||
const tabs = [backup, hr]
|
||||
|
||||
onMounted(() => {
|
||||
console.log('Setting onMounted')
|
||||
backup.value.listSetting()
|
||||
tabs[activeTabIndex].value.listSetting()
|
||||
})
|
||||
const fetchTableData = async () => {
|
||||
state.loading = true
|
||||
@@ -58,7 +60,8 @@ export default {
|
||||
fetchTableData()
|
||||
}
|
||||
const handleTabClick = (tab) => {
|
||||
console.log('handleTabClick', tab)
|
||||
activeTabIndex = tab.index
|
||||
tabs[activeTabIndex].value.listSetting()
|
||||
}
|
||||
return {
|
||||
...toRefs(state),
|
||||
|
||||
@@ -2,10 +2,13 @@
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\HitAndRun;
|
||||
use App\Repositories\SettingRepository;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class SettingController extends Controller
|
||||
{
|
||||
@@ -36,7 +39,10 @@ class SettingController extends Controller
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
$result = $this->repository->store($request->all());
|
||||
$data = $request->all();
|
||||
$prefix = Arr::first(array_keys($data));
|
||||
$request->validate($this->getRules($prefix));
|
||||
$result = $this->repository->store($data);
|
||||
return $this->success($result, 'Save setting success!');
|
||||
}
|
||||
|
||||
@@ -74,4 +80,28 @@ class SettingController extends Controller
|
||||
|
||||
}
|
||||
|
||||
private function getRules($prefix): array
|
||||
{
|
||||
$allRules = [
|
||||
'hr' => [
|
||||
'ban_user_when_counts_reach' => 'required|integer|min:1',
|
||||
'ignore_when_ratio_reach' => 'required|numeric',
|
||||
'inspect_time' => 'required|integer|min:1',
|
||||
'seed_time_minimum' => 'required|integer|lt:hr.inspect_time',
|
||||
'mode' => ['required', Rule::in(array_keys(HitAndRun::$modes))],
|
||||
],
|
||||
];
|
||||
|
||||
$result = [];
|
||||
foreach ($allRules as $rulePrefix => $rules) {
|
||||
if ($rulePrefix != $prefix) {
|
||||
continue;
|
||||
}
|
||||
foreach ($rules as $key => $value) {
|
||||
$result["$prefix.$key"] = $value;
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -7,6 +7,6 @@ class Standard extends NexusModel
|
||||
{
|
||||
public static function getLabelName()
|
||||
{
|
||||
return nexus_trans('searchbox.sub_standard_source_label');
|
||||
return nexus_trans('searchbox.sub_category_standard_label');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ use App\Models\BonusLogs;
|
||||
use App\Models\Category;
|
||||
use App\Models\Exam;
|
||||
use App\Models\ExamUser;
|
||||
use App\Models\HitAndRun;
|
||||
use App\Models\Icon;
|
||||
use App\Models\Setting;
|
||||
use App\Models\User;
|
||||
@@ -132,6 +133,7 @@ class Update extends Install
|
||||
if (WITH_LARAVEL && version_compare(VERSION_NUMBER, '1.6.0-beta12', '>=')) {
|
||||
$this->addSetting('authority.torrent_hr', User::CLASS_ADMINISTRATOR);
|
||||
$this->addSetting('bonus.cancel_hr', BonusLogs::DEFAULT_BONUS_CANCEL_ONE_HIT_AND_RUN);
|
||||
$this->addSetting('hr.mode', HitAndRun::MODE_DISABLED);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -8,5 +8,5 @@ return [
|
||||
'sub_category_team_label' => '制作组',
|
||||
'sub_category_processing_label' => '处理',
|
||||
'sub_category_codec_label' => '编码',
|
||||
'sub_category_audio_codec_label' => '音频编码',
|
||||
'sub_category_audio_codec_label' => '音频编码',
|
||||
];
|
||||
|
||||
Reference in New Issue
Block a user