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