up.
This commit is contained in:
parent
5e0bbfdaa1
commit
3da7dee576
@ -16,9 +16,9 @@ class ConfigController extends BaseController
|
|||||||
'group'=> $this->request->get('group/s','')
|
'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)
|
public function data(string $name)
|
||||||
@ -38,7 +38,8 @@ class ConfigController extends BaseController
|
|||||||
'options' => '',
|
'options' => '',
|
||||||
'name' => '',
|
'name' => '',
|
||||||
'comments' => '',
|
'comments' => '',
|
||||||
'group'=> ''
|
'group'=> '',
|
||||||
|
'bind'=>''
|
||||||
]);
|
]);
|
||||||
$user = new SysConfig();
|
$user = new SysConfig();
|
||||||
$user->save($data);
|
$user->save($data);
|
||||||
@ -57,7 +58,8 @@ class ConfigController extends BaseController
|
|||||||
'options' => '',
|
'options' => '',
|
||||||
'name' => '',
|
'name' => '',
|
||||||
'comments' => '',
|
'comments' => '',
|
||||||
'group'=> ''
|
'group'=> '',
|
||||||
|
'bind'=>''
|
||||||
]);
|
]);
|
||||||
$user = SysConfig::findOrFail($data['id']);
|
$user = SysConfig::findOrFail($data['id']);
|
||||||
$user->save($data);
|
$user->save($data);
|
||||||
|
|||||||
@ -2,15 +2,64 @@ import {configData} from "@/api/system/config";
|
|||||||
|
|
||||||
export async function getSysConfig(name) {
|
export async function getSysConfig(name) {
|
||||||
const config = await configData({name});
|
const config = await configData({name});
|
||||||
switch (config.type) {
|
config.valueData = strToValue(config.type, config.value);
|
||||||
case 'json':
|
|
||||||
config.valueData = JSON.parse(config.value);
|
|
||||||
break
|
|
||||||
case 'int':
|
|
||||||
config.valueData = parseInt(config.value)
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
config.valueData = config.value;
|
|
||||||
}
|
|
||||||
return config;
|
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 {};
|
||||||
|
}
|
||||||
|
|||||||
@ -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>
|
||||||
@ -1,14 +1,14 @@
|
|||||||
<template>
|
<template>
|
||||||
<ele-page>
|
<ele-page>
|
||||||
|
<el-card>
|
||||||
<ele-tabs
|
<el-button
|
||||||
type="card"
|
class="ele-btn-icon"
|
||||||
v-model="configGroup"
|
:icon="Refresh"
|
||||||
:items="groupItems"
|
@click="reload()"
|
||||||
@tabChange="reload()"
|
:loading="configLoading"
|
||||||
/>
|
>
|
||||||
|
刷新
|
||||||
<ele-card :body-style="{ paddingTop: '8px' }">
|
</el-button>
|
||||||
<el-button
|
<el-button
|
||||||
type="danger"
|
type="danger"
|
||||||
class="ele-btn-icon"
|
class="ele-btn-icon"
|
||||||
@ -16,25 +16,57 @@
|
|||||||
>
|
>
|
||||||
同步配置
|
同步配置
|
||||||
</el-button>
|
</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-card>
|
||||||
</ele-page>
|
</ele-page>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import {onMounted, ref} from 'vue';
|
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 {listConfig} from "@/api/system/config";
|
||||||
import {getSysConfig} from "@/utils/sys-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'});
|
defineOptions({name: 'SystemConfigSet'});
|
||||||
|
|
||||||
|
/** 表单数据 */
|
||||||
|
const [form, resetFields, assignFields] = useFormData<Config>({});
|
||||||
const configList = ref([]);
|
const configList = ref([]);
|
||||||
|
const configLoading = ref(false);
|
||||||
/** 搜索 */
|
/** 搜索 */
|
||||||
const reload = () => {
|
const reload = () => {
|
||||||
listConfig({group: configGroup.value, limit: 999}).then((data)=>{
|
configLoading.value = true;
|
||||||
configList.value = data || [];
|
listConfig({group: configGroup.value, limit: 999}).then((data) => {
|
||||||
|
configList.value = data;
|
||||||
|
configLoading.value = false;
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -70,6 +70,14 @@
|
|||||||
placeholder="请输入配置项"
|
placeholder="请输入配置项"
|
||||||
/>
|
/>
|
||||||
</el-form-item>
|
</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-form-item label="配置说明">
|
||||||
<el-input
|
<el-input
|
||||||
:rows="4"
|
:rows="4"
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user