hlw-uniapp 1.0.0

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 ADDED
@@ -0,0 +1,43 @@
1
+ {
2
+ "name": "hlw-uniapp",
3
+ "version": "1.0.0",
4
+ "description": "UniApp Vue 3 通用组件库",
5
+ "type": "module",
6
+ "main": "./src/index.ts",
7
+ "module": "./src/index.ts",
8
+ "types": "./src/types.ts",
9
+ "exports": {
10
+ ".": {
11
+ "import": "./src/index.ts",
12
+ "types": "./src/types.ts"
13
+ },
14
+ "./src/components/*": "./src/components/*",
15
+ "./core": {
16
+ "import": "./src/core/index.ts",
17
+ "types": "./src/core/index.ts"
18
+ }
19
+ },
20
+ "files": [
21
+ "src"
22
+ ],
23
+ "sideEffects": [
24
+ "**/*.vue",
25
+ "**/*.scss"
26
+ ],
27
+ "peerDependencies": {
28
+ "vue": "^3.4.0"
29
+ },
30
+ "keywords": [
31
+ "uniapp",
32
+ "vue3",
33
+ "components",
34
+ "weixin",
35
+ "miniprogram"
36
+ ],
37
+ "author": "",
38
+ "license": "MIT",
39
+ "repository": {
40
+ "type": "git",
41
+ "url": ""
42
+ }
43
+ }
@@ -0,0 +1,90 @@
1
+ <template>
2
+ <view class="hlw-header" :style="{ height: totalNavBarHeight + 'px' }">
3
+ <view class="header-bg-layer" :class="hasBgSlot ? '' : props.bgClass">
4
+ <slot name="bg"></slot>
5
+ </view>
6
+ <view class="status-bar-spacer" :style="{ height: statusBarHeight + 'px' }"></view>
7
+ <view class="header-content-area" :style="{ height: NAV_BAR_CONTENT_HEIGHT + 'px' }">
8
+ <slot></slot>
9
+ </view>
10
+ </view>
11
+ </template>
12
+
13
+ <script setup lang="ts">
14
+ import { ref, computed, useSlots } from 'vue';
15
+
16
+ const getNavBarContentHeight = (): number => {
17
+ try {
18
+ const menuInfo = uni.getMenuButtonBoundingClientRect?.();
19
+ if (!menuInfo) return 44;
20
+
21
+ const systemInfo = uni.getSystemInfoSync();
22
+ return (menuInfo.top - systemInfo.statusBarHeight!) * 2 + menuInfo.height;
23
+ } catch {
24
+ return 44;
25
+ }
26
+ };
27
+
28
+ const getStatusBarHeight = (): number => {
29
+ try {
30
+ const systemInfo = uni.getSystemInfoSync();
31
+ return systemInfo.statusBarHeight || 20;
32
+ } catch {
33
+ return 20;
34
+ }
35
+ };
36
+
37
+ const NAV_BAR_CONTENT_HEIGHT = getNavBarContentHeight();
38
+
39
+ interface Props {
40
+ extraHeight?: number;
41
+ bgClass?: string;
42
+ }
43
+
44
+ const props = withDefaults(defineProps<Props>(), {
45
+ extraHeight: 0,
46
+ bgClass: ''
47
+ });
48
+
49
+ const slots = useSlots();
50
+ const hasBgSlot = computed(() => !!slots.bg);
51
+ const statusBarHeight = ref(getStatusBarHeight());
52
+
53
+ const totalNavBarHeight = computed(() => statusBarHeight.value + NAV_BAR_CONTENT_HEIGHT + props.extraHeight);
54
+ </script>
55
+
56
+ <style lang="scss" scoped>
57
+ .hlw-header {
58
+ position: sticky;
59
+ top: 0;
60
+ z-index: 999;
61
+ display: flex;
62
+ flex-direction: column;
63
+ overflow: hidden;
64
+ }
65
+
66
+ .header-bg-layer {
67
+ position: absolute;
68
+ top: 0;
69
+ left: 0;
70
+ right: 0;
71
+ bottom: 0;
72
+ z-index: 0;
73
+ }
74
+
75
+ .status-bar-spacer {
76
+ flex-shrink: 0;
77
+ width: 100%;
78
+ position: relative;
79
+ z-index: 1;
80
+ }
81
+
82
+ .header-content-area {
83
+ flex-shrink: 0;
84
+ width: 100%;
85
+ display: flex;
86
+ align-items: center;
87
+ position: relative;
88
+ z-index: 1;
89
+ }
90
+ </style>
@@ -0,0 +1,40 @@
1
+ <template>
2
+ <view class="hlw-page">
3
+ <view class="hlw-page-header">
4
+ <slot name="header"></slot>
5
+ </view>
6
+
7
+ <scroll-view
8
+ class="hlw-page-content"
9
+ :scroll-y="true"
10
+ :enable-flex="true"
11
+ :enhanced="true"
12
+ :show-scrollbar="true"
13
+ >
14
+ <slot></slot>
15
+ </scroll-view>
16
+ </view>
17
+ </template>
18
+
19
+ <script setup lang="ts">
20
+ </script>
21
+
22
+ <style lang="scss" scoped>
23
+ .hlw-page {
24
+ width: 100%;
25
+ height: 100vh;
26
+ display: flex;
27
+ flex-direction: column;
28
+ overflow: hidden;
29
+ }
30
+
31
+ .hlw-page-header {
32
+ flex-shrink: 0;
33
+ }
34
+
35
+ .hlw-page-content {
36
+ flex: 1;
37
+ height: 0;
38
+ width: 100%;
39
+ }
40
+ </style>
@@ -0,0 +1,2 @@
1
+ export { default as HlwHeader } from './hlw-header/index.vue'
2
+ export { default as HlwPage } from './hlw-page/index.vue'
@@ -0,0 +1,2 @@
1
+ export * from './refs'
2
+ export type { UseRefsReturn } from './refs'
@@ -0,0 +1,20 @@
1
+ import { onBeforeUpdate, ref, type Ref } from 'vue'
2
+
3
+ export interface UseRefsReturn {
4
+ refs: Ref<Record<string, any>>
5
+ setRefs: (index: string) => (el: any) => void
6
+ }
7
+
8
+ export function useRefs(): UseRefsReturn {
9
+ const refs = ref<Record<string, any>>({})
10
+
11
+ onBeforeUpdate(() => {
12
+ refs.value = {}
13
+ })
14
+
15
+ const setRefs = (index: string) => (el: any) => {
16
+ refs.value[index] = el
17
+ }
18
+
19
+ return { refs, setRefs }
20
+ }
package/src/index.ts ADDED
@@ -0,0 +1,6 @@
1
+ // Components
2
+ export { HlwHeader, HlwPage } from './components'
3
+
4
+ // Composables
5
+ export { useRefs } from './core'
6
+ export type { UseRefsReturn } from './core'
package/src/types.ts ADDED
@@ -0,0 +1,17 @@
1
+ import type { Ref } from 'vue'
2
+
3
+ // HlwHeader Props
4
+ export interface HlwHeaderProps {
5
+ extraHeight?: number
6
+ bgClass?: string
7
+ }
8
+
9
+ // useRefs return type
10
+ export interface UseRefsReturn {
11
+ refs: Ref<Record<string, any>>
12
+ setRefs: (index: string) => (el: any) => void
13
+ }
14
+
15
+ // Re-export
16
+ export { useRefs } from './core'
17
+ export { HlwHeader, HlwPage } from './components'