Commit 3861fdf4515d9066b33e28501fa7620a8bfb7779

Authored by YunaiV
1 parent 4ce201c5

feat:【infra】移动端 admin uniapp 的代码生成的优化(增加时间范围的条件生成)

yudao-module-infra/src/main/resources/codegen/vue3_admin_uniapp/components/search-form.vue.vm
1 -<!-- TODO @AI:参考 /Users/yunai/Java/yudao-ui-admin-uniapp-next-v4/src/pages/message/components/search-form.vue 和 /Users/yunai/Java/yudao-ui-admin-uniapp-next-v4/src/pages/message/index.vue,实现对 time + 范围的处理; -->  
2 <template> 1 <template>
3 <!-- 搜索框入口 --> 2 <!-- 搜索框入口 -->
4 <wd-search 3 <wd-search
5 - :placeholder="searchPlaceholder" 4 + :placeholder="placeholder"
6 :hide-cancel="true" 5 :hide-cancel="true"
7 disabled 6 disabled
8 @click="visible = true" 7 @click="visible = true"
@@ -174,9 +173,9 @@ @@ -174,9 +173,9 @@
174 #set ($hasDateTimeBetween = 1) 173 #set ($hasDateTimeBetween = 1)
175 #end 174 #end
176 #end 175 #end
177 -import { computed, reactive, ref, watch } from 'vue' 176 +import { computed, reactive, ref } from 'vue'
178 #if ($hasDateTimeBetween == 1) 177 #if ($hasDateTimeBetween == 1)
179 -import { formatDate } from '@/utils/date' 178 +import { formatDate, formatDateRange } from '@/utils/date'
180 #end 179 #end
181 #if ($hasDict == 1) 180 #if ($hasDict == 1)
182 #set ($dictImportNames = "getDictLabel, ") 181 #set ($dictImportNames = "getDictLabel, ")
@@ -198,65 +197,39 @@ import { $dictImportNames } from &#39;@/hooks/useDict&#39; @@ -198,65 +197,39 @@ import { $dictImportNames } from &#39;@/hooks/useDict&#39;
198 import { DICT_TYPE } from '@/utils/constants' 197 import { DICT_TYPE } from '@/utils/constants'
199 #end 198 #end
200 199
201 -/** 搜索表单数据 */  
202 -export interface SearchFormData {  
203 -#foreach($column in $columns)  
204 - #if ($column.listOperation)  
205 - #set ($javaType = $column.javaType.toLowerCase())  
206 - #if ($column.htmlType == "datetime" && $column.listOperationCondition == "BETWEEN")  
207 - ${column.javaField}?: [number | undefined, number | undefined]  
208 - #elseif ($column.dictType && "" != $column.dictType)  
209 - #if(${javaType} == "string")  
210 - ${column.javaField}?: string | number  
211 - #elseif(${javaType} == "boolean")  
212 - ${column.javaField}?: boolean | number  
213 - #else  
214 - ${column.javaField}?: number  
215 - #end  
216 - #elseif(${javaType} == "long" || ${javaType} == "integer" || ${javaType} == "short" || ${javaType} == "double" || ${javaType} == "bigdecimal" || ${javaType} == "byte")  
217 - ${column.javaField}?: number  
218 - #elseif(${javaType} == "boolean")  
219 - ${column.javaField}?: boolean  
220 - #else  
221 - ${column.javaField}?: string  
222 - #end  
223 - #end  
224 -#end  
225 -}  
226 -  
227 -const props = defineProps<{  
228 - searchParams?: Partial<SearchFormData>  
229 -}>()  
230 -  
231 const emit = defineEmits<{ 200 const emit = defineEmits<{
232 - search: [data: SearchFormData] 201 + search: [data: Record<string, any>]
233 reset: [] 202 reset: []
234 }>() 203 }>()
235 204
236 const visible = ref(false) 205 const visible = ref(false)
237 -const formData = reactive<SearchFormData>({ 206 +const formData = reactive({
238 #foreach($column in $columns) 207 #foreach($column in $columns)
239 #if ($column.listOperation) 208 #if ($column.listOperation)
  209 + #set ($javaType = $column.javaType.toLowerCase())
240 #if ($column.htmlType == "datetime" && $column.listOperationCondition == "BETWEEN") 210 #if ($column.htmlType == "datetime" && $column.listOperationCondition == "BETWEEN")
241 ${column.javaField}: [undefined, undefined] as [number | undefined, number | undefined], 211 ${column.javaField}: [undefined, undefined] as [number | undefined, number | undefined],
242 #elseif ($column.dictType && "" != $column.dictType) 212 #elseif ($column.dictType && "" != $column.dictType)
243 - #set ($javaType = $column.javaType.toLowerCase())  
244 #if(${javaType} == "string") 213 #if(${javaType} == "string")
245 - ${column.javaField}: -1 as number | string, 214 + ${column.javaField}: -1 as -1 | string, // -1 表示全部
246 #elseif(${javaType} == "boolean") 215 #elseif(${javaType} == "boolean")
247 - ${column.javaField}: -1 as number | boolean, 216 + ${column.javaField}: -1 as -1 | boolean, // -1 表示全部
248 #else 217 #else
249 - ${column.javaField}: -1 as number, 218 + ${column.javaField}: -1, // -1 表示全部
250 #end 219 #end
  220 + #elseif(${javaType} == "long" || ${javaType} == "integer" || ${javaType} == "short" || ${javaType} == "double" || ${javaType} == "bigdecimal" || ${javaType} == "byte")
  221 + ${column.javaField}: undefined as number | undefined,
  222 + #elseif(${javaType} == "boolean")
  223 + ${column.javaField}: undefined as boolean | undefined,
251 #else 224 #else
252 - ${column.javaField}: undefined, 225 + ${column.javaField}: undefined as string | undefined,
253 #end 226 #end
254 #end 227 #end
255 #end 228 #end
256 }) 229 })
257 230
258 /** 搜索条件 placeholder 拼接 */ 231 /** 搜索条件 placeholder 拼接 */
259 -const searchPlaceholder = computed(() => { 232 +const placeholder = computed(() => {
260 const conditions: string[] = [] 233 const conditions: string[] = []
261 #foreach($column in $columns) 234 #foreach($column in $columns)
262 #if ($column.listOperation) 235 #if ($column.listOperation)
@@ -265,46 +238,29 @@ const searchPlaceholder = computed(() =&gt; { @@ -265,46 +238,29 @@ const searchPlaceholder = computed(() =&gt; {
265 #set ($javaType = $column.javaType.toLowerCase()) 238 #set ($javaType = $column.javaType.toLowerCase())
266 #set ($comment = $column.columnComment) 239 #set ($comment = $column.columnComment)
267 #if ($column.htmlType == "datetime" && $column.listOperationCondition == "BETWEEN") 240 #if ($column.htmlType == "datetime" && $column.listOperationCondition == "BETWEEN")
268 - if (props.searchParams?.${javaField}?.[0] && props.searchParams?.${javaField}?.[1]) {  
269 - conditions.push(`${comment}:#[[${]]#formatDate(props.searchParams.${javaField}[0])#[[}]]#~#[[${]]#formatDate(props.searchParams.${javaField}[1])#[[}]]#`) 241 + if (formData.${javaField}?.[0] && formData.${javaField}?.[1]) {
  242 + conditions.push(`${comment}:#[[${]]#formatDate(formData.${javaField}[0])#[[}]]#~#[[${]]#formatDate(formData.${javaField}[1])#[[}]]#`)
270 } 243 }
271 #elseif ($dictType && "" != $dictType) 244 #elseif ($dictType && "" != $dictType)
272 - if (props.searchParams?.${javaField} !== undefined && props.searchParams.${javaField} !== -1) {  
273 - conditions.push(`${comment}:#[[${]]#getDictLabel(DICT_TYPE.${dictType.toUpperCase()}, props.searchParams.${javaField})#[[}]]#`) 245 + if (formData.${javaField} !== -1) {
  246 + conditions.push(`${comment}:#[[${]]#getDictLabel(DICT_TYPE.${dictType.toUpperCase()}, formData.${javaField})#[[}]]#`)
274 } 247 }
275 #else 248 #else
276 - #if(${javaType} == "long" || ${javaType} == "integer" || ${javaType} == "short" || ${javaType} == "double" || ${javaType} == "bigdecimal" || ${javaType} == "byte" || ${javaType} == "boolean")  
277 - if (props.searchParams?.${javaField} !== undefined) {  
278 - conditions.push(`${comment}:#[[${]]#props.searchParams.${javaField}#[[}]]#`) 249 + #if(${javaType} == "long" || ${javaType} == "integer" || ${javaType} == "short" || ${javaType} == "double" || ${javaType} == "bigdecimal" || ${javaType} == "byte" || ${javaType} == "boolean")
  250 + if (formData.${javaField} !== undefined) {
  251 + conditions.push(`${comment}:#[[${]]#formData.${javaField}#[[}]]#`)
279 } 252 }
280 - #else  
281 - if (props.searchParams?.${javaField}) {  
282 - conditions.push(`${comment}:#[[${]]#props.searchParams.${javaField}#[[}]]#`) 253 + #else
  254 + if (formData.${javaField}) {
  255 + conditions.push(`${comment}:#[[${]]#formData.${javaField}#[[}]]#`)
283 } 256 }
284 - #end 257 + #end
285 #end 258 #end
286 #end 259 #end
287 #end 260 #end
288 return conditions.length > 0 ? conditions.join(' | ') : '搜索${table.classComment}' 261 return conditions.length > 0 ? conditions.join(' | ') : '搜索${table.classComment}'
289 }) 262 })
290 263
291 -/** 监听弹窗打开,同步外部参数 */  
292 -watch(visible, (val) => {  
293 - if (val && props.searchParams) {  
294 -#foreach($column in $columns)  
295 - #if ($column.listOperation)  
296 - #if ($column.htmlType == "datetime" && $column.listOperationCondition == "BETWEEN")  
297 - formData.${column.javaField} = props.searchParams.${column.javaField} ?? [undefined, undefined]  
298 - #elseif ($column.dictType && "" != $column.dictType)  
299 - formData.${column.javaField} = props.searchParams.${column.javaField} ?? -1  
300 - #else  
301 - formData.${column.javaField} = props.searchParams.${column.javaField}  
302 - #end  
303 - #end  
304 -#end  
305 - }  
306 -})  
307 -  
308 #if ($hasDateTimeBetween == 1) 264 #if ($hasDateTimeBetween == 1)
309 // 时间范围选择器状态 265 // 时间范围选择器状态
310 #foreach($column in $columns) 266 #foreach($column in $columns)
@@ -342,7 +298,18 @@ function handle${AttrName}1Cancel() { @@ -342,7 +298,18 @@ function handle${AttrName}1Cancel() {
342 /** 搜索 */ 298 /** 搜索 */
343 function handleSearch() { 299 function handleSearch() {
344 visible.value = false 300 visible.value = false
345 - emit('search', { ...formData } as SearchFormData) 301 + emit('search', {
  302 + ...formData,
  303 +#foreach($column in $columns)
  304 + #if ($column.listOperation)
  305 + #if ($column.dictType && "" != $column.dictType)
  306 + ${column.javaField}: formData.${column.javaField} === -1 ? undefined : formData.${column.javaField},
  307 + #elseif ($column.htmlType == "datetime" && $column.listOperationCondition == "BETWEEN")
  308 + ${column.javaField}: formatDateRange(formData.${column.javaField}),
  309 + #end
  310 + #end
  311 +#end
  312 + })
346 } 313 }
347 314
348 /** 重置 */ 315 /** 重置 */
@@ -362,3 +329,4 @@ function handleReset() { @@ -362,3 +329,4 @@ function handleReset() {
362 emit('reset') 329 emit('reset')
363 } 330 }
364 </script> 331 </script>
  332 +
yudao-module-infra/src/main/resources/codegen/vue3_admin_uniapp/views/index.vue.vm
@@ -8,11 +8,7 @@ @@ -8,11 +8,7 @@
8 /> 8 />
9 9
10 <!-- 搜索组件 --> 10 <!-- 搜索组件 -->
11 - <SearchForm  
12 - :search-params="queryParams"  
13 - @search="handleQuery"  
14 - @reset="handleReset"  
15 - /> 11 + <SearchForm @search="handleQuery" @reset="handleReset" />
16 12
17 <!-- ${table.classComment}列表 --> 13 <!-- ${table.classComment}列表 -->
18 <view class="p-24rpx"> 14 <view class="p-24rpx">
@@ -111,17 +107,10 @@ @@ -111,17 +107,10 @@
111 #end 107 #end
112 #end 108 #end
113 #end 109 #end
114 -#set ($hasDateTimeBetween = 0)  
115 -#foreach($column in $columns)  
116 - #if ($hasDateTimeBetween == 0 && $column.listOperation && $column.htmlType == "datetime" && $column.listOperationCondition == "BETWEEN")  
117 - #set ($hasDateTimeBetween = 1)  
118 - #end  
119 -#end  
120 -import type { SearchFormData } from './components/search-form.vue'  
121 import type { ${simpleClassName} } from '@/api/${table.moduleName}/${table.businessName}' 110 import type { ${simpleClassName} } from '@/api/${table.moduleName}/${table.businessName}'
122 import type { LoadMoreState } from '@/http/types' 111 import type { LoadMoreState } from '@/http/types'
123 import { onReachBottom } from '@dcloudio/uni-app' 112 import { onReachBottom } from '@dcloudio/uni-app'
124 -import { onMounted, reactive, ref } from 'vue' 113 +import { onMounted, ref } from 'vue'
125 import { get${simpleClassName}Page } from '@/api/${table.moduleName}/${table.businessName}' 114 import { get${simpleClassName}Page } from '@/api/${table.moduleName}/${table.businessName}'
126 import { useAccess } from '@/hooks/useAccess' 115 import { useAccess } from '@/hooks/useAccess'
127 import { navigateBackPlus } from '@/utils' 116 import { navigateBackPlus } from '@/utils'
@@ -131,9 +120,6 @@ import { DICT_TYPE } from &#39;@/utils/constants&#39; @@ -131,9 +120,6 @@ import { DICT_TYPE } from &#39;@/utils/constants&#39;
131 #if ($hasDateTime == 1) 120 #if ($hasDateTime == 1)
132 import { formatDateTime } from '@/utils/date' 121 import { formatDateTime } from '@/utils/date'
133 #end 122 #end
134 -#if ($hasDateTimeBetween == 1)  
135 -import { formatDateRange } from '@/utils/date'  
136 -#end  
137 import SearchForm from './components/search-form.vue' 123 import SearchForm from './components/search-form.vue'
138 124
139 definePage({ 125 definePage({
@@ -147,31 +133,9 @@ const { hasAccessByCodes } = useAccess() @@ -147,31 +133,9 @@ const { hasAccessByCodes } = useAccess()
147 const total = ref(0) 133 const total = ref(0)
148 const list = ref<${simpleClassName}[]>([]) 134 const list = ref<${simpleClassName}[]>([])
149 const loadMoreState = ref<LoadMoreState>('loading') 135 const loadMoreState = ref<LoadMoreState>('loading')
150 -const queryParams = reactive({ 136 +const queryParams = ref({
151 pageNo: 1, 137 pageNo: 1,
152 pageSize: 10, 138 pageSize: 10,
153 -#foreach($column in $columns)  
154 - #if ($column.listOperation)  
155 - #set ($javaType = $column.javaType.toLowerCase())  
156 - #if ($column.htmlType == "datetime" && $column.listOperationCondition == "BETWEEN")  
157 - ${column.javaField}: [undefined, undefined] as [number | undefined, number | undefined],  
158 - #elseif ($column.dictType && "" != $column.dictType)  
159 - #if(${javaType} == "string")  
160 - ${column.javaField}: -1 as number | string, // -1 表示全部  
161 - #elseif(${javaType} == "boolean")  
162 - ${column.javaField}: -1 as number | boolean, // -1 表示全部  
163 - #else  
164 - ${column.javaField}: -1 as number, // -1 表示全部  
165 - #end  
166 - #elseif(${javaType} == "long" || ${javaType} == "integer" || ${javaType} == "short" || ${javaType} == "double" || ${javaType} == "bigdecimal" || ${javaType} == "byte")  
167 - ${column.javaField}: undefined as number | undefined,  
168 - #elseif(${javaType} == "boolean")  
169 - ${column.javaField}: undefined as boolean | undefined,  
170 - #else  
171 - ${column.javaField}: undefined as string | undefined,  
172 - #end  
173 - #end  
174 -#end  
175 }) 139 })
176 140
177 /** 返回上一页 */ 141 /** 返回上一页 */
@@ -183,41 +147,23 @@ function handleBack() { @@ -183,41 +147,23 @@ function handleBack() {
183 async function getList() { 147 async function getList() {
184 loadMoreState.value = 'loading' 148 loadMoreState.value = 'loading'
185 try { 149 try {
186 - const params: any = { ...queryParams }  
187 -#foreach($column in $columns)  
188 - #if ($column.listOperation && $column.dictType && "" != $column.dictType)  
189 - params.${column.javaField} = queryParams.${column.javaField} === -1 ? undefined : queryParams.${column.javaField}  
190 - #end  
191 -#end  
192 -#foreach($column in $columns)  
193 - #if ($column.listOperation && $column.htmlType == "datetime" && $column.listOperationCondition == "BETWEEN")  
194 - params.${column.javaField} = formatDateRange(queryParams.${column.javaField})  
195 - #end  
196 -#end  
197 - const data = await get${simpleClassName}Page(params) 150 + const data = await get${simpleClassName}Page(queryParams.value)
198 list.value = [...list.value, ...data.list] 151 list.value = [...list.value, ...data.list]
199 total.value = data.total 152 total.value = data.total
200 loadMoreState.value = list.value.length >= total.value ? 'finished' : 'loading' 153 loadMoreState.value = list.value.length >= total.value ? 'finished' : 'loading'
201 } catch { 154 } catch {
202 - queryParams.pageNo = queryParams.pageNo > 1 ? queryParams.pageNo - 1 : 1 155 + queryParams.value.pageNo = queryParams.value.pageNo > 1 ? queryParams.value.pageNo - 1 : 1
203 loadMoreState.value = 'error' 156 loadMoreState.value = 'error'
204 } 157 }
205 } 158 }
206 159
207 /** 搜索按钮操作 */ 160 /** 搜索按钮操作 */
208 -function handleQuery(data?: SearchFormData) {  
209 -#foreach($column in $columns)  
210 - #if ($column.listOperation)  
211 - #if ($column.htmlType == "datetime" && $column.listOperationCondition == "BETWEEN")  
212 - queryParams.${column.javaField} = data?.${column.javaField} ?? [undefined, undefined]  
213 - #elseif ($column.dictType && "" != $column.dictType)  
214 - queryParams.${column.javaField} = data?.${column.javaField} ?? -1  
215 - #else  
216 - queryParams.${column.javaField} = data?.${column.javaField}  
217 - #end  
218 - #end  
219 -#end  
220 - queryParams.pageNo = 1 161 +function handleQuery(data?: Record<string, any>) {
  162 + queryParams.value = {
  163 + ...data,
  164 + pageNo: 1,
  165 + pageSize: queryParams.value.pageSize,
  166 + }
221 list.value = [] 167 list.value = []
222 getList() 168 getList()
223 } 169 }
@@ -232,7 +178,7 @@ function loadMore() { @@ -232,7 +178,7 @@ function loadMore() {
232 if (loadMoreState.value === 'finished') { 178 if (loadMoreState.value === 'finished') {
233 return 179 return
234 } 180 }
235 - queryParams.pageNo++ 181 + queryParams.value.pageNo++
236 getList() 182 getList()
237 } 183 }
238 184