@litianxiang/portal-core 0.1.13 → 0.1.14

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
@@ -218,4 +218,36 @@ declare function useTime(): {
218
218
  isInRange: typeof isInRange;
219
219
  };
220
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 };
221
+ type ThemeMode = 'light' | 'dark';
222
+ type FontSize = 'sm' | 'md' | 'lg';
223
+ interface ThemeConfig {
224
+ mode: ThemeMode;
225
+ fontSize: FontSize;
226
+ }
227
+ /**
228
+ * 从本地缓存初始化主题配置
229
+ */
230
+ declare function initTheme(): ThemeConfig;
231
+ /**
232
+ * 应用主题到文档根节点
233
+ */
234
+ declare function applyTheme(config: ThemeConfig): void;
235
+ /**
236
+ * 监听主题配置变化并自动应用+持久化
237
+ */
238
+ declare function useThemeWatcher(config: ThemeConfig): void;
239
+
240
+ /**
241
+ * 将数字转换为亿元(1 亿元 = 1e8),并格式化小数位
242
+ */
243
+ declare function formatToYi(value: number | string | null | undefined, decimals?: number): string;
244
+ /**
245
+ * 将“手”数转换为“万手”(1 万手 = 10000 手),并格式化小数位
246
+ */
247
+ declare function formatToWanShou(value: number | string | null | undefined, decimals?: number): string;
248
+ /**
249
+ * 将“万元”转换为“亿元”
250
+ */
251
+ declare function formatWanYuanToYi(value: number | string | null | undefined, decimals?: number): string;
252
+
253
+ export { type AppRouterOptions, type BreadcrumbItem, type CoreMenuItem, type CreateAuthHttpClientOptions, type FontSize, type InactivityConfig, type InactivityResult, type LogoutToAuthOptions, type MenuHelper, type MenuHelperOptions, type PermissionHelper, type PermissionHelperOptions, type PresetRangeKey, type ThemeConfig, type ThemeMode, type TimeInput, type TimeRange, type TransformMenuOptions, applyTheme, buildAllMenuTree, buildPageMenuList, calcInactivityAction, createAppRouter, createAuthHttpClient, createLogoutToAuth, createMenuHelper, createPermissionHelper, createRange, findFirstPagePath, formatRange, formatTime, formatToMonthDay, formatToWanShou, formatToYi, formatWanYuanToYi, getPresetRange, humanizeTime, initTheme, isInRange, timeDiff, transformMenuTree, useThemeWatcher, useTime };
package/dist/index.js CHANGED
@@ -693,7 +693,60 @@ function useTime() {
693
693
  isInRange
694
694
  };
695
695
  }
696
+
697
+ // src/theme/theme.ts
698
+ import { watchEffect } from "vue";
699
+ var STORAGE_KEY = "theme_config";
700
+ function initTheme() {
701
+ if (typeof window === "undefined") {
702
+ return { mode: "light", fontSize: "md" };
703
+ }
704
+ const saved = localStorage.getItem(STORAGE_KEY);
705
+ return saved ? JSON.parse(saved) : { mode: "light", fontSize: "md" };
706
+ }
707
+ function applyTheme(config) {
708
+ if (typeof document === "undefined") return;
709
+ const root = document.documentElement;
710
+ const colors = config.mode === "light" ? { primary: "#409EFF", background: "#f5f7fa", text: "#303133", menuBg: "#ffffff" } : { primary: "#1890ff", background: "#001529", text: "rgba(255,255,255,0.85)", menuBg: "#001529" };
711
+ Object.entries(colors).forEach(([name, value]) => {
712
+ root.style.setProperty(`--color-${name}`, value);
713
+ });
714
+ const sizes = { sm: "12px", md: "14px", lg: "16px" };
715
+ root.style.setProperty("--font-size-base", sizes[config.fontSize]);
716
+ }
717
+ function useThemeWatcher(config) {
718
+ watchEffect(() => {
719
+ applyTheme(config);
720
+ if (typeof window !== "undefined") {
721
+ localStorage.setItem(STORAGE_KEY, JSON.stringify(config));
722
+ }
723
+ });
724
+ }
725
+
726
+ // src/number/number.ts
727
+ function formatToYi(value, decimals = 2) {
728
+ if (value === null || value === void 0 || value === "") return "\u2014";
729
+ const num = Number(value);
730
+ if (Number.isNaN(num)) return "\u2014";
731
+ const yi = num / 1e8;
732
+ return yi.toFixed(decimals);
733
+ }
734
+ function formatToWanShou(value, decimals = 2) {
735
+ if (value === null || value === void 0 || value === "") return "\u2014";
736
+ const num = Number(value);
737
+ if (Number.isNaN(num)) return "\u2014";
738
+ const wanShou = num / 1e4;
739
+ return wanShou.toFixed(decimals);
740
+ }
741
+ function formatWanYuanToYi(value, decimals = 2) {
742
+ if (value === null || value === void 0 || value === "") return "\u2014";
743
+ const num = Number(value);
744
+ if (Number.isNaN(num)) return "\u2014";
745
+ const yi = num / 1e4;
746
+ return `${yi.toFixed(decimals)} \u4EBF\u5143`;
747
+ }
696
748
  export {
749
+ applyTheme,
697
750
  buildAllMenuTree,
698
751
  buildPageMenuList,
699
752
  calcInactivityAction,
@@ -707,10 +760,15 @@ export {
707
760
  formatRange,
708
761
  formatTime,
709
762
  formatToMonthDay,
763
+ formatToWanShou,
764
+ formatToYi,
765
+ formatWanYuanToYi,
710
766
  getPresetRange,
711
767
  humanizeTime,
768
+ initTheme,
712
769
  isInRange,
713
770
  timeDiff,
714
771
  transformMenuTree,
772
+ useThemeWatcher,
715
773
  useTime
716
774
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@litianxiang/portal-core",
3
- "version": "0.1.13",
3
+ "version": "0.1.14",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "main": "dist/index.js",