D2Admin 1.7

Former-commit-id: 3010ce31114fdc121006451c72f9e18306239fd2
This commit is contained in:
liyang
2019-05-07 09:26:18 +08:00
parent 46bc6ca451
commit d07d15ed8c
952 changed files with 171232 additions and 0 deletions
+3
View File
@@ -0,0 +1,3 @@
> 1%
last 2 versions
not ie <= 8
+21
View File
@@ -0,0 +1,21 @@
.DS_Store
node_modules
/dist
# local env files
.env.local
.env.*.local
# Log files
npm-debug.log*
yarn-debug.log*
yarn-error.log*
# Editor directories and files
.idea
.vscode
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw*
+5
View File
@@ -0,0 +1,5 @@
module.exports = {
plugins: {
autoprefixer: {}
}
}
+1
View File
@@ -0,0 +1 @@
# filters-dayjs
+5
View File
@@ -0,0 +1,5 @@
module.exports = {
presets: [
'@vue/app'
]
}
File diff suppressed because it is too large Load Diff
+18
View File
@@ -0,0 +1,18 @@
{
"name": "@d2-admin/filters-dayjs",
"version": "1.0.3",
"main": "dist/@d2-admin/filters-dayjs.common.js",
"scripts": {
"build": "vue-cli-service build --target lib --name @d2-admin/filters-dayjs --entry src/main.js"
},
"dependencies": {
"core-js": "^2.6.5",
"dayjs": "^1.8.12",
"vue": "^2.6.6"
},
"devDependencies": {
"@vue/cli-plugin-babel": "^3.0.0",
"@vue/cli-service": "^3.0.0",
"vue-template-compiler": "^2.5.21"
}
}
+86
View File
@@ -0,0 +1,86 @@
// 日期时间相关 filter
// https://github.com/iamkun/dayjs/blob/master/docs/zh-cn/API-reference.md
import dayjs from 'dayjs'
// 对象代理
const P = Day => {
return new Proxy(Day, {
get (target, key) {
if (dayjs.isDayjs(target)) {
// 是 Dayjs 对象,正常返回
return target[key]
} else {
// 不是 Dayjs 对象
if (dayjs(target).isValid()) {
// 尝试帮用户解析成 Dayjs 对象
return dayjs(target)[key]
} else {
// 无法解析
return function () {
return '无效日期'
}
}
}
},
set (target, key, value) {
target[key] = value
}
})
}
export default {
// ---------- [ dayjs 解析 ] ----------
// 时间字符串 | Date 对象 | Unix 时间戳 (毫秒)
day: value => dayjs(value),
// Unix 时间戳 (秒)
date_unix: value => dayjs.unix(value),
// ---------- [ 获取 ] ----------
date_year: Day => P(Day).year(),
date_month: Day => P(Day).month(),
date_date: Day => P(Day).date(),
date_day: Day => P(Day).day(),
date_hour: Day => P(Day).hour(),
date_minute: Day => P(Day).minute(),
date_second: Day => P(Day).second(),
date_millisecond: Day => P(Day).millisecond(),
// ---------- [ 设置 ] ----------
// date | day | month | year | hour | minute | second | millisecond
// 对大小写不敏感
date_set: (Day, unit, value) => P(Day).set(unit, value),
// ---------- [ 操作 ] ----------
// 增加
date_add: (Day, value, unit) => P(Day).add(value, unit),
// 减少
date_subtract: (Day, value, unit) => P(Day).subtract(value, unit),
// 开头时间
date_startof: (Day, unit) => P(Day).startOf(unit),
// 末尾时间
date_endof: (Day, unit) => P(Day).endOf(unit),
// ---------- [ 显示 ] ----------
// 格式化
date_format: (Day, setting = 'YYYY-MM-DD HH:mm:ss') => P(Day).format(setting),
// 时间差
date_diff: (Day, Day2 = '', unit = 'millisecond', accurate = false) => P(Day).diff(dayjs(Day2), unit, accurate),
// Unix 时间戳 (毫秒)
date_value_millisecond: Day => P(Day).valueOf(),
// Unix 时间戳 (秒)
date_value_second: Day => P(Day).unix(),
// 月份的天数
date_days_in_month: Day => P(Day).daysInMonth(),
// Date 对象
date_to_date: Day => P(Day).toDate(),
// JSON
date_to_json: Day => P(Day).toJSON(),
// ISO8601 格式
date_to_iso: Day => P(Day).toISOString(),
// 字符
date_to_string: Day => P(Day).toString(),
// ---------- [ 查询 ] ----------
// 是否之前
date_is_before: (Day, Day2, unit = 'millisecond') => P(Day).isBefore(dayjs(Day2), unit),
// 是否之后
date_is_after: (Day, Day2, unit = 'millisecond') => P(Day).isAfter(dayjs(Day2), unit),
// 是否相同
date_is_same: (Day, Day2, unit = 'millisecond') => P(Day).isSame(dayjs(Day2), unit)
}
+15
View File
@@ -0,0 +1,15 @@
import filters from './filters'
const vueFiltersDate = {
install: function (Vue, options) {
Object.keys(filters).forEach(name => {
Vue.filter(name, filters[name])
})
}
}
if (typeof window !== 'undefined' && window.Vue) {
window.Vue.use(vueFiltersDate)
}
export default vueFiltersDate
File diff suppressed because it is too large Load Diff