UNPKG

ci-plus

Version:

ci组件库

73 lines (71 loc) 1.69 kB
import { ref } from 'vue' export type Shortcuts = { text: string; value: Date | (() => Date) } export type DefaltShortcuts = Record<ShortcutsKey, Shortcuts> export type ShortcutsKey = | 'today' | 'tomorrow' | 'yesterday' | 'nextweek' | 'nextmonth' | 'prevmonth' export const defaltShortcuts = { today: { text: '今天', value: new Date(), }, tomorrow: { text: '明天', value: () => { const date = new Date() date.setTime(date.getTime() + 3600 * 1000 * 24) return date }, }, yesterday: { text: '昨天', value: () => { const date = new Date() date.setTime(date.getTime() - 3600 * 1000 * 24) return date }, }, nextweek: { text: '下周', value: () => { const date = new Date() date.setTime(date.getTime() + 3600 * 1000 * 24 * 7) return date }, }, nextmonth: { text: '下个月', value: () => { const date = new Date() date.setTime(date.getTime() + 3600 * 1000 * 24 * 30) return date }, }, prevmonth: { text: '上个月', value: () => { const date = new Date() date.setTime(date.getTime() - 3600 * 1000 * 24 * 30) return date }, }, } as DefaltShortcuts export const shortcuts = (keys?: ShortcutsKey[], is_ref = false) => { if (!keys) { if (!is_ref) return defaltShortcuts return ref(defaltShortcuts) } else { const tem = [] as Shortcuts[] keys.forEach((key) => { if (defaltShortcuts[key]) { tem.push(defaltShortcuts[key]) } }) if (!is_ref) return tem return ref(tem) } }