@litianxiang/portal-core 0.1.12 → 0.1.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import * as vue_router from 'vue-router';
2
2
  import { RouteRecordRaw } from 'vue-router';
3
+ import { Dayjs } from 'dayjs';
3
4
 
4
5
  interface AppRouterOptions {
5
6
  staticRoutes: RouteRecordRaw[];
@@ -168,4 +169,53 @@ declare function buildPageMenuList(menuList: CoreMenuItem[]): CoreMenuItem[];
168
169
  */
169
170
  declare function findFirstPagePath(menuList: CoreMenuItem[]): string | null;
170
171
 
171
- export { type AppRouterOptions, type BreadcrumbItem, type CoreMenuItem, type CreateAuthHttpClientOptions, type InactivityConfig, type InactivityResult, type LogoutToAuthOptions, type MenuHelper, type MenuHelperOptions, type PermissionHelper, type PermissionHelperOptions, type TransformMenuOptions, buildAllMenuTree, buildPageMenuList, calcInactivityAction, createAppRouter, createAuthHttpClient, createLogoutToAuth, createMenuHelper, createPermissionHelper, findFirstPagePath, transformMenuTree };
172
+ type TimeInput = string | number | Date | Dayjs;
173
+ interface TimeRange<T = Dayjs> {
174
+ start: T;
175
+ end: T;
176
+ }
177
+ /**
178
+ * 标准时间格式化
179
+ */
180
+ declare function formatTime(date: TimeInput, format?: string): string;
181
+ /**
182
+ * 人性化相对时间(如:3分钟前)
183
+ */
184
+ declare function humanizeTime(date: TimeInput): string;
185
+ /**
186
+ * 计算时间差(毫秒)
187
+ */
188
+ declare function timeDiff(start: TimeInput, end?: TimeInput): number;
189
+ /**
190
+ * 将日期转换为月-日格式
191
+ */
192
+ declare function formatToMonthDay(date: TimeInput): string;
193
+ /**
194
+ * 生成日期区间对象(Dayjs)
195
+ */
196
+ declare function createRange(start: TimeInput, end: TimeInput): TimeRange<Dayjs>;
197
+ /**
198
+ * 将日期区间格式化为字符串:2026-02-01 ~ 2026-02-23
199
+ */
200
+ declare function formatRange(start: TimeInput, end: TimeInput, format?: string): string;
201
+ type PresetRangeKey = 'today' | 'yesterday' | 'last7days' | 'last30days' | 'thisMonth' | 'lastMonth';
202
+ /**
203
+ * 获取常用日期区间(用于统计/筛选快捷选项)
204
+ */
205
+ declare function getPresetRange(key: PresetRangeKey, now?: TimeInput): TimeRange<Dayjs>;
206
+ /**
207
+ * 判断某个时间是否在区间内(含边界)
208
+ */
209
+ declare function isInRange(value: TimeInput, range: TimeRange<TimeInput>): boolean;
210
+ declare function useTime(): {
211
+ formatTime: typeof formatTime;
212
+ humanizeTime: typeof humanizeTime;
213
+ timeDiff: typeof timeDiff;
214
+ formatToMonthDay: typeof formatToMonthDay;
215
+ createRange: typeof createRange;
216
+ formatRange: typeof formatRange;
217
+ getPresetRange: typeof getPresetRange;
218
+ isInRange: typeof isInRange;
219
+ };
220
+
221
+ export { type AppRouterOptions, type BreadcrumbItem, type CoreMenuItem, type CreateAuthHttpClientOptions, type InactivityConfig, type InactivityResult, type LogoutToAuthOptions, type MenuHelper, type MenuHelperOptions, type PermissionHelper, type PermissionHelperOptions, type PresetRangeKey, type TimeInput, type TimeRange, type TransformMenuOptions, buildAllMenuTree, buildPageMenuList, calcInactivityAction, createAppRouter, createAuthHttpClient, createLogoutToAuth, createMenuHelper, createPermissionHelper, createRange, findFirstPagePath, formatRange, formatTime, formatToMonthDay, getPresetRange, humanizeTime, isInRange, timeDiff, transformMenuTree, useTime };
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- // src/router.ts
1
+ // src/router/router.ts
2
2
  import { createRouter, createWebHashHistory } from "vue-router";
3
3
  function createAppRouter(options) {
4
4
  const { staticRoutes, getUserStore, getTabStore, getFirstPage, authLoginUrl } = options;
@@ -154,7 +154,7 @@ function createAppRouter(options) {
154
154
  return router;
155
155
  }
156
156
 
157
- // src/auth.ts
157
+ // src/auth/auth.ts
158
158
  function createLogoutToAuth(options) {
159
159
  const {
160
160
  getUserStore,
@@ -223,7 +223,7 @@ function calcInactivityAction(lastActiveTime, now, config = {}) {
223
223
  };
224
224
  }
225
225
 
226
- // src/http.ts
226
+ // src/http/http.ts
227
227
  function createAuthHttpClient(options) {
228
228
  const {
229
229
  axios,
@@ -371,7 +371,7 @@ function createAuthHttpClient(options) {
371
371
  return { http, logoutToAuth };
372
372
  }
373
373
 
374
- // src/permission.ts
374
+ // src/permission/permission.ts
375
375
  function normalizePath(raw) {
376
376
  if (!raw) return "";
377
377
  const [base] = raw.split("?");
@@ -427,7 +427,7 @@ function createPermissionHelper(options) {
427
427
  };
428
428
  }
429
429
 
430
- // src/menu.ts
430
+ // src/menu/menu.ts
431
431
  function normalizePath2(raw) {
432
432
  if (!raw) return "";
433
433
  const [base] = raw.split("?");
@@ -595,6 +595,104 @@ function findFirstPagePath(menuList) {
595
595
  }
596
596
  return null;
597
597
  }
598
+
599
+ // src/time/time.ts
600
+ import dayjs from "dayjs";
601
+ import relativeTime from "dayjs/plugin/relativeTime";
602
+ import isSameOrAfter from "dayjs/plugin/isSameOrAfter";
603
+ import isSameOrBefore from "dayjs/plugin/isSameOrBefore";
604
+ import "dayjs/locale/zh-cn";
605
+ dayjs.extend(relativeTime);
606
+ dayjs.extend(isSameOrAfter);
607
+ dayjs.extend(isSameOrBefore);
608
+ dayjs.locale("zh-cn");
609
+ function formatTime(date, format = "YYYY-MM-DD HH:mm:ss") {
610
+ const d = dayjs(date);
611
+ if (!d.isValid()) return "";
612
+ return d.format(format);
613
+ }
614
+ function humanizeTime(date) {
615
+ return dayjs(date).fromNow();
616
+ }
617
+ function timeDiff(start, end = Date.now()) {
618
+ return dayjs(end).diff(dayjs(start));
619
+ }
620
+ function formatToMonthDay(date) {
621
+ const d = dayjs(date);
622
+ if (!d.isValid()) return "";
623
+ return d.format("MM-DD");
624
+ }
625
+ function createRange(start, end) {
626
+ const s = dayjs(start);
627
+ const e = dayjs(end);
628
+ return s.isBefore(e) ? { start: s, end: e } : { start: e, end: s };
629
+ }
630
+ function formatRange(start, end, format = "YYYY-MM-DD") {
631
+ const { start: s, end: e } = createRange(start, end);
632
+ if (!s.isValid() || !e.isValid()) return "";
633
+ return `${s.format(format)} ~ ${e.format(format)}`;
634
+ }
635
+ function getPresetRange(key, now = dayjs()) {
636
+ const base = dayjs(now);
637
+ switch (key) {
638
+ case "today": {
639
+ const start = base.startOf("day");
640
+ const end = base.endOf("day");
641
+ return { start, end };
642
+ }
643
+ case "yesterday": {
644
+ const start = base.subtract(1, "day").startOf("day");
645
+ const end = base.subtract(1, "day").endOf("day");
646
+ return { start, end };
647
+ }
648
+ case "last7days": {
649
+ const start = base.subtract(6, "day").startOf("day");
650
+ const end = base.endOf("day");
651
+ return { start, end };
652
+ }
653
+ case "last30days": {
654
+ const start = base.subtract(29, "day").startOf("day");
655
+ const end = base.endOf("day");
656
+ return { start, end };
657
+ }
658
+ case "thisMonth": {
659
+ const start = base.startOf("month");
660
+ const end = base.endOf("month");
661
+ return { start, end };
662
+ }
663
+ case "lastMonth": {
664
+ const prev = base.subtract(1, "month");
665
+ const start = prev.startOf("month");
666
+ const end = prev.endOf("month");
667
+ return { start, end };
668
+ }
669
+ default: {
670
+ const start = base.startOf("day");
671
+ const end = base.endOf("day");
672
+ return { start, end };
673
+ }
674
+ }
675
+ }
676
+ function isInRange(value, range) {
677
+ const v = dayjs(value);
678
+ const s = dayjs(range.start);
679
+ const e = dayjs(range.end);
680
+ if (!v.isValid() || !s.isValid() || !e.isValid()) return false;
681
+ const { start, end } = createRange(s, e);
682
+ return v.isSameOrAfter(start) && v.isSameOrBefore(end);
683
+ }
684
+ function useTime() {
685
+ return {
686
+ formatTime,
687
+ humanizeTime,
688
+ timeDiff,
689
+ formatToMonthDay,
690
+ createRange,
691
+ formatRange,
692
+ getPresetRange,
693
+ isInRange
694
+ };
695
+ }
598
696
  export {
599
697
  buildAllMenuTree,
600
698
  buildPageMenuList,
@@ -604,6 +702,15 @@ export {
604
702
  createLogoutToAuth,
605
703
  createMenuHelper,
606
704
  createPermissionHelper,
705
+ createRange,
607
706
  findFirstPagePath,
608
- transformMenuTree
707
+ formatRange,
708
+ formatTime,
709
+ formatToMonthDay,
710
+ getPresetRange,
711
+ humanizeTime,
712
+ isInRange,
713
+ timeDiff,
714
+ transformMenuTree,
715
+ useTime
609
716
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@litianxiang/portal-core",
3
- "version": "0.1.12",
3
+ "version": "0.1.13",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -14,11 +14,13 @@
14
14
  },
15
15
  "peerDependencies": {
16
16
  "vue": "^3.5.0",
17
- "vue-router": "^4.5.0"
17
+ "vue-router": "^4.5.0",
18
+ "dayjs": "^1.11.0"
18
19
  },
19
20
  "devDependencies": {
20
21
  "tsup": "^8.3.0",
21
- "typescript": "^5.6.3"
22
+ "typescript": "^5.6.3",
23
+ "dayjs": "^1.11.13"
22
24
  },
23
25
  "license": "UNLICENSED"
24
26
  }