feat:优化时间范围的变量、方法的命名,和代码生成器进一步统一

This commit is contained in:
YunaiV
2025-12-17 21:22:15 +08:00
parent 9ae1cb9bdf
commit d6a50762bd
8 changed files with 234 additions and 159 deletions

View File

@@ -71,6 +71,10 @@ const emit = defineEmits<{
}>()
const visible = ref(false)
const formData = reactive<SearchFormData>({
userId: undefined,
applicationName: undefined,
})
/** 搜索条件 placeholder 拼接 */
const searchPlaceholder = computed(() => {
@@ -84,11 +88,6 @@ const searchPlaceholder = computed(() => {
return conditions.length > 0 ? conditions.join(' | ') : '搜索日志'
})
const formData = reactive<SearchFormData>({
userId: undefined,
applicationName: undefined,
})
/** 监听弹窗打开,同步外部参数 */
watch(visible, (val) => {
if (val && props.searchParams) {

View File

@@ -72,6 +72,10 @@ const emit = defineEmits<{
}>()
const visible = ref(false)
const formData = reactive<SearchFormData>({
name: undefined,
status: undefined,
})
/** 搜索条件 placeholder 拼接 */
const searchPlaceholder = computed(() => {
@@ -88,11 +92,6 @@ const searchPlaceholder = computed(() => {
return conditions.length > 0 ? conditions.join(' | ') : '搜索菜单'
})
const formData = reactive<SearchFormData>({
name: undefined,
status: undefined,
})
/** 监听弹窗打开,同步外部参数 */
watch(visible, (val) => {
if (val && props.searchParams) {

View File

@@ -60,6 +60,7 @@ function handleBack() {
}
/** 获取请求 URL */
// TODO @AI放在界面里这里不要这么搞
function getRequestUrl() {
if (formData.value?.requestMethod && formData.value?.requestUrl) {
return `${formData.value.requestMethod} ${formData.value.requestUrl}`

View File

@@ -34,7 +34,7 @@
抄送时间
</view>
<view class="flex items-center gap-16rpx">
<view class="flex-1" @click="showStartPicker = true">
<view class="flex-1" @click="visibleCreateTime[0] = true">
<view
class="h-72rpx flex items-center justify-center rounded-8rpx bg-[#f5f5f5] px-24rpx text-28rpx"
>
@@ -42,7 +42,7 @@
</view>
</view>
<text class="text-28rpx text-[#999]"></text>
<view class="flex-1" @click="showEndPicker = true">
<view class="flex-1" @click="visibleCreateTime[1] = true">
<view
class="h-72rpx flex items-center justify-center rounded-8rpx bg-[#f5f5f5] px-24rpx text-28rpx"
>
@@ -51,30 +51,30 @@
</view>
</view>
<wd-datetime-picker-view
v-if="showStartPicker"
v-if="visibleCreateTime[0]"
v-model="tempCreateTime[0]"
type="date"
:columns-height="200"
/>
<view v-if="showStartPicker" class="mt-16rpx flex justify-end gap-16rpx">
<wd-button size="small" plain @click="handleStartCancel">
<view v-if="visibleCreateTime[0]" class="mt-16rpx flex justify-end gap-16rpx">
<wd-button size="small" plain @click="handleCreateTime0Cancel">
取消
</wd-button>
<wd-button size="small" type="primary" @click="handleStartConfirm">
<wd-button size="small" type="primary" @click="handleCreateTime0Confirm">
确定
</wd-button>
</view>
<wd-datetime-picker-view
v-if="showEndPicker"
v-if="visibleCreateTime[1]"
v-model="tempCreateTime[1]"
type="date"
:columns-height="200"
/>
<view v-if="showEndPicker" class="mt-16rpx flex justify-end gap-16rpx">
<wd-button size="small" plain @click="handleEndCancel">
<view v-if="visibleCreateTime[1]" class="mt-16rpx flex justify-end gap-16rpx">
<wd-button size="small" plain @click="handleCreateTime1Cancel">
取消
</wd-button>
<wd-button size="small" type="primary" @click="handleEndConfirm">
<wd-button size="small" type="primary" @click="handleCreateTime1Confirm">
确定
</wd-button>
</view>
@@ -130,30 +130,29 @@ const formData = reactive<CopySearchFormData>({
})
// 时间选择器状态
const showStartPicker = ref(false)
const showEndPicker = ref(false)
const visibleCreateTime = ref<[boolean, boolean]>([false, false])
const tempCreateTime = ref<[number, number]>([Date.now(), Date.now()])
/** 开始时间确认 */
function handleStartConfirm() {
/** 创建时间[0]确认 */
function handleCreateTime0Confirm() {
formData.createTime = [tempCreateTime.value[0], formData.createTime?.[1]]
showStartPicker.value = false
visibleCreateTime.value[0] = false
}
/** 开始时间取消 */
function handleStartCancel() {
showStartPicker.value = false
/** 创建时间[0]取消 */
function handleCreateTime0Cancel() {
visibleCreateTime.value[0] = false
}
/** 结束时间确认 */
function handleEndConfirm() {
/** 创建时间[1]确认 */
function handleCreateTime1Confirm() {
formData.createTime = [formData.createTime?.[0], tempCreateTime.value[1]]
showEndPicker.value = false
visibleCreateTime.value[1] = false
}
/** 结束时间取消 */
function handleEndCancel() {
showEndPicker.value = false
/** 创建时间[1]取消 */
function handleCreateTime1Cancel() {
visibleCreateTime.value[1] = false
}
/** 监听弹窗打开,同步外部参数 */

View File

@@ -72,7 +72,7 @@
发起时间
</view>
<view class="flex items-center gap-16rpx">
<view class="flex-1" @click="showStartPicker = true">
<view class="flex-1" @click="visibleCreateTime[0] = true">
<view
class="h-72rpx flex items-center justify-center rounded-8rpx bg-[#f5f5f5] px-24rpx text-28rpx"
>
@@ -80,7 +80,7 @@
</view>
</view>
<text class="text-28rpx text-[#999]"></text>
<view class="flex-1" @click="showEndPicker = true">
<view class="flex-1" @click="visibleCreateTime[1] = true">
<view
class="h-72rpx flex items-center justify-center rounded-8rpx bg-[#f5f5f5] px-24rpx text-28rpx"
>
@@ -89,30 +89,30 @@
</view>
</view>
<wd-datetime-picker-view
v-if="showStartPicker"
v-if="visibleCreateTime[0]"
v-model="tempCreateTime[0]"
type="date"
:columns-height="200"
/>
<view v-if="showStartPicker" class="mt-16rpx flex justify-end gap-16rpx">
<wd-button size="small" plain @click="handleStartCancel">
<view v-if="visibleCreateTime[0]" class="mt-16rpx flex justify-end gap-16rpx">
<wd-button size="small" plain @click="handleCreateTime0Cancel">
取消
</wd-button>
<wd-button size="small" type="primary" @click="handleStartConfirm">
<wd-button size="small" type="primary" @click="handleCreateTime0Confirm">
确定
</wd-button>
</view>
<wd-datetime-picker-view
v-if="showEndPicker"
v-if="visibleCreateTime[1]"
v-model="tempCreateTime[1]"
type="date"
:columns-height="200"
/>
<view v-if="showEndPicker" class="mt-16rpx flex justify-end gap-16rpx">
<wd-button size="small" plain @click="handleEndCancel">
<view v-if="visibleCreateTime[1]" class="mt-16rpx flex justify-end gap-16rpx">
<wd-button size="small" plain @click="handleCreateTime1Cancel">
取消
</wd-button>
<wd-button size="small" type="primary" @click="handleEndConfirm">
<wd-button size="small" type="primary" @click="handleCreateTime1Confirm">
确定
</wd-button>
</view>
@@ -185,30 +185,29 @@ const categoryList = ref<Category[]>([])
const processDefinitionList = ref<ProcessDefinition[]>([])
// 时间选择器状态
const showStartPicker = ref(false)
const showEndPicker = ref(false)
const visibleCreateTime = ref<[boolean, boolean]>([false, false])
const tempCreateTime = ref<[number, number]>([Date.now(), Date.now()])
/** 开始时间确认 */
function handleStartConfirm() {
/** 创建时间[0]确认 */
function handleCreateTime0Confirm() {
formData.createTime = [tempCreateTime.value[0], formData.createTime?.[1]]
showStartPicker.value = false
visibleCreateTime.value[0] = false
}
/** 开始时间取消 */
function handleStartCancel() {
showStartPicker.value = false
/** 创建时间[0]取消 */
function handleCreateTime0Cancel() {
visibleCreateTime.value[0] = false
}
/** 结束时间确认 */
function handleEndConfirm() {
/** 创建时间[1]确认 */
function handleCreateTime1Confirm() {
formData.createTime = [formData.createTime?.[0], tempCreateTime.value[1]]
showEndPicker.value = false
visibleCreateTime.value[1] = false
}
/** 结束时间取消 */
function handleEndCancel() {
showEndPicker.value = false
/** 创建时间[1]取消 */
function handleCreateTime1Cancel() {
visibleCreateTime.value[1] = false
}
/** 获取流程分类列表 */

View File

@@ -47,7 +47,7 @@
发起时间
</view>
<view class="flex items-center gap-16rpx">
<view class="flex-1" @click="showStartPicker = true">
<view class="flex-1" @click="visibleCreateTime[0] = true">
<view
class="h-72rpx flex items-center justify-center rounded-8rpx bg-[#f5f5f5] px-24rpx text-28rpx"
>
@@ -55,7 +55,7 @@
</view>
</view>
<text class="text-28rpx text-[#999]"></text>
<view class="flex-1" @click="showEndPicker = true">
<view class="flex-1" @click="visibleCreateTime[1] = true">
<view
class="h-72rpx flex items-center justify-center rounded-8rpx bg-[#f5f5f5] px-24rpx text-28rpx"
>
@@ -64,30 +64,30 @@
</view>
</view>
<wd-datetime-picker-view
v-if="showStartPicker"
v-if="visibleCreateTime[0]"
v-model="tempCreateTime[0]"
type="date"
:columns-height="200"
/>
<view v-if="showStartPicker" class="mt-16rpx flex justify-end gap-16rpx">
<wd-button size="small" plain @click="handleStartCancel">
<view v-if="visibleCreateTime[0]" class="mt-16rpx flex justify-end gap-16rpx">
<wd-button size="small" plain @click="handleCreateTime0Cancel">
取消
</wd-button>
<wd-button size="small" type="primary" @click="handleStartConfirm">
<wd-button size="small" type="primary" @click="handleCreateTime0Confirm">
确定
</wd-button>
</view>
<wd-datetime-picker-view
v-if="showEndPicker"
v-if="visibleCreateTime[1]"
v-model="tempCreateTime[1]"
type="date"
:columns-height="200"
/>
<view v-if="showEndPicker" class="mt-16rpx flex justify-end gap-16rpx">
<wd-button size="small" plain @click="handleEndCancel">
<view v-if="visibleCreateTime[1]" class="mt-16rpx flex justify-end gap-16rpx">
<wd-button size="small" plain @click="handleCreateTime1Cancel">
取消
</wd-button>
<wd-button size="small" type="primary" @click="handleEndConfirm">
<wd-button size="small" type="primary" @click="handleCreateTime1Confirm">
确定
</wd-button>
</view>
@@ -185,30 +185,29 @@ const categoryList = ref<Category[]>([])
const processDefinitionList = ref<ProcessDefinition[]>([])
// 时间选择器状态
const showStartPicker = ref(false)
const showEndPicker = ref(false)
const visibleCreateTime = ref<[boolean, boolean]>([false, false])
const tempCreateTime = ref<[number, number]>([Date.now(), Date.now()])
/** 开始时间确认 */
function handleStartConfirm() {
/** 创建时间[0]确认 */
function handleCreateTime0Confirm() {
formData.createTime = [tempCreateTime.value[0], formData.createTime?.[1]]
showStartPicker.value = false
visibleCreateTime.value[0] = false
}
/** 开始时间取消 */
function handleStartCancel() {
showStartPicker.value = false
/** 创建时间[0]取消 */
function handleCreateTime0Cancel() {
visibleCreateTime.value[0] = false
}
/** 结束时间确认 */
function handleEndConfirm() {
/** 创建时间[1]确认 */
function handleCreateTime1Confirm() {
formData.createTime = [formData.createTime?.[0], tempCreateTime.value[1]]
showEndPicker.value = false
visibleCreateTime.value[1] = false
}
/** 结束时间取消 */
function handleEndCancel() {
showEndPicker.value = false
/** 创建时间[1]取消 */
function handleCreateTime1Cancel() {
visibleCreateTime.value[1] = false
}
/** 获取流程分类列表 */

View File

@@ -72,7 +72,7 @@
发起时间
</view>
<view class="flex items-center gap-16rpx">
<view class="flex-1" @click="showStartPicker = true">
<view class="flex-1" @click="visibleCreateTime[0] = true">
<view
class="h-72rpx flex items-center justify-center rounded-8rpx bg-[#f5f5f5] px-24rpx text-28rpx"
>
@@ -80,7 +80,7 @@
</view>
</view>
<text class="text-28rpx text-[#999]"></text>
<view class="flex-1" @click="showEndPicker = true">
<view class="flex-1" @click="visibleCreateTime[1] = true">
<view
class="h-72rpx flex items-center justify-center rounded-8rpx bg-[#f5f5f5] px-24rpx text-28rpx"
>
@@ -89,30 +89,30 @@
</view>
</view>
<wd-datetime-picker-view
v-if="showStartPicker"
v-if="visibleCreateTime[0]"
v-model="tempCreateTime[0]"
type="date"
:columns-height="200"
/>
<view v-if="showStartPicker" class="mt-16rpx flex justify-end gap-16rpx">
<wd-button size="small" plain @click="handleStartCancel">
<view v-if="visibleCreateTime[0]" class="mt-16rpx flex justify-end gap-16rpx">
<wd-button size="small" plain @click="handleCreateTime0Cancel">
取消
</wd-button>
<wd-button size="small" type="primary" @click="handleStartConfirm">
<wd-button size="small" type="primary" @click="handleCreateTime0Confirm">
确定
</wd-button>
</view>
<wd-datetime-picker-view
v-if="showEndPicker"
v-if="visibleCreateTime[1]"
v-model="tempCreateTime[1]"
type="date"
:columns-height="200"
/>
<view v-if="showEndPicker" class="mt-16rpx flex justify-end gap-16rpx">
<wd-button size="small" plain @click="handleEndCancel">
<view v-if="visibleCreateTime[1]" class="mt-16rpx flex justify-end gap-16rpx">
<wd-button size="small" plain @click="handleCreateTime1Cancel">
取消
</wd-button>
<wd-button size="small" type="primary" @click="handleEndConfirm">
<wd-button size="small" type="primary" @click="handleCreateTime1Confirm">
确定
</wd-button>
</view>
@@ -185,30 +185,29 @@ const categoryList = ref<Category[]>([])
const processDefinitionList = ref<ProcessDefinition[]>([])
// 时间选择器状态
const showStartPicker = ref(false)
const showEndPicker = ref(false)
const visibleCreateTime = ref<[boolean, boolean]>([false, false])
const tempCreateTime = ref<[number, number]>([Date.now(), Date.now()])
/** 开始时间确认 */
function handleStartConfirm() {
/** 创建时间[0]确认 */
function handleCreateTime0Confirm() {
formData.createTime = [tempCreateTime.value[0], formData.createTime?.[1]]
showStartPicker.value = false
visibleCreateTime.value[0] = false
}
/** 开始时间取消 */
function handleStartCancel() {
showStartPicker.value = false
/** 创建时间[0]取消 */
function handleCreateTime0Cancel() {
visibleCreateTime.value[0] = false
}
/** 结束时间确认 */
function handleEndConfirm() {
/** 创建时间[1]确认 */
function handleCreateTime1Confirm() {
formData.createTime = [formData.createTime?.[0], tempCreateTime.value[1]]
showEndPicker.value = false
visibleCreateTime.value[1] = false
}
/** 结束时间取消 */
function handleEndCancel() {
showEndPicker.value = false
/** 创建时间[1]取消 */
function handleCreateTime1Cancel() {
visibleCreateTime.value[1] = false
}
/** 获取流程分类列表 */

View File

@@ -1,11 +1,20 @@
<template>
<wd-search
:placeholder="searchPlaceholder"
:hide-cancel="true"
disabled
@click="visible = true"
/>
<!-- 搜索框入口 -->
<view class="flex items-center bg-white pr-30rpx">
<view class="flex-1">
<wd-search
:placeholder="searchPlaceholder"
:hide-cancel="true"
disabled
@click="visible = true"
/>
</view>
<view class="text-28rpx text-[#1890ff]" @click="handleReadAll">
全部已读
</view>
</view>
<!-- 搜索弹窗 -->
<wd-popup
v-model="visible"
position="top"
@@ -15,38 +24,74 @@
>
<view class="p-32rpx">
<view class="mb-24rpx text-32rpx text-[#333] font-semibold">
搜索通知公告
搜索消息
</view>
<view class="mb-24rpx">
<view class="mb-12rpx text-28rpx text-[#666]">
公告标题
已读状态
</view>
<wd-input
v-model="formData.title"
placeholder="请输入公告标题"
clearable
/>
</view>
<view class="mb-32rpx">
<view class="mb-12rpx text-28rpx text-[#666]">
公告状态0正常 1关闭
</view>
<wd-radio-group v-model="formData.status" shape="button">
<wd-radio-group v-model="formData.readStatus" shape="button">
<wd-radio :value="-1">
全部
</wd-radio>
<wd-radio
v-for="dict in getIntDictOptions(DICT_TYPE.COMMON_STATUS)"
:key="dict.value"
:value="dict.value"
>
{{ dict.label }}
<wd-radio :value="1">
已读
</wd-radio>
<wd-radio :value="0">
未读
</wd-radio>
</wd-radio-group>
</view>
<view class="mb-32rpx">
<view class="mb-12rpx text-28rpx text-[#666]">
发送时间
</view>
<view class="flex items-center gap-16rpx">
<view class="flex-1" @click="visibleCreateTime[0] = true">
<view
class="h-72rpx flex items-center justify-center rounded-8rpx bg-[#f5f5f5] px-24rpx text-28rpx"
>
{{ formatDate(formData.createTime?.[0]) || '开始日期' }}
</view>
</view>
<text class="text-28rpx text-[#999]"></text>
<view class="flex-1" @click="visibleCreateTime[1] = true">
<view
class="h-72rpx flex items-center justify-center rounded-8rpx bg-[#f5f5f5] px-24rpx text-28rpx"
>
{{ formatDate(formData.createTime?.[1]) || '结束日期' }}
</view>
</view>
</view>
<wd-datetime-picker-view
v-if="visibleCreateTime[0]"
v-model="tempCreateTime[0]"
type="date"
:columns-height="200"
/>
<view v-if="visibleCreateTime[0]" class="mt-16rpx flex justify-end gap-16rpx">
<wd-button size="small" plain @click="handleCreateTime0Cancel">
取消
</wd-button>
<wd-button size="small" type="primary" @click="handleCreateTime0Confirm">
确定
</wd-button>
</view>
<wd-datetime-picker-view
v-if="visibleCreateTime[1]"
v-model="tempCreateTime[1]"
type="date"
:columns-height="200"
/>
<view v-if="visibleCreateTime[1]" class="mt-16rpx flex justify-end gap-16rpx">
<wd-button size="small" plain @click="handleCreateTime1Cancel">
取消
</wd-button>
<wd-button size="small" type="primary" @click="handleCreateTime1Confirm">
确定
</wd-button>
</view>
</view>
<view class="w-full flex justify-center gap-24rpx">
<wd-button class="flex-1" plain @click="handleReset">
重置
@@ -61,58 +106,93 @@
<script lang="ts" setup>
import { computed, reactive, ref, watch } from 'vue'
import { getDictLabel, getIntDictOptions } from '@/hooks/useDict'
import { DICT_TYPE } from '@/utils/constants'
import { formatDate } from '@/utils/date'
/** 搜索表单数据 */
export interface SearchFormData {
title?: string
status?: number
readStatus: number // -1 表示全部, 0 未读, 1 已读
createTime?: [number | undefined, number | undefined]
}
const props = defineProps<{
searchParams?: Partial<SearchFormData>
searchParams?: Partial<SearchFormData> // 初始搜索参数
}>()
const emit = defineEmits<{
search: [data: SearchFormData]
reset: []
readAll: []
}>()
const visible = ref(false)
const formData = reactive<SearchFormData>({
title: undefined,
status: -1 as number,
readStatus: -1,
createTime: [undefined, undefined],
})
/** 搜索条件 placeholder 拼接 */
const searchPlaceholder = computed(() => {
const conditions: string[] = []
if (props.searchParams?.title) {
conditions.push(`公告标题:${props.searchParams.title}`)
if (props.searchParams?.readStatus === 1) {
conditions.push('已读')
} else if (props.searchParams?.readStatus === 0) {
conditions.push('未读')
}
if (props.searchParams?.status !== undefined && props.searchParams.status !== -1) {
conditions.push(`公告状态0正常 1关闭:${getDictLabel(DICT_TYPE.COMMON_STATUS, props.searchParams.status)}`)
if (props.searchParams?.createTime?.[0] && props.searchParams?.createTime?.[1]) {
conditions.push(`${formatDate(props.searchParams.createTime[0])}~${formatDate(props.searchParams.createTime[1])}`)
}
return conditions.length > 0 ? conditions.join(' | ') : '搜索通知公告'
return conditions.length > 0 ? conditions.join(' | ') : '搜索消息'
})
watch(visible, (val) => {
if (val && props.searchParams) {
formData.title = props.searchParams.title
formData.status = props.searchParams.status ?? -1
}
})
function handleSearch() {
visible.value = false
emit('search', { ...formData } as SearchFormData)
/** 全部已读 */
function handleReadAll() {
emit('readAll')
}
// 时间选择器状态
const visibleCreateTime = ref<[boolean, boolean]>([false, false])
const tempCreateTime = ref<[number, number]>([Date.now(), Date.now()])
/** 创建时间[0]确认 */
function handleCreateTime0Confirm() {
formData.createTime = [tempCreateTime.value[0], formData.createTime?.[1]]
visibleCreateTime.value[0] = false
}
/** 创建时间[0]取消 */
function handleCreateTime0Cancel() {
visibleCreateTime.value[0] = false
}
/** 创建时间[1]确认 */
function handleCreateTime1Confirm() {
formData.createTime = [formData.createTime?.[0], tempCreateTime.value[1]]
visibleCreateTime.value[1] = false
}
/** 创建时间[1]取消 */
function handleCreateTime1Cancel() {
visibleCreateTime.value[1] = false
}
/** 监听弹窗打开,同步外部参数 */
watch(visible, (val) => {
if (val && props.searchParams) {
formData.readStatus = props.searchParams.readStatus ?? -1
formData.createTime = props.searchParams.createTime ?? [undefined, undefined]
}
})
/** 搜索 */
function handleSearch() {
visible.value = false
emit('search', { ...formData })
}
/** 重置 */
function handleReset() {
formData.title = undefined
formData.status = -1
formData.readStatus = -1
formData.createTime = [undefined, undefined]
visible.value = false
emit('reset')
}