This commit is contained in:
u2nyakim 2025-08-22 17:26:45 +08:00
parent 5e0bbfdaa1
commit 3da7dee576
5 changed files with 192 additions and 28 deletions

View File

@ -16,9 +16,9 @@ class ConfigController extends BaseController
'group'=> $this->request->get('group/s','')
]);
$paginate = CurdService::getPaginate($this->request, $model);
$data = CurdService::getList($this->request, $model);
return $this->writeSuccess('success', $paginate);
return $this->writeSuccess('success', $data);
}
public function data(string $name)
@ -38,7 +38,8 @@ class ConfigController extends BaseController
'options' => '',
'name' => '',
'comments' => '',
'group'=> ''
'group'=> '',
'bind'=>''
]);
$user = new SysConfig();
$user->save($data);
@ -57,7 +58,8 @@ class ConfigController extends BaseController
'options' => '',
'name' => '',
'comments' => '',
'group'=> ''
'group'=> '',
'bind'=>''
]);
$user = SysConfig::findOrFail($data['id']);
$user->save($data);

View File

@ -2,15 +2,64 @@ import {configData} from "@/api/system/config";
export async function getSysConfig(name) {
const config = await configData({name});
switch (config.type) {
case 'json':
config.valueData = JSON.parse(config.value);
break
case 'int':
config.valueData = parseInt(config.value)
break;
default:
config.valueData = config.value;
}
config.valueData = strToValue(config.type, config.value);
return config;
}
export function strToValue(type: string, value: string): any {
switch (type) {
case 'json':
return JSON.parse(value);
case 'int':
return parseInt(value)
case 'switch':
return value == '1'
case 'checkbox':
return value.split(",");
case 'text':
case 'textarea':
default:
return value
}
}
export function strToOption(type: string, option: string): any {
try {
switch (type) {
case 'json':
case 'int':
case 'switch':
case 'text':
case 'textarea':
case 'checkbox':
default:
if (option) {
return JSON.parse(option);
}
}
} catch (e) {
console.error(e);
}
return {};
}
export function strToBind(type: string, option: string): any {
try {
switch (type) {
case 'json':
case 'int':
case 'switch':
case 'text':
case 'textarea':
case 'checkbox':
default:
if (option) {
return JSON.parse(option);
}
}
} catch (e) {
console.error(e);
}
return {};
}

View File

@ -0,0 +1,73 @@
<template>
<el-form-item :label="props.title" :prop="props.name">
<template v-if="props.type === 'text'">
<el-input v-model="dataValue" :placeholder="'请输入' + props.title" v-bind="dataBind"/>
</template>
<template v-else-if="props.type === 'textarea'">
<el-input type="textarea"
v-model="dataValue"
:placeholder="'请输入' + props.title"
v-bind="dataBind"
/>
</template>
<template v-else-if="props.type === 'password'">
<el-input
show-password
type="password"
v-model="dataValue"
:placeholder="'请输入' + props.title"
v-bind="dataBind"
/>
</template>
<template v-else-if="props.type === 'switch'">
<el-switch
size="small"
:model-value="dataValue"
@update:modelValue="(val) => updatedataValue(val)"
v-bind="dataBind"
/>
</template>
<template v-else-if="props.type === 'number'">
<el-input-number v-model="dataValue" :placeholder="'请输入' + props.title" v-bind="dataBind"/>
</template>
<template v-else-if="props.type === 'checkbox'">
<el-checkbox-group v-model="dataValue" v-bind="dataBind">
<template v-if="dataOptions">
<el-checkbox v-for="item in dataOptions" :label="item.label" :value="item.value" />
</template>
</el-checkbox-group>
</template>
</el-form-item>
</template>
<script setup lang="ts">
import {ref, onMounted} from "vue";
import {strToBind, strToOption, strToValue} from "@/utils/sys-config";
const props = defineProps<{
name: string;
title: string;
type: string;
value: string;
options: string;
}>();
const dataValue = ref<any>();
const dataOptions = ref<any>()
const dataBind = ref<any>({})
onMounted(() => {
dataBind.value = strToBind(props.type, props.bind);
dataValue.value = strToValue(props.type, props.value);
dataOptions.value = strToOption(props.type, props.options);
console.log("渲染完成", props, dataValue.value, dataOptions.value);
});
const updatedataValue = (val) => {
console.log("更新val", val);
}
</script>
<style scoped lang="scss">
</style>

View File

@ -1,14 +1,14 @@
<template>
<ele-page>
<ele-tabs
type="card"
v-model="configGroup"
:items="groupItems"
@tabChange="reload()"
/>
<ele-card :body-style="{ paddingTop: '8px' }">
<el-card>
<el-button
class="ele-btn-icon"
:icon="Refresh"
@click="reload()"
:loading="configLoading"
>
刷新
</el-button>
<el-button
type="danger"
class="ele-btn-icon"
@ -16,25 +16,57 @@
>
同步配置
</el-button>
{{ configList }}
</el-card>
<ele-card :body-style="{ paddingTop: '8px' }" v-loading="configLoading">
<template #header>
<ele-tabs
type="tag"
v-model="configGroup"
:items="groupItems"
@tabChange="reload()"
/>
</template>
<el-form
ref="formRef"
:model="form"
label-width="80px"
@submit.prevent=""
>
<template v-for="config in configList">
<config-form-item :name="config.name" :title="config.title" :type="config.type" :value="config.value"
:options="config.options"/>
<el-form-item v-if="config.tips">
<ele-text type="placeholder" style="line-height: 1.6">
{{ config.tips }}
</ele-text>
</el-form-item>
</template>
</el-form>
</ele-card>
</ele-page>
</template>
<script lang="ts" setup>
import {onMounted, ref} from 'vue';
import { Refresh } from "@element-plus/icons-vue"
import {Refresh} from "@element-plus/icons-vue"
import {listConfig} from "@/api/system/config";
import {getSysConfig} from "@/utils/sys-config";
import {useFormData} from "@/utils/use-form-data";
import type {Config} from "@/api/system/config/model";
import ConfigFormItem from "./components/config-form-item.vue";
defineOptions({name: 'SystemConfigSet'});
/** 表单数据 */
const [form, resetFields, assignFields] = useFormData<Config>({});
const configList = ref([]);
const configLoading = ref(false);
/** 搜索 */
const reload = () => {
listConfig({group: configGroup.value, limit: 999}).then((data)=>{
configList.value = data || [];
configLoading.value = true;
listConfig({group: configGroup.value, limit: 999}).then((data) => {
configList.value = data;
configLoading.value = false;
});
};

View File

@ -70,6 +70,14 @@
placeholder="请输入配置项"
/>
</el-form-item>
<el-form-item label="Bind属性">
<el-input
:rows="4"
type="textarea"
v-model="form.bind"
placeholder="请输入Bind属性"
/>
</el-form-item>
<el-form-item label="配置说明">
<el-input
:rows="4"