2022-08-26 20:15:36 +08:00
|
|
|
<template>
|
|
|
|
|
<div>
|
2022-10-29 20:08:15 +08:00
|
|
|
<el-dialog :title="title" v-model="dvisible" :show-close="false" :before-close="cancel" width="750px"
|
|
|
|
|
:destroy-on-close="true">
|
2023-07-03 21:42:04 +08:00
|
|
|
<el-form ref="configForm" :model="form" label-width="auto">
|
2022-08-26 20:15:36 +08:00
|
|
|
<el-form-item prop="name" label="配置项:" required>
|
|
|
|
|
<el-input v-model="form.name"></el-input>
|
|
|
|
|
</el-form-item>
|
|
|
|
|
<el-form-item prop="key" label="配置key:" required>
|
|
|
|
|
<el-input :disabled="form.id != null" v-model="form.key"></el-input>
|
|
|
|
|
</el-form-item>
|
2022-10-26 20:49:29 +08:00
|
|
|
|
|
|
|
|
<el-row style="margin-left: 30px; margin-bottom: 5px">
|
|
|
|
|
<el-button @click="onAddParam" size="small" type="success">新增配置项</el-button>
|
|
|
|
|
</el-row>
|
|
|
|
|
<el-form-item :key="param" v-for="(param, index) in params" prop="params" :label="`参数${index + 1}`">
|
|
|
|
|
<el-row>
|
2022-10-29 20:08:15 +08:00
|
|
|
<el-col :span="5">
|
|
|
|
|
<el-input v-model="param.model" placeholder="model"></el-input>
|
|
|
|
|
</el-col>
|
2023-03-06 16:59:57 +08:00
|
|
|
<span :span="1">
|
|
|
|
|
<el-divider direction="vertical" border-style="dashed" />
|
|
|
|
|
</span>
|
2022-10-29 20:08:15 +08:00
|
|
|
<el-col :span="4">
|
|
|
|
|
<el-input v-model="param.name" placeholder="字段名"></el-input>
|
|
|
|
|
</el-col>
|
2023-03-06 16:59:57 +08:00
|
|
|
<span :span="1">
|
|
|
|
|
<el-divider direction="vertical" border-style="dashed" />
|
|
|
|
|
</span>
|
2022-10-29 20:08:15 +08:00
|
|
|
<el-col :span="4">
|
|
|
|
|
<el-input v-model="param.placeholder" placeholder="字段说明"></el-input>
|
|
|
|
|
</el-col>
|
2023-03-06 16:59:57 +08:00
|
|
|
<span :span="1">
|
|
|
|
|
<el-divider direction="vertical" border-style="dashed" />
|
|
|
|
|
</span>
|
2022-10-26 20:49:29 +08:00
|
|
|
<el-col :span="4">
|
|
|
|
|
<el-input v-model="param.options" placeholder="可选值 ,分割"></el-input>
|
|
|
|
|
</el-col>
|
2023-03-06 16:59:57 +08:00
|
|
|
<span :span="1">
|
|
|
|
|
<el-divider direction="vertical" border-style="dashed" />
|
|
|
|
|
</span>
|
2022-10-29 20:08:15 +08:00
|
|
|
<el-col :span="2">
|
|
|
|
|
<el-button @click="onDeleteParam(index)" size="small" type="danger">删除</el-button>
|
|
|
|
|
</el-col>
|
2022-10-26 20:49:29 +08:00
|
|
|
</el-row>
|
2022-08-26 20:15:36 +08:00
|
|
|
</el-form-item>
|
2022-10-26 20:49:29 +08:00
|
|
|
<!-- <el-form-item prop="value" label="配置值:" required>
|
|
|
|
|
<el-input v-model="form.value"></el-input>
|
|
|
|
|
</el-form-item> -->
|
2022-08-26 20:15:36 +08:00
|
|
|
<el-form-item label="备注:">
|
|
|
|
|
<el-input v-model="form.remark" type="textarea" :rows="2"></el-input>
|
|
|
|
|
</el-form-item>
|
|
|
|
|
</el-form>
|
|
|
|
|
<template #footer>
|
|
|
|
|
<div class="dialog-footer">
|
|
|
|
|
<el-button @click="cancel()">取 消</el-button>
|
|
|
|
|
<el-button type="primary" :loading="btnLoading" @click="btnOk">确 定</el-button>
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
</el-dialog>
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
|
2022-10-29 20:08:15 +08:00
|
|
|
<script lang="ts" setup>
|
2022-11-05 15:13:40 +08:00
|
|
|
import { ref, toRefs, reactive, watch } from 'vue';
|
2022-08-26 20:15:36 +08:00
|
|
|
import { configApi } from '../api';
|
|
|
|
|
|
2022-10-29 20:08:15 +08:00
|
|
|
const props = defineProps({
|
|
|
|
|
visible: {
|
|
|
|
|
type: Boolean,
|
|
|
|
|
},
|
|
|
|
|
data: {
|
|
|
|
|
type: [Boolean, Object],
|
2022-08-26 20:15:36 +08:00
|
|
|
},
|
2022-10-29 20:08:15 +08:00
|
|
|
title: {
|
|
|
|
|
type: String,
|
|
|
|
|
},
|
|
|
|
|
})
|
2022-08-26 20:15:36 +08:00
|
|
|
|
2022-10-29 20:08:15 +08:00
|
|
|
//定义事件
|
|
|
|
|
const emit = defineEmits(['update:visible', 'cancel', 'val-change'])
|
2022-08-26 20:15:36 +08:00
|
|
|
|
2022-10-26 20:49:29 +08:00
|
|
|
|
2022-10-29 20:08:15 +08:00
|
|
|
const configForm: any = ref(null);
|
2022-10-26 20:49:29 +08:00
|
|
|
|
2022-10-29 20:08:15 +08:00
|
|
|
const state = reactive({
|
|
|
|
|
dvisible: false,
|
|
|
|
|
params: [] as any,
|
|
|
|
|
form: {
|
|
|
|
|
id: null,
|
|
|
|
|
name: '',
|
|
|
|
|
key: '',
|
|
|
|
|
params: '',
|
|
|
|
|
value: '',
|
|
|
|
|
remark: '',
|
|
|
|
|
},
|
|
|
|
|
btnLoading: false,
|
|
|
|
|
});
|
2022-08-26 20:15:36 +08:00
|
|
|
|
2022-10-29 20:08:15 +08:00
|
|
|
const {
|
|
|
|
|
dvisible,
|
|
|
|
|
params,
|
|
|
|
|
form,
|
|
|
|
|
btnLoading,
|
|
|
|
|
} = toRefs(state)
|
2022-08-26 20:15:36 +08:00
|
|
|
|
2022-10-29 20:08:15 +08:00
|
|
|
watch(props, (newValue: any) => {
|
|
|
|
|
state.dvisible = newValue.visible;
|
|
|
|
|
if (newValue.data) {
|
|
|
|
|
state.form = { ...newValue.data };
|
|
|
|
|
if (state.form.params) {
|
|
|
|
|
state.params = JSON.parse(state.form.params);
|
|
|
|
|
} else {
|
|
|
|
|
state.params = [];
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
state.form = {} as any;
|
|
|
|
|
state.params = [];
|
|
|
|
|
}
|
2022-08-26 20:15:36 +08:00
|
|
|
});
|
2022-10-29 20:08:15 +08:00
|
|
|
|
|
|
|
|
const onAddParam = () => {
|
|
|
|
|
state.params.push({ name: '', model: '', placeholder: '' });
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const onDeleteParam = (idx: number) => {
|
|
|
|
|
state.params.splice(idx, 1);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const cancel = () => {
|
|
|
|
|
// 更新父组件visible prop对应的值为false
|
|
|
|
|
emit('update:visible', false);
|
|
|
|
|
// 若父组件有取消事件,则调用
|
|
|
|
|
emit('cancel');
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const btnOk = async () => {
|
|
|
|
|
configForm.value.validate(async (valid: boolean) => {
|
|
|
|
|
if (valid) {
|
|
|
|
|
if (state.params) {
|
|
|
|
|
state.form.params = JSON.stringify(state.params);
|
|
|
|
|
}
|
|
|
|
|
await configApi.save.request(state.form);
|
|
|
|
|
emit('val-change', state.form);
|
|
|
|
|
cancel();
|
|
|
|
|
state.btnLoading = true;
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
state.btnLoading = false;
|
|
|
|
|
}, 1000);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
};
|
2022-08-26 20:15:36 +08:00
|
|
|
</script>
|
2023-03-06 16:59:57 +08:00
|
|
|
<style lang="scss"></style>
|