Bladeren bron

!1578 修复部分已知bug,并优化部分功能
Merge pull request !1578 from 喵你个汪/next

zuohuaijun 1 jaar geleden
bovenliggende
commit
5500feda57

+ 12 - 1
Admin.NET/Admin.NET.Web.Entry/wwwroot/template/Service.cs.vm

@@ -249,6 +249,17 @@ public class @(Model.ClassName)Service : IDynamicApiController, ITransient
     @:{
         @:var list = (await Page(input)).Items?.Adapt<List<Export@(Model.ClassName)Output>>() ?? new();
         @:if (input.SelectKeyList?.Count > 0) list = list.Where(x => input.SelectKeyList.Contains(x.@(Model.PrimaryKeyFieldList.First().PropertyName))).ToList();
+        var dictFields = Model.TableField.Where(x => x.WhetherImport == "Y" && x.EffectType == "DictSelector") ?? default;
+        foreach (var column in dictFields) {
+        @:var @(column.LowerPropertyName)DictMap = _sysDictTypeService.GetDataList(new GetDataDictTypeInput { Code = "@(column.DictTypeCode)" }).Result.ToDictionary(x => x.Value, x => x.Label);
+        }
+        if (dictFields.Count() > 0) {
+        @:list.ForEach(e => {
+        foreach (var column in dictFields) {
+            @:e.@(column.ExtendedPropertyName) = @(column.LowerPropertyName)DictMap.GetValueOrDefault(e.@(column.PropertyName) ?? "", e.@(column.PropertyName));
+        }
+        @:});
+        }
         @:return ExcelHelper.ExportTemplate(list, "@(Model.BusName)导出记录");
     @:}
     @:
@@ -312,7 +323,7 @@ public class @(Model.ClassName)Service : IDynamicApiController, ITransient
                     @:// 映射字典值
                     @:foreach(var item in pageItems) {
                         foreach (var column in dictTableField) {
-                        @:if (item.@(column.PropertyName) == null) continue;
+                        @:if (string.IsNullOrWhiteSpace(item.@(column.ExtendedPropertyName))) continue;
                         @:item.@(column.PropertyName) = @(column.LowerPropertyName)DictMap.GetValueOrDefault(item.@(column.ExtendedPropertyName));
                         @:if (item.@(column.PropertyName) == null) item.Error = "@(column.ColumnComment)字典映射失败";
                         }

+ 8 - 3
Web/src/components/sysDict/sysDict.vue

@@ -1,3 +1,4 @@
+<!-- 组件使用文档: https://gitee.com/zuohuaijun/Admin.NET/pulls/1559  -->
 <script setup lang="ts">
 import { reactive, watch } from 'vue';
 import { DictItem } from '/@/types/global';
@@ -27,6 +28,10 @@ const props = defineProps({
 		type: Function,
 		default: (dict: any): boolean => dict,
 	},
+  onItemFormatter: {
+    type: Function as (dict: any) => (string | undefined | null),
+    default: () => undefined
+  },
 	renderAs: {
 		type: String,
 		default: 'tag',
@@ -59,19 +64,19 @@ watch(
 <template>
 	<!-- 渲染标签 -->
 	<template v-if="props.renderAs === 'tag'">
-		<el-tag v-if="state.dict" v-bind="$attrs" :type="state.dict.tagType" :style="state.dict.styleSetting" :class="state.dict.classSetting">{{ state.dict[props.propLabel] }}</el-tag>
+		<el-tag v-if="state.dict" v-bind="$attrs" :type="state.dict.tagType" :style="state.dict.styleSetting" :class="state.dict.classSetting">{{ onItemFormatter(state.dict) ?? state.dict[props.propLabel] }}</el-tag>
 		<span v-else>{{ state.value }}</span>
 	</template>
 	<!-- 渲染选择器 -->
 	<template v-if="props.renderAs === 'select'">
 		<el-select v-model="state.value" v-bind="$attrs" @change="(newValue: any) => emit('update:modelValue', newValue)">
-			<el-option :label="`[${item[props.propValue]}]${item[props.propLabel]}`" :value="item[props.propValue]" v-for="(item, index) in state.dictData" :key="index" />
+			<el-option :label="onItemFormatter(item) ?? item[props.propLabel]" :value="item[props.propValue]" v-for="(item, index) in state.dictData" :key="index" />
 		</el-select>
 	</template>
 	<!-- 渲染单选框 -->
 	<template v-if="props.renderAs === 'radio'">
 		<el-radio-group v-model="state.value" v-bind="$attrs" @change="(newValue: any) => emit('update:modelValue', newValue)">
-			<el-radio :value="item[props.propValue]" v-for="(item, index) in state.dictData" :key="index">{{ item[props.propLabel] }}</el-radio>
+			<el-radio :value="item[props.propValue]" v-for="(item, index) in state.dictData" :key="index">{{ onItemFormatter(item) ?? item[props.propLabel] }}</el-radio>
 		</el-radio-group>
 	</template>
 </template>

+ 3 - 2
Web/src/views/system/codeGen/component/editCodeGenDialog.vue

@@ -149,7 +149,7 @@
 											<span class="ml5">字段</span>
 										</template>
 										<el-select v-model="state.ruleForm.tableUniqueList[k].columns" @change="(val: any) => changeTableUniqueColumn(val, k)" multiple filterable clearable collapse-tags collapse-tags-tooltip class="w100">
-											<el-option v-for="item in state.columnData" :key="item.columnName" :label="item.columnName + ' [' + item.columnComment + ']'" :value="item.columnName" />
+											<el-option v-for="item in state.columnData" :key="item.propertyName" :label="item.propertyName + ' [' + item.columnComment + ']'" :value="item.propertyName" />
 										</el-select>
 									</el-form-item>
 								</el-col>
@@ -226,7 +226,7 @@ const tableChanged = (item: any) => {
 // 表唯一约束配置项字段改变事件
 const changeTableUniqueColumn = (value: any, index: number) => {
   if (value?.length === 1 && !state.ruleForm.tableUniqueList[index].message) {
-    state.ruleForm.tableUniqueList[index].message = state.columnData.find((u: any) => u.columnName === value[0])?.columnComment;
+    state.ruleForm.tableUniqueList[index].message = state.columnData.find((u: any) => u.propertyName === value[0])?.columnComment;
   }
 }
 
@@ -258,6 +258,7 @@ const getGlobalComponentSize = computed(() => {
 const openDialog = (row: any) => {
 	state.ruleForm = JSON.parse(JSON.stringify(row));
   dbChanged().then(() => getColumnInfoList());
+  state.ruleForm.tableUniqueList ??= [];
 	state.isShowDialog = true;
 	ruleFormRef.value?.resetFields();
 };