uview-ultra 4.5.48 → 4.5.53

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.
@@ -0,0 +1,14 @@
1
+ /*
2
+ * @Author : jry
3
+ * @Description : up-root 组件默认值
4
+ */
5
+ export default {
6
+ // root组件
7
+ root: {
8
+ // 是否为根节点附加页面底色(--up-page-bg-color)
9
+ background: true,
10
+ // 是否内嵌全局 toast/notify 宿主
11
+ toastHost: true,
12
+ customStyle: {}
13
+ }
14
+ } as UTSJSONObject
@@ -0,0 +1,57 @@
1
+ <template>
2
+ <view class="up-root" :style="rootStyle">
3
+ <slot></slot>
4
+ <up-root-toast-host v-if="toastHost"></up-root-toast-host>
5
+ </view>
6
+ </template>
7
+
8
+ <script setup lang="uts">
9
+ /**
10
+ * up-root 页面级根组件(uni-app x 蒸汽模式)。
11
+ *
12
+ * uni-app x 的 App.uvue 不允许 template,无法像老工程那样在应用根注入
13
+ * 主题变量 —— 用 up-root 作为每个页面的根容器:把运行时主题系统的
14
+ * CSS 变量表(--up-* / --u-*)绑定到根节点 style,页面与子组件
15
+ * (styleIsolation: 'app-and-page')即可通过 var(--up-*) 消费,
16
+ * 切换暗黑时整页自动刷新。
17
+ */
18
+ defineOptions({
19
+ name: 'up-root',
20
+ styleIsolation: 'app-and-page'
21
+ })
22
+
23
+ import { computed } from 'vue'
24
+ import { propsRoot } from './props.uts'
25
+ import { upThemeVarsStyle, upThemeVar } from '../../libs/theme/theme.uts'
26
+
27
+ const props = defineProps(propsRoot)
28
+
29
+ const rootStyle = computed((): UTSJSONObject => {
30
+ const style = {} as UTSJSONObject
31
+ const vars = upThemeVarsStyle()
32
+ UTSJSONObject.keys(vars).forEach((key: string) => {
33
+ const value = vars[key]
34
+ if (typeof value === 'string') {
35
+ style[key] = value
36
+ }
37
+ })
38
+ if (props.background) {
39
+ style['backgroundColor'] = upThemeVar('--up-page-bg-color', '#f3f4f6')
40
+ style['color'] = upThemeVar('--up-main-color', '#303133')
41
+ }
42
+ const customStyle = props.customStyle
43
+ if (customStyle instanceof UTSJSONObject) {
44
+ const custom = customStyle as UTSJSONObject
45
+ UTSJSONObject.keys(custom).forEach((key: string) => {
46
+ style[key] = custom[key]
47
+ })
48
+ }
49
+ return style
50
+ })
51
+ </script>
52
+
53
+ <style>
54
+ .up-root {
55
+ flex: 1;
56
+ }
57
+ </style>
@@ -0,0 +1,35 @@
1
+ <template>
2
+ <view class="up-root" :style="[rootVars, backgroundStyle, customStyle]">
3
+ <slot></slot>
4
+ <RootToastHost v-if="toastHost"></RootToastHost>
5
+ </view>
6
+ </template>
7
+
8
+ <script setup>
9
+ /**
10
+ * up-root 页面级根组件(uni-app Vue3 侧)。
11
+ *
12
+ * Vue3 侧的主题变量由 index.js 安装的全局属性 helpers 提供
13
+ * (upThemeVars / upThemePageStyle),行为与 .uvue 版对齐。
14
+ */
15
+ defineOptions({
16
+ name: 'up-root',
17
+ styleIsolation: 'app-and-page'
18
+ })
19
+
20
+ import { computed, getCurrentInstance } from 'vue'
21
+ import { propsRoot } from './props.js'
22
+ import RootToastHost from '../up-root-toast-host/up-root-toast-host.vue'
23
+
24
+ const props = defineProps(propsRoot)
25
+ const { proxy } = getCurrentInstance() || {}
26
+
27
+ const rootVars = computed(() => proxy?.upThemeVars || {})
28
+ const backgroundStyle = computed(() => (props.background ? (proxy?.upThemePageStyle || {}) : {}))
29
+ </script>
30
+
31
+ <style scoped>
32
+ .up-root {
33
+ min-height: 100vh;
34
+ }
35
+ </style>
@@ -0,0 +1,27 @@
1
+ <template>
2
+ <up-toast ref="toastRef"></up-toast>
3
+ <up-notify ref="notifyRef"></up-notify>
4
+ </template>
5
+
6
+ <script setup lang="uts">
7
+ defineOptions({
8
+ name: 'up-root-toast-host',
9
+ styleIsolation: 'app-and-page'
10
+ })
11
+
12
+ import { onBeforeUnmount, onMounted, ref } from 'vue'
13
+ import { setRootToastRef, setRootNotifyRef } from '../../libs/root/rootState.uts'
14
+
15
+ const toastRef = ref<ComponentPublicInstance | null>(null)
16
+ const notifyRef = ref<ComponentPublicInstance | null>(null)
17
+
18
+ onMounted(() => {
19
+ setRootToastRef(toastRef.value)
20
+ setRootNotifyRef(notifyRef.value)
21
+ })
22
+
23
+ onBeforeUnmount(() => {
24
+ setRootToastRef(null)
25
+ setRootNotifyRef(null)
26
+ })
27
+ </script>
package/index.uts CHANGED
@@ -81,9 +81,56 @@ class UPUtils {
81
81
  }
82
82
  }
83
83
  const uputils = new UPUtils()
84
+
85
+ // 运行时主题系统(蒸汽模式暗黑支持)
86
+ import {
87
+ initThemeSystem,
88
+ setTheme,
89
+ setThemePreference,
90
+ getThemePreference,
91
+ getSystemTheme,
92
+ getThemeVars,
93
+ upThemeVar,
94
+ upThemeIsDark,
95
+ upThemeVarsStyle,
96
+ getThemePageStyle,
97
+ getThemeCardStyle,
98
+ getThemeTabBarStyle,
99
+ applyNativeThemeUI,
100
+ upThemeMode,
101
+ upThemePreference,
102
+ upThemeVersion,
103
+ upThemeVars
104
+ } from './libs/theme/theme.uts'
105
+ export {
106
+ initThemeSystem,
107
+ setTheme,
108
+ setThemePreference,
109
+ getThemePreference,
110
+ getSystemTheme,
111
+ getThemeVars,
112
+ upThemeVar,
113
+ upThemeIsDark,
114
+ upThemeVarsStyle,
115
+ getThemePageStyle,
116
+ getThemeCardStyle,
117
+ getThemeTabBarStyle,
118
+ applyNativeThemeUI
119
+ }
120
+
121
+ // 全局 root 宿主(up-root + 全局 toast/notify)
122
+ import {
123
+ rootToast,
124
+ rootNotify,
125
+ setRootToastRef,
126
+ setRootNotifyRef
127
+ } from './libs/root/rootState.uts'
128
+ export { rootToast, rootNotify, setRootToastRef, setRootNotifyRef }
129
+
84
130
  export const install = (app: VueApp): void => {
85
131
  app.config.globalProperties.$u = uputils
86
132
  app.config.globalProperties.$up = uputils
133
+ initThemeSystem()
87
134
  }
88
135
 
89
136
  export default {
@@ -0,0 +1,74 @@
1
+ /**
2
+ * uni-app x(蒸汽模式)全局 root 宿主状态。
3
+ *
4
+ * up-root-toast-host.uvue 挂载时把 up-toast / up-notify 的组件实例注册进来,
5
+ * 业务侧通过 rootToast() / rootNotify() 触发全局提示;没有宿主时降级
6
+ * uni.showToast。
7
+ */
8
+ import { ref } from 'vue'
9
+
10
+ export const rootToastRef = ref<ComponentPublicInstance | null>(null)
11
+ export const rootNotifyRef = ref<ComponentPublicInstance | null>(null)
12
+
13
+ export function setRootToastRef(instance: ComponentPublicInstance | null): void {
14
+ rootToastRef.value = instance
15
+ }
16
+
17
+ export function setRootNotifyRef(instance: ComponentPublicInstance | null): void {
18
+ rootNotifyRef.value = instance
19
+ }
20
+
21
+ function normalizeOptions(options: UTSJSONObject | string): UTSJSONObject {
22
+ if (options instanceof String) {
23
+ const obj = {} as UTSJSONObject
24
+ obj['message'] = options.toString()
25
+ return obj
26
+ }
27
+ const source = options as UTSJSONObject
28
+ const message = source['message']
29
+ if (message == null) {
30
+ const title = source['title']
31
+ if (title != null && typeof title === 'string') {
32
+ source['message'] = title
33
+ }
34
+ }
35
+ return source
36
+ }
37
+
38
+ export function rootToast(options: UTSJSONObject | string): void {
39
+ const toastOptions = normalizeOptions(options)
40
+ const instance = rootToastRef.value
41
+ if (instance != null) {
42
+ instance.$callMethod('show', toastOptions)
43
+ return
44
+ }
45
+ const message = toastOptions['message']
46
+ if (message == null || typeof message !== 'string') return
47
+ const durationValue = toastOptions['duration']
48
+ let duration = 2000
49
+ if (typeof durationValue === 'number') duration = Math.round(durationValue as number)
50
+ uni.showToast({
51
+ title: message as string,
52
+ icon: 'none',
53
+ duration
54
+ })
55
+ }
56
+
57
+ export function rootNotify(options: UTSJSONObject | string): void {
58
+ const notifyOptions = normalizeOptions(options)
59
+ const instance = rootNotifyRef.value
60
+ if (instance != null) {
61
+ instance.$callMethod('show', notifyOptions)
62
+ return
63
+ }
64
+ const message = notifyOptions['message']
65
+ if (message == null || typeof message !== 'string') return
66
+ const durationValue = notifyOptions['duration']
67
+ let duration = 3000
68
+ if (typeof durationValue === 'number') duration = Math.round(durationValue as number)
69
+ uni.showToast({
70
+ title: message as string,
71
+ icon: 'none',
72
+ duration
73
+ })
74
+ }