-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
151 additions
and
1 deletion.
There are no files selected for viewing
Submodule fs-admin-antdv
updated
4 files
+16 −11 | src/plugin/fast-crud/index.ts | |
+11 −0 | src/views/crud/component/date/crud.jsx | |
+2 −0 | src/views/crud/component/date/mock.js | |
+3 −9 | src/views/crud/component/switch/crud.jsx |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
packages/fast-extends/src/time/components/fs-time-humanize.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
<template> | ||
<span>{{ formatted }}</span> | ||
</template> | ||
|
||
<script lang="ts"> | ||
import dayjs, { Dayjs } from "dayjs"; | ||
import { computed, PropType } from "vue"; | ||
import _ from "lodash-es"; | ||
import humanizeDuration, { HumanizerOptions } from "humanize-duration"; | ||
const defaultOptions = { | ||
language: "zh_CN", | ||
largest: 1 | ||
}; | ||
/** | ||
* 日期人性化格式展示组件 | ||
* 例如几天前,几分钟前,几个小时前 | ||
*/ | ||
export default { | ||
name: "FsTimeHumanize", | ||
props: { | ||
/** | ||
* 日期时间值,支持long,string,date等,由dayjs转化 | ||
*/ | ||
modelValue: { required: false, default: undefined }, | ||
/** | ||
* 输入格式化,不传则由dayjs自动转化 | ||
*/ | ||
valueFormat: { type: String, default: undefined, required: false }, | ||
/** | ||
* 日期输出格式化 | ||
*/ | ||
format: { type: String, default: "YYYY-MM-DD HH:mm:ss", required: false }, | ||
/** | ||
* 距离时间超过多少毫秒时,直接使用format格式,默认大于3天后 | ||
*/ | ||
useFormatGreater: { type: Number, default: 1000 * 60 * 60 * 24 * 3, required: false }, | ||
/** | ||
* HumanizeDuration参数 | ||
* https://github.com/EvanHahn/HumanizeDuration.js | ||
*/ | ||
options: { | ||
type: Object as PropType<HumanizerOptions>, | ||
default() { | ||
return {}; | ||
} | ||
}, | ||
/** | ||
* 前后文本 | ||
*/ | ||
text: { | ||
type: Object as PropType<{ prev: string; after: string }>, | ||
default() { | ||
return {}; | ||
} | ||
} | ||
}, | ||
setup(props) { | ||
const formatted = computed(() => { | ||
if (props.modelValue == null || props.modelValue === "") { | ||
return ""; | ||
} | ||
let date: Dayjs; | ||
if (props.valueFormat != null) { | ||
date = dayjs(props.modelValue, props.valueFormat); | ||
} else { | ||
date = dayjs(props.modelValue); | ||
} | ||
let duration = dayjs().valueOf() - date.valueOf(); | ||
let suffix = props.text.ago ?? "前"; | ||
if (duration < 0) { | ||
suffix = props.text.after ?? "后"; | ||
duration = -duration; | ||
} | ||
if (duration > props.useFormatGreater) { | ||
//间隔时长超过3天,则直接显示格式化时间 | ||
return date.format(props.format); | ||
} | ||
return humanizeDuration(duration, _.merge({}, defaultOptions, props.options)) + suffix; | ||
}); | ||
return { | ||
formatted | ||
}; | ||
} | ||
}; | ||
</script> |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import FsExtendsType from "./type"; | ||
import { utils } from "@fast-crud/fast-crud"; | ||
const asyncModules = import.meta.glob("./components/*.vue"); | ||
const FsExtendsComponents = { | ||
install(app) { | ||
//加载异步组件,异步组件将会被懒加载,所以不用担心打包之后的体积问题 | ||
utils.vite.installAsyncComponents(app, asyncModules, []); | ||
} | ||
}; | ||
|
||
export const FsExtendsTime = { | ||
install(app, options) { | ||
app.use(FsExtendsType, options); | ||
app.use(FsExtendsComponents); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import FsExtendsType from "./type"; | ||
import { utils } from "@fast-crud/fast-crud"; | ||
const modules = import.meta.globEager("./components/*.vue"); | ||
const FsExtendsComponents = { | ||
install(app) { | ||
utils.vite.installSyncComponents(app, modules); | ||
} | ||
}; | ||
|
||
export const FsExtendsTime = { | ||
install(app, options) { | ||
app.use(FsExtendsType, options); | ||
app.use(FsExtendsComponents); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { useTypes } from "@fast-crud/fast-crud"; | ||
import types from "./types"; | ||
|
||
//兼容旧版本 | ||
export default { | ||
install(app, options) { | ||
const newTypes = types(); | ||
const { addTypes } = useTypes(); | ||
addTypes(newTypes); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
export default function () { | ||
return { | ||
"time-humanize": { | ||
column: { | ||
component: { | ||
name: "fs-time-humanize", | ||
vModel: "modelValue" | ||
} | ||
} | ||
} | ||
}; | ||
} |