Commit 94a1c4636f204c400fabcfffbdbffbbd4eab8f63
1 parent
33fb112d
feat:【infra】移动端 admin uniapp 的代码生成的优化(api.ts、detail、form 的模版)
Showing
4 changed files
with
92 additions
and
57 deletions
yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/service/codegen/inner/CodegenEngine.java
| @@ -397,8 +397,8 @@ public class CodegenEngine { | @@ -397,8 +397,8 @@ public class CodegenEngine { | ||
| 397 | * @return 格式化后的代码 | 397 | * @return 格式化后的代码 |
| 398 | */ | 398 | */ |
| 399 | private String prettyCode(String content, String vmPath) { | 399 | private String prettyCode(String content, String vmPath) { |
| 400 | - // Vue 界面:去除字段后面多余的 , 逗号,解决前端的 Pretty 代码格式检查的报错(需要排除 vben5) | ||
| 401 | - if (!StrUtil.contains(vmPath, "vben5")) { | 400 | + // Vue 界面:去除字段后面多余的 , 逗号,解决前端的 Pretty 代码格式检查的报错(需要排除 vben5、vue3_admin_uniapp) |
| 401 | + if (!StrUtil.containsAny(vmPath, "vben5", "vue3_admin_uniapp")) { | ||
| 402 | content = content.replaceAll(",\n}", "\n}").replaceAll(",\n }", "\n }"); | 402 | content = content.replaceAll(",\n}", "\n}").replaceAll(",\n }", "\n }"); |
| 403 | } | 403 | } |
| 404 | // Vue 界面:去除多的 dateFormatter,只有一个的情况下,说明没使用到 | 404 | // Vue 界面:去除多的 dateFormatter,只有一个的情况下,说明没使用到 |
yudao-module-infra/src/main/resources/codegen/vue3_admin_uniapp/api/api.ts.vm
| 1 | import type { PageParam, PageResult } from '@/http/types' | 1 | import type { PageParam, PageResult } from '@/http/types' |
| 2 | import { http } from '@/http/http' | 2 | import { http } from '@/http/http' |
| 3 | 3 | ||
| 4 | -// TODO @AI:不使用 baseUrl,而是参考之前的,直接写在每个方法里。 | ||
| 5 | -#set ($baseURL = "/${table.moduleName}/${simpleClassName_strikeCase}") | ||
| 6 | -const baseUrl = '${baseURL}' | ||
| 7 | - | ||
| 8 | #set ($primaryJavaType = $primaryColumn.javaType.toLowerCase()) | 4 | #set ($primaryJavaType = $primaryColumn.javaType.toLowerCase()) |
| 9 | #if(${primaryJavaType} == "long" || ${primaryJavaType} == "integer" || ${primaryJavaType} == "short" || ${primaryJavaType} == "double" || ${primaryJavaType} == "bigdecimal" || ${primaryJavaType} == "byte") | 5 | #if(${primaryJavaType} == "long" || ${primaryJavaType} == "integer" || ${primaryJavaType} == "short" || ${primaryJavaType} == "double" || ${primaryJavaType} == "bigdecimal" || ${primaryJavaType} == "byte") |
| 10 | #set ($primaryTsType = "number") | 6 | #set ($primaryTsType = "number") |
| @@ -17,9 +13,12 @@ export interface ${simpleClassName} { | @@ -17,9 +13,12 @@ export interface ${simpleClassName} { | ||
| 17 | #foreach ($column in $columns) | 13 | #foreach ($column in $columns) |
| 18 | #if ($column.primaryKey || $column.createOperation || $column.updateOperation || $column.listOperationResult) | 14 | #if ($column.primaryKey || $column.createOperation || $column.updateOperation || $column.listOperationResult) |
| 19 | #set ($javaType = $column.javaType.toLowerCase()) | 15 | #set ($javaType = $column.javaType.toLowerCase()) |
| 20 | - #set ($optional = $column.nullable || $column.primaryKey) | 16 | + #set ($javaFieldLower = $column.javaField.toLowerCase()) |
| 17 | + #set ($optional = $column.nullable || $column.primaryKey || $javaFieldLower == "createtime" || $javaFieldLower == "updatetime") | ||
| 21 | #if(${javaType} == "long" || ${javaType} == "integer" || ${javaType} == "short" || ${javaType} == "double" || ${javaType} == "bigdecimal" || ${javaType} == "byte") | 18 | #if(${javaType} == "long" || ${javaType} == "integer" || ${javaType} == "short" || ${javaType} == "double" || ${javaType} == "bigdecimal" || ${javaType} == "byte") |
| 22 | ${column.javaField}#if($optional)?#end: number | 19 | ${column.javaField}#if($optional)?#end: number |
| 20 | + #elseif(${javaType} == "date" || ${javaType} == "localdate" || ${javaType} == "localdatetime") | ||
| 21 | + ${column.javaField}#if($optional)?#end: Date | ||
| 23 | #elseif(${javaType} == "boolean") | 22 | #elseif(${javaType} == "boolean") |
| 24 | ${column.javaField}#if($optional)?#end: boolean | 23 | ${column.javaField}#if($optional)?#end: boolean |
| 25 | #else | 24 | #else |
| @@ -31,25 +30,25 @@ export interface ${simpleClassName} { | @@ -31,25 +30,25 @@ export interface ${simpleClassName} { | ||
| 31 | 30 | ||
| 32 | /** 获取${table.classComment}分页列表 */ | 31 | /** 获取${table.classComment}分页列表 */ |
| 33 | export function get${simpleClassName}Page(params: PageParam) { | 32 | export function get${simpleClassName}Page(params: PageParam) { |
| 34 | - return http.get<PageResult<${simpleClassName}>>(baseUrl + '/page', params) | 33 | + return http.get<PageResult<${simpleClassName}>>('/${table.moduleName}/${simpleClassName_strikeCase}/page', params) |
| 35 | } | 34 | } |
| 36 | 35 | ||
| 37 | /** 获取${table.classComment}详情 */ | 36 | /** 获取${table.classComment}详情 */ |
| 38 | export function get${simpleClassName}(id: ${primaryTsType}) { | 37 | export function get${simpleClassName}(id: ${primaryTsType}) { |
| 39 | - return http.get<${simpleClassName}>(baseUrl + '/get?id=' + id) | 38 | + return http.get<${simpleClassName}>('/${table.moduleName}/${simpleClassName_strikeCase}/get?id=' + id) |
| 40 | } | 39 | } |
| 41 | 40 | ||
| 42 | /** 创建${table.classComment} */ | 41 | /** 创建${table.classComment} */ |
| 43 | export function create${simpleClassName}(data: ${simpleClassName}) { | 42 | export function create${simpleClassName}(data: ${simpleClassName}) { |
| 44 | - return http.post<number>(baseUrl + '/create', data) | 43 | + return http.post<number>('/${table.moduleName}/${simpleClassName_strikeCase}/create', data) |
| 45 | } | 44 | } |
| 46 | 45 | ||
| 47 | /** 更新${table.classComment} */ | 46 | /** 更新${table.classComment} */ |
| 48 | export function update${simpleClassName}(data: ${simpleClassName}) { | 47 | export function update${simpleClassName}(data: ${simpleClassName}) { |
| 49 | - return http.put<boolean>(baseUrl + '/update', data) | 48 | + return http.put<boolean>('/${table.moduleName}/${simpleClassName_strikeCase}/update', data) |
| 50 | } | 49 | } |
| 51 | 50 | ||
| 52 | /** 删除${table.classComment} */ | 51 | /** 删除${table.classComment} */ |
| 53 | export function delete${simpleClassName}(id: ${primaryTsType}) { | 52 | export function delete${simpleClassName}(id: ${primaryTsType}) { |
| 54 | - return http.delete<boolean>(baseUrl + '/delete?id=' + id) | 53 | + return http.delete<boolean>('/${table.moduleName}/${simpleClassName_strikeCase}/delete?id=' + id) |
| 55 | } | 54 | } |
yudao-module-infra/src/main/resources/codegen/vue3_admin_uniapp/views/detail/index.vue.vm
| 1 | <template> | 1 | <template> |
| 2 | <view class="page-container"> | 2 | <view class="page-container"> |
| 3 | + <!-- 顶部导航栏 --> | ||
| 3 | <wd-navbar | 4 | <wd-navbar |
| 4 | title="${table.classComment}详情" | 5 | title="${table.classComment}详情" |
| 5 | left-arrow placeholder safe-area-inset-top fixed | 6 | left-arrow placeholder safe-area-inset-top fixed |
| 6 | @click-left="handleBack" | 7 | @click-left="handleBack" |
| 7 | /> | 8 | /> |
| 8 | 9 | ||
| 10 | + <!-- 详情内容 --> | ||
| 9 | <view> | 11 | <view> |
| 10 | <wd-cell-group border> | 12 | <wd-cell-group border> |
| 11 | #foreach($column in $columns) | 13 | #foreach($column in $columns) |
| @@ -26,6 +28,7 @@ | @@ -26,6 +28,7 @@ | ||
| 26 | </wd-cell-group> | 28 | </wd-cell-group> |
| 27 | </view> | 29 | </view> |
| 28 | 30 | ||
| 31 | + <!-- 底部操作按钮 --> | ||
| 29 | <view class="fixed bottom-0 left-0 right-0 bg-white p-24rpx"> | 32 | <view class="fixed bottom-0 left-0 right-0 bg-white p-24rpx"> |
| 30 | <view class="w-full flex gap-24rpx"> | 33 | <view class="w-full flex gap-24rpx"> |
| 31 | <wd-button | 34 | <wd-button |
| @@ -46,27 +49,27 @@ | @@ -46,27 +49,27 @@ | ||
| 46 | </template> | 49 | </template> |
| 47 | 50 | ||
| 48 | <script lang="ts" setup> | 51 | <script lang="ts" setup> |
| 49 | -import type { ${simpleClassName} } from '@/api/${table.moduleName}/${table.businessName}' | ||
| 50 | -import { onMounted, ref } from 'vue' | ||
| 51 | -import { useToast } from 'wot-design-uni' | ||
| 52 | -import { delete${simpleClassName}, get${simpleClassName} } from '@/api/${table.moduleName}/${table.businessName}' | ||
| 53 | -import { useAccess } from '@/hooks/useAccess' | ||
| 54 | -import { navigateBackPlus } from '@/utils' | ||
| 55 | #set ($hasDict = 0) | 52 | #set ($hasDict = 0) |
| 56 | #foreach($column in $columns) | 53 | #foreach($column in $columns) |
| 57 | #if ($hasDict == 0 && $column.dictType && "" != $column.dictType) | 54 | #if ($hasDict == 0 && $column.dictType && "" != $column.dictType) |
| 58 | #set ($hasDict = 1) | 55 | #set ($hasDict = 1) |
| 59 | #end | 56 | #end |
| 60 | #end | 57 | #end |
| 61 | -#if ($hasDict == 1) | ||
| 62 | -import { DICT_TYPE } from '@/utils/constants' | ||
| 63 | -#end | ||
| 64 | #set ($hasDateTime = 0) | 58 | #set ($hasDateTime = 0) |
| 65 | #foreach($column in $columns) | 59 | #foreach($column in $columns) |
| 66 | #if ($hasDateTime == 0 && $column.javaType == "LocalDateTime") | 60 | #if ($hasDateTime == 0 && $column.javaType == "LocalDateTime") |
| 67 | #set ($hasDateTime = 1) | 61 | #set ($hasDateTime = 1) |
| 68 | #end | 62 | #end |
| 69 | #end | 63 | #end |
| 64 | +import type { ${simpleClassName} } from '@/api/${table.moduleName}/${table.businessName}' | ||
| 65 | +import { onMounted, ref } from 'vue' | ||
| 66 | +import { useToast } from 'wot-design-uni' | ||
| 67 | +import { delete${simpleClassName}, get${simpleClassName} } from '@/api/${table.moduleName}/${table.businessName}' | ||
| 68 | +import { useAccess } from '@/hooks/useAccess' | ||
| 69 | +import { navigateBackPlus } from '@/utils' | ||
| 70 | +#if ($hasDict == 1) | ||
| 71 | +import { DICT_TYPE } from '@/utils/constants' | ||
| 72 | +#end | ||
| 70 | #if ($hasDateTime == 1) | 73 | #if ($hasDateTime == 1) |
| 71 | import { formatDateTime } from '@/utils/date' | 74 | import { formatDateTime } from '@/utils/date' |
| 72 | #end | 75 | #end |
| @@ -84,13 +87,15 @@ definePage({ | @@ -84,13 +87,15 @@ definePage({ | ||
| 84 | 87 | ||
| 85 | const { hasAccessByCodes } = useAccess() | 88 | const { hasAccessByCodes } = useAccess() |
| 86 | const toast = useToast() | 89 | const toast = useToast() |
| 87 | -const formData = ref<${simpleClassName}>() | ||
| 88 | -const deleting = ref(false) | 90 | +const formData = ref<${simpleClassName}>() // 详情数据 |
| 91 | +const deleting = ref(false) // 删除中 | ||
| 89 | 92 | ||
| 93 | +/** 返回上一页 */ | ||
| 90 | function handleBack() { | 94 | function handleBack() { |
| 91 | navigateBackPlus('/pages-${table.moduleName}/${table.businessName}/index') | 95 | navigateBackPlus('/pages-${table.moduleName}/${table.businessName}/index') |
| 92 | } | 96 | } |
| 93 | 97 | ||
| 98 | +/** 加载${table.classComment}详情 */ | ||
| 94 | async function getDetail() { | 99 | async function getDetail() { |
| 95 | if (!props.id) { | 100 | if (!props.id) { |
| 96 | return | 101 | return |
| @@ -103,12 +108,14 @@ async function getDetail() { | @@ -103,12 +108,14 @@ async function getDetail() { | ||
| 103 | } | 108 | } |
| 104 | } | 109 | } |
| 105 | 110 | ||
| 111 | +/** 编辑${table.classComment} */ | ||
| 106 | function handleEdit() { | 112 | function handleEdit() { |
| 107 | uni.navigateTo({ | 113 | uni.navigateTo({ |
| 108 | - url: '/pages-${table.moduleName}/${table.businessName}/form/index?id=' + props.id, | 114 | + url: `/pages-${table.moduleName}/${table.businessName}/form/index?id=\${props.id}`, |
| 109 | }) | 115 | }) |
| 110 | } | 116 | } |
| 111 | 117 | ||
| 118 | +/** 删除${table.classComment} */ | ||
| 112 | function handleDelete() { | 119 | function handleDelete() { |
| 113 | if (!props.id) { | 120 | if (!props.id) { |
| 114 | return | 121 | return |
| @@ -134,6 +141,7 @@ function handleDelete() { | @@ -134,6 +141,7 @@ function handleDelete() { | ||
| 134 | }) | 141 | }) |
| 135 | } | 142 | } |
| 136 | 143 | ||
| 144 | +/** 初始化 */ | ||
| 137 | onMounted(() => { | 145 | onMounted(() => { |
| 138 | getDetail() | 146 | getDetail() |
| 139 | }) | 147 | }) |
yudao-module-infra/src/main/resources/codegen/vue3_admin_uniapp/views/form/index.vue.vm
| 1 | <template> | 1 | <template> |
| 2 | <view class="page-container"> | 2 | <view class="page-container"> |
| 3 | + <!-- 顶部导航栏 --> | ||
| 3 | <wd-navbar | 4 | <wd-navbar |
| 4 | :title="getTitle" | 5 | :title="getTitle" |
| 5 | left-arrow placeholder safe-area-inset-top fixed | 6 | left-arrow placeholder safe-area-inset-top fixed |
| 6 | @click-left="handleBack" | 7 | @click-left="handleBack" |
| 7 | /> | 8 | /> |
| 8 | 9 | ||
| 10 | + <!-- 表单区域 --> | ||
| 9 | <view> | 11 | <view> |
| 10 | <wd-form ref="formRef" :model="formData" :rules="formRules"> | 12 | <wd-form ref="formRef" :model="formData" :rules="formRules"> |
| 11 | <wd-cell-group border> | 13 | <wd-cell-group border> |
| @@ -23,18 +25,46 @@ | @@ -23,18 +25,46 @@ | ||
| 23 | #elseif ($javaType == "Boolean") | 25 | #elseif ($javaType == "Boolean") |
| 24 | #set ($dictMethod = "getBoolDictOptions") | 26 | #set ($dictMethod = "getBoolDictOptions") |
| 25 | #end | 27 | #end |
| 26 | - | ||
| 27 | - #if (${javaType.toLowerCase()} == "long" || ${javaType.toLowerCase()} == "integer" || ${javaType.toLowerCase()} == "short" || ${javaType.toLowerCase()} == "double" || ${javaType.toLowerCase()} == "bigdecimal" || ${javaType.toLowerCase()} == "byte") | 28 | + ## 优先判断是否有字典,有字典则使用 radio-group |
| 29 | + #if (($column.htmlType == "select" || $column.htmlType == "radio") && $dictType && "" != $dictType) | ||
| 30 | + <wd-cell title="${comment}" title-width="180rpx" prop="${javaField}" center> | ||
| 31 | + <wd-radio-group v-model="formData.${javaField}" shape="button" size="medium"> | ||
| 32 | + <wd-radio | ||
| 33 | + v-for="dict in $dictMethod(DICT_TYPE.${dictType.toUpperCase()})" | ||
| 34 | + :key="dict.value" | ||
| 35 | + :value="dict.value" | ||
| 36 | + > | ||
| 37 | + {{ dict.label }} | ||
| 38 | + </wd-radio> | ||
| 39 | + </wd-radio-group> | ||
| 40 | + </wd-cell> | ||
| 41 | + ## 数字类型(无字典) | ||
| 42 | + #elseif (${javaType.toLowerCase()} == "long" || ${javaType.toLowerCase()} == "integer" || ${javaType.toLowerCase()} == "short" || ${javaType.toLowerCase()} == "double" || ${javaType.toLowerCase()} == "bigdecimal" || ${javaType.toLowerCase()} == "byte") | ||
| 28 | <wd-cell title="${comment}" title-width="180rpx" prop="${javaField}" center> | 43 | <wd-cell title="${comment}" title-width="180rpx" prop="${javaField}" center> |
| 29 | <wd-input-number | 44 | <wd-input-number |
| 30 | v-model="formData.${javaField}" | 45 | v-model="formData.${javaField}" |
| 31 | :min="0" | 46 | :min="0" |
| 32 | /> | 47 | /> |
| 33 | </wd-cell> | 48 | </wd-cell> |
| 49 | + ## 布尔类型 | ||
| 34 | #elseif (${javaType.toLowerCase()} == "boolean") | 50 | #elseif (${javaType.toLowerCase()} == "boolean") |
| 35 | <wd-cell title="${comment}" title-width="180rpx" prop="${javaField}" center> | 51 | <wd-cell title="${comment}" title-width="180rpx" prop="${javaField}" center> |
| 36 | <wd-switch v-model="formData.${javaField}" /> | 52 | <wd-switch v-model="formData.${javaField}" /> |
| 37 | </wd-cell> | 53 | </wd-cell> |
| 54 | + ## 日期时间类型 | ||
| 55 | + #elseif (${javaType.toLowerCase()} == "date" || ${javaType.toLowerCase()} == "localdate" || ${javaType.toLowerCase()} == "localdatetime") | ||
| 56 | + #set ($pickerType = "date") | ||
| 57 | + #if (${javaType.toLowerCase()} == "localdatetime") | ||
| 58 | + #set ($pickerType = "datetime") | ||
| 59 | + #end | ||
| 60 | + <wd-datetime-picker | ||
| 61 | + v-model="formData.${javaField}" | ||
| 62 | + type="${pickerType}" | ||
| 63 | + label="${comment}" | ||
| 64 | + label-width="180rpx" | ||
| 65 | + prop="${javaField}" | ||
| 66 | + /> | ||
| 67 | + ## 文本域 | ||
| 38 | #elseif ($column.htmlType == "textarea") | 68 | #elseif ($column.htmlType == "textarea") |
| 39 | <wd-textarea | 69 | <wd-textarea |
| 40 | v-model="formData.${javaField}" | 70 | v-model="formData.${javaField}" |
| @@ -45,18 +75,7 @@ | @@ -45,18 +75,7 @@ | ||
| 45 | show-word-limit | 75 | show-word-limit |
| 46 | clearable | 76 | clearable |
| 47 | /> | 77 | /> |
| 48 | - #elseif (($column.htmlType == "select" || $column.htmlType == "radio") && $dictType && "" != $dictType) | ||
| 49 | - <wd-cell title="${comment}" title-width="180rpx" prop="${javaField}" center> | ||
| 50 | - <wd-radio-group v-model="formData.${javaField}" shape="button" size="medium"> | ||
| 51 | - <wd-radio | ||
| 52 | - v-for="dict in $dictMethod(DICT_TYPE.$dictType.toUpperCase())" | ||
| 53 | - :key="dict.value" | ||
| 54 | - :value="dict.value" | ||
| 55 | - > | ||
| 56 | - {{ dict.label }} | ||
| 57 | - </wd-radio> | ||
| 58 | - </wd-radio-group> | ||
| 59 | - </wd-cell> | 78 | + ## 默认:文本输入 |
| 60 | #else | 79 | #else |
| 61 | <wd-input | 80 | <wd-input |
| 62 | v-model="formData.${javaField}" | 81 | v-model="formData.${javaField}" |
| @@ -73,6 +92,7 @@ | @@ -73,6 +92,7 @@ | ||
| 73 | </wd-form> | 92 | </wd-form> |
| 74 | </view> | 93 | </view> |
| 75 | 94 | ||
| 95 | + <!-- 底部保存按钮 --> | ||
| 76 | <view class="fixed bottom-0 left-0 right-0 bg-white p-24rpx"> | 96 | <view class="fixed bottom-0 left-0 right-0 bg-white p-24rpx"> |
| 77 | <wd-button | 97 | <wd-button |
| 78 | type="primary" | 98 | type="primary" |
| @@ -87,19 +107,12 @@ | @@ -87,19 +107,12 @@ | ||
| 87 | </template> | 107 | </template> |
| 88 | 108 | ||
| 89 | <script lang="ts" setup> | 109 | <script lang="ts" setup> |
| 90 | -import type { ${simpleClassName} } from '@/api/${table.moduleName}/${table.businessName}' | ||
| 91 | -import { computed, onMounted, ref } from 'vue' | ||
| 92 | -import { useToast } from 'wot-design-uni' | ||
| 93 | -import { create${simpleClassName}, get${simpleClassName}, update${simpleClassName} } from '@/api/${table.moduleName}/${table.businessName}' | ||
| 94 | -import { navigateBackPlus } from '@/utils' | ||
| 95 | - | ||
| 96 | #set ($primaryJavaType = $primaryColumn.javaType.toLowerCase()) | 110 | #set ($primaryJavaType = $primaryColumn.javaType.toLowerCase()) |
| 97 | #if(${primaryJavaType} == "long" || ${primaryJavaType} == "integer" || ${primaryJavaType} == "short" || ${primaryJavaType} == "double" || ${primaryJavaType} == "bigdecimal" || ${primaryJavaType} == "byte") | 111 | #if(${primaryJavaType} == "long" || ${primaryJavaType} == "integer" || ${primaryJavaType} == "short" || ${primaryJavaType} == "double" || ${primaryJavaType} == "bigdecimal" || ${primaryJavaType} == "byte") |
| 98 | #set ($primaryTsType = "number") | 112 | #set ($primaryTsType = "number") |
| 99 | #else | 113 | #else |
| 100 | #set ($primaryTsType = "string") | 114 | #set ($primaryTsType = "string") |
| 101 | #end | 115 | #end |
| 102 | - | ||
| 103 | #set ($hasDict = 0) | 116 | #set ($hasDict = 0) |
| 104 | #set ($hasGetDictOptions = 0) | 117 | #set ($hasGetDictOptions = 0) |
| 105 | #set ($hasGetIntDictOptions = 0) | 118 | #set ($hasGetIntDictOptions = 0) |
| @@ -121,22 +134,31 @@ import { navigateBackPlus } from '@/utils' | @@ -121,22 +134,31 @@ import { navigateBackPlus } from '@/utils' | ||
| 121 | #end | 134 | #end |
| 122 | #end | 135 | #end |
| 123 | #end | 136 | #end |
| 137 | +import type { ${simpleClassName} } from '@/api/${table.moduleName}/${table.businessName}' | ||
| 138 | +import { computed, onMounted, ref } from 'vue' | ||
| 139 | +import { useToast } from 'wot-design-uni' | ||
| 140 | +import { create${simpleClassName}, get${simpleClassName}, update${simpleClassName} } from '@/api/${table.moduleName}/${table.businessName}' | ||
| 124 | #if ($hasDict == 1) | 141 | #if ($hasDict == 1) |
| 125 | -import { DICT_TYPE } from '@/utils/constants' | ||
| 126 | -import { | 142 | + #set ($dictImportNames = "") |
| 127 | #if ($hasGetDictOptions == 1) | 143 | #if ($hasGetDictOptions == 1) |
| 128 | - getDictOptions, | 144 | + #set ($dictImportNames = "${dictImportNames}getDictOptions, ") |
| 129 | #end | 145 | #end |
| 130 | #if ($hasGetIntDictOptions == 1) | 146 | #if ($hasGetIntDictOptions == 1) |
| 131 | - getIntDictOptions, | 147 | + #set ($dictImportNames = "${dictImportNames}getIntDictOptions, ") |
| 132 | #end | 148 | #end |
| 133 | #if ($hasGetStrDictOptions == 1) | 149 | #if ($hasGetStrDictOptions == 1) |
| 134 | - getStrDictOptions, | 150 | + #set ($dictImportNames = "${dictImportNames}getStrDictOptions, ") |
| 135 | #end | 151 | #end |
| 136 | #if ($hasGetBoolDictOptions == 1) | 152 | #if ($hasGetBoolDictOptions == 1) |
| 137 | - getBoolDictOptions, | 153 | + #set ($dictImportNames = "${dictImportNames}getBoolDictOptions, ") |
| 138 | #end | 154 | #end |
| 139 | -} from '@/hooks/useDict' | 155 | + #set ($dictImportNames = $dictImportNames.trim()) |
| 156 | + #set ($dictImportNames = $dictImportNames.substring(0, $dictImportNames.length() - 1)) | ||
| 157 | +import { $dictImportNames } from '@/hooks/useDict' | ||
| 158 | +#end | ||
| 159 | +import { navigateBackPlus } from '@/utils' | ||
| 160 | +#if ($hasDict == 1) | ||
| 161 | +import { DICT_TYPE } from '@/utils/constants' | ||
| 140 | #end | 162 | #end |
| 141 | 163 | ||
| 142 | const props = defineProps<{ | 164 | const props = defineProps<{ |
| @@ -153,39 +175,43 @@ definePage({ | @@ -153,39 +175,43 @@ definePage({ | ||
| 153 | const toast = useToast() | 175 | const toast = useToast() |
| 154 | const getTitle = computed(() => props.id ? '编辑${table.classComment}' : '新增${table.classComment}') | 176 | const getTitle = computed(() => props.id ? '编辑${table.classComment}' : '新增${table.classComment}') |
| 155 | const formLoading = ref(false) | 177 | const formLoading = ref(false) |
| 156 | - | ||
| 157 | -// TODO @AI:date + 时间范围,需要特殊处理;参考 /Users/yunai/Java/yudao-ui-admin-uniapp-next-v4/src/pages/message/components/search-form.vue 里的开始结束时间的处理;注意,index.vue.vm 也要调整; | ||
| 158 | const formData = ref<${simpleClassName}>({ | 178 | const formData = ref<${simpleClassName}>({ |
| 159 | #foreach($column in $columns) | 179 | #foreach($column in $columns) |
| 160 | #if (($column.createOperation || $column.updateOperation) || $column.primaryKey) | 180 | #if (($column.createOperation || $column.updateOperation) || $column.primaryKey) |
| 161 | #set ($javaType = $column.javaType.toLowerCase()) | 181 | #set ($javaType = $column.javaType.toLowerCase()) |
| 182 | + #set ($javaFieldLower = $column.javaField.toLowerCase()) | ||
| 183 | + #set ($optional = $column.nullable || $column.primaryKey || $javaFieldLower == "createtime" || $javaFieldLower == "updatetime") | ||
| 162 | #if ($column.primaryKey) | 184 | #if ($column.primaryKey) |
| 163 | ${column.javaField}: undefined, | 185 | ${column.javaField}: undefined, |
| 164 | #elseif(${javaType} == "long" || ${javaType} == "integer" || ${javaType} == "short" || ${javaType} == "double" || ${javaType} == "bigdecimal" || ${javaType} == "byte") | 186 | #elseif(${javaType} == "long" || ${javaType} == "integer" || ${javaType} == "short" || ${javaType} == "double" || ${javaType} == "bigdecimal" || ${javaType} == "byte") |
| 165 | ${column.javaField}: 0, | 187 | ${column.javaField}: 0, |
| 166 | #elseif(${javaType} == "boolean") | 188 | #elseif(${javaType} == "boolean") |
| 167 | ${column.javaField}: false, | 189 | ${column.javaField}: false, |
| 190 | + #elseif(${javaType} == "date" || ${javaType} == "localdate" || ${javaType} == "localdatetime") | ||
| 191 | + ${column.javaField}: undefined, | ||
| 168 | #else | 192 | #else |
| 169 | ${column.javaField}: '', | 193 | ${column.javaField}: '', |
| 170 | #end | 194 | #end |
| 171 | #end | 195 | #end |
| 172 | #end | 196 | #end |
| 173 | }) | 197 | }) |
| 174 | - | ||
| 175 | const formRules = { | 198 | const formRules = { |
| 176 | #foreach($column in $columns) | 199 | #foreach($column in $columns) |
| 177 | - #if (($column.createOperation || $column.updateOperation) && !$column.nullable && !$column.primaryKey) | 200 | + #set ($javaFieldLower = $column.javaField.toLowerCase()) |
| 201 | + #if (($column.createOperation || $column.updateOperation) && !$column.nullable && !$column.primaryKey | ||
| 202 | + && $javaFieldLower != "createtime" && $javaFieldLower != "updatetime") | ||
| 178 | ${column.javaField}: [{ required: true, message: '${column.columnComment}不能为空' }], | 203 | ${column.javaField}: [{ required: true, message: '${column.columnComment}不能为空' }], |
| 179 | #end | 204 | #end |
| 180 | #end | 205 | #end |
| 181 | } | 206 | } |
| 182 | - | ||
| 183 | const formRef = ref() | 207 | const formRef = ref() |
| 184 | 208 | ||
| 209 | +/** 返回上一页 */ | ||
| 185 | function handleBack() { | 210 | function handleBack() { |
| 186 | navigateBackPlus('/pages-${table.moduleName}/${table.businessName}/index') | 211 | navigateBackPlus('/pages-${table.moduleName}/${table.businessName}/index') |
| 187 | } | 212 | } |
| 188 | 213 | ||
| 214 | +/** 加载${table.classComment}详情 */ | ||
| 189 | async function getDetail() { | 215 | async function getDetail() { |
| 190 | if (!props.id) { | 216 | if (!props.id) { |
| 191 | return | 217 | return |
| @@ -193,6 +219,7 @@ async function getDetail() { | @@ -193,6 +219,7 @@ async function getDetail() { | ||
| 193 | formData.value = await get${simpleClassName}(props.id) | 219 | formData.value = await get${simpleClassName}(props.id) |
| 194 | } | 220 | } |
| 195 | 221 | ||
| 222 | +/** 提交表单 */ | ||
| 196 | async function handleSubmit() { | 223 | async function handleSubmit() { |
| 197 | const { valid } = await formRef.value.validate() | 224 | const { valid } = await formRef.value.validate() |
| 198 | if (!valid) { | 225 | if (!valid) { |
| @@ -216,6 +243,7 @@ async function handleSubmit() { | @@ -216,6 +243,7 @@ async function handleSubmit() { | ||
| 216 | } | 243 | } |
| 217 | } | 244 | } |
| 218 | 245 | ||
| 246 | +/** 初始化 */ | ||
| 219 | onMounted(() => { | 247 | onMounted(() => { |
| 220 | getDetail() | 248 | getDetail() |
| 221 | }) | 249 | }) |