From 5046d0d13dc6a8563b8e54e31913bc44cfa1072f Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期二, 26 四月 2022 19:23:18 +0800
Subject: [PATCH] 2022-04-26

---
 src/tabviews/zshare/mutilform/mkDatePicker/index.jsx |   32 +++++++++++++++++++++++---------
 1 files changed, 23 insertions(+), 9 deletions(-)

diff --git a/src/tabviews/zshare/mutilform/mkDatePicker/index.jsx b/src/tabviews/zshare/mutilform/mkDatePicker/index.jsx
index b2acd83..a3d0899 100644
--- a/src/tabviews/zshare/mutilform/mkDatePicker/index.jsx
+++ b/src/tabviews/zshare/mutilform/mkDatePicker/index.jsx
@@ -20,13 +20,19 @@
     if (config.type === 'datemonth') {
       mode = 'month'
       format = 'YYYY-MM'
-    } else if (config.type === 'datetime') {
-      mode = 'datetime'
+    } else if (config.precision === 'day') {
+      format = 'YYYY-MM-DD'
+    } else if (config.precision === 'hour') {
+      format = 'YYYY-MM-DD HH'
+    } else if (config.precision === 'minute') {
+      format = 'YYYY-MM-DD HH:mm'
+    } else if (config.precision === 'second') {
       format = 'YYYY-MM-DD HH:mm:ss'
     }
+
     let value = config.initval || null
     if (value) {
-      value = moment(value, format)
+      value = moment(value, 'YYYY-MM-DD HH:mm:ss')
     }
 
     this.state = {
@@ -49,9 +55,19 @@
   }
 
   onChange = (val) => {
-    const { format } = this.state
+    const { config } = this.props
+    const { format, mode } = this.state
+    let _val = val ? moment(val).format(format) : ''
 
-    this.props.onChange(val ? moment(val).format(format) : '')
+    if (mode === 'date' && _val) {
+      if (config.precision === 'hour') {
+        _val = _val + ':00:00'
+      } else if (config.precision === 'minute') {
+        _val = _val + ':00'
+      }
+    }
+
+    this.props.onChange(_val)
   }
 
   disabledDate = (current) => {
@@ -72,14 +88,12 @@
 
   render() {
     const { config } = this.props
-    const { value, mode } = this.state
+    const { value, mode, format } = this.state
 
     if (mode === 'date') {
-      return <DatePicker defaultValue={value} disabledDate={this.disabledDate} disabled={config.readonly} onChange={this.onChange}/>
+      return <DatePicker dropdownClassName={'mk-date-picker ' + config.precision} showTime={format !== 'YYYY-MM-DD'} format={format} defaultValue={value} disabledDate={this.disabledDate} disabled={config.readonly} onChange={this.onChange}/>
     } else if (mode === 'month') {
       return <MonthPicker defaultValue={value} disabled={config.readonly} onChange={this.onChange}/>
-    } else if (mode === 'datetime') {
-      return <DatePicker defaultValue={value} disabledDate={this.disabledDate} showTime disabled={config.readonly} onChange={this.onChange}/>
     }
   }
 }

--
Gitblit v1.8.0