Merge pull request '优化字典表中的枚举型' (#413) from koy07555/Admin.NET.Pro:优化字典表中的枚举型 into v2
Reviewed-on: https://code.adminnet.top/Admin.NET/Admin.NET.Pro/pulls/413
This commit is contained in:
commit
e6be8a200e
@ -95,4 +95,13 @@ public partial class SysDictData : EntityBase
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnDescription = "状态", DefaultValue = "1")]
|
||||
public StatusEnum Status { get; set; } = StatusEnum.Enable;
|
||||
|
||||
/// <summary>
|
||||
/// 是否是枚举转换字典(Y-是,N-否)
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// 这里为Y时,导出种子数据时不导出这些记录,如果有其它由代码自动生成的字典数据,也可以借用这个字段来处理。
|
||||
/// </remarks>
|
||||
[SugarColumn(ColumnDescription = "是否是枚举转换字典", DefaultValue = "2")]
|
||||
public virtual YesNoEnum IsEnum { get; set; } = YesNoEnum.N;
|
||||
}
|
||||
@ -1,4 +1,4 @@
|
||||
// Admin.NET 项目的版权、商标、专利和其他相关权利均受相应法律法规的保护。使用本项目应遵守相关法律法规和许可证的要求。
|
||||
// Admin.NET 项目的版权、商标、专利和其他相关权利均受相应法律法规的保护。使用本项目应遵守相关法律法规和许可证的要求。
|
||||
//
|
||||
// 本项目主要遵循 MIT 许可证和 Apache 许可证(版本 2.0)进行分发和使用。许可证位于源代码树根目录中的 LICENSE-MIT 和 LICENSE-APACHE 文件。
|
||||
//
|
||||
@ -60,6 +60,16 @@ public partial class SysDictType : EntityBase
|
||||
[SugarColumn(ColumnDescription = "是否是租户字典", DefaultValue = "2")]
|
||||
public virtual YesNoEnum IsTenant { get; set; } = YesNoEnum.N;
|
||||
|
||||
/// <summary>
|
||||
/// 是否是枚举转换字典(Y-是,N-否)
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// 这里为Y时,导出种子数据时不导出这些记录,如果有其它由代码自动生成的字典数据,也可以借用这个字段来处理。
|
||||
/// </remarks>
|
||||
[SugarColumn(ColumnDescription = "是否是枚举转换字典", DefaultValue = "2")]
|
||||
public virtual YesNoEnum IsEnum { get; set; } = YesNoEnum.N;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 字典值集合
|
||||
/// </summary>
|
||||
|
||||
@ -477,6 +477,15 @@ public class SysDatabaseService : IDynamicApiController, ITransient
|
||||
|
||||
// 查询所有数据
|
||||
var query = db.QueryableByObject(entityType);
|
||||
// 如果 entityType.Name=="SysDictType"或"SysDictData"或"SysDictDataTenant" 加入查询条件 u.IsEnum!=1
|
||||
if (entityType.Name == "SysDictType" || entityType.Name == "SysDictData" || entityType.Name == "SysDictDataTenant")
|
||||
{
|
||||
if (config.DbSettings.EnableUnderLine)
|
||||
query = query.Where("is_enum != 1");
|
||||
else
|
||||
query = query.Where("IsEnum != 1");
|
||||
}
|
||||
|
||||
// 优先用创建时间排序
|
||||
DbColumnInfo orderField = dbColumnInfos.FirstOrDefault(u => u.DbColumnName.ToLower() == "create_time" || u.DbColumnName.ToLower() == "createtime");
|
||||
if (orderField != null) query = query.OrderBy(orderField.DbColumnName);
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
// Admin.NET 项目的版权、商标、专利和其他相关权利均受相应法律法规的保护。使用本项目应遵守相关法律法规和许可证的要求。
|
||||
// Admin.NET 项目的版权、商标、专利和其他相关权利均受相应法律法规的保护。使用本项目应遵守相关法律法规和许可证的要求。
|
||||
//
|
||||
// 本项目主要遵循 MIT 许可证和 Apache 许可证(版本 2.0)进行分发和使用。许可证位于源代码树根目录中的 LICENSE-MIT 和 LICENSE-APACHE 文件。
|
||||
//
|
||||
@ -40,6 +40,7 @@ public class SysDictTypeService : IDynamicApiController, ITransient
|
||||
.WhereIF(!string.IsNullOrEmpty(input.Code?.Trim()), u => u.Code.Contains(input.Code))
|
||||
.WhereIF(!string.IsNullOrEmpty(input.Name?.Trim()), u => u.Name.Contains(input.Name))
|
||||
.WhereIF(input.SysFlag > 0, u => u.SysFlag == input.SysFlag)
|
||||
.OrderByDescending(u => u.IsEnum)
|
||||
.OrderBy(u => new { u.OrderNo, u.Code })
|
||||
.ToPagedListAsync(input.Page, input.PageSize);
|
||||
}
|
||||
|
||||
@ -203,6 +203,7 @@ public class SysEnumService : IDynamicApiController, ITransient
|
||||
Remark = u.TypeRemark,
|
||||
Status = StatusEnum.Enable,
|
||||
SysFlag = YesNoEnum.Y,
|
||||
IsEnum = YesNoEnum.Y
|
||||
}).ToList();
|
||||
|
||||
// 新增字典数据
|
||||
@ -218,6 +219,7 @@ public class SysEnumService : IDynamicApiController, ITransient
|
||||
Remark = t2.Remark,
|
||||
OrderNo = u.Value + OrderOffset,
|
||||
TagType = u.Theme != "" ? u.Theme : DefaultTagType,
|
||||
IsEnum = YesNoEnum.Y
|
||||
}).ToList()
|
||||
}).SelectMany(x => x.Data).ToList();
|
||||
|
||||
@ -253,6 +255,7 @@ public class SysEnumService : IDynamicApiController, ITransient
|
||||
var updatedDictType = value;
|
||||
updatedDictType.Name = e.TypeDescribe;
|
||||
updatedDictType.Remark = e.TypeRemark;
|
||||
updatedDictType.IsEnum = YesNoEnum.Y;
|
||||
updatedSysDictTypes.Add(updatedDictType);
|
||||
var updatedDictData = updatedDictType.Children.Where(u => u.DictTypeId == updatedDictType.Id).ToList();
|
||||
|
||||
@ -267,6 +270,7 @@ public class SysEnumService : IDynamicApiController, ITransient
|
||||
dictData.Value = enumData.Value.ToString();
|
||||
dictData.OrderNo = enumData.Value + OrderOffset;
|
||||
dictData.TagType = enumData.Theme != "" ? enumData.Theme : dictData.TagType != "" ? dictData.TagType : DefaultTagType;
|
||||
dictData.IsEnum = YesNoEnum.Y;
|
||||
updatedSysDictData.Add(dictData);
|
||||
}
|
||||
}
|
||||
@ -288,6 +292,7 @@ public class SysEnumService : IDynamicApiController, ITransient
|
||||
Remark = updatedDictType.Remark,
|
||||
OrderNo = enumData.Value + OrderOffset,
|
||||
TagType = enumData.Theme != "" ? enumData.Theme : DefaultTagType,
|
||||
IsEnum = YesNoEnum.Y
|
||||
};
|
||||
dictData.TagType = enumData.Theme != "" ? enumData.Theme : dictData.TagType != "" ? dictData.TagType : DefaultTagType;
|
||||
newSysDictData.Add(dictData);
|
||||
|
||||
@ -9,17 +9,17 @@
|
||||
</template>
|
||||
<el-form :model="state.ruleForm" ref="formRef" label-width="auto">
|
||||
<el-row :gutter="10">
|
||||
<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
|
||||
<el-col :xs="24" :sm="8" :md="8" :lg="8" :xl="8" class="mb20">
|
||||
<el-form-item label="显示文本" prop="label" :rules="[{ required: true, message: '显示文本不能为空', trigger: 'blur' }]">
|
||||
<el-input v-model="state.ruleForm.label" placeholder="显示文本" clearable />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
|
||||
<el-col :xs="24" :sm="8" :md="8" :lg="8" :xl="8" class="mb20">
|
||||
<el-form-item label="字典值" prop="value" :rules="[{ required: true, message: '字典值不能为空', trigger: 'blur' }]">
|
||||
<el-input v-model="state.ruleForm.value" placeholder="字典值" clearable />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
|
||||
<el-col :xs="24" :sm="8" :md="8" :lg="8" :xl="8" class="mb20">
|
||||
<el-form-item label="编码" prop="code" :rules="[{ required: true, message: '编码不能为空', trigger: 'blur' }]">
|
||||
<el-input v-model="state.ruleForm.code" placeholder="编码" clearable />
|
||||
</el-form-item>
|
||||
@ -35,12 +35,12 @@
|
||||
</el-radio-group>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20">
|
||||
<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
|
||||
<el-form-item label="样式(Style)" prop="styleSetting">
|
||||
<el-input v-model="state.ruleForm.styleSetting" placeholder="样式(Style)" clearable />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20">
|
||||
<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
|
||||
<el-form-item label="样式(Class)" prop="classSetting">
|
||||
<el-input v-model="state.ruleForm.classSetting" placeholder="样式(Class)" clearable />
|
||||
</el-form-item>
|
||||
@ -57,7 +57,12 @@
|
||||
</el-col>
|
||||
<el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20">
|
||||
<el-form-item label="拓展数据">
|
||||
<el-input v-model="state.ruleForm.extData" placeholder="请输入拓展数据" clearable type="textarea" :rows="6" />
|
||||
<div style="display: flex; flex-direction: column; gap: 10px; width: 100%;">
|
||||
<el-input v-model="state.ruleForm.extData" placeholder="请输入拓展数据" clearable type="textarea" :rows="12" style="width: 100%;" />
|
||||
<div style="width: 100%;">
|
||||
<el-button type="primary" @click="formatJSON" style="width: 100%;">格式化JSON</el-button>
|
||||
</div>
|
||||
</div>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20">
|
||||
@ -78,7 +83,9 @@
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup name="sysEditDictData">
|
||||
// 在import部分添加
|
||||
import { reactive, ref } from 'vue';
|
||||
import { ElMessage } from 'element-plus';
|
||||
|
||||
import { getAPI } from '/@/utils/axios-utils';
|
||||
import { SysDictDataApi } from '/@/api-services/system/api';
|
||||
@ -130,6 +137,23 @@ const submit = () => {
|
||||
});
|
||||
};
|
||||
|
||||
// 格式化JSON
|
||||
const formatJSON = () => {
|
||||
try {
|
||||
if (!state.ruleForm.extData) {
|
||||
ElMessage.warning('请先输入JSON字符串');
|
||||
return;
|
||||
}
|
||||
// 解析并格式化JSON
|
||||
const parsedJSON = JSON.parse(state.ruleForm.extData.trim());
|
||||
state.ruleForm.extData = JSON.stringify(parsedJSON, null, 2);
|
||||
ElMessage.success('JSON格式化成功');
|
||||
} catch (error) {
|
||||
ElMessage.error('JSON格式不正确,请检查输入');
|
||||
console.error('JSON格式化错误:', error);
|
||||
}
|
||||
};
|
||||
|
||||
// 导出对象
|
||||
defineExpose({ openDialog });
|
||||
</script>
|
||||
|
||||
@ -44,6 +44,9 @@
|
||||
<template #row_sysFlag="{ row }">
|
||||
<g-sys-dict v-model="row.sysFlag" code="YesNoEnum" />
|
||||
</template>
|
||||
<template #row_isEnum="{ row }">
|
||||
<g-sys-dict v-model="row.isEnum" code="YesNoEnum" />
|
||||
</template>
|
||||
<template #row_status="{ row }">
|
||||
<g-sys-dict v-model="row.status" code="StatusEnum" />
|
||||
</template>
|
||||
@ -190,11 +193,12 @@ const optionsDictType = useVxeTable<SysDictType>(
|
||||
{ field: 'seq', type: 'seq', title: '序号', width: 60, fixed: 'left' },
|
||||
{ field: 'name', title: '字典名称', minWidth: 140, align: 'left', headerAlign: 'center', showOverflow: 'tooltip' },
|
||||
{ field: 'code', title: '字典编码', minWidth: 140, align: 'left', headerAlign: 'center', showOverflow: 'tooltip' },
|
||||
{ field: 'isTenant', title: '租户隔离', width: 80, showOverflow: 'tooltip', visible: userInfo.accountType === AccountTypeEnum.NUMBER_999, slots: { default: 'row_isTenant' } },
|
||||
{ field: 'sysFlag', title: '是否内置', width: 80, showOverflow: 'tooltip', slots: { default: 'row_sysFlag' } },
|
||||
{ field: 'orderNo', title: '排序', width: 80, showOverflow: 'tooltip' },
|
||||
{ field: 'status', title: '状态', width: 80, showOverflow: 'tooltip', slots: { default: 'row_status' } },
|
||||
{ field: 'record', title: '修改记录', width: 100, showOverflow: 'tooltip', slots: { default: 'row_record' } },
|
||||
{ field: 'isTenant', title: '租户隔离', width: 70, showOverflow: 'tooltip', visible: userInfo.accountType === AccountTypeEnum.NUMBER_999, slots: { default: 'row_isTenant' } },
|
||||
{ field: 'sysFlag', title: '是否内置', width: 70, showOverflow: 'tooltip', slots: { default: 'row_sysFlag' } },
|
||||
{ field: 'isEnum', title: '是否枚举', width: 70, showOverflow: 'tooltip', slots: { default: 'row_isEnum' } },
|
||||
{ field: 'orderNo', title: '排序', width: 70, showOverflow: 'tooltip' },
|
||||
{ field: 'status', title: '状态', width: 70, showOverflow: 'tooltip', slots: { default: 'row_status' } },
|
||||
{ field: 'record', title: '修改记录', width: 90, showOverflow: 'tooltip', slots: { default: 'row_record' } },
|
||||
{ field: 'buttons', title: '操作', fixed: 'right', width: 100, showOverflow: true, slots: { default: 'row_buttons' } },
|
||||
],
|
||||
},
|
||||
|
||||
Loading…
Reference in New Issue
Block a user