Browse Source

fix: 修改日期格式

bill 2 years ago
parent
commit
c8af23d70b
3 changed files with 24 additions and 14 deletions
  1. 1 1
      src/api/constant.ts
  2. 6 5
      src/hook/usePaging.ts
  3. 17 8
      src/views/project/list.vue

+ 1 - 1
src/api/constant.ts

@@ -3,7 +3,7 @@ export enum ResCode {
   SUCCESS = 0
   SUCCESS = 0
 }
 }
 
 
-export const all = null as unknown as 'null'
+export const all = '___all___'
 export type All = typeof all
 export type All = typeof all
 
 
 export const ResCodeDesc: { [key in ResCode]: string } = {
 export const ResCodeDesc: { [key in ResCode]: string } = {

+ 6 - 5
src/hook/usePaging.ts

@@ -1,15 +1,14 @@
 import { useRealtime } from './useRealtime'
 import { useRealtime } from './useRealtime'
-import { reactive, watch, isProxy } from 'vue'
+import { reactive, watch, isProxy, Ref, isRef } from 'vue'
 import { useActive } from './useActive'
 import { useActive } from './useActive'
 
 
 import type { PageRequest, PageResult } from '@/api'
 import type { PageRequest, PageResult } from '@/api'
 
 
 export function usePaging<P extends {}, A>(
 export function usePaging<P extends {}, A>(
   fetch: (p: PageRequest<P>) => Promise<PageResult<A>>,
   fetch: (p: PageRequest<P>) => Promise<PageResult<A>>,
-  initial: P,
+  initial: P | Ref<P>,
   setting?: { pageSize?: number; auto?: boolean }
   setting?: { pageSize?: number; auto?: boolean }
 ) {
 ) {
-  console.log(setting)
   const pagination = reactive({
   const pagination = reactive({
     current: 1,
     current: 1,
     total: 0,
     total: 0,
@@ -23,7 +22,7 @@ export function usePaging<P extends {}, A>(
 
 
   const [list, updateList] = useRealtime(async () => {
   const [list, updateList] = useRealtime(async () => {
     const result = await fetch({
     const result = await fetch({
-      ...initial,
+      ...(isRef(initial) ? initial.value : initial),
       pageNum: pagination.current,
       pageNum: pagination.current,
       pageSize: pagination.pageSize
       pageSize: pagination.pageSize
     })
     })
@@ -33,7 +32,9 @@ export function usePaging<P extends {}, A>(
 
 
   if (!setting || !('auto' in setting) || setting?.auto) {
   if (!setting || !('auto' in setting) || setting?.auto) {
     const active = useActive()
     const active = useActive()
-    isProxy(initial) && watch(initial, () => active.value && updateList())
+    if (isRef(initial) || isProxy(initial)) {
+      watch(initial, () => active.value && updateList())
+    }
   }
   }
 
 
   return { list, pagination, updateList }
   return { list, pagination, updateList }

+ 17 - 8
src/views/project/list.vue

@@ -23,9 +23,9 @@
           allow-clear
           allow-clear
         />
         />
       </a-form-item>
       </a-form-item>
-      <a-form-item label="选择日期" name="startTime">
+      <a-form-item label="选择日期" name="day">
         <a-date-picker
         <a-date-picker
-          v-model:value="filterState.startTime"
+          v-model:value="filterState.day"
           style="width: 100%"
           style="width: 100%"
           placeholder="选择项目创建日期"
           placeholder="选择项目创建日期"
           allow-clear
           allow-clear
@@ -72,7 +72,7 @@
 import InsertProject from './edit.vue'
 import InsertProject from './edit.vue'
 import { HeadPanl, BodyPanl } from '@/layout/panl'
 import { HeadPanl, BodyPanl } from '@/layout/panl'
 import { projectColumns } from './columns'
 import { projectColumns } from './columns'
-import { reactive, ref } from 'vue'
+import { computed, reactive, ref } from 'vue'
 import { usePaging } from '@/hook'
 import { usePaging } from '@/hook'
 import { renderModal } from '@/helper'
 import { renderModal } from '@/helper'
 import { useProject } from '@/store'
 import { useProject } from '@/store'
@@ -87,6 +87,7 @@ import {
 
 
 import type { All, InsertProjectData } from '@/api'
 import type { All, InsertProjectData } from '@/api'
 import type { FormInstance } from 'ant-design-vue'
 import type { FormInstance } from 'ant-design-vue'
+import type { Dayjs } from 'dayjs'
 
 
 const statusOptions = [
 const statusOptions = [
   { label: '全部', value: all },
   { label: '全部', value: all },
@@ -100,20 +101,28 @@ const statusOptions = [
 type FilterState = {
 type FilterState = {
   projectName: string
   projectName: string
   projectCreater: string
   projectCreater: string
-  startTime: string
+  day?: Dayjs
   projectStatus: ProjectStatus | All
   projectStatus: ProjectStatus | All
 }
 }
 
 
 const filterState: FilterState = reactive({
 const filterState: FilterState = reactive({
   projectName: '',
   projectName: '',
   projectCreater: '',
   projectCreater: '',
-  startTime: '',
   projectStatus: all
   projectStatus: all
 })
 })
 
 
-const { list, pagination, updateList } = usePaging(fetchProjects, filterState, {
-  auto: false
-})
+const { list, pagination, updateList } = usePaging(
+  fetchProjects,
+  computed(() => ({
+    ...filterState,
+    day: filterState.day?.format('YYYY-MM-DD'),
+    projectStatus:
+      filterState.projectStatus === all ? undefined : filterState.projectStatus
+  })),
+  {
+    auto: false
+  }
+)
 
 
 const filterFromRef = ref<FormInstance>()
 const filterFromRef = ref<FormInstance>()
 const resetFilter = () => {
 const resetFilter = () => {