create-weapp-vite 2.3.15 → 2.3.16
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/cli.js +1 -1
- package/dist/index.js +1 -1
- package/dist/{src-D8uqfCKh.js → src-C8kzMXK7.js} +1 -1
- package/package.json +1 -1
- package/templates/wevu/README.md +3 -3
- package/templates/wevu/package.json +1 -1
- package/templates/wevu/src/app.vue +1 -60
- package/templates/wevu/src/pages/index/index.vue +26 -194
- package/templates/wevu/src/pages/layouts/index.vue +0 -18
- package/templates/wevu/weapp-vite.config.ts +0 -7
- package/templates/wevu-tdesign/README.md +3 -6
- package/templates/wevu-tdesign/package.json +1 -1
- package/templates/wevu-tdesign/project.private.config.json +0 -66
- package/templates/wevu-tdesign/src/app.vue +1 -73
- package/templates/wevu-tdesign/src/pages/index/index.vue +19 -362
- package/templates/wevu/src/components/InfoPanel/index.vue +0 -52
- package/templates/wevu/src/components/StatusPill/index.vue +0 -42
- package/templates/wevu/src/packageA/pages/workspace/index.vue +0 -137
- package/templates/wevu/src/packageB/pages/settings/index.vue +0 -131
- package/templates/wevu/src/pages/overview/index.vue +0 -149
- package/templates/wevu-tdesign/public/tabbar/ability-active.png +0 -0
- package/templates/wevu-tdesign/public/tabbar/ability.png +0 -0
- package/templates/wevu-tdesign/public/tabbar/data-active.png +0 -0
- package/templates/wevu-tdesign/public/tabbar/data.png +0 -0
- package/templates/wevu-tdesign/public/tabbar/form-active.png +0 -0
- package/templates/wevu-tdesign/public/tabbar/form.png +0 -0
- package/templates/wevu-tdesign/public/tabbar/home-active.png +0 -0
- package/templates/wevu-tdesign/public/tabbar/home.png +0 -0
- package/templates/wevu-tdesign/public/tabbar/list-active.png +0 -0
- package/templates/wevu-tdesign/public/tabbar/list.png +0 -0
- package/templates/wevu-tdesign/src/components/EmptyState/index.vue +0 -36
- package/templates/wevu-tdesign/src/components/FilterBar/index.vue +0 -64
- package/templates/wevu-tdesign/src/components/FormRow/index.vue +0 -43
- package/templates/wevu-tdesign/src/components/FormStep/index.vue +0 -48
- package/templates/wevu-tdesign/src/components/KpiBoard/index.vue +0 -145
- package/templates/wevu-tdesign/src/components/QuickActionGrid/index.vue +0 -79
- package/templates/wevu-tdesign/src/components/ResultCard/index.vue +0 -51
- package/templates/wevu-tdesign/src/components/SectionTitle/index.vue +0 -34
- package/templates/wevu-tdesign/src/components/TrendCard/index.vue +0 -101
- package/templates/wevu-tdesign/src/components/VirtualHostClassDemo/BrokenCard.vue +0 -46
- package/templates/wevu-tdesign/src/components/VirtualHostClassDemo/FixedExternalClassCard.vue +0 -50
- package/templates/wevu-tdesign/src/components/VirtualHostClassDemo/RecommendedCard.vue +0 -53
- package/templates/wevu-tdesign/src/hooks/useDialog.ts +0 -205
- package/templates/wevu-tdesign/src/hooks/useFormBinder.ts +0 -17
- package/templates/wevu-tdesign/src/hooks/useLayoutFeedbackBridge.ts +0 -17
- package/templates/wevu-tdesign/src/hooks/usePullDownRefresh.ts +0 -12
- package/templates/wevu-tdesign/src/hooks/useToast.ts +0 -100
- package/templates/wevu-tdesign/src/layouts/admin.vue +0 -41
- package/templates/wevu-tdesign/src/layouts/default.vue +0 -23
- package/templates/wevu-tdesign/src/pages/ability/index.vue +0 -164
- package/templates/wevu-tdesign/src/pages/data/index.vue +0 -189
- package/templates/wevu-tdesign/src/pages/form/index.vue +0 -271
- package/templates/wevu-tdesign/src/pages/layout-feedback/components/FeedbackCallerCard.vue +0 -79
- package/templates/wevu-tdesign/src/pages/layout-feedback/index.vue +0 -211
- package/templates/wevu-tdesign/src/pages/layout-store/index.vue +0 -127
- package/templates/wevu-tdesign/src/pages/layouts/index.vue +0 -120
- package/templates/wevu-tdesign/src/pages/list/index.vue +0 -146
- package/templates/wevu-tdesign/src/stores/layoutInteractionDemo.ts +0 -129
- package/templates/wevu-tdesign/src/subpackages/ability/index.vue +0 -103
- package/templates/wevu-tdesign/src/subpackages/lab/class-binding/index.vue +0 -440
- package/templates/wevu-tdesign/src/subpackages/lab/index.vue +0 -169
- package/templates/wevu-tdesign/src/subpackages/lab/virtual-host-class/index.vue +0 -94
- package/templates/wevu-tdesign/src/types/action.ts +0 -14
- package/templates/wevu-tdesign/src/types/list.ts +0 -17
- package/templates/wevu-tdesign/src/utils/changeEvent.ts +0 -53
- package/templates/wevu-tdesign/src/utils/listFilters.ts +0 -34
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
<script setup lang="ts">
|
|
2
|
-
import type { QuickActionItem } from '@/types/action'
|
|
3
|
-
|
|
4
|
-
import { computed } from 'wevu'
|
|
5
|
-
|
|
6
|
-
const props = withDefaults(defineProps<{
|
|
7
|
-
title: string
|
|
8
|
-
subtitle?: string
|
|
9
|
-
items?: QuickActionItem[]
|
|
10
|
-
}>(), {
|
|
11
|
-
subtitle: '',
|
|
12
|
-
items: () => [],
|
|
13
|
-
})
|
|
14
|
-
|
|
15
|
-
const emit = defineEmits<{
|
|
16
|
-
(e: 'select', item: QuickActionItem): void
|
|
17
|
-
}>()
|
|
18
|
-
|
|
19
|
-
defineComponentJson({
|
|
20
|
-
styleIsolation: 'apply-shared',
|
|
21
|
-
})
|
|
22
|
-
|
|
23
|
-
const cards = computed(() => (Array.isArray(props.items) ? props.items : []))
|
|
24
|
-
|
|
25
|
-
function onSelect(item: QuickActionItem) {
|
|
26
|
-
if (item.disabled) {
|
|
27
|
-
return
|
|
28
|
-
}
|
|
29
|
-
emit('select', item)
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
function toneClass(tone?: 'brand' | 'neutral') {
|
|
33
|
-
if (tone === 'brand') {
|
|
34
|
-
return 'bg-[#eef2ff] text-[#3534a5]'
|
|
35
|
-
}
|
|
36
|
-
return 'bg-[#f2f4f8] text-[#5c5b7a]'
|
|
37
|
-
}
|
|
38
|
-
</script>
|
|
39
|
-
|
|
40
|
-
<template>
|
|
41
|
-
<view class="rounded-[24rpx] bg-white p-[20rpx] shadow-[0_18rpx_40rpx_rgba(17,24,39,0.08)]">
|
|
42
|
-
<view class="flex items-end justify-between">
|
|
43
|
-
<view>
|
|
44
|
-
<text class="text-[28rpx] font-semibold text-[#1f1a3f]">
|
|
45
|
-
{{ title }}
|
|
46
|
-
</text>
|
|
47
|
-
<text v-if="subtitle" class="mt-[6rpx] block text-[22rpx] text-[#6f6b8a]">
|
|
48
|
-
{{ subtitle }}
|
|
49
|
-
</text>
|
|
50
|
-
</view>
|
|
51
|
-
</view>
|
|
52
|
-
<view class="mt-[16rpx] grid grid-cols-2 gap-[12rpx]">
|
|
53
|
-
<view
|
|
54
|
-
v-for="item in cards"
|
|
55
|
-
:key="item.key"
|
|
56
|
-
class="rounded-[18rpx] bg-[#f7f7fb] p-[16rpx]"
|
|
57
|
-
:class="item.disabled ? 'opacity-50' : 'opacity-100'"
|
|
58
|
-
@tap="onSelect(item)"
|
|
59
|
-
>
|
|
60
|
-
<view class="flex items-center justify-between">
|
|
61
|
-
<view class="flex items-center gap-[8rpx]">
|
|
62
|
-
<view class="flex h-[36rpx] w-[36rpx] items-center justify-center rounded-[12rpx]" :class="toneClass(item.tone)">
|
|
63
|
-
<t-icon :name="item.icon ?? 'app'" size="22" />
|
|
64
|
-
</view>
|
|
65
|
-
<text class="text-[24rpx] font-semibold text-[#1f1a3f]">
|
|
66
|
-
{{ item.title }}
|
|
67
|
-
</text>
|
|
68
|
-
</view>
|
|
69
|
-
<t-tag v-if="item.tag" size="small" theme="primary" variant="light">
|
|
70
|
-
{{ item.tag }}
|
|
71
|
-
</t-tag>
|
|
72
|
-
</view>
|
|
73
|
-
<text v-if="item.description" class="mt-[10rpx] block text-[20rpx] text-[#6f6b8a]">
|
|
74
|
-
{{ item.description }}
|
|
75
|
-
</text>
|
|
76
|
-
</view>
|
|
77
|
-
</view>
|
|
78
|
-
</view>
|
|
79
|
-
</template>
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
<script setup lang="ts">
|
|
2
|
-
import { computed } from 'wevu'
|
|
3
|
-
|
|
4
|
-
defineOptions({
|
|
5
|
-
options: {
|
|
6
|
-
multipleSlots: true,
|
|
7
|
-
},
|
|
8
|
-
})
|
|
9
|
-
|
|
10
|
-
const props = withDefaults(
|
|
11
|
-
defineProps<{
|
|
12
|
-
title: string
|
|
13
|
-
items?: ResultItem[]
|
|
14
|
-
}>(),
|
|
15
|
-
{
|
|
16
|
-
items: () => [],
|
|
17
|
-
},
|
|
18
|
-
)
|
|
19
|
-
|
|
20
|
-
defineComponentJson({
|
|
21
|
-
styleIsolation: 'apply-shared',
|
|
22
|
-
})
|
|
23
|
-
|
|
24
|
-
interface ResultItem {
|
|
25
|
-
label: string
|
|
26
|
-
value: string | number
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
const rows = computed(() => props.items ?? [])
|
|
30
|
-
</script>
|
|
31
|
-
|
|
32
|
-
<template>
|
|
33
|
-
<view class="rounded-[20rpx] bg-white p-[20rpx] shadow-[0_12rpx_28rpx_rgba(17,24,39,0.08)]">
|
|
34
|
-
<view class="flex items-center justify-between">
|
|
35
|
-
<text class="text-[26rpx] font-semibold text-[#1f1a3f]">
|
|
36
|
-
{{ title }}
|
|
37
|
-
</text>
|
|
38
|
-
<slot name="action" />
|
|
39
|
-
</view>
|
|
40
|
-
<view class="mt-[12rpx] space-y-[10rpx]">
|
|
41
|
-
<view v-for="row in rows" :key="row.label" class="flex items-center justify-between">
|
|
42
|
-
<text class="text-[22rpx] text-[#6f6b8a]">
|
|
43
|
-
{{ row.label }}
|
|
44
|
-
</text>
|
|
45
|
-
<text class="text-[22rpx] font-semibold text-[#1f1a3f]">
|
|
46
|
-
{{ row.value }}
|
|
47
|
-
</text>
|
|
48
|
-
</view>
|
|
49
|
-
</view>
|
|
50
|
-
</view>
|
|
51
|
-
</template>
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
<script setup lang="ts">
|
|
2
|
-
defineOptions({
|
|
3
|
-
options: {
|
|
4
|
-
multipleSlots: true,
|
|
5
|
-
},
|
|
6
|
-
})
|
|
7
|
-
|
|
8
|
-
withDefaults(
|
|
9
|
-
defineProps<{
|
|
10
|
-
title: string
|
|
11
|
-
subtitle?: string
|
|
12
|
-
}>(),
|
|
13
|
-
{
|
|
14
|
-
subtitle: '',
|
|
15
|
-
},
|
|
16
|
-
)
|
|
17
|
-
|
|
18
|
-
defineComponentJson({
|
|
19
|
-
styleIsolation: 'apply-shared',
|
|
20
|
-
})
|
|
21
|
-
</script>
|
|
22
|
-
|
|
23
|
-
<template>
|
|
24
|
-
<view class="flex items-end justify-between">
|
|
25
|
-
<view>
|
|
26
|
-
<text class="text-[30rpx] font-semibold text-[#1f1a3f]">
|
|
27
|
-
{{ title }}
|
|
28
|
-
</text>
|
|
29
|
-
<text v-if="subtitle" class="mt-[6rpx] block text-[22rpx] text-[#6f6b8a]">
|
|
30
|
-
{{ subtitle }}
|
|
31
|
-
</text>
|
|
32
|
-
</view>
|
|
33
|
-
</view>
|
|
34
|
-
</template>
|
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
<script setup lang="ts">
|
|
2
|
-
import { computed } from 'wevu'
|
|
3
|
-
|
|
4
|
-
const props = withDefaults(
|
|
5
|
-
defineProps<{
|
|
6
|
-
title: string
|
|
7
|
-
value: number
|
|
8
|
-
unit?: string
|
|
9
|
-
delta?: number
|
|
10
|
-
progress?: number
|
|
11
|
-
}>(),
|
|
12
|
-
{
|
|
13
|
-
unit: '',
|
|
14
|
-
delta: undefined,
|
|
15
|
-
progress: undefined,
|
|
16
|
-
},
|
|
17
|
-
)
|
|
18
|
-
|
|
19
|
-
defineComponentJson({
|
|
20
|
-
styleIsolation: 'apply-shared',
|
|
21
|
-
})
|
|
22
|
-
|
|
23
|
-
type TrendTone = 'positive' | 'negative' | 'neutral'
|
|
24
|
-
|
|
25
|
-
const tone = computed<TrendTone>(() => {
|
|
26
|
-
if (props.delta === undefined || Number.isNaN(props.delta)) {
|
|
27
|
-
return 'neutral'
|
|
28
|
-
}
|
|
29
|
-
if (props.delta > 0) {
|
|
30
|
-
return 'positive'
|
|
31
|
-
}
|
|
32
|
-
if (props.delta < 0) {
|
|
33
|
-
return 'negative'
|
|
34
|
-
}
|
|
35
|
-
return 'neutral'
|
|
36
|
-
})
|
|
37
|
-
|
|
38
|
-
const hasProgress = computed(() => {
|
|
39
|
-
if (props.progress === undefined || props.progress === null) {
|
|
40
|
-
return false
|
|
41
|
-
}
|
|
42
|
-
return Number.isFinite(Number(props.progress))
|
|
43
|
-
})
|
|
44
|
-
|
|
45
|
-
const progressValue = computed(() => {
|
|
46
|
-
if (!hasProgress.value) {
|
|
47
|
-
return 0
|
|
48
|
-
}
|
|
49
|
-
const raw = Number(props.progress)
|
|
50
|
-
return Math.min(Math.max(raw, 0), 100)
|
|
51
|
-
})
|
|
52
|
-
|
|
53
|
-
function toneText(toneValue: TrendTone) {
|
|
54
|
-
if (toneValue === 'positive') {
|
|
55
|
-
return '↑'
|
|
56
|
-
}
|
|
57
|
-
if (toneValue === 'negative') {
|
|
58
|
-
return '↓'
|
|
59
|
-
}
|
|
60
|
-
return '→'
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
function toneClass(toneValue: TrendTone) {
|
|
64
|
-
if (toneValue === 'positive') {
|
|
65
|
-
return 'text-[#1b7a3a]'
|
|
66
|
-
}
|
|
67
|
-
if (toneValue === 'negative') {
|
|
68
|
-
return 'text-[#b42318]'
|
|
69
|
-
}
|
|
70
|
-
return 'text-[#64748b]'
|
|
71
|
-
}
|
|
72
|
-
</script>
|
|
73
|
-
|
|
74
|
-
<template>
|
|
75
|
-
<view class="rounded-[20rpx] bg-white p-[18rpx] shadow-[0_12rpx_28rpx_rgba(17,24,39,0.08)]">
|
|
76
|
-
<view class="flex items-center justify-between">
|
|
77
|
-
<text class="text-[24rpx] text-[#5b5876]">
|
|
78
|
-
{{ title }}
|
|
79
|
-
</text>
|
|
80
|
-
<text class="text-[20rpx]" :class="toneClass(tone)">
|
|
81
|
-
{{ toneText(tone) }}
|
|
82
|
-
{{ delta === undefined ? '--' : delta }}
|
|
83
|
-
</text>
|
|
84
|
-
</view>
|
|
85
|
-
<view class="mt-[12rpx] flex items-baseline gap-[6rpx]">
|
|
86
|
-
<text class="text-[36rpx] font-bold text-[#1f1a3f]">
|
|
87
|
-
{{ value }}
|
|
88
|
-
</text>
|
|
89
|
-
<text v-if="unit" class="text-[20rpx] text-[#7a7aa0]">
|
|
90
|
-
{{ unit }}
|
|
91
|
-
</text>
|
|
92
|
-
</view>
|
|
93
|
-
<t-progress
|
|
94
|
-
v-if="hasProgress"
|
|
95
|
-
class="mt-[12rpx]"
|
|
96
|
-
:percentage="progressValue"
|
|
97
|
-
status="active"
|
|
98
|
-
stroke-width="6"
|
|
99
|
-
/>
|
|
100
|
-
</view>
|
|
101
|
-
</template>
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
<script setup lang="ts">
|
|
2
|
-
defineProps<{
|
|
3
|
-
title: string
|
|
4
|
-
subtitle: string
|
|
5
|
-
}>()
|
|
6
|
-
|
|
7
|
-
defineComponentJson({
|
|
8
|
-
styleIsolation: 'apply-shared',
|
|
9
|
-
})
|
|
10
|
-
</script>
|
|
11
|
-
|
|
12
|
-
<template>
|
|
13
|
-
<view class="demo-card">
|
|
14
|
-
<text class="demo-title">
|
|
15
|
-
{{ title }}
|
|
16
|
-
</text>
|
|
17
|
-
<text class="demo-subtitle">
|
|
18
|
-
{{ subtitle }}
|
|
19
|
-
</text>
|
|
20
|
-
</view>
|
|
21
|
-
</template>
|
|
22
|
-
|
|
23
|
-
<style>
|
|
24
|
-
.demo-card {
|
|
25
|
-
display: flex;
|
|
26
|
-
flex-direction: column;
|
|
27
|
-
gap: 10rpx;
|
|
28
|
-
padding: 20rpx;
|
|
29
|
-
background: #fff;
|
|
30
|
-
border-radius: 20rpx;
|
|
31
|
-
box-shadow: 0 12rpx 28rpx rgb(17 24 39 / 8%);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
.demo-title {
|
|
35
|
-
display: block;
|
|
36
|
-
font-size: 28rpx;
|
|
37
|
-
font-weight: 600;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
.demo-subtitle {
|
|
41
|
-
display: block;
|
|
42
|
-
font-size: 22rpx;
|
|
43
|
-
line-height: 1.6;
|
|
44
|
-
opacity: 0.82;
|
|
45
|
-
}
|
|
46
|
-
</style>
|
package/templates/wevu-tdesign/src/components/VirtualHostClassDemo/FixedExternalClassCard.vue
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
<script setup lang="ts">
|
|
2
|
-
defineOptions({
|
|
3
|
-
externalClasses: ['class'],
|
|
4
|
-
})
|
|
5
|
-
|
|
6
|
-
defineProps<{
|
|
7
|
-
title: string
|
|
8
|
-
subtitle: string
|
|
9
|
-
}>()
|
|
10
|
-
|
|
11
|
-
defineComponentJson({
|
|
12
|
-
styleIsolation: 'apply-shared',
|
|
13
|
-
})
|
|
14
|
-
</script>
|
|
15
|
-
|
|
16
|
-
<template>
|
|
17
|
-
<view class="demo-card class">
|
|
18
|
-
<text class="demo-title">
|
|
19
|
-
{{ title }}
|
|
20
|
-
</text>
|
|
21
|
-
<text class="demo-subtitle">
|
|
22
|
-
{{ subtitle }}
|
|
23
|
-
</text>
|
|
24
|
-
</view>
|
|
25
|
-
</template>
|
|
26
|
-
|
|
27
|
-
<style>
|
|
28
|
-
.demo-card {
|
|
29
|
-
display: flex;
|
|
30
|
-
flex-direction: column;
|
|
31
|
-
gap: 10rpx;
|
|
32
|
-
padding: 20rpx;
|
|
33
|
-
background: #fff;
|
|
34
|
-
border-radius: 20rpx;
|
|
35
|
-
box-shadow: 0 12rpx 28rpx rgb(17 24 39 / 8%);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
.demo-title {
|
|
39
|
-
display: block;
|
|
40
|
-
font-size: 28rpx;
|
|
41
|
-
font-weight: 600;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
.demo-subtitle {
|
|
45
|
-
display: block;
|
|
46
|
-
font-size: 22rpx;
|
|
47
|
-
line-height: 1.6;
|
|
48
|
-
opacity: 0.82;
|
|
49
|
-
}
|
|
50
|
-
</style>
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
<script setup lang="ts">
|
|
2
|
-
defineOptions({
|
|
3
|
-
externalClasses: ['custom-class'],
|
|
4
|
-
})
|
|
5
|
-
|
|
6
|
-
const props = withDefaults(defineProps<{
|
|
7
|
-
title: string
|
|
8
|
-
subtitle: string
|
|
9
|
-
rootStyle?: string
|
|
10
|
-
}>(), {
|
|
11
|
-
rootStyle: '',
|
|
12
|
-
})
|
|
13
|
-
|
|
14
|
-
defineComponentJson({
|
|
15
|
-
styleIsolation: 'apply-shared',
|
|
16
|
-
})
|
|
17
|
-
</script>
|
|
18
|
-
|
|
19
|
-
<template>
|
|
20
|
-
<view class="demo-card custom-class" :style="props.rootStyle">
|
|
21
|
-
<text class="demo-title">
|
|
22
|
-
{{ title }}
|
|
23
|
-
</text>
|
|
24
|
-
<text class="demo-subtitle">
|
|
25
|
-
{{ subtitle }}
|
|
26
|
-
</text>
|
|
27
|
-
</view>
|
|
28
|
-
</template>
|
|
29
|
-
|
|
30
|
-
<style>
|
|
31
|
-
.demo-card {
|
|
32
|
-
display: flex;
|
|
33
|
-
flex-direction: column;
|
|
34
|
-
gap: 10rpx;
|
|
35
|
-
padding: 20rpx;
|
|
36
|
-
background: #fff;
|
|
37
|
-
border-radius: 20rpx;
|
|
38
|
-
box-shadow: 0 12rpx 28rpx rgb(17 24 39 / 8%);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
.demo-title {
|
|
42
|
-
display: block;
|
|
43
|
-
font-size: 28rpx;
|
|
44
|
-
font-weight: 600;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
.demo-subtitle {
|
|
48
|
-
display: block;
|
|
49
|
-
font-size: 22rpx;
|
|
50
|
-
line-height: 1.6;
|
|
51
|
-
opacity: 0.82;
|
|
52
|
-
}
|
|
53
|
-
</style>
|
|
@@ -1,205 +0,0 @@
|
|
|
1
|
-
import Dialog from 'tdesign-miniprogram/dialog/index'
|
|
2
|
-
import { getCurrentInstance, resolveLayoutBridge, resolveLayoutHost } from 'wevu'
|
|
3
|
-
import { LAYOUT_DIALOG_BRIDGE_KEY } from '@/hooks/useLayoutFeedbackBridge'
|
|
4
|
-
|
|
5
|
-
export interface DialogOptions {
|
|
6
|
-
bridgeKey?: string
|
|
7
|
-
context?: any
|
|
8
|
-
selector?: string
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
interface BaseDialogPayload {
|
|
12
|
-
bridgeKey?: string
|
|
13
|
-
confirmBtn?: string
|
|
14
|
-
content: string
|
|
15
|
-
context?: any
|
|
16
|
-
selector?: string
|
|
17
|
-
title: string
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export interface AlertOptions extends BaseDialogPayload {}
|
|
21
|
-
|
|
22
|
-
export interface ConfirmOptions extends BaseDialogPayload {
|
|
23
|
-
cancelBtn?: string
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
interface HostDialogInstance {
|
|
27
|
-
_onCancel?: (reason?: unknown) => void
|
|
28
|
-
_onConfirm?: (value?: unknown) => void
|
|
29
|
-
close?: () => void
|
|
30
|
-
setData?: (payload: Record<string, unknown>) => void
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
type DialogMode = 'alert' | 'confirm'
|
|
34
|
-
|
|
35
|
-
type ResolvedDialogPayload<T extends BaseDialogPayload> = Omit<T, 'bridgeKey' | 'context' | 'selector'>
|
|
36
|
-
|
|
37
|
-
function resolveDialogContext(options: DialogOptions) {
|
|
38
|
-
return options.bridgeKey
|
|
39
|
-
? resolveLayoutBridge(options.bridgeKey, options.context ?? getCurrentInstance())
|
|
40
|
-
: options.context ?? getCurrentInstance()
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
function resolveDialogHost(options: DialogOptions) {
|
|
44
|
-
const bridgeKey = options.bridgeKey ?? LAYOUT_DIALOG_BRIDGE_KEY
|
|
45
|
-
const context = resolveDialogContext({
|
|
46
|
-
bridgeKey,
|
|
47
|
-
context: options.context,
|
|
48
|
-
})
|
|
49
|
-
const host = bridgeKey
|
|
50
|
-
? resolveLayoutHost<HostDialogInstance>(bridgeKey, { context })
|
|
51
|
-
: options.selector
|
|
52
|
-
? context?.selectComponent?.(options.selector) ?? null
|
|
53
|
-
: null
|
|
54
|
-
|
|
55
|
-
return {
|
|
56
|
-
context,
|
|
57
|
-
host,
|
|
58
|
-
selector: options.selector,
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
function closeDialogHost(host: HostDialogInstance) {
|
|
63
|
-
if (typeof host.close === 'function') {
|
|
64
|
-
host.close()
|
|
65
|
-
return
|
|
66
|
-
}
|
|
67
|
-
if (typeof host.setData === 'function') {
|
|
68
|
-
host.setData({ visible: false })
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
function attachHostDialogHandlers(
|
|
73
|
-
host: HostDialogInstance,
|
|
74
|
-
handlers: {
|
|
75
|
-
onCancel?: (reason?: unknown) => void
|
|
76
|
-
onConfirm?: (value?: unknown) => void
|
|
77
|
-
},
|
|
78
|
-
) {
|
|
79
|
-
const originalConfirm = typeof host._onConfirm === 'function' ? host._onConfirm : undefined
|
|
80
|
-
const originalCancel = typeof host._onCancel === 'function' ? host._onCancel : undefined
|
|
81
|
-
|
|
82
|
-
host._onConfirm = (value?: unknown) => {
|
|
83
|
-
host._onConfirm = originalConfirm
|
|
84
|
-
host._onCancel = originalCancel
|
|
85
|
-
|
|
86
|
-
if (originalConfirm) {
|
|
87
|
-
originalConfirm.call(host, value)
|
|
88
|
-
}
|
|
89
|
-
else {
|
|
90
|
-
closeDialogHost(host)
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
handlers.onConfirm?.(value)
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
host._onCancel = (reason?: unknown) => {
|
|
97
|
-
host._onConfirm = originalConfirm
|
|
98
|
-
host._onCancel = originalCancel
|
|
99
|
-
|
|
100
|
-
if (originalCancel) {
|
|
101
|
-
originalCancel.call(host, reason)
|
|
102
|
-
}
|
|
103
|
-
else {
|
|
104
|
-
closeDialogHost(host)
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
handlers.onCancel?.(reason)
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
function normalizeDialogPayload<T extends BaseDialogPayload>(
|
|
112
|
-
mode: DialogMode,
|
|
113
|
-
payload: T,
|
|
114
|
-
): ResolvedDialogPayload<T> {
|
|
115
|
-
const { bridgeKey: _bridgeKey, context: _context, selector: _selector, ...rest } = payload
|
|
116
|
-
|
|
117
|
-
if (mode === 'alert') {
|
|
118
|
-
return {
|
|
119
|
-
...rest,
|
|
120
|
-
cancelBtn: null,
|
|
121
|
-
} as ResolvedDialogPayload<T>
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
return rest as ResolvedDialogPayload<T>
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
function openDialogWithHost<T extends BaseDialogPayload>(
|
|
128
|
-
mode: DialogMode,
|
|
129
|
-
host: HostDialogInstance,
|
|
130
|
-
payload: ResolvedDialogPayload<T>,
|
|
131
|
-
) {
|
|
132
|
-
return new Promise((resolve, reject) => {
|
|
133
|
-
host.setData?.({
|
|
134
|
-
...payload,
|
|
135
|
-
visible: true,
|
|
136
|
-
})
|
|
137
|
-
|
|
138
|
-
attachHostDialogHandlers(host, {
|
|
139
|
-
onConfirm: resolve,
|
|
140
|
-
...(mode === 'confirm' ? { onCancel: reject } : {}),
|
|
141
|
-
})
|
|
142
|
-
})
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
function openDialog<T extends BaseDialogPayload>(mode: DialogMode, payload: T) {
|
|
146
|
-
const bridgeKey = payload.bridgeKey ?? LAYOUT_DIALOG_BRIDGE_KEY
|
|
147
|
-
const { context, host, selector } = resolveDialogHost({
|
|
148
|
-
bridgeKey,
|
|
149
|
-
context: payload.context,
|
|
150
|
-
selector: payload.selector,
|
|
151
|
-
})
|
|
152
|
-
|
|
153
|
-
if (!context) {
|
|
154
|
-
return Promise.resolve()
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
const normalizedPayload = normalizeDialogPayload(mode, payload)
|
|
158
|
-
|
|
159
|
-
if (host && typeof host.setData === 'function') {
|
|
160
|
-
return openDialogWithHost(mode, host, normalizedPayload)
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
if (!selector) {
|
|
164
|
-
return Promise.resolve()
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
const open = mode === 'alert' ? Dialog.alert : Dialog.confirm
|
|
168
|
-
|
|
169
|
-
return open({
|
|
170
|
-
selector,
|
|
171
|
-
context: context as any,
|
|
172
|
-
...normalizedPayload,
|
|
173
|
-
})
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
export function alertDialog(payload: AlertOptions) {
|
|
177
|
-
return openDialog('alert', payload)
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
export function confirmDialog(payload: ConfirmOptions) {
|
|
181
|
-
return openDialog('confirm', payload)
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
export function useDialog(options: DialogOptions = {}) {
|
|
185
|
-
const bridgeKey = options.bridgeKey ?? LAYOUT_DIALOG_BRIDGE_KEY
|
|
186
|
-
const context = options.context ?? getCurrentInstance()
|
|
187
|
-
|
|
188
|
-
function withDefaults<T extends BaseDialogPayload>(payload: T): T {
|
|
189
|
-
return {
|
|
190
|
-
...payload,
|
|
191
|
-
bridgeKey,
|
|
192
|
-
context: payload.context ?? context,
|
|
193
|
-
selector: payload.selector ?? options.selector,
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
return {
|
|
198
|
-
alert(payload: AlertOptions) {
|
|
199
|
-
return alertDialog(withDefaults(payload))
|
|
200
|
-
},
|
|
201
|
-
confirm(payload: ConfirmOptions) {
|
|
202
|
-
return confirmDialog(withDefaults(payload))
|
|
203
|
-
},
|
|
204
|
-
}
|
|
205
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type { ModelBindingOptions, ModelBindingPayload } from 'wevu'
|
|
2
|
-
import { useBindModel } from 'wevu'
|
|
3
|
-
|
|
4
|
-
export function useFormBinder() {
|
|
5
|
-
const bindModel = useBindModel()
|
|
6
|
-
|
|
7
|
-
function changeModel<T, ValueProp extends string = 'value', Formatted = T>(
|
|
8
|
-
path: string,
|
|
9
|
-
options?: ModelBindingOptions<T, 'change', ValueProp, Formatted>,
|
|
10
|
-
): ModelBindingPayload<T, 'change', ValueProp, Formatted> {
|
|
11
|
-
return bindModel(path).model({ event: 'change', ...options })
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
return {
|
|
15
|
-
changeModel,
|
|
16
|
-
}
|
|
17
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
export const LAYOUT_TOAST_BRIDGE_KEY = 'layout-toast'
|
|
2
|
-
export const LAYOUT_DIALOG_BRIDGE_KEY = 'layout-dialog'
|
|
3
|
-
|
|
4
|
-
export interface ToastHostInstance {
|
|
5
|
-
hide?: () => void
|
|
6
|
-
show: (options: Record<string, unknown>) => void
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export interface DialogHostInstance {
|
|
10
|
-
_onCancel?: (reason?: unknown) => void
|
|
11
|
-
_onConfirm?: (value?: unknown) => void
|
|
12
|
-
close?: () => void
|
|
13
|
-
onCancel?: (reason?: unknown) => void
|
|
14
|
-
onConfirm?: (value?: unknown) => void
|
|
15
|
-
properties?: Record<string, unknown>
|
|
16
|
-
setData: (payload: Record<string, unknown>) => void
|
|
17
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { onPullDownRefresh } from 'wevu'
|
|
2
|
-
import { wpi } from 'wevu/api'
|
|
3
|
-
|
|
4
|
-
export function usePullDownRefresh(refresh: () => void | Promise<void>) {
|
|
5
|
-
onPullDownRefresh(async () => {
|
|
6
|
-
try {
|
|
7
|
-
await refresh()
|
|
8
|
-
}
|
|
9
|
-
catch {}
|
|
10
|
-
await wpi.stopPullDownRefresh()
|
|
11
|
-
})
|
|
12
|
-
}
|