You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
263 lines
9.3 KiB
263 lines
9.3 KiB
<template>
|
|
<div class="@(@Model.LowerClassName)-container">
|
|
<el-dialog v-model="isShowDialog" :title="props.title" :width="700" draggable="">
|
|
<el-form :model="ruleForm" ref="ruleFormRef" size="default" label-width="100px" :rules="rules">
|
|
<el-row :gutter="35">
|
|
@foreach (var column in Model.TableField){
|
|
if(@column.ColumnKey == "True"){
|
|
@:<el-form-item v-show="false">
|
|
<el-input v-model="ruleForm.@(@column.LowerColumnName)" />
|
|
</el-form-item>
|
|
}else{
|
|
if (@column.WhetherAddUpdate == "Y"){
|
|
if(@column.EffectType == "fk"){
|
|
@:<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
|
|
@:<el-form-item label="@column.ColumnComment" prop="@(@column.LowerColumnName)">
|
|
@:<el-select clearable filterable v-model="ruleForm.@(@column.LowerColumnName)" placeholder="请选择@(@column.ColumnComment)">
|
|
@:<el-option v-for="(item,index) in @LowerFirstLetter(@column.FkEntityName)DropdownList" :key="index" :value="item.value" :label="item.label" />
|
|
@:
|
|
</el-select>
|
|
@:
|
|
</el-form-item>
|
|
@:
|
|
</el-col>
|
|
}else if(@column.EffectType == "Input"){
|
|
@:<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
|
|
@:<el-form-item label="@column.ColumnComment" prop="@(@column.LowerColumnName)">
|
|
@:<el-input v-model="ruleForm.@(@column.LowerColumnName)" placeholder="请输入@(@column.ColumnComment)" clearable />
|
|
@:
|
|
</el-form-item>
|
|
@:
|
|
</el-col>
|
|
}else if(@column.EffectType == "InputNumber"){
|
|
@:<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
|
|
@:<el-form-item label="@column.ColumnComment" prop="@(@column.LowerColumnName)">
|
|
@:<el-input-number v-model="ruleForm.@(@column.LowerColumnName)" placeholder="请输入@(@column.ColumnComment)" clearable />
|
|
@:
|
|
</el-form-item>
|
|
@:
|
|
</el-col>
|
|
}else if(@column.EffectType == "InputTextArea"){
|
|
@:<el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20">
|
|
@:<el-form-item label="@column.ColumnComment" prop="@(@column.LowerColumnName)">
|
|
@:<el-input v-model="ruleForm.@(@column.LowerColumnName)" placeholder="请输入@(@column.ColumnComment)" type="textarea" clearable />
|
|
@:
|
|
</el-form-item>
|
|
@:
|
|
</el-col>
|
|
}else if(@column.EffectType == "Select"){
|
|
@:<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
|
|
@:<el-form-item label="@column.ColumnComment" prop="@(@column.LowerColumnName)">
|
|
@:<el-select clearable v-model="ruleForm.@(@column.LowerColumnName)" placeholder="请选择@(@column.ColumnComment)">
|
|
@:<el-option v-for="(item,index) in getEdit@(@column.LowerColumnName)Data" :key="index" :value="item.code" :label="item.value"></el-option>
|
|
@:
|
|
</el-select>
|
|
@:
|
|
</el-form-item>
|
|
@:
|
|
</el-col>
|
|
}else if(@column.EffectType == "ConstSelector"){
|
|
@:<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
|
|
@:<el-form-item label="@column.ColumnComment" prop="@(@column.LowerColumnName)">
|
|
@:<el-select clearable v-model="ruleForm.@(@column.LowerColumnName)" placeholder="请选择@(@column.ColumnComment)">
|
|
@:<el-option v-for="(item,index) in getSelectorList('@column.DictTypeCode')" :key="index" :value="item.code">{{ item.name }}</el-option>
|
|
@:
|
|
</el-select>
|
|
@:
|
|
</el-form-item>
|
|
@:
|
|
</el-col>
|
|
}else if(@column.EffectType == "Switch"){
|
|
@:<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
|
|
@:<el-form-item label="@column.ColumnComment" prop="@(@column.LowerColumnName)">
|
|
@:<el-switch v-model="ruleForm.@(@column.LowerColumnName)" active-text="是" inactive-text="否" />
|
|
@:
|
|
</el-form-item>
|
|
@:
|
|
</el-col>
|
|
}else if(@column.EffectType == "DatePicker"){
|
|
@:<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
|
|
@:<el-form-item label="@column.ColumnComment" prop="@(@column.LowerColumnName)">
|
|
@:<el-date-picker v-model="ruleForm.@(@column.LowerColumnName)" type="date" placeholder="@(@column.ColumnComment)" />
|
|
@:
|
|
</el-form-item>
|
|
@:
|
|
</el-col>
|
|
}else if(@column.EffectType == "Upload"){
|
|
@:<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
|
|
@:<el-form-item label="@column.ColumnComment" prop="@(@column.LowerColumnName)">
|
|
@:<el-upload
|
|
@:list-type="picture-card"
|
|
@::limit="1"
|
|
@::show-file-list="false"
|
|
@::http-request="upload@(@column.ColumnName)Handle">
|
|
@:<img
|
|
@:v-if="ruleForm.@(@column.LowerColumnName)"
|
|
@::src="ruleForm.@(@column.LowerColumnName)"
|
|
@:style="width: 100%; height: 100%; object-fit: contain"/>
|
|
@:<el-icon v-else><Plus /></el-icon>
|
|
@:
|
|
</el-upload>
|
|
@:
|
|
</el-form-item>
|
|
@:
|
|
</el-col>
|
|
}else{
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
</el-row>
|
|
</el-form>
|
|
<template #footer>
|
|
<span class="dialog-footer">
|
|
<el-button @@click="cancel" size="default">取 消</el-button>
|
|
<el-button type="primary" @@click="submit" size="default">确 定</el-button>
|
|
</span>
|
|
</template>
|
|
</el-dialog>
|
|
</div>
|
|
</template>
|
|
|
|
<script lang="ts" setup>
|
|
import { ref,onMounted } from "vue";
|
|
import { ElMessage } from "element-plus";
|
|
import type { FormRules } from "element-plus";
|
|
@if(@Model.TableField.Any(x=>x.EffectType == "Upload")){
|
|
@:import { Plus } from "@@element-plus/icons-vue";
|
|
@:import { UploadRequestOptions } from "element-plus";
|
|
@:import {@string.Join(",",Model.TableField.Where(x=>x.EffectType == "Upload").Select(x=>"upload"+x.ColumnName).ToList())} from '/@@/api/main/@(@Model.LowerClassName)';
|
|
}
|
|
import { add@(@Model.ClassName), update@(@Model.ClassName) } from "/@@/api/main/@(@Model.LowerClassName)";
|
|
@foreach (var column in Model.TableField){
|
|
if(@column.EffectType == "fk"){
|
|
@:import { get@(@column.FkEntityName)Dropdown } from '/@@/api/main/@(@Model.LowerClassName)';
|
|
}
|
|
}
|
|
@if(@Model.TableField.Any(x=>x.EffectType == "Select")){
|
|
@:import { getDictDataList } from '/@@/api/system/admin';
|
|
|
|
}
|
|
@foreach (var column in Model.TableField){
|
|
if(@column.EffectType == "Select"){
|
|
@:const getEdit@(@column.LowerColumnName)Data = ref<any>([]);
|
|
}
|
|
}
|
|
//父级传递来的参数
|
|
var props = defineProps({
|
|
title: {
|
|
type: String,
|
|
default: "",
|
|
},
|
|
});
|
|
//父级传递来的函数,用于回调
|
|
const emit = defineEmits(["reloadTable"]);
|
|
const ruleFormRef = ref();
|
|
const isShowDialog = ref(false);
|
|
const ruleForm = ref<any>({});
|
|
//自行添加其他规则
|
|
const rules = ref<FormRules>({
|
|
@foreach (var column in Model.TableField){
|
|
if(@column.WhetherRequired == "Y"){
|
|
if(@column.EffectType == "Input" || @column.EffectType == "InputNumber" ||@column.EffectType == "InputTextArea"){
|
|
@:@column.LowerColumnName: [{required: true, message: '请输入@(@column.ColumnComment)!', trigger: 'blur',},],
|
|
}else if(@column.EffectType == "DatePicker" || @column.EffectType == "Select" ||@column.EffectType == "ApiTreeSelect"){
|
|
@:@column.LowerColumnName: [{required: true, message: '请选择@(@column.ColumnComment)!', trigger: 'change',},],
|
|
}
|
|
}
|
|
}
|
|
});
|
|
|
|
// 打开弹窗
|
|
const openDialog = (row: any) => {
|
|
ruleForm.value = JSON.parse(JSON.stringify(row));
|
|
isShowDialog.value = true;
|
|
};
|
|
|
|
// 关闭弹窗
|
|
const closeDialog = () => {
|
|
emit("reloadTable");
|
|
isShowDialog.value = false;
|
|
};
|
|
|
|
// 取消
|
|
const cancel = () => {
|
|
isShowDialog.value = false;
|
|
};
|
|
|
|
// 提交
|
|
const submit = async () => {
|
|
ruleFormRef.value.validate(async (isValid: boolean, fields?: any) => {
|
|
if (isValid) {
|
|
let values = ruleForm.value;
|
|
if (ruleForm.value.id != undefined && ruleForm.value.id > 0) {
|
|
await update@(@Model.ClassName)(values);
|
|
} else {
|
|
await add@(@Model.ClassName)(values);
|
|
}
|
|
closeDialog();
|
|
} else {
|
|
ElMessage({
|
|
message: `表单有${Object.keys(fields).length}处验证失败,请修改后再提交`,
|
|
type: "error",
|
|
});
|
|
}
|
|
});
|
|
};
|
|
|
|
@foreach (var column in Model.TableField){
|
|
if(@column.EffectType == "Select"){
|
|
@:const dictTypeDataList = async (val: any) => {
|
|
@:let list = await getDictDataList(val);
|
|
@:return list.data.result ?? [];
|
|
@:};
|
|
break;
|
|
}
|
|
}
|
|
|
|
@foreach (var column in Model.QueryWhetherList){
|
|
if(@column.EffectType == "fk"){
|
|
@:const @LowerFirstLetter(@column.FkEntityName)DropdownList = ref<any>([]);
|
|
@:const get@(@column.FkEntityName)DropdownList = async () => {
|
|
@:let list = await get@(@column.FkEntityName)Dropdown();
|
|
@:@LowerFirstLetter(@column.FkEntityName)DropdownList.value = list.data.result ?? [];
|
|
@:};
|
|
@:get@(@column.FkEntityName)DropdownList();
|
|
@:
|
|
}
|
|
}
|
|
|
|
@foreach (var column in Model.TableField){
|
|
if(column.WhetherAddUpdate=="N") continue;
|
|
if(@column.EffectType == "Upload"){
|
|
@:const upload@(@column.ColumnName)Handle = async (options: UploadRequestOptions) => {
|
|
@:const res = await upload@(@column.ColumnName)(options);
|
|
@:ruleForm.value.@(column.LowerColumnName) = res.data.result?.url;
|
|
@:};
|
|
}
|
|
}
|
|
|
|
|
|
// 页面加载时
|
|
onMounted(async () => {
|
|
@foreach (var column in Model.TableField){
|
|
if(@column.EffectType == "Select"){
|
|
@:getEdit@(@column.LowerColumnName)Data.value= await dictTypeDataList('@(@column.DictTypeCode)');
|
|
}
|
|
}
|
|
});
|
|
|
|
//将属性或者函数暴露给父组件
|
|
defineExpose({ openDialog });
|
|
</script>
|
|
|
|
|
|
|
|
|
|
@{
|
|
string LowerFirstLetter(string text)
|
|
{
|
|
return text.ToString()[..1].ToLower() + text[1..]; // 首字母小写
|
|
}
|
|
}
|