feat:【infra】移动端 admin uniapp 的代码生成的优化(search-form、list 的模版)
This commit is contained in:
parent
94a1c4636f
commit
2a5ebb5ad1
@ -1,4 +1,5 @@
|
|||||||
<template>
|
<template>
|
||||||
|
<!-- 搜索框入口 -->
|
||||||
<wd-search
|
<wd-search
|
||||||
:placeholder="searchPlaceholder"
|
:placeholder="searchPlaceholder"
|
||||||
:hide-cancel="true"
|
:hide-cancel="true"
|
||||||
@ -6,6 +7,7 @@
|
|||||||
@click="visible = true"
|
@click="visible = true"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
<!-- 搜索弹窗 -->
|
||||||
<wd-popup
|
<wd-popup
|
||||||
v-model="visible"
|
v-model="visible"
|
||||||
position="top"
|
position="top"
|
||||||
@ -17,14 +19,12 @@
|
|||||||
<view class="mb-24rpx text-32rpx text-[#333] font-semibold">
|
<view class="mb-24rpx text-32rpx text-[#333] font-semibold">
|
||||||
搜索${table.classComment}
|
搜索${table.classComment}
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
#set ($hasDict = 0)
|
#set ($hasDict = 0)
|
||||||
#foreach ($column in $columns)
|
#foreach ($column in $columns)
|
||||||
#if ($hasDict == 0 && $column.listOperation && $column.dictType && "" != $column.dictType)
|
#if ($hasDict == 0 && $column.listOperation && $column.dictType && "" != $column.dictType)
|
||||||
#set ($hasDict = 1)
|
#set ($hasDict = 1)
|
||||||
#end
|
#end
|
||||||
#end
|
#end
|
||||||
|
|
||||||
#foreach($column in $columns)
|
#foreach($column in $columns)
|
||||||
#if ($column.listOperation)
|
#if ($column.listOperation)
|
||||||
#set ($dictType = $column.dictType)
|
#set ($dictType = $column.dictType)
|
||||||
@ -39,7 +39,6 @@
|
|||||||
#elseif ($javaType == "Boolean")
|
#elseif ($javaType == "Boolean")
|
||||||
#set ($dictMethod = "getBoolDictOptions")
|
#set ($dictMethod = "getBoolDictOptions")
|
||||||
#end
|
#end
|
||||||
|
|
||||||
#if ($column.htmlType == "input")
|
#if ($column.htmlType == "input")
|
||||||
<view class="mb-24rpx">
|
<view class="mb-24rpx">
|
||||||
<view class="mb-12rpx text-28rpx text-[#666]">
|
<view class="mb-12rpx text-28rpx text-[#666]">
|
||||||
@ -83,7 +82,6 @@
|
|||||||
#end
|
#end
|
||||||
#end
|
#end
|
||||||
#end
|
#end
|
||||||
|
|
||||||
<view class="w-full flex justify-center gap-24rpx">
|
<view class="w-full flex justify-center gap-24rpx">
|
||||||
<wd-button class="flex-1" plain @click="handleReset">
|
<wd-button class="flex-1" plain @click="handleReset">
|
||||||
重置
|
重置
|
||||||
@ -97,8 +95,6 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { computed, reactive, ref, watch } from 'vue'
|
|
||||||
|
|
||||||
#set ($hasDict = 0)
|
#set ($hasDict = 0)
|
||||||
#set ($hasGetDictOptions = 0)
|
#set ($hasGetDictOptions = 0)
|
||||||
#set ($hasGetIntDictOptions = 0)
|
#set ($hasGetIntDictOptions = 0)
|
||||||
@ -120,23 +116,25 @@ import { computed, reactive, ref, watch } from 'vue'
|
|||||||
#end
|
#end
|
||||||
#end
|
#end
|
||||||
#end
|
#end
|
||||||
|
import { computed, reactive, ref, watch } from 'vue'
|
||||||
#if ($hasDict == 1)
|
#if ($hasDict == 1)
|
||||||
import { DICT_TYPE } from '@/utils/constants'
|
#set ($dictImportNames = "getDictLabel, ")
|
||||||
import {
|
|
||||||
#if ($hasGetDictOptions == 1)
|
#if ($hasGetDictOptions == 1)
|
||||||
getDictOptions,
|
#set ($dictImportNames = "${dictImportNames}getDictOptions, ")
|
||||||
#end
|
#end
|
||||||
#if ($hasGetIntDictOptions == 1)
|
#if ($hasGetIntDictOptions == 1)
|
||||||
getIntDictOptions,
|
#set ($dictImportNames = "${dictImportNames}getIntDictOptions, ")
|
||||||
#end
|
#end
|
||||||
#if ($hasGetStrDictOptions == 1)
|
#if ($hasGetStrDictOptions == 1)
|
||||||
getStrDictOptions,
|
#set ($dictImportNames = "${dictImportNames}getStrDictOptions, ")
|
||||||
#end
|
#end
|
||||||
#if ($hasGetBoolDictOptions == 1)
|
#if ($hasGetBoolDictOptions == 1)
|
||||||
getBoolDictOptions,
|
#set ($dictImportNames = "${dictImportNames}getBoolDictOptions, ")
|
||||||
#end
|
#end
|
||||||
getDictLabel,
|
#set ($dictImportNames = $dictImportNames.trim())
|
||||||
} from '@/hooks/useDict'
|
#set ($dictImportNames = $dictImportNames.substring(0, $dictImportNames.length() - 1))
|
||||||
|
import { $dictImportNames } from '@/hooks/useDict'
|
||||||
|
import { DICT_TYPE } from '@/utils/constants'
|
||||||
#end
|
#end
|
||||||
|
|
||||||
/** 搜索表单数据 */
|
/** 搜索表单数据 */
|
||||||
@ -185,16 +183,16 @@ const searchPlaceholder = computed(() => {
|
|||||||
#set ($comment = $column.columnComment)
|
#set ($comment = $column.columnComment)
|
||||||
#if ($dictType && "" != $dictType)
|
#if ($dictType && "" != $dictType)
|
||||||
if (props.searchParams?.${javaField} !== undefined && props.searchParams.${javaField} !== -1) {
|
if (props.searchParams?.${javaField} !== undefined && props.searchParams.${javaField} !== -1) {
|
||||||
conditions.push('${comment}:' + getDictLabel(DICT_TYPE.$dictType.toUpperCase(), props.searchParams.${javaField}))
|
conditions.push(`${comment}:#[[${]]#getDictLabel(DICT_TYPE.${dictType.toUpperCase()}, props.searchParams.${javaField})#[[}]]#`)
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
#if(${javaType} == "long" || ${javaType} == "integer" || ${javaType} == "short" || ${javaType} == "double" || ${javaType} == "bigdecimal" || ${javaType} == "byte" || ${javaType} == "boolean")
|
#if(${javaType} == "long" || ${javaType} == "integer" || ${javaType} == "short" || ${javaType} == "double" || ${javaType} == "bigdecimal" || ${javaType} == "byte" || ${javaType} == "boolean")
|
||||||
if (props.searchParams?.${javaField} !== undefined) {
|
if (props.searchParams?.${javaField} !== undefined) {
|
||||||
conditions.push('${comment}:' + props.searchParams.${javaField})
|
conditions.push(`${comment}:#[[${]]#props.searchParams.${javaField}#[[}]]#`)
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
if (props.searchParams?.${javaField}) {
|
if (props.searchParams?.${javaField}) {
|
||||||
conditions.push('${comment}:' + props.searchParams.${javaField})
|
conditions.push(`${comment}:#[[${]]#props.searchParams.${javaField}#[[}]]#`)
|
||||||
}
|
}
|
||||||
#end
|
#end
|
||||||
#end
|
#end
|
||||||
@ -222,6 +220,7 @@ const formData = reactive<SearchFormData>({
|
|||||||
#end
|
#end
|
||||||
})
|
})
|
||||||
|
|
||||||
|
/** 监听弹窗打开,同步外部参数 */
|
||||||
watch(visible, (val) => {
|
watch(visible, (val) => {
|
||||||
if (val && props.searchParams) {
|
if (val && props.searchParams) {
|
||||||
#foreach($column in $columns)
|
#foreach($column in $columns)
|
||||||
@ -236,11 +235,13 @@ watch(visible, (val) => {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
/** 搜索 */
|
||||||
function handleSearch() {
|
function handleSearch() {
|
||||||
visible.value = false
|
visible.value = false
|
||||||
emit('search', { ...formData } as SearchFormData)
|
emit('search', { ...formData } as SearchFormData)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 重置 */
|
||||||
function handleReset() {
|
function handleReset() {
|
||||||
#foreach($column in $columns)
|
#foreach($column in $columns)
|
||||||
#if ($column.listOperation)
|
#if ($column.listOperation)
|
||||||
|
|||||||
@ -21,7 +21,7 @@
|
|||||||
#elseif ($column.javaType == "LocalDateTime")
|
#elseif ($column.javaType == "LocalDateTime")
|
||||||
<wd-cell title="${comment}" :value="formatDateTime(formData?.${javaField}) || '-'" />
|
<wd-cell title="${comment}" :value="formatDateTime(formData?.${javaField}) || '-'" />
|
||||||
#else
|
#else
|
||||||
<wd-cell title="${comment}" :value="String(formData?.${javaField} ?? '-')" />
|
<wd-cell title="${comment}" :value="formData?.${javaField} ?? '-'" />
|
||||||
#end
|
#end
|
||||||
#end
|
#end
|
||||||
#end
|
#end
|
||||||
@ -87,8 +87,8 @@ definePage({
|
|||||||
|
|
||||||
const { hasAccessByCodes } = useAccess()
|
const { hasAccessByCodes } = useAccess()
|
||||||
const toast = useToast()
|
const toast = useToast()
|
||||||
const formData = ref<${simpleClassName}>() // 详情数据
|
const formData = ref<${simpleClassName}>()
|
||||||
const deleting = ref(false) // 删除中
|
const deleting = ref(false)
|
||||||
|
|
||||||
/** 返回上一页 */
|
/** 返回上一页 */
|
||||||
function handleBack() {
|
function handleBack() {
|
||||||
@ -111,7 +111,7 @@ async function getDetail() {
|
|||||||
/** 编辑${table.classComment} */
|
/** 编辑${table.classComment} */
|
||||||
function handleEdit() {
|
function handleEdit() {
|
||||||
uni.navigateTo({
|
uni.navigateTo({
|
||||||
url: `/pages-${table.moduleName}/${table.businessName}/form/index?id=\${props.id}`,
|
url: `/pages-${table.moduleName}/${table.businessName}/form/index?id=#[[${]]#props.id#[[}]]#`,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -22,7 +22,6 @@
|
|||||||
class="mb-24rpx overflow-hidden rounded-12rpx bg-white shadow-sm"
|
class="mb-24rpx overflow-hidden rounded-12rpx bg-white shadow-sm"
|
||||||
@click="handleDetail(item)"
|
@click="handleDetail(item)"
|
||||||
>
|
>
|
||||||
<!-- TODO @AI:下面的 view 部分代码,缩进可能不太对; -->
|
|
||||||
<view class="p-24rpx">
|
<view class="p-24rpx">
|
||||||
#set ($titleField = "")
|
#set ($titleField = "")
|
||||||
#set ($statusField = "")
|
#set ($statusField = "")
|
||||||
@ -37,23 +36,38 @@
|
|||||||
#set ($statusDictType = $column.dictType)
|
#set ($statusDictType = $column.dictType)
|
||||||
#end
|
#end
|
||||||
#end
|
#end
|
||||||
|
#if ($titleField == "")
|
||||||
|
#set ($titleField = $primaryColumn.javaField)
|
||||||
|
#end
|
||||||
<view class="mb-16rpx flex items-center justify-between">
|
<view class="mb-16rpx flex items-center justify-between">
|
||||||
<view class="text-32rpx text-[#333] font-semibold">
|
<view class="text-32rpx text-[#333] font-semibold">
|
||||||
{{ item.#if($titleField != "")${titleField}#else ${primaryColumn.javaField}#end }}
|
{{ item.${titleField} }}
|
||||||
</view>
|
</view>
|
||||||
#if($statusField != "")
|
#if($statusField != "")
|
||||||
<dict-tag :type="DICT_TYPE.$statusDictType.toUpperCase()" :value="item.$statusField" />
|
<dict-tag :type="DICT_TYPE.${statusDictType.toUpperCase()}" :value="item.${statusField}" />
|
||||||
#end
|
#end
|
||||||
</view>
|
</view>
|
||||||
#set ($infoCount = 0)
|
|
||||||
#foreach($column in $columns)
|
#foreach($column in $columns)
|
||||||
#if ($column.listOperationResult && !$column.primaryKey && $column.javaField != $titleField && $column.javaField != $statusField)
|
#if ($column.listOperationResult && !$column.primaryKey && $column.javaField != $titleField && $column.javaField != $statusField)
|
||||||
#if ($infoCount < 2)
|
#set ($javaField = $column.javaField)
|
||||||
<view class="mb-12rpx flex items-center text-28rpx text-[#666]">
|
#set ($comment = $column.columnComment)
|
||||||
<text class="mr-8rpx text-[#999]">${column.columnComment}:</text>
|
#set ($dictType = $column.dictType)
|
||||||
<text class="line-clamp-1">{{ item.${column.javaField} }}</text>
|
#set ($javaType = $column.javaType)
|
||||||
</view>
|
#if ($dictType && "" != $dictType)
|
||||||
#set ($infoCount = $infoCount + 1)
|
<view class="mb-12rpx flex items-center text-28rpx text-[#666]">
|
||||||
|
<text class="mr-8rpx text-[#999]">${comment}:</text>
|
||||||
|
<dict-tag :type="DICT_TYPE.${dictType.toUpperCase()}" :value="item.${javaField}" />
|
||||||
|
</view>
|
||||||
|
#elseif ($javaType == "LocalDateTime")
|
||||||
|
<view class="mb-12rpx flex items-center text-28rpx text-[#666]">
|
||||||
|
<text class="mr-8rpx text-[#999]">${comment}:</text>
|
||||||
|
<text class="line-clamp-1">{{ formatDateTime(item.${javaField}) || '-' }}</text>
|
||||||
|
</view>
|
||||||
|
#else
|
||||||
|
<view class="mb-12rpx flex items-center text-28rpx text-[#666]">
|
||||||
|
<text class="mr-8rpx text-[#999]">${comment}:</text>
|
||||||
|
<text class="line-clamp-1">{{ item.${javaField} }}</text>
|
||||||
|
</view>
|
||||||
#end
|
#end
|
||||||
#end
|
#end
|
||||||
#end
|
#end
|
||||||
@ -83,6 +97,20 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
|
#set ($hasDict = 0)
|
||||||
|
#foreach($column in $columns)
|
||||||
|
#if ($hasDict == 0 && $column.listOperationResult && $column.dictType && "" != $column.dictType)
|
||||||
|
#set ($hasDict = 1)
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
#set ($hasDateTime = 0)
|
||||||
|
#foreach($column in $columns)
|
||||||
|
#if ($column.listOperationResult)
|
||||||
|
#if ($hasDateTime == 0 && $column.javaType == "LocalDateTime")
|
||||||
|
#set ($hasDateTime = 1)
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
#end
|
||||||
import type { SearchFormData } from './components/search-form.vue'
|
import type { SearchFormData } from './components/search-form.vue'
|
||||||
import type { ${simpleClassName} } from '@/api/${table.moduleName}/${table.businessName}'
|
import type { ${simpleClassName} } from '@/api/${table.moduleName}/${table.businessName}'
|
||||||
import type { LoadMoreState } from '@/http/types'
|
import type { LoadMoreState } from '@/http/types'
|
||||||
@ -91,16 +119,13 @@ import { onMounted, reactive, ref } from 'vue'
|
|||||||
import { get${simpleClassName}Page } from '@/api/${table.moduleName}/${table.businessName}'
|
import { get${simpleClassName}Page } from '@/api/${table.moduleName}/${table.businessName}'
|
||||||
import { useAccess } from '@/hooks/useAccess'
|
import { useAccess } from '@/hooks/useAccess'
|
||||||
import { navigateBackPlus } from '@/utils'
|
import { navigateBackPlus } from '@/utils'
|
||||||
import SearchForm from './components/search-form.vue'
|
|
||||||
#set ($hasDict = 0)
|
|
||||||
#foreach($column in $columns)
|
|
||||||
#if ($hasDict == 0 && $column.listOperationResult && $column.dictType && "" != $column.dictType)
|
|
||||||
#set ($hasDict = 1)
|
|
||||||
#end
|
|
||||||
#end
|
|
||||||
#if ($hasDict == 1)
|
#if ($hasDict == 1)
|
||||||
import { DICT_TYPE } from '@/utils/constants'
|
import { DICT_TYPE } from '@/utils/constants'
|
||||||
#end
|
#end
|
||||||
|
#if ($hasDateTime == 1)
|
||||||
|
import { formatDateTime } from '@/utils/date'
|
||||||
|
#end
|
||||||
|
import SearchForm from './components/search-form.vue'
|
||||||
|
|
||||||
definePage({
|
definePage({
|
||||||
style: {
|
style: {
|
||||||
@ -112,8 +137,7 @@ definePage({
|
|||||||
const { hasAccessByCodes } = useAccess()
|
const { hasAccessByCodes } = useAccess()
|
||||||
const total = ref(0)
|
const total = ref(0)
|
||||||
const list = ref<${simpleClassName}[]>([])
|
const list = ref<${simpleClassName}[]>([])
|
||||||
const loadMoreState = ref<LoadMoreState>('loading') // 加载更多状态
|
const loadMoreState = ref<LoadMoreState>('loading')
|
||||||
|
|
||||||
const queryParams = reactive({
|
const queryParams = reactive({
|
||||||
pageNo: 1,
|
pageNo: 1,
|
||||||
pageSize: 10,
|
pageSize: 10,
|
||||||
@ -201,7 +225,7 @@ function handleAdd() {
|
|||||||
/** 查看详情 */
|
/** 查看详情 */
|
||||||
function handleDetail(item: ${simpleClassName}) {
|
function handleDetail(item: ${simpleClassName}) {
|
||||||
uni.navigateTo({
|
uni.navigateTo({
|
||||||
url: '/pages-${table.moduleName}/${table.businessName}/detail/index?id=' + item.${primaryColumn.javaField},
|
url: `/pages-${table.moduleName}/${table.businessName}/detail/index?id=#[[${]]#item.${primaryColumn.javaField}#[[}]]#`,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user