mirror of
https://gitee.com/wonderful-code/buildadmin
synced 2024-11-21 06:29:50 +00:00
refactor(BaTable):设置通用搜索数据时对时间日期的识别优化
This commit is contained in:
parent
bd480ce3b4
commit
c336587e2f
@ -40,11 +40,7 @@
|
||||
<el-date-picker
|
||||
class="datetime-picker w100"
|
||||
v-model="baTable.comSearch.form[item.prop!]"
|
||||
:default-value="
|
||||
baTable.comSearch.form[item.prop! + '-default']
|
||||
? baTable.comSearch.form[item.prop! + '-default']
|
||||
: [new Date(), new Date()]
|
||||
"
|
||||
:default-time="[new Date(2000, 1, 1, 0, 0, 0), new Date(2000, 1, 1, 23, 59, 59)]"
|
||||
:type="item.comSearchRender == 'date' ? 'daterange' : 'datetimerange'"
|
||||
:range-separator="$t('To')"
|
||||
:start-placeholder="$t('el.datepicker.startDate')"
|
||||
@ -87,11 +83,6 @@
|
||||
:type="item.comSearchRender == 'date' ? 'date' : 'datetime'"
|
||||
:value-format="item.comSearchRender == 'date' ? 'YYYY-MM-DD' : 'YYYY-MM-DD HH:mm:ss'"
|
||||
:placeholder="item.operatorPlaceholder"
|
||||
:default-value="
|
||||
baTable.comSearch.form[item.prop! + '-default']
|
||||
? baTable.comSearch.form[item.prop! + '-default']
|
||||
: new Date()
|
||||
"
|
||||
:teleported="false"
|
||||
/>
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
import type { FormInstance, TableColumnCtx } from 'element-plus'
|
||||
import { ElNotification } from 'element-plus'
|
||||
import { ElNotification, dayjs } from 'element-plus'
|
||||
import { cloneDeep, isEmpty } from 'lodash-es'
|
||||
import Sortable from 'sortablejs'
|
||||
import { reactive } from 'vue'
|
||||
@ -526,9 +526,19 @@ export default class baTable {
|
||||
const queryProp = query[prop] ?? ''
|
||||
if (this.table.column[key].operator == 'RANGE' || this.table.column[key].operator == 'NOT RANGE') {
|
||||
const range = queryProp.split(',')
|
||||
if (this.table.column[key].render == 'datetime') {
|
||||
if (this.table.column[key].render == 'datetime' || this.table.column[key].comSearchRender == 'date') {
|
||||
if (range && range.length >= 2) {
|
||||
this.comSearch.form[prop + '-default'] = [new Date(range[0]), new Date(range[1])]
|
||||
const rangeDayJs = [dayjs(range[0]), dayjs(range[1])]
|
||||
if (rangeDayJs[0].isValid() && rangeDayJs[1].isValid()) {
|
||||
if (this.table.column[key].comSearchRender == 'date') {
|
||||
this.comSearch.form[prop] = [rangeDayJs[0].format('YYYY-MM-DD'), rangeDayJs[1].format('YYYY-MM-DD')]
|
||||
} else {
|
||||
this.comSearch.form[prop] = [
|
||||
rangeDayJs[0].format('YYYY-MM-DD HH:mm:ss'),
|
||||
rangeDayJs[1].format('YYYY-MM-DD HH:mm:ss'),
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
this.comSearch.form[prop + '-start'] = range[0] ?? ''
|
||||
@ -536,8 +546,13 @@ export default class baTable {
|
||||
}
|
||||
} else if (this.table.column[key].operator == 'NULL' || this.table.column[key].operator == 'NOT NULL') {
|
||||
this.comSearch.form[prop] = queryProp ? true : false
|
||||
} else if (this.table.column[key].render == 'datetime') {
|
||||
this.comSearch.form[prop + '-default'] = new Date(queryProp)
|
||||
} else if (this.table.column[key].render == 'datetime' || this.table.column[key].comSearchRender == 'date') {
|
||||
const propDayJs = dayjs(queryProp)
|
||||
if (propDayJs.isValid()) {
|
||||
this.comSearch.form[prop] = propDayJs.format(
|
||||
this.table.column[key].comSearchRender == 'date' ? 'YYYY-MM-DD' : 'YYYY-MM-DD HH:mm:ss'
|
||||
)
|
||||
}
|
||||
} else {
|
||||
this.comSearch.form[prop] = queryProp
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user