Skip to content

Commit 254a9b5

Browse files
author
jingwenzheng
committed
feat: 更新例子
1 parent 71f65e1 commit 254a9b5

File tree

11 files changed

+153
-190
lines changed

11 files changed

+153
-190
lines changed

src/App.tsx

-13
This file was deleted.

src/main.tsx

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import { createApp } from 'vue'
2-
import './style.css'
32

43
import Home from './views/home'
54

6-
import { Navigator, navigation, onPageChange } from '@0x30/vue-navigation'
5+
import { navigation, onPageChange } from '@0x30/vue-navigation'
76

87
// or use this mode
98
// createApp(
@@ -20,5 +19,5 @@ onPageChange(
2019
(from, to) => {
2120
console.log('页面变化', from, to)
2221
},
23-
{ isEvery: true }
22+
{ isEvery: true },
2423
)

src/routers.tsx

-19
This file was deleted.

src/style.css

-19
This file was deleted.

src/util/index.tsx

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import {
2+
onDidAppear,
3+
onDidDisappear,
4+
onWillAppear,
5+
onWillDisappear,
6+
} from '@0x30/vue-navigation'
7+
8+
const useHooks = (title: string) => {
9+
onWillAppear(() => {
10+
console.log(title, '即将展示')
11+
})
12+
13+
onWillDisappear(() => {
14+
console.log(title, '即将消失')
15+
})
16+
17+
onDidAppear(() => {
18+
console.log(title, '展示')
19+
})
20+
21+
onDidDisappear(() => {
22+
console.log(title, '消失')
23+
})
24+
}
25+
26+
const wait = (timeout: number = 1000) =>
27+
new Promise<void>((res) => {
28+
window.setTimeout(res, timeout)
29+
})
30+
31+
export { useHooks, wait }

src/views/alert/index.module.scss

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
.body {
2-
background-color: red;
2+
background-color: #fff;
3+
display: flex;
4+
flex-direction: column;
5+
padding: 20px;
36
}

src/views/alert/index.tsx

+29-5
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,41 @@
11
import { type PropType, defineComponent } from 'vue'
2-
import { NavPage, SidePage } from '@0x30/vue-navigation-layout'
2+
import { SidePage } from '@0x30/vue-navigation-layout'
33

44
import styles from './index.module.scss'
5+
import { back, push, useQuietPage } from '@0x30/vue-navigation'
56

67
const Component = defineComponent({
78
name: 'AlertPage',
8-
setup: (props, { slots }) => {
9+
props: {
10+
onConfirm: Function as PropType<(res: boolean) => void>,
11+
},
12+
setup: (props) => {
13+
/// 将此页面配置为 安静的页面
14+
useQuietPage()
15+
16+
const onClick = (res: boolean) => {
17+
return async () => {
18+
await back()
19+
props.onConfirm?.(res)
20+
}
21+
}
22+
923
return () => (
10-
<SidePage position='center'>
11-
<div class={styles.body}>detail</div>
24+
<SidePage position="center">
25+
<div class={styles.body}>
26+
<span>是否要返回</span>
27+
<div>
28+
<button onClick={onClick(true)}>确定</button>
29+
<button onClick={onClick(false)}>取消</button>
30+
</div>
31+
</div>
1232
</SidePage>
1333
)
1434
},
1535
})
1636

17-
export default Component
37+
export const useConfirm = () => {
38+
return new Promise<boolean>((resolve) => {
39+
push(<Component onConfirm={resolve} />)
40+
})
41+
}

src/views/detail/index.module.scss

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.body {
2+
background-color: #fff;
3+
}

src/views/detail/index.tsx

+12-27
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,24 @@
11
import { defineComponent } from 'vue'
22
import { NavPage } from '@0x30/vue-navigation-layout'
3-
import { onDidAppear, onDidDisappear, onWillAppear, onWillDisappear, push } from '@0x30/vue-navigation'
3+
import { back, useLeaveBefore } from '@0x30/vue-navigation'
44

5-
import AlertPage from '../alert'
5+
import { useConfirm } from '../alert'
6+
import styles from './index.module.scss'
7+
import { useHooks } from '../../util'
68

79
const Component = defineComponent({
810
name: 'HomePage',
9-
setup: (props, { slots }) => {
10-
11-
onWillAppear(() => {
12-
console.log('detail', '即将展示')
13-
})
14-
15-
onWillDisappear(() => {
16-
console.log('detail', '即将消失')
17-
})
18-
19-
onDidAppear(() => {
20-
console.log('detail', '展示')
21-
})
22-
23-
onDidDisappear(() => {
24-
console.log('detail', '消失')
25-
})
11+
setup: () => {
12+
useHooks('详情')
13+
/// 返回的时候 先弹出框询问用户
14+
useLeaveBefore(useConfirm)
2615

2716
return () => (
28-
<NavPage>
17+
<NavPage class={styles.body}>
2918
detail
30-
<button
31-
onClick={() => {
32-
push(<AlertPage />)
33-
}}
34-
>
35-
alert
36-
</button>
19+
<div>
20+
<button onClick={back}>back</button>
21+
</div>
3722
</NavPage>
3823
)
3924
},

src/views/home/index.module.scss

+5-43
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,8 @@
11
.body {
2-
position: fixed !important;
3-
top: 0 !important;
4-
left: 0 !important;
5-
right: 0 !important;
6-
bottom: 0 !important;
7-
8-
display: flex;
9-
flex-direction: column;
10-
align-items: center;
11-
justify-content: center;
12-
pointer-events: none;
13-
14-
.main {
15-
padding: 20px;
16-
border-radius: 8px;
17-
background-color: rgba(0, 0, 0, 0.7);
18-
color: #fff;
19-
20-
display: flex;
21-
flex-direction: column;
22-
align-items: center;
23-
justify-content: center;
24-
25-
min-width: 88px;
26-
height: 88px;
27-
28-
margin: 0 30px;
29-
30-
box-shadow: -5px 0px 20px 0px rgba(100, 100, 100, 0.15);
31-
32-
*:nth-child(2) {
33-
margin-top: 16px;
34-
}
35-
36-
img {
37-
width: 30px;
38-
height: 30px;
39-
}
2+
background-color: #fff;
3+
}
404

41-
span {
42-
font-size: 14px;
43-
text-align: center;
44-
}
45-
}
5+
.content {
6+
background-color: red;
7+
position: relative;
468
}

0 commit comments

Comments
 (0)