Skip to content

Commit

Permalink
datetime filter future date, form datetime rule
Browse files Browse the repository at this point in the history
  • Loading branch information
szuprefix committed Feb 5, 2020
1 parent 0da02c7 commit 143383f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 15 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vue-django",
"version": "0.7.2",
"version": "0.7.3",
"description": "个人实验项目, 本框架的目标是借鉴并超越django admin的自动化思想, 实现UI前端的极简快速定制开发",
"main": "index.js",
"files": [
Expand Down
2 changes: 1 addition & 1 deletion src/components/form/Form.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export function defaultRuleType(f){
if (f.choices && f.choices.length > 0) {
return typeof f.choices[0][0]
}
return f.model ? 'number' : (['field', 'time'].includes(f.type) ? 'string' : (['integer', 'decimal'].includes(f.type) ? 'number' : f.type))
return f.model ? 'number' : (['field', 'time', 'datetime'].includes(f.type) ? 'string' : (['integer', 'decimal'].includes(f.type) ? 'number' : f.type))
}

export function defaultSpan(f){
Expand Down
27 changes: 14 additions & 13 deletions src/utils/filters.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
/**
* Created by denishuang on 2017/11/16.
*/
import { formatRelative, subDays, distance_in_words_to_now } from 'date-fns'
import {formatRelative, subDays, distance_in_words_to_now} from 'date-fns'
import zh_cn from 'date-fns/locale/zh_cn'
export function date2now(d) {
"use strict";
return d
}

export function date(d) {
return distance_in_words_to_now(d, { locale: zh_cn})
return distance_in_words_to_now(d, {locale: zh_cn})
}

function pluralize(time, label) {
Expand Down Expand Up @@ -74,20 +74,21 @@ export function formatTime(time, option) {
const now = new Date()

const diff = (now - d) / 1000

if (diff < 30) {
return '刚刚'
} else if (diff < 3600) { // less 1 hour
return Math.ceil(diff / 60) + '分钟前'
} else if (diff < 3600 * 24) {
return Math.ceil(diff / 3600) + '小时前'
} else if (diff < 3600 * 24 * 2) {
return '1天前'
if (diff >= 0) {
if (diff < 30) {
return '刚刚'
} else if (diff < 3600) { // less 1 hour
return Math.ceil(diff / 60) + '分钟前'
} else if (diff < 3600 * 24) {
return Math.ceil(diff / 3600) + '小时前'
} else if (diff < 3600 * 24 * 2) {
return '1天前'
}
}
if (option) {
return parseTime(time, option)
} else {
if(d.getYear()!=now.getYear()){
if (d.getYear() != now.getYear()) {
return parseTime(d, '{y}-{m}-{d} {h}:{i}')
}
return (d.getMonth() + 1) + '月' + d.getDate() + '日' + d.getHours() + '时' + d.getMinutes() + '分'
Expand Down Expand Up @@ -122,7 +123,7 @@ export function toThousandslsFilter(num) {
return (+num || 0).toString().replace(/^-?\d+/g, m => m.replace(/(?=(?!\b)(\d{3})+$)/g, ','))
}

export function percent(value){
export function percent(value) {
let a = value && (value * 100).toFixed(2)
return `${a}%`
}
Expand Down

0 comments on commit 143383f

Please sign in to comment.