mirror of
https://gitee.com/yudaocode/yudao-boot-mini.git
synced 2026-03-22 05:27:15 +08:00
feat:【infra】移动端 admin uniapp 的代码生成的优化(增加时间范围的条件生成)
This commit is contained in:
@@ -1,8 +1,7 @@
|
||||
<!-- 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 + 范围的处理; -->
|
||||
<template>
|
||||
<!-- 搜索框入口 -->
|
||||
<wd-search
|
||||
:placeholder="searchPlaceholder"
|
||||
:placeholder="placeholder"
|
||||
:hide-cancel="true"
|
||||
disabled
|
||||
@click="visible = true"
|
||||
@@ -174,9 +173,9 @@
|
||||
#set ($hasDateTimeBetween = 1)
|
||||
#end
|
||||
#end
|
||||
import { computed, reactive, ref, watch } from 'vue'
|
||||
import { computed, reactive, ref } from 'vue'
|
||||
#if ($hasDateTimeBetween == 1)
|
||||
import { formatDate } from '@/utils/date'
|
||||
import { formatDate, formatDateRange } from '@/utils/date'
|
||||
#end
|
||||
#if ($hasDict == 1)
|
||||
#set ($dictImportNames = "getDictLabel, ")
|
||||
@@ -198,65 +197,39 @@ import { $dictImportNames } from '@/hooks/useDict'
|
||||
import { DICT_TYPE } from '@/utils/constants'
|
||||
#end
|
||||
|
||||
/** 搜索表单数据 */
|
||||
export interface SearchFormData {
|
||||
#foreach($column in $columns)
|
||||
#if ($column.listOperation)
|
||||
#set ($javaType = $column.javaType.toLowerCase())
|
||||
#if ($column.htmlType == "datetime" && $column.listOperationCondition == "BETWEEN")
|
||||
${column.javaField}?: [number | undefined, number | undefined]
|
||||
#elseif ($column.dictType && "" != $column.dictType)
|
||||
#if(${javaType} == "string")
|
||||
${column.javaField}?: string | number
|
||||
#elseif(${javaType} == "boolean")
|
||||
${column.javaField}?: boolean | number
|
||||
#else
|
||||
${column.javaField}?: number
|
||||
#end
|
||||
#elseif(${javaType} == "long" || ${javaType} == "integer" || ${javaType} == "short" || ${javaType} == "double" || ${javaType} == "bigdecimal" || ${javaType} == "byte")
|
||||
${column.javaField}?: number
|
||||
#elseif(${javaType} == "boolean")
|
||||
${column.javaField}?: boolean
|
||||
#else
|
||||
${column.javaField}?: string
|
||||
#end
|
||||
#end
|
||||
#end
|
||||
}
|
||||
|
||||
const props = defineProps<{
|
||||
searchParams?: Partial<SearchFormData>
|
||||
}>()
|
||||
|
||||
const emit = defineEmits<{
|
||||
search: [data: SearchFormData]
|
||||
search: [data: Record<string, any>]
|
||||
reset: []
|
||||
}>()
|
||||
|
||||
const visible = ref(false)
|
||||
const formData = reactive<SearchFormData>({
|
||||
const formData = reactive({
|
||||
#foreach($column in $columns)
|
||||
#if ($column.listOperation)
|
||||
#set ($javaType = $column.javaType.toLowerCase())
|
||||
#if ($column.htmlType == "datetime" && $column.listOperationCondition == "BETWEEN")
|
||||
${column.javaField}: [undefined, undefined] as [number | undefined, number | undefined],
|
||||
#elseif ($column.dictType && "" != $column.dictType)
|
||||
#set ($javaType = $column.javaType.toLowerCase())
|
||||
#if(${javaType} == "string")
|
||||
${column.javaField}: -1 as number | string,
|
||||
${column.javaField}: -1 as -1 | string, // -1 表示全部
|
||||
#elseif(${javaType} == "boolean")
|
||||
${column.javaField}: -1 as number | boolean,
|
||||
${column.javaField}: -1 as -1 | boolean, // -1 表示全部
|
||||
#else
|
||||
${column.javaField}: -1 as number,
|
||||
${column.javaField}: -1, // -1 表示全部
|
||||
#end
|
||||
#elseif(${javaType} == "long" || ${javaType} == "integer" || ${javaType} == "short" || ${javaType} == "double" || ${javaType} == "bigdecimal" || ${javaType} == "byte")
|
||||
${column.javaField}: undefined as number | undefined,
|
||||
#elseif(${javaType} == "boolean")
|
||||
${column.javaField}: undefined as boolean | undefined,
|
||||
#else
|
||||
${column.javaField}: undefined,
|
||||
${column.javaField}: undefined as string | undefined,
|
||||
#end
|
||||
#end
|
||||
#end
|
||||
})
|
||||
|
||||
/** 搜索条件 placeholder 拼接 */
|
||||
const searchPlaceholder = computed(() => {
|
||||
const placeholder = computed(() => {
|
||||
const conditions: string[] = []
|
||||
#foreach($column in $columns)
|
||||
#if ($column.listOperation)
|
||||
@@ -265,46 +238,29 @@ const searchPlaceholder = computed(() => {
|
||||
#set ($javaType = $column.javaType.toLowerCase())
|
||||
#set ($comment = $column.columnComment)
|
||||
#if ($column.htmlType == "datetime" && $column.listOperationCondition == "BETWEEN")
|
||||
if (props.searchParams?.${javaField}?.[0] && props.searchParams?.${javaField}?.[1]) {
|
||||
conditions.push(`${comment}:#[[${]]#formatDate(props.searchParams.${javaField}[0])#[[}]]#~#[[${]]#formatDate(props.searchParams.${javaField}[1])#[[}]]#`)
|
||||
if (formData.${javaField}?.[0] && formData.${javaField}?.[1]) {
|
||||
conditions.push(`${comment}:#[[${]]#formatDate(formData.${javaField}[0])#[[}]]#~#[[${]]#formatDate(formData.${javaField}[1])#[[}]]#`)
|
||||
}
|
||||
#elseif ($dictType && "" != $dictType)
|
||||
if (props.searchParams?.${javaField} !== undefined && props.searchParams.${javaField} !== -1) {
|
||||
conditions.push(`${comment}:#[[${]]#getDictLabel(DICT_TYPE.${dictType.toUpperCase()}, props.searchParams.${javaField})#[[}]]#`)
|
||||
if (formData.${javaField} !== -1) {
|
||||
conditions.push(`${comment}:#[[${]]#getDictLabel(DICT_TYPE.${dictType.toUpperCase()}, formData.${javaField})#[[}]]#`)
|
||||
}
|
||||
#else
|
||||
#if(${javaType} == "long" || ${javaType} == "integer" || ${javaType} == "short" || ${javaType} == "double" || ${javaType} == "bigdecimal" || ${javaType} == "byte" || ${javaType} == "boolean")
|
||||
if (props.searchParams?.${javaField} !== undefined) {
|
||||
conditions.push(`${comment}:#[[${]]#props.searchParams.${javaField}#[[}]]#`)
|
||||
#if(${javaType} == "long" || ${javaType} == "integer" || ${javaType} == "short" || ${javaType} == "double" || ${javaType} == "bigdecimal" || ${javaType} == "byte" || ${javaType} == "boolean")
|
||||
if (formData.${javaField} !== undefined) {
|
||||
conditions.push(`${comment}:#[[${]]#formData.${javaField}#[[}]]#`)
|
||||
}
|
||||
#else
|
||||
if (props.searchParams?.${javaField}) {
|
||||
conditions.push(`${comment}:#[[${]]#props.searchParams.${javaField}#[[}]]#`)
|
||||
#else
|
||||
if (formData.${javaField}) {
|
||||
conditions.push(`${comment}:#[[${]]#formData.${javaField}#[[}]]#`)
|
||||
}
|
||||
#end
|
||||
#end
|
||||
#end
|
||||
#end
|
||||
#end
|
||||
return conditions.length > 0 ? conditions.join(' | ') : '搜索${table.classComment}'
|
||||
})
|
||||
|
||||
/** 监听弹窗打开,同步外部参数 */
|
||||
watch(visible, (val) => {
|
||||
if (val && props.searchParams) {
|
||||
#foreach($column in $columns)
|
||||
#if ($column.listOperation)
|
||||
#if ($column.htmlType == "datetime" && $column.listOperationCondition == "BETWEEN")
|
||||
formData.${column.javaField} = props.searchParams.${column.javaField} ?? [undefined, undefined]
|
||||
#elseif ($column.dictType && "" != $column.dictType)
|
||||
formData.${column.javaField} = props.searchParams.${column.javaField} ?? -1
|
||||
#else
|
||||
formData.${column.javaField} = props.searchParams.${column.javaField}
|
||||
#end
|
||||
#end
|
||||
#end
|
||||
}
|
||||
})
|
||||
|
||||
#if ($hasDateTimeBetween == 1)
|
||||
// 时间范围选择器状态
|
||||
#foreach($column in $columns)
|
||||
@@ -342,7 +298,18 @@ function handle${AttrName}1Cancel() {
|
||||
/** 搜索 */
|
||||
function handleSearch() {
|
||||
visible.value = false
|
||||
emit('search', { ...formData } as SearchFormData)
|
||||
emit('search', {
|
||||
...formData,
|
||||
#foreach($column in $columns)
|
||||
#if ($column.listOperation)
|
||||
#if ($column.dictType && "" != $column.dictType)
|
||||
${column.javaField}: formData.${column.javaField} === -1 ? undefined : formData.${column.javaField},
|
||||
#elseif ($column.htmlType == "datetime" && $column.listOperationCondition == "BETWEEN")
|
||||
${column.javaField}: formatDateRange(formData.${column.javaField}),
|
||||
#end
|
||||
#end
|
||||
#end
|
||||
})
|
||||
}
|
||||
|
||||
/** 重置 */
|
||||
@@ -362,3 +329,4 @@ function handleReset() {
|
||||
emit('reset')
|
||||
}
|
||||
</script>
|
||||
|
||||
|
||||
@@ -8,11 +8,7 @@
|
||||
/>
|
||||
|
||||
<!-- 搜索组件 -->
|
||||
<SearchForm
|
||||
:search-params="queryParams"
|
||||
@search="handleQuery"
|
||||
@reset="handleReset"
|
||||
/>
|
||||
<SearchForm @search="handleQuery" @reset="handleReset" />
|
||||
|
||||
<!-- ${table.classComment}列表 -->
|
||||
<view class="p-24rpx">
|
||||
@@ -111,17 +107,10 @@
|
||||
#end
|
||||
#end
|
||||
#end
|
||||
#set ($hasDateTimeBetween = 0)
|
||||
#foreach($column in $columns)
|
||||
#if ($hasDateTimeBetween == 0 && $column.listOperation && $column.htmlType == "datetime" && $column.listOperationCondition == "BETWEEN")
|
||||
#set ($hasDateTimeBetween = 1)
|
||||
#end
|
||||
#end
|
||||
import type { SearchFormData } from './components/search-form.vue'
|
||||
import type { ${simpleClassName} } from '@/api/${table.moduleName}/${table.businessName}'
|
||||
import type { LoadMoreState } from '@/http/types'
|
||||
import { onReachBottom } from '@dcloudio/uni-app'
|
||||
import { onMounted, reactive, ref } from 'vue'
|
||||
import { onMounted, ref } from 'vue'
|
||||
import { get${simpleClassName}Page } from '@/api/${table.moduleName}/${table.businessName}'
|
||||
import { useAccess } from '@/hooks/useAccess'
|
||||
import { navigateBackPlus } from '@/utils'
|
||||
@@ -131,9 +120,6 @@ import { DICT_TYPE } from '@/utils/constants'
|
||||
#if ($hasDateTime == 1)
|
||||
import { formatDateTime } from '@/utils/date'
|
||||
#end
|
||||
#if ($hasDateTimeBetween == 1)
|
||||
import { formatDateRange } from '@/utils/date'
|
||||
#end
|
||||
import SearchForm from './components/search-form.vue'
|
||||
|
||||
definePage({
|
||||
@@ -147,31 +133,9 @@ const { hasAccessByCodes } = useAccess()
|
||||
const total = ref(0)
|
||||
const list = ref<${simpleClassName}[]>([])
|
||||
const loadMoreState = ref<LoadMoreState>('loading')
|
||||
const queryParams = reactive({
|
||||
const queryParams = ref({
|
||||
pageNo: 1,
|
||||
pageSize: 10,
|
||||
#foreach($column in $columns)
|
||||
#if ($column.listOperation)
|
||||
#set ($javaType = $column.javaType.toLowerCase())
|
||||
#if ($column.htmlType == "datetime" && $column.listOperationCondition == "BETWEEN")
|
||||
${column.javaField}: [undefined, undefined] as [number | undefined, number | undefined],
|
||||
#elseif ($column.dictType && "" != $column.dictType)
|
||||
#if(${javaType} == "string")
|
||||
${column.javaField}: -1 as number | string, // -1 表示全部
|
||||
#elseif(${javaType} == "boolean")
|
||||
${column.javaField}: -1 as number | boolean, // -1 表示全部
|
||||
#else
|
||||
${column.javaField}: -1 as number, // -1 表示全部
|
||||
#end
|
||||
#elseif(${javaType} == "long" || ${javaType} == "integer" || ${javaType} == "short" || ${javaType} == "double" || ${javaType} == "bigdecimal" || ${javaType} == "byte")
|
||||
${column.javaField}: undefined as number | undefined,
|
||||
#elseif(${javaType} == "boolean")
|
||||
${column.javaField}: undefined as boolean | undefined,
|
||||
#else
|
||||
${column.javaField}: undefined as string | undefined,
|
||||
#end
|
||||
#end
|
||||
#end
|
||||
})
|
||||
|
||||
/** 返回上一页 */
|
||||
@@ -183,41 +147,23 @@ function handleBack() {
|
||||
async function getList() {
|
||||
loadMoreState.value = 'loading'
|
||||
try {
|
||||
const params: any = { ...queryParams }
|
||||
#foreach($column in $columns)
|
||||
#if ($column.listOperation && $column.dictType && "" != $column.dictType)
|
||||
params.${column.javaField} = queryParams.${column.javaField} === -1 ? undefined : queryParams.${column.javaField}
|
||||
#end
|
||||
#end
|
||||
#foreach($column in $columns)
|
||||
#if ($column.listOperation && $column.htmlType == "datetime" && $column.listOperationCondition == "BETWEEN")
|
||||
params.${column.javaField} = formatDateRange(queryParams.${column.javaField})
|
||||
#end
|
||||
#end
|
||||
const data = await get${simpleClassName}Page(params)
|
||||
const data = await get${simpleClassName}Page(queryParams.value)
|
||||
list.value = [...list.value, ...data.list]
|
||||
total.value = data.total
|
||||
loadMoreState.value = list.value.length >= total.value ? 'finished' : 'loading'
|
||||
} catch {
|
||||
queryParams.pageNo = queryParams.pageNo > 1 ? queryParams.pageNo - 1 : 1
|
||||
queryParams.value.pageNo = queryParams.value.pageNo > 1 ? queryParams.value.pageNo - 1 : 1
|
||||
loadMoreState.value = 'error'
|
||||
}
|
||||
}
|
||||
|
||||
/** 搜索按钮操作 */
|
||||
function handleQuery(data?: SearchFormData) {
|
||||
#foreach($column in $columns)
|
||||
#if ($column.listOperation)
|
||||
#if ($column.htmlType == "datetime" && $column.listOperationCondition == "BETWEEN")
|
||||
queryParams.${column.javaField} = data?.${column.javaField} ?? [undefined, undefined]
|
||||
#elseif ($column.dictType && "" != $column.dictType)
|
||||
queryParams.${column.javaField} = data?.${column.javaField} ?? -1
|
||||
#else
|
||||
queryParams.${column.javaField} = data?.${column.javaField}
|
||||
#end
|
||||
#end
|
||||
#end
|
||||
queryParams.pageNo = 1
|
||||
function handleQuery(data?: Record<string, any>) {
|
||||
queryParams.value = {
|
||||
...data,
|
||||
pageNo: 1,
|
||||
pageSize: queryParams.value.pageSize,
|
||||
}
|
||||
list.value = []
|
||||
getList()
|
||||
}
|
||||
@@ -232,7 +178,7 @@ function loadMore() {
|
||||
if (loadMoreState.value === 'finished') {
|
||||
return
|
||||
}
|
||||
queryParams.pageNo++
|
||||
queryParams.value.pageNo++
|
||||
getList()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user