feat:【infra】移动端 admin uniapp 的代码生成的优化(增加时间范围的条件生成)
This commit is contained in:
parent
3c88d4d488
commit
4ce201c540
@ -1,3 +1,4 @@
|
|||||||
|
<!-- 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>
|
<template>
|
||||||
<!-- 搜索框入口 -->
|
<!-- 搜索框入口 -->
|
||||||
<wd-search
|
<wd-search
|
||||||
@ -30,6 +31,7 @@
|
|||||||
#set ($dictType = $column.dictType)
|
#set ($dictType = $column.dictType)
|
||||||
#set ($javaField = $column.javaField)
|
#set ($javaField = $column.javaField)
|
||||||
#set ($javaType = $column.javaType)
|
#set ($javaType = $column.javaType)
|
||||||
|
#set ($listOperationCondition = $column.listOperationCondition)
|
||||||
#set ($comment = $column.columnComment)
|
#set ($comment = $column.columnComment)
|
||||||
#set ($dictMethod = "getDictOptions")
|
#set ($dictMethod = "getDictOptions")
|
||||||
#if ($javaType == "Integer" || $javaType == "Long" || $javaType == "Byte" || $javaType == "Short")
|
#if ($javaType == "Integer" || $javaType == "Long" || $javaType == "Byte" || $javaType == "Short")
|
||||||
@ -50,6 +52,58 @@
|
|||||||
clearable
|
clearable
|
||||||
/>
|
/>
|
||||||
</view>
|
</view>
|
||||||
|
#elseif ($column.htmlType == "datetime" && $listOperationCondition == "BETWEEN")
|
||||||
|
#set ($AttrName = $javaField.substring(0,1).toUpperCase() + ${javaField.substring(1)})
|
||||||
|
<view class="mb-32rpx">
|
||||||
|
<view class="mb-12rpx text-28rpx text-[#666]">
|
||||||
|
${comment}
|
||||||
|
</view>
|
||||||
|
<view class="flex items-center gap-16rpx">
|
||||||
|
<view class="flex-1" @click="visible${AttrName}[0] = true">
|
||||||
|
<view
|
||||||
|
class="h-72rpx flex items-center justify-center rounded-8rpx bg-[#f5f5f5] px-24rpx text-28rpx"
|
||||||
|
>
|
||||||
|
{{ formatDate(formData.${javaField}?.[0]) || '开始日期' }}
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
<text class="text-28rpx text-[#999]">至</text>
|
||||||
|
<view class="flex-1" @click="visible${AttrName}[1] = true">
|
||||||
|
<view
|
||||||
|
class="h-72rpx flex items-center justify-center rounded-8rpx bg-[#f5f5f5] px-24rpx text-28rpx"
|
||||||
|
>
|
||||||
|
{{ formatDate(formData.${javaField}?.[1]) || '结束日期' }}
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
<wd-datetime-picker-view
|
||||||
|
v-if="visible${AttrName}[0]"
|
||||||
|
v-model="temp${AttrName}[0]"
|
||||||
|
type="date"
|
||||||
|
:columns-height="200"
|
||||||
|
/>
|
||||||
|
<view v-if="visible${AttrName}[0]" class="mt-16rpx flex justify-end gap-16rpx">
|
||||||
|
<wd-button size="small" plain @click="handle${AttrName}0Cancel">
|
||||||
|
取消
|
||||||
|
</wd-button>
|
||||||
|
<wd-button size="small" type="primary" @click="handle${AttrName}0Confirm">
|
||||||
|
确定
|
||||||
|
</wd-button>
|
||||||
|
</view>
|
||||||
|
<wd-datetime-picker-view
|
||||||
|
v-if="visible${AttrName}[1]"
|
||||||
|
v-model="temp${AttrName}[1]"
|
||||||
|
type="date"
|
||||||
|
:columns-height="200"
|
||||||
|
/>
|
||||||
|
<view v-if="visible${AttrName}[1]" class="mt-16rpx flex justify-end gap-16rpx">
|
||||||
|
<wd-button size="small" plain @click="handle${AttrName}1Cancel">
|
||||||
|
取消
|
||||||
|
</wd-button>
|
||||||
|
<wd-button size="small" type="primary" @click="handle${AttrName}1Confirm">
|
||||||
|
确定
|
||||||
|
</wd-button>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
#elseif (($column.htmlType == "select" || $column.htmlType == "radio") && $dictType && "" != $dictType)
|
#elseif (($column.htmlType == "select" || $column.htmlType == "radio") && $dictType && "" != $dictType)
|
||||||
<view class="mb-32rpx">
|
<view class="mb-32rpx">
|
||||||
<view class="mb-12rpx text-28rpx text-[#666]">
|
<view class="mb-12rpx text-28rpx text-[#666]">
|
||||||
@ -100,6 +154,7 @@
|
|||||||
#set ($hasGetIntDictOptions = 0)
|
#set ($hasGetIntDictOptions = 0)
|
||||||
#set ($hasGetStrDictOptions = 0)
|
#set ($hasGetStrDictOptions = 0)
|
||||||
#set ($hasGetBoolDictOptions = 0)
|
#set ($hasGetBoolDictOptions = 0)
|
||||||
|
#set ($hasDateTimeBetween = 0)
|
||||||
#foreach($column in $columns)
|
#foreach($column in $columns)
|
||||||
#if ($column.listOperation && $column.dictType && "" != $column.dictType)
|
#if ($column.listOperation && $column.dictType && "" != $column.dictType)
|
||||||
#set ($hasDict = 1)
|
#set ($hasDict = 1)
|
||||||
@ -115,8 +170,14 @@
|
|||||||
#end
|
#end
|
||||||
#end
|
#end
|
||||||
#end
|
#end
|
||||||
|
#if ($hasDateTimeBetween == 0 && $column.listOperation && $column.htmlType == "datetime" && $column.listOperationCondition == "BETWEEN")
|
||||||
|
#set ($hasDateTimeBetween = 1)
|
||||||
|
#end
|
||||||
#end
|
#end
|
||||||
import { computed, reactive, ref, watch } from 'vue'
|
import { computed, reactive, ref, watch } from 'vue'
|
||||||
|
#if ($hasDateTimeBetween == 1)
|
||||||
|
import { formatDate } from '@/utils/date'
|
||||||
|
#end
|
||||||
#if ($hasDict == 1)
|
#if ($hasDict == 1)
|
||||||
#set ($dictImportNames = "getDictLabel, ")
|
#set ($dictImportNames = "getDictLabel, ")
|
||||||
#if ($hasGetDictOptions == 1)
|
#if ($hasGetDictOptions == 1)
|
||||||
@ -142,7 +203,9 @@ export interface SearchFormData {
|
|||||||
#foreach($column in $columns)
|
#foreach($column in $columns)
|
||||||
#if ($column.listOperation)
|
#if ($column.listOperation)
|
||||||
#set ($javaType = $column.javaType.toLowerCase())
|
#set ($javaType = $column.javaType.toLowerCase())
|
||||||
#if ($column.dictType && "" != $column.dictType)
|
#if ($column.htmlType == "datetime" && $column.listOperationCondition == "BETWEEN")
|
||||||
|
${column.javaField}?: [number | undefined, number | undefined]
|
||||||
|
#elseif ($column.dictType && "" != $column.dictType)
|
||||||
#if(${javaType} == "string")
|
#if(${javaType} == "string")
|
||||||
${column.javaField}?: string | number
|
${column.javaField}?: string | number
|
||||||
#elseif(${javaType} == "boolean")
|
#elseif(${javaType} == "boolean")
|
||||||
@ -174,7 +237,9 @@ const visible = ref(false)
|
|||||||
const formData = reactive<SearchFormData>({
|
const formData = reactive<SearchFormData>({
|
||||||
#foreach($column in $columns)
|
#foreach($column in $columns)
|
||||||
#if ($column.listOperation)
|
#if ($column.listOperation)
|
||||||
#if ($column.dictType && "" != $column.dictType)
|
#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())
|
#set ($javaType = $column.javaType.toLowerCase())
|
||||||
#if(${javaType} == "string")
|
#if(${javaType} == "string")
|
||||||
${column.javaField}: -1 as number | string,
|
${column.javaField}: -1 as number | string,
|
||||||
@ -199,7 +264,11 @@ const searchPlaceholder = computed(() => {
|
|||||||
#set ($javaField = $column.javaField)
|
#set ($javaField = $column.javaField)
|
||||||
#set ($javaType = $column.javaType.toLowerCase())
|
#set ($javaType = $column.javaType.toLowerCase())
|
||||||
#set ($comment = $column.columnComment)
|
#set ($comment = $column.columnComment)
|
||||||
#if ($dictType && "" != $dictType)
|
#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])#[[}]]#`)
|
||||||
|
}
|
||||||
|
#elseif ($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})#[[}]]#`)
|
||||||
}
|
}
|
||||||
@ -224,7 +293,9 @@ watch(visible, (val) => {
|
|||||||
if (val && props.searchParams) {
|
if (val && props.searchParams) {
|
||||||
#foreach($column in $columns)
|
#foreach($column in $columns)
|
||||||
#if ($column.listOperation)
|
#if ($column.listOperation)
|
||||||
#if ($column.dictType && "" != $column.dictType)
|
#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
|
formData.${column.javaField} = props.searchParams.${column.javaField} ?? -1
|
||||||
#else
|
#else
|
||||||
formData.${column.javaField} = props.searchParams.${column.javaField}
|
formData.${column.javaField} = props.searchParams.${column.javaField}
|
||||||
@ -234,6 +305,40 @@ watch(visible, (val) => {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
#if ($hasDateTimeBetween == 1)
|
||||||
|
// 时间范围选择器状态
|
||||||
|
#foreach($column in $columns)
|
||||||
|
#if ($column.listOperation && $column.htmlType == "datetime" && $column.listOperationCondition == "BETWEEN")
|
||||||
|
#set ($javaField = $column.javaField)
|
||||||
|
#set ($AttrName = $javaField.substring(0,1).toUpperCase() + ${javaField.substring(1)})
|
||||||
|
const visible${AttrName} = ref<[boolean, boolean]>([false, false])
|
||||||
|
const temp${AttrName} = ref<[number, number]>([Date.now(), Date.now()])
|
||||||
|
|
||||||
|
/** ${column.columnComment}[0]确认 */
|
||||||
|
function handle${AttrName}0Confirm() {
|
||||||
|
formData.${javaField} = [temp${AttrName}.value[0], formData.${javaField}?.[1]]
|
||||||
|
visible${AttrName}.value[0] = false
|
||||||
|
}
|
||||||
|
|
||||||
|
/** ${column.columnComment}[0]取消 */
|
||||||
|
function handle${AttrName}0Cancel() {
|
||||||
|
visible${AttrName}.value[0] = false
|
||||||
|
}
|
||||||
|
|
||||||
|
/** ${column.columnComment}[1]确认 */
|
||||||
|
function handle${AttrName}1Confirm() {
|
||||||
|
formData.${javaField} = [formData.${javaField}?.[0], temp${AttrName}.value[1]]
|
||||||
|
visible${AttrName}.value[1] = false
|
||||||
|
}
|
||||||
|
|
||||||
|
/** ${column.columnComment}[1]取消 */
|
||||||
|
function handle${AttrName}1Cancel() {
|
||||||
|
visible${AttrName}.value[1] = false
|
||||||
|
}
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
|
||||||
/** 搜索 */
|
/** 搜索 */
|
||||||
function handleSearch() {
|
function handleSearch() {
|
||||||
visible.value = false
|
visible.value = false
|
||||||
@ -244,7 +349,9 @@ function handleSearch() {
|
|||||||
function handleReset() {
|
function handleReset() {
|
||||||
#foreach($column in $columns)
|
#foreach($column in $columns)
|
||||||
#if ($column.listOperation)
|
#if ($column.listOperation)
|
||||||
#if ($column.dictType && "" != $column.dictType)
|
#if ($column.htmlType == "datetime" && $column.listOperationCondition == "BETWEEN")
|
||||||
|
formData.${column.javaField} = [undefined, undefined]
|
||||||
|
#elseif ($column.dictType && "" != $column.dictType)
|
||||||
formData.${column.javaField} = -1
|
formData.${column.javaField} = -1
|
||||||
#else
|
#else
|
||||||
formData.${column.javaField} = undefined
|
formData.${column.javaField} = undefined
|
||||||
|
|||||||
@ -111,6 +111,12 @@
|
|||||||
#end
|
#end
|
||||||
#end
|
#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 { 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'
|
||||||
@ -125,6 +131,9 @@ import { DICT_TYPE } from '@/utils/constants'
|
|||||||
#if ($hasDateTime == 1)
|
#if ($hasDateTime == 1)
|
||||||
import { formatDateTime } from '@/utils/date'
|
import { formatDateTime } from '@/utils/date'
|
||||||
#end
|
#end
|
||||||
|
#if ($hasDateTimeBetween == 1)
|
||||||
|
import { formatDateRange } from '@/utils/date'
|
||||||
|
#end
|
||||||
import SearchForm from './components/search-form.vue'
|
import SearchForm from './components/search-form.vue'
|
||||||
|
|
||||||
definePage({
|
definePage({
|
||||||
@ -144,7 +153,9 @@ const queryParams = reactive({
|
|||||||
#foreach($column in $columns)
|
#foreach($column in $columns)
|
||||||
#if ($column.listOperation)
|
#if ($column.listOperation)
|
||||||
#set ($javaType = $column.javaType.toLowerCase())
|
#set ($javaType = $column.javaType.toLowerCase())
|
||||||
#if ($column.dictType && "" != $column.dictType)
|
#if ($column.htmlType == "datetime" && $column.listOperationCondition == "BETWEEN")
|
||||||
|
${column.javaField}: [undefined, undefined] as [number | undefined, number | undefined],
|
||||||
|
#elseif ($column.dictType && "" != $column.dictType)
|
||||||
#if(${javaType} == "string")
|
#if(${javaType} == "string")
|
||||||
${column.javaField}: -1 as number | string, // -1 表示全部
|
${column.javaField}: -1 as number | string, // -1 表示全部
|
||||||
#elseif(${javaType} == "boolean")
|
#elseif(${javaType} == "boolean")
|
||||||
@ -172,14 +183,18 @@ function handleBack() {
|
|||||||
async function getList() {
|
async function getList() {
|
||||||
loadMoreState.value = 'loading'
|
loadMoreState.value = 'loading'
|
||||||
try {
|
try {
|
||||||
const data = await get${simpleClassName}Page({
|
const params: any = { ...queryParams }
|
||||||
...queryParams,
|
|
||||||
#foreach($column in $columns)
|
#foreach($column in $columns)
|
||||||
#if ($column.listOperation && $column.dictType && "" != $column.dictType)
|
#if ($column.listOperation && $column.dictType && "" != $column.dictType)
|
||||||
${column.javaField}: queryParams.${column.javaField} === -1 ? undefined : queryParams.${column.javaField},
|
params.${column.javaField} = queryParams.${column.javaField} === -1 ? undefined : queryParams.${column.javaField}
|
||||||
#end
|
#end
|
||||||
#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)
|
||||||
list.value = [...list.value, ...data.list]
|
list.value = [...list.value, ...data.list]
|
||||||
total.value = data.total
|
total.value = data.total
|
||||||
loadMoreState.value = list.value.length >= total.value ? 'finished' : 'loading'
|
loadMoreState.value = list.value.length >= total.value ? 'finished' : 'loading'
|
||||||
@ -193,7 +208,13 @@ async function getList() {
|
|||||||
function handleQuery(data?: SearchFormData) {
|
function handleQuery(data?: SearchFormData) {
|
||||||
#foreach($column in $columns)
|
#foreach($column in $columns)
|
||||||
#if ($column.listOperation)
|
#if ($column.listOperation)
|
||||||
queryParams.${column.javaField} = data?.${column.javaField}#if ($column.dictType && "" != $column.dictType) ?? -1#end
|
#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
|
||||||
#end
|
#end
|
||||||
queryParams.pageNo = 1
|
queryParams.pageNo = 1
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user