@ysgroup/ui 0.1.38 → 0.1.39

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ysgroup/ui",
3
- "version": "0.1.38",
3
+ "version": "0.1.39",
4
4
  "type": "module",
5
5
  "main": "src/index.ts",
6
6
  "types": "src/index.ts",
@@ -9,7 +9,7 @@
9
9
  "@ysgroup/contracts": "0.1.8"
10
10
  },
11
11
  "peerDependencies": {
12
- "@ysgroup/theme": ">=0.2.0",
12
+ "@ysgroup/theme": ">=0.2.3",
13
13
  "element-plus": ">=2.9",
14
14
  "vue": ">=3.5"
15
15
  },
@@ -20,5 +20,8 @@
20
20
  ],
21
21
  "publishConfig": {
22
22
  "access": "public"
23
+ },
24
+ "devDependencies": {
25
+ "@ysgroup/theme": "^0.2.3"
23
26
  }
24
- }
27
+ }
@@ -1,17 +1,28 @@
1
1
  <script setup lang="ts">
2
- import { ref } from "vue";
2
+ import { onBeforeUnmount, ref } from "vue";
3
3
  import { Moon, Setting, Sunny } from "@element-plus/icons-vue";
4
- import { applyTheme, currentMode, type ThemeMode } from "@ysgroup/theme";
4
+ import {
5
+ applyTheme,
6
+ currentMode,
7
+ resolvedMode,
8
+ THEME_CHANGE_EVENT,
9
+ type ThemeMode,
10
+ } from "@ysgroup/theme";
5
11
 
6
12
  defineProps<{ username?: string }>();
7
13
  const emit = defineEmits<{ settings: []; logout: [] }>();
8
- const mode = ref<ThemeMode>(
9
- document.documentElement.getAttribute("data-theme") === "dark"
10
- ? "dark"
11
- : "light",
12
- );
14
+ const mode = ref<ThemeMode>(resolvedMode());
13
15
  const dropdown = ref<{ handleClose: () => void } | null>(null);
14
- if (currentMode() === "auto") applyTheme(mode.value);
16
+ if (currentMode() === "auto") applyTheme(mode.value, "sync");
17
+
18
+ // 登录后按账号偏好切换、或别处切换时,图标跟着变。
19
+ function onThemeChange() {
20
+ mode.value = resolvedMode();
21
+ }
22
+ window.addEventListener(THEME_CHANGE_EVENT, onThemeChange);
23
+ onBeforeUnmount(() =>
24
+ window.removeEventListener(THEME_CHANGE_EVENT, onThemeChange),
25
+ );
15
26
 
16
27
  function selectTheme(next: ThemeMode) {
17
28
  if (next !== "light" && next !== "dark") return;
@@ -1,8 +1,13 @@
1
1
  <!-- YsLoginPage —— 统一登录页。口令由 @ysgroup/core 密封后提交。 -->
2
2
  <script setup lang="ts">
3
- import { ref } from "vue";
3
+ import { onBeforeUnmount, ref } from "vue";
4
4
  import { Loading, Moon, Sunny } from "@element-plus/icons-vue";
5
- import { applyTheme, type ThemeMode } from "@ysgroup/theme";
5
+ import {
6
+ applyTheme,
7
+ resolvedMode,
8
+ THEME_CHANGE_EVENT,
9
+ type ThemeMode,
10
+ } from "@ysgroup/theme";
6
11
 
7
12
  const props = withDefaults(
8
13
  defineProps<{
@@ -31,13 +36,17 @@ const emit = defineEmits<{
31
36
  const username = ref("");
32
37
  const password = ref("");
33
38
  const validationError = ref("");
34
- const mode = ref<ThemeMode>(
35
- document.documentElement.getAttribute("data-theme") === "dark"
36
- ? "dark"
37
- : "light",
38
- );
39
+ const mode = ref<ThemeMode>(resolvedMode());
39
40
  const themeMenu = ref<{ handleClose: () => void } | null>(null);
40
41
 
42
+ function onThemeChange() {
43
+ mode.value = resolvedMode();
44
+ }
45
+ window.addEventListener(THEME_CHANGE_EVENT, onThemeChange);
46
+ onBeforeUnmount(() =>
47
+ window.removeEventListener(THEME_CHANGE_EVENT, onThemeChange),
48
+ );
49
+
41
50
  function selectTheme(next: ThemeMode) {
42
51
  if (next !== "light" && next !== "dark") return;
43
52
  mode.value = next;