Commit 2a5ebb5ad17731e0be1d8273feb00ec885cfdfe2

Authored by YunaiV
1 parent 94a1c463

feat:【infra】移动端 admin uniapp 的代码生成的优化(search-form、list 的模版)

yudao-module-infra/src/main/resources/codegen/vue3_admin_uniapp/components/search-form.vue.vm
1 <template> 1 <template>
  2 + <!-- 搜索框入口 -->
2 <wd-search 3 <wd-search
3 :placeholder="searchPlaceholder" 4 :placeholder="searchPlaceholder"
4 :hide-cancel="true" 5 :hide-cancel="true"
@@ -6,6 +7,7 @@ @@ -6,6 +7,7 @@
6 @click="visible = true" 7 @click="visible = true"
7 /> 8 />
8 9
  10 + <!-- 搜索弹窗 -->
9 <wd-popup 11 <wd-popup
10 v-model="visible" 12 v-model="visible"
11 position="top" 13 position="top"
@@ -17,14 +19,12 @@ @@ -17,14 +19,12 @@
17 <view class="mb-24rpx text-32rpx text-[#333] font-semibold"> 19 <view class="mb-24rpx text-32rpx text-[#333] font-semibold">
18 搜索${table.classComment} 20 搜索${table.classComment}
19 </view> 21 </view>
20 -  
21 #set ($hasDict = 0) 22 #set ($hasDict = 0)
22 #foreach ($column in $columns) 23 #foreach ($column in $columns)
23 #if ($hasDict == 0 && $column.listOperation && $column.dictType && "" != $column.dictType) 24 #if ($hasDict == 0 && $column.listOperation && $column.dictType && "" != $column.dictType)
24 #set ($hasDict = 1) 25 #set ($hasDict = 1)
25 #end 26 #end
26 #end 27 #end
27 -  
28 #foreach($column in $columns) 28 #foreach($column in $columns)
29 #if ($column.listOperation) 29 #if ($column.listOperation)
30 #set ($dictType = $column.dictType) 30 #set ($dictType = $column.dictType)
@@ -39,7 +39,6 @@ @@ -39,7 +39,6 @@
39 #elseif ($javaType == "Boolean") 39 #elseif ($javaType == "Boolean")
40 #set ($dictMethod = "getBoolDictOptions") 40 #set ($dictMethod = "getBoolDictOptions")
41 #end 41 #end
42 -  
43 #if ($column.htmlType == "input") 42 #if ($column.htmlType == "input")
44 <view class="mb-24rpx"> 43 <view class="mb-24rpx">
45 <view class="mb-12rpx text-28rpx text-[#666]"> 44 <view class="mb-12rpx text-28rpx text-[#666]">
@@ -83,7 +82,6 @@ @@ -83,7 +82,6 @@
83 #end 82 #end
84 #end 83 #end
85 #end 84 #end
86 -  
87 <view class="w-full flex justify-center gap-24rpx"> 85 <view class="w-full flex justify-center gap-24rpx">
88 <wd-button class="flex-1" plain @click="handleReset"> 86 <wd-button class="flex-1" plain @click="handleReset">
89 重置 87 重置
@@ -97,8 +95,6 @@ @@ -97,8 +95,6 @@
97 </template> 95 </template>
98 96
99 <script lang="ts" setup> 97 <script lang="ts" setup>
100 -import { computed, reactive, ref, watch } from 'vue'  
101 -  
102 #set ($hasDict = 0) 98 #set ($hasDict = 0)
103 #set ($hasGetDictOptions = 0) 99 #set ($hasGetDictOptions = 0)
104 #set ($hasGetIntDictOptions = 0) 100 #set ($hasGetIntDictOptions = 0)
@@ -120,23 +116,25 @@ import { computed, reactive, ref, watch } from &#39;vue&#39; @@ -120,23 +116,25 @@ import { computed, reactive, ref, watch } from &#39;vue&#39;
120 #end 116 #end
121 #end 117 #end
122 #end 118 #end
  119 +import { computed, reactive, ref, watch } from 'vue'
123 #if ($hasDict == 1) 120 #if ($hasDict == 1)
124 -import { DICT_TYPE } from '@/utils/constants'  
125 -import { 121 + #set ($dictImportNames = "getDictLabel, ")
126 #if ($hasGetDictOptions == 1) 122 #if ($hasGetDictOptions == 1)
127 - getDictOptions, 123 + #set ($dictImportNames = "${dictImportNames}getDictOptions, ")
128 #end 124 #end
129 #if ($hasGetIntDictOptions == 1) 125 #if ($hasGetIntDictOptions == 1)
130 - getIntDictOptions, 126 + #set ($dictImportNames = "${dictImportNames}getIntDictOptions, ")
131 #end 127 #end
132 #if ($hasGetStrDictOptions == 1) 128 #if ($hasGetStrDictOptions == 1)
133 - getStrDictOptions, 129 + #set ($dictImportNames = "${dictImportNames}getStrDictOptions, ")
134 #end 130 #end
135 #if ($hasGetBoolDictOptions == 1) 131 #if ($hasGetBoolDictOptions == 1)
136 - getBoolDictOptions, 132 + #set ($dictImportNames = "${dictImportNames}getBoolDictOptions, ")
137 #end 133 #end
138 - getDictLabel,  
139 -} from '@/hooks/useDict' 134 + #set ($dictImportNames = $dictImportNames.trim())
  135 + #set ($dictImportNames = $dictImportNames.substring(0, $dictImportNames.length() - 1))
  136 +import { $dictImportNames } from '@/hooks/useDict'
  137 +import { DICT_TYPE } from '@/utils/constants'
140 #end 138 #end
141 139
142 /** 搜索表单数据 */ 140 /** 搜索表单数据 */
@@ -185,16 +183,16 @@ const searchPlaceholder = computed(() =&gt; { @@ -185,16 +183,16 @@ const searchPlaceholder = computed(() =&gt; {
185 #set ($comment = $column.columnComment) 183 #set ($comment = $column.columnComment)
186 #if ($dictType && "" != $dictType) 184 #if ($dictType && "" != $dictType)
187 if (props.searchParams?.${javaField} !== undefined && props.searchParams.${javaField} !== -1) { 185 if (props.searchParams?.${javaField} !== undefined && props.searchParams.${javaField} !== -1) {
188 - conditions.push('${comment}:' + getDictLabel(DICT_TYPE.$dictType.toUpperCase(), props.searchParams.${javaField})) 186 + conditions.push(`${comment}:#[[${]]#getDictLabel(DICT_TYPE.${dictType.toUpperCase()}, props.searchParams.${javaField})#[[}]]#`)
189 } 187 }
190 #else 188 #else
191 #if(${javaType} == "long" || ${javaType} == "integer" || ${javaType} == "short" || ${javaType} == "double" || ${javaType} == "bigdecimal" || ${javaType} == "byte" || ${javaType} == "boolean") 189 #if(${javaType} == "long" || ${javaType} == "integer" || ${javaType} == "short" || ${javaType} == "double" || ${javaType} == "bigdecimal" || ${javaType} == "byte" || ${javaType} == "boolean")
192 if (props.searchParams?.${javaField} !== undefined) { 190 if (props.searchParams?.${javaField} !== undefined) {
193 - conditions.push('${comment}:' + props.searchParams.${javaField}) 191 + conditions.push(`${comment}:#[[${]]#props.searchParams.${javaField}#[[}]]#`)
194 } 192 }
195 #else 193 #else
196 if (props.searchParams?.${javaField}) { 194 if (props.searchParams?.${javaField}) {
197 - conditions.push('${comment}:' + props.searchParams.${javaField}) 195 + conditions.push(`${comment}:#[[${]]#props.searchParams.${javaField}#[[}]]#`)
198 } 196 }
199 #end 197 #end
200 #end 198 #end
@@ -222,6 +220,7 @@ const formData = reactive&lt;SearchFormData&gt;({ @@ -222,6 +220,7 @@ const formData = reactive&lt;SearchFormData&gt;({
222 #end 220 #end
223 }) 221 })
224 222
  223 +/** 监听弹窗打开,同步外部参数 */
225 watch(visible, (val) => { 224 watch(visible, (val) => {
226 if (val && props.searchParams) { 225 if (val && props.searchParams) {
227 #foreach($column in $columns) 226 #foreach($column in $columns)
@@ -236,11 +235,13 @@ watch(visible, (val) =&gt; { @@ -236,11 +235,13 @@ watch(visible, (val) =&gt; {
236 } 235 }
237 }) 236 })
238 237
  238 +/** 搜索 */
239 function handleSearch() { 239 function handleSearch() {
240 visible.value = false 240 visible.value = false
241 emit('search', { ...formData } as SearchFormData) 241 emit('search', { ...formData } as SearchFormData)
242 } 242 }
243 243
  244 +/** 重置 */
244 function handleReset() { 245 function handleReset() {
245 #foreach($column in $columns) 246 #foreach($column in $columns)
246 #if ($column.listOperation) 247 #if ($column.listOperation)
yudao-module-infra/src/main/resources/codegen/vue3_admin_uniapp/views/detail/index.vue.vm
@@ -21,7 +21,7 @@ @@ -21,7 +21,7 @@
21 #elseif ($column.javaType == "LocalDateTime") 21 #elseif ($column.javaType == "LocalDateTime")
22 <wd-cell title="${comment}" :value="formatDateTime(formData?.${javaField}) || '-'" /> 22 <wd-cell title="${comment}" :value="formatDateTime(formData?.${javaField}) || '-'" />
23 #else 23 #else
24 - <wd-cell title="${comment}" :value="String(formData?.${javaField} ?? '-')" /> 24 + <wd-cell title="${comment}" :value="formData?.${javaField} ?? '-'" />
25 #end 25 #end
26 #end 26 #end
27 #end 27 #end
@@ -87,8 +87,8 @@ definePage({ @@ -87,8 +87,8 @@ definePage({
87 87
88 const { hasAccessByCodes } = useAccess() 88 const { hasAccessByCodes } = useAccess()
89 const toast = useToast() 89 const toast = useToast()
90 -const formData = ref<${simpleClassName}>() // 详情数据  
91 -const deleting = ref(false) // 删除中 90 +const formData = ref<${simpleClassName}>()
  91 +const deleting = ref(false)
92 92
93 /** 返回上一页 */ 93 /** 返回上一页 */
94 function handleBack() { 94 function handleBack() {
@@ -111,7 +111,7 @@ async function getDetail() { @@ -111,7 +111,7 @@ async function getDetail() {
111 /** 编辑${table.classComment} */ 111 /** 编辑${table.classComment} */
112 function handleEdit() { 112 function handleEdit() {
113 uni.navigateTo({ 113 uni.navigateTo({
114 - url: `/pages-${table.moduleName}/${table.businessName}/form/index?id=\${props.id}`, 114 + url: `/pages-${table.moduleName}/${table.businessName}/form/index?id=#[[${]]#props.id#[[}]]#`,
115 }) 115 })
116 } 116 }
117 117
yudao-module-infra/src/main/resources/codegen/vue3_admin_uniapp/views/index.vue.vm
@@ -22,7 +22,6 @@ @@ -22,7 +22,6 @@
22 class="mb-24rpx overflow-hidden rounded-12rpx bg-white shadow-sm" 22 class="mb-24rpx overflow-hidden rounded-12rpx bg-white shadow-sm"
23 @click="handleDetail(item)" 23 @click="handleDetail(item)"
24 > 24 >
25 - <!-- TODO @AI:下面的 view 部分代码,缩进可能不太对; -->  
26 <view class="p-24rpx"> 25 <view class="p-24rpx">
27 #set ($titleField = "") 26 #set ($titleField = "")
28 #set ($statusField = "") 27 #set ($statusField = "")
@@ -37,23 +36,38 @@ @@ -37,23 +36,38 @@
37 #set ($statusDictType = $column.dictType) 36 #set ($statusDictType = $column.dictType)
38 #end 37 #end
39 #end 38 #end
  39 + #if ($titleField == "")
  40 + #set ($titleField = $primaryColumn.javaField)
  41 + #end
40 <view class="mb-16rpx flex items-center justify-between"> 42 <view class="mb-16rpx flex items-center justify-between">
41 <view class="text-32rpx text-[#333] font-semibold"> 43 <view class="text-32rpx text-[#333] font-semibold">
42 - {{ item.#if($titleField != "")${titleField}#else ${primaryColumn.javaField}#end }} 44 + {{ item.${titleField} }}
43 </view> 45 </view>
44 #if($statusField != "") 46 #if($statusField != "")
45 - <dict-tag :type="DICT_TYPE.$statusDictType.toUpperCase()" :value="item.$statusField" /> 47 + <dict-tag :type="DICT_TYPE.${statusDictType.toUpperCase()}" :value="item.${statusField}" />
46 #end 48 #end
47 </view> 49 </view>
48 -#set ($infoCount = 0)  
49 #foreach($column in $columns) 50 #foreach($column in $columns)
50 #if ($column.listOperationResult && !$column.primaryKey && $column.javaField != $titleField && $column.javaField != $statusField) 51 #if ($column.listOperationResult && !$column.primaryKey && $column.javaField != $titleField && $column.javaField != $statusField)
51 - #if ($infoCount < 2)  
52 - <view class="mb-12rpx flex items-center text-28rpx text-[#666]">  
53 - <text class="mr-8rpx text-[#999]">${column.columnComment}:</text>  
54 - <text class="line-clamp-1">{{ item.${column.javaField} }}</text>  
55 - </view>  
56 - #set ($infoCount = $infoCount + 1) 52 + #set ($javaField = $column.javaField)
  53 + #set ($comment = $column.columnComment)
  54 + #set ($dictType = $column.dictType)
  55 + #set ($javaType = $column.javaType)
  56 + #if ($dictType && "" != $dictType)
  57 + <view class="mb-12rpx flex items-center text-28rpx text-[#666]">
  58 + <text class="mr-8rpx text-[#999]">${comment}:</text>
  59 + <dict-tag :type="DICT_TYPE.${dictType.toUpperCase()}" :value="item.${javaField}" />
  60 + </view>
  61 + #elseif ($javaType == "LocalDateTime")
  62 + <view class="mb-12rpx flex items-center text-28rpx text-[#666]">
  63 + <text class="mr-8rpx text-[#999]">${comment}:</text>
  64 + <text class="line-clamp-1">{{ formatDateTime(item.${javaField}) || '-' }}</text>
  65 + </view>
  66 + #else
  67 + <view class="mb-12rpx flex items-center text-28rpx text-[#666]">
  68 + <text class="mr-8rpx text-[#999]">${comment}:</text>
  69 + <text class="line-clamp-1">{{ item.${javaField} }}</text>
  70 + </view>
57 #end 71 #end
58 #end 72 #end
59 #end 73 #end
@@ -83,6 +97,20 @@ @@ -83,6 +97,20 @@
83 </template> 97 </template>
84 98
85 <script lang="ts" setup> 99 <script lang="ts" setup>
  100 +#set ($hasDict = 0)
  101 +#foreach($column in $columns)
  102 + #if ($hasDict == 0 && $column.listOperationResult && $column.dictType && "" != $column.dictType)
  103 + #set ($hasDict = 1)
  104 + #end
  105 +#end
  106 +#set ($hasDateTime = 0)
  107 +#foreach($column in $columns)
  108 + #if ($column.listOperationResult)
  109 + #if ($hasDateTime == 0 && $column.javaType == "LocalDateTime")
  110 + #set ($hasDateTime = 1)
  111 + #end
  112 + #end
  113 +#end
86 import type { SearchFormData } from './components/search-form.vue' 114 import type { SearchFormData } from './components/search-form.vue'
87 import type { ${simpleClassName} } from '@/api/${table.moduleName}/${table.businessName}' 115 import type { ${simpleClassName} } from '@/api/${table.moduleName}/${table.businessName}'
88 import type { LoadMoreState } from '@/http/types' 116 import type { LoadMoreState } from '@/http/types'
@@ -91,16 +119,13 @@ import { onMounted, reactive, ref } from &#39;vue&#39; @@ -91,16 +119,13 @@ import { onMounted, reactive, ref } from &#39;vue&#39;
91 import { get${simpleClassName}Page } from '@/api/${table.moduleName}/${table.businessName}' 119 import { get${simpleClassName}Page } from '@/api/${table.moduleName}/${table.businessName}'
92 import { useAccess } from '@/hooks/useAccess' 120 import { useAccess } from '@/hooks/useAccess'
93 import { navigateBackPlus } from '@/utils' 121 import { navigateBackPlus } from '@/utils'
94 -import SearchForm from './components/search-form.vue'  
95 -#set ($hasDict = 0)  
96 -#foreach($column in $columns)  
97 - #if ($hasDict == 0 && $column.listOperationResult && $column.dictType && "" != $column.dictType)  
98 - #set ($hasDict = 1)  
99 - #end  
100 -#end  
101 #if ($hasDict == 1) 122 #if ($hasDict == 1)
102 import { DICT_TYPE } from '@/utils/constants' 123 import { DICT_TYPE } from '@/utils/constants'
103 #end 124 #end
  125 +#if ($hasDateTime == 1)
  126 +import { formatDateTime } from '@/utils/date'
  127 +#end
  128 +import SearchForm from './components/search-form.vue'
104 129
105 definePage({ 130 definePage({
106 style: { 131 style: {
@@ -112,8 +137,7 @@ definePage({ @@ -112,8 +137,7 @@ definePage({
112 const { hasAccessByCodes } = useAccess() 137 const { hasAccessByCodes } = useAccess()
113 const total = ref(0) 138 const total = ref(0)
114 const list = ref<${simpleClassName}[]>([]) 139 const list = ref<${simpleClassName}[]>([])
115 -const loadMoreState = ref<LoadMoreState>('loading') // 加载更多状态  
116 - 140 +const loadMoreState = ref<LoadMoreState>('loading')
117 const queryParams = reactive({ 141 const queryParams = reactive({
118 pageNo: 1, 142 pageNo: 1,
119 pageSize: 10, 143 pageSize: 10,
@@ -201,7 +225,7 @@ function handleAdd() { @@ -201,7 +225,7 @@ function handleAdd() {
201 /** 查看详情 */ 225 /** 查看详情 */
202 function handleDetail(item: ${simpleClassName}) { 226 function handleDetail(item: ${simpleClassName}) {
203 uni.navigateTo({ 227 uni.navigateTo({
204 - url: '/pages-${table.moduleName}/${table.businessName}/detail/index?id=' + item.${primaryColumn.javaField}, 228 + url: `/pages-${table.moduleName}/${table.businessName}/detail/index?id=#[[${]]#item.${primaryColumn.javaField}#[[}]]#`,
205 }) 229 })
206 } 230 }
207 231