create-weapp-vite 2.3.14 → 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-JolaD7Ia.js → src-C8kzMXK7.js} +11 -7
- package/package.json +1 -1
- package/templates/default/.vscode/extensions.json +2 -1
- package/templates/default/package.json +3 -0
- package/templates/lib/.vscode/extensions.json +2 -1
- package/templates/lib/package.json +4 -1
- package/templates/plugin/.vscode/extensions.json +7 -0
- package/templates/plugin/package.json +3 -0
- package/templates/tailwindcss/.vscode/extensions.json +2 -1
- package/templates/tailwindcss/package.json +3 -0
- package/templates/tdesign/.vscode/extensions.json +2 -1
- package/templates/tdesign/package.json +3 -0
- package/templates/vant/.vscode/extensions.json +2 -1
- package/templates/vant/package.json +3 -0
- package/templates/wevu/.vscode/extensions.json +2 -1
- package/templates/wevu/README.md +3 -3
- package/templates/wevu/package.json +4 -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/.vscode/extensions.json +2 -1
- package/templates/wevu-tdesign/README.md +3 -6
- package/templates/wevu-tdesign/package.json +4 -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,169 +0,0 @@
|
|
|
1
|
-
<script setup lang="ts">
|
|
2
|
-
import { computed, ref } from 'wevu'
|
|
3
|
-
import { wpi } from 'wevu/api'
|
|
4
|
-
|
|
5
|
-
import SectionTitle from '@/components/SectionTitle/index.vue'
|
|
6
|
-
import { resolveBooleanChangeValue, resolveNumberChangeValue, resolveStringChangeValue } from '@/utils/changeEvent'
|
|
7
|
-
|
|
8
|
-
definePageJson({
|
|
9
|
-
navigationBarTitleText: '组件实验室',
|
|
10
|
-
backgroundColor: '#f6f7fb',
|
|
11
|
-
})
|
|
12
|
-
|
|
13
|
-
const activeTab = ref('base')
|
|
14
|
-
const rating = ref(4)
|
|
15
|
-
const progress = ref(68)
|
|
16
|
-
const slider = ref(42)
|
|
17
|
-
const toggle = ref(true)
|
|
18
|
-
|
|
19
|
-
const progressValue = computed(() => (Number.isFinite(progress.value) ? progress.value : 0))
|
|
20
|
-
|
|
21
|
-
const tabs = [
|
|
22
|
-
{ value: 'base', label: '基础' },
|
|
23
|
-
{ value: 'feedback', label: '反馈' },
|
|
24
|
-
{ value: 'display', label: '展示' },
|
|
25
|
-
]
|
|
26
|
-
|
|
27
|
-
function handleTabChange(event: unknown) {
|
|
28
|
-
activeTab.value = resolveStringChangeValue(event, activeTab.value)
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
function handleRateChange(event: unknown) {
|
|
32
|
-
rating.value = resolveNumberChangeValue(event, rating.value)
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
function handleSliderChange(event: unknown) {
|
|
36
|
-
slider.value = resolveNumberChangeValue(event, slider.value)
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
function handleToggleChange(event: unknown) {
|
|
40
|
-
toggle.value = resolveBooleanChangeValue(event, !toggle.value)
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
async function navigateTo(url: string) {
|
|
44
|
-
await wpi.navigateTo({
|
|
45
|
-
url,
|
|
46
|
-
})
|
|
47
|
-
}
|
|
48
|
-
</script>
|
|
49
|
-
|
|
50
|
-
<template>
|
|
51
|
-
<view class="min-h-screen bg-[#f6f7fb] px-[28rpx] pb-[88rpx] pt-[24rpx] text-[#1c1c3c]">
|
|
52
|
-
<view class="rounded-[28rpx] bg-linear-to-br from-[#f5f3ff] via-[#ffffff] to-[#eef2ff] p-[20rpx]">
|
|
53
|
-
<SectionTitle title="TDesign 组件实验室" subtitle="常用组件的组合应用" />
|
|
54
|
-
<view class="mt-[12rpx]">
|
|
55
|
-
<t-tabs :value="activeTab" @change="handleTabChange">
|
|
56
|
-
<t-tab-panel v-for="tab in tabs" :key="tab.value" :value="tab.value" :label="tab.label" />
|
|
57
|
-
</t-tabs>
|
|
58
|
-
</view>
|
|
59
|
-
</view>
|
|
60
|
-
|
|
61
|
-
<view class="mt-[18rpx] rounded-[24rpx] bg-white p-[20rpx] shadow-[0_18rpx_40rpx_rgba(17,24,39,0.08)]">
|
|
62
|
-
<view v-if="activeTab === 'base'" class="space-y-[14rpx]">
|
|
63
|
-
<SectionTitle title="基础组件" subtitle="标签、徽标、头像" />
|
|
64
|
-
<view class="flex flex-wrap gap-[10rpx]">
|
|
65
|
-
<t-tag theme="primary" variant="light">
|
|
66
|
-
新品
|
|
67
|
-
</t-tag>
|
|
68
|
-
<t-tag theme="warning" variant="light">
|
|
69
|
-
加急
|
|
70
|
-
</t-tag>
|
|
71
|
-
<t-tag theme="success" variant="light">
|
|
72
|
-
已完成
|
|
73
|
-
</t-tag>
|
|
74
|
-
<t-tag theme="default" variant="outline">
|
|
75
|
-
低风险
|
|
76
|
-
</t-tag>
|
|
77
|
-
</view>
|
|
78
|
-
<view class="flex items-center gap-[14rpx]">
|
|
79
|
-
<t-badge count="8">
|
|
80
|
-
<t-avatar size="small" shape="round">
|
|
81
|
-
A
|
|
82
|
-
</t-avatar>
|
|
83
|
-
</t-badge>
|
|
84
|
-
<t-badge count="new">
|
|
85
|
-
<t-avatar size="small" shape="round">
|
|
86
|
-
B
|
|
87
|
-
</t-avatar>
|
|
88
|
-
</t-badge>
|
|
89
|
-
<t-avatar-group :max="3" size="small">
|
|
90
|
-
<t-avatar>U1</t-avatar>
|
|
91
|
-
<t-avatar>U2</t-avatar>
|
|
92
|
-
<t-avatar>U3</t-avatar>
|
|
93
|
-
<t-avatar>U4</t-avatar>
|
|
94
|
-
</t-avatar-group>
|
|
95
|
-
</view>
|
|
96
|
-
<view class="rounded-[18rpx] bg-[#f7f7fb] p-[16rpx]">
|
|
97
|
-
<SectionTitle title="Vue 模板语法" subtitle="class 绑定、对象/数组语法" />
|
|
98
|
-
<view class="mt-[8rpx]">
|
|
99
|
-
<t-cell-group>
|
|
100
|
-
<t-cell title="Class 绑定实验室" note="子包:/subpackages/lab/class-binding" arrow @tap="navigateTo('/subpackages/lab/class-binding/index')" />
|
|
101
|
-
<t-cell title="virtualHost class 透传实验" note="子包:/subpackages/lab/virtual-host-class" arrow @tap="navigateTo('/subpackages/lab/virtual-host-class/index')" />
|
|
102
|
-
</t-cell-group>
|
|
103
|
-
</view>
|
|
104
|
-
</view>
|
|
105
|
-
</view>
|
|
106
|
-
|
|
107
|
-
<view v-else-if="activeTab === 'feedback'" class="space-y-[14rpx]">
|
|
108
|
-
<SectionTitle title="反馈组件" subtitle="进度、评分、滑块" />
|
|
109
|
-
<t-progress :percentage="progressValue" status="active" stroke-width="8" />
|
|
110
|
-
<view class="flex items-center justify-between">
|
|
111
|
-
<text class="text-[22rpx] text-[#6f6b8a]">
|
|
112
|
-
满意度评分
|
|
113
|
-
</text>
|
|
114
|
-
<t-rate :value="rating" @change="handleRateChange" />
|
|
115
|
-
</view>
|
|
116
|
-
<view class="flex items-center justify-between">
|
|
117
|
-
<text class="text-[22rpx] text-[#6f6b8a]">
|
|
118
|
-
阈值调整
|
|
119
|
-
</text>
|
|
120
|
-
<view class="flex items-center gap-[12rpx]">
|
|
121
|
-
<t-slider :value="slider" @change="handleSliderChange" />
|
|
122
|
-
<text class="text-[22rpx] text-[#6f6b8a]">
|
|
123
|
-
{{ slider }}%
|
|
124
|
-
</text>
|
|
125
|
-
</view>
|
|
126
|
-
</view>
|
|
127
|
-
<view class="flex items-center justify-between">
|
|
128
|
-
<text class="text-[22rpx] text-[#6f6b8a]">
|
|
129
|
-
自动提醒
|
|
130
|
-
</text>
|
|
131
|
-
<t-switch :value="toggle" @change="handleToggleChange" />
|
|
132
|
-
</view>
|
|
133
|
-
</view>
|
|
134
|
-
|
|
135
|
-
<view v-else class="space-y-[14rpx]">
|
|
136
|
-
<SectionTitle title="展示组件" subtitle="提示、轮播、二维码" />
|
|
137
|
-
<t-notice-bar theme="info" content="TDesign 组件可用于丰富产品体验。" />
|
|
138
|
-
<t-swiper :autoplay="true" height="140">
|
|
139
|
-
<t-swiper-item>
|
|
140
|
-
<view class="h-full rounded-[20rpx] bg-linear-to-br from-[#c7d2fe] to-[#f0abfc] p-[16rpx]">
|
|
141
|
-
<text class="text-[24rpx] font-semibold text-white">
|
|
142
|
-
品牌展示
|
|
143
|
-
</text>
|
|
144
|
-
<text class="mt-[6rpx] block text-[20rpx] text-white/80">
|
|
145
|
-
适合做活动横幅
|
|
146
|
-
</text>
|
|
147
|
-
</view>
|
|
148
|
-
</t-swiper-item>
|
|
149
|
-
<t-swiper-item>
|
|
150
|
-
<view class="h-full rounded-[20rpx] bg-linear-to-br from-[#fde68a] to-[#fca5a5] p-[16rpx]">
|
|
151
|
-
<text class="text-[24rpx] font-semibold text-white">
|
|
152
|
-
营销推荐
|
|
153
|
-
</text>
|
|
154
|
-
<text class="mt-[6rpx] block text-[20rpx] text-white/80">
|
|
155
|
-
支持多色主题
|
|
156
|
-
</text>
|
|
157
|
-
</view>
|
|
158
|
-
</t-swiper-item>
|
|
159
|
-
</t-swiper>
|
|
160
|
-
<view class="flex items-center justify-between">
|
|
161
|
-
<text class="text-[22rpx] text-[#6f6b8a]">
|
|
162
|
-
扫码体验
|
|
163
|
-
</text>
|
|
164
|
-
<t-qrcode value="https://vite.icebreaker.top" :size="90" />
|
|
165
|
-
</view>
|
|
166
|
-
</view>
|
|
167
|
-
</view>
|
|
168
|
-
</view>
|
|
169
|
-
</template>
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
<script setup lang="ts">
|
|
2
|
-
import BrokenCard from '@/components/VirtualHostClassDemo/BrokenCard.vue'
|
|
3
|
-
import FixedExternalClassCard from '@/components/VirtualHostClassDemo/FixedExternalClassCard.vue'
|
|
4
|
-
import RecommendedCard from '@/components/VirtualHostClassDemo/RecommendedCard.vue'
|
|
5
|
-
|
|
6
|
-
definePageJson({
|
|
7
|
-
navigationBarTitleText: 'virtualHost class demo',
|
|
8
|
-
backgroundColor: '#f6f7fb',
|
|
9
|
-
})
|
|
10
|
-
|
|
11
|
-
const classCase = 'rounded-[20rpx] border border-red-500 bg-red-50 px-[20rpx] py-[16rpx] text-red-500'
|
|
12
|
-
const inlineStyleCase = 'color:#2563eb;background:#dbeafe;padding:16rpx;border-radius:20rpx;border:2rpx solid #60a5fa;'
|
|
13
|
-
</script>
|
|
14
|
-
|
|
15
|
-
<template>
|
|
16
|
-
<view class="min-h-screen bg-[#f6f7fb] px-[28rpx] pb-[88rpx] pt-[24rpx] text-[#1c1c3c]">
|
|
17
|
-
<view class="rounded-[28rpx] bg-linear-to-br from-[#f5f3ff] via-[#ffffff] to-[#eef2ff] p-[20rpx]">
|
|
18
|
-
<text class="text-[32rpx] font-semibold text-[#1f1a3f]">
|
|
19
|
-
virtualHost + class/style 透传实验
|
|
20
|
-
</text>
|
|
21
|
-
<text class="mt-[10rpx] block text-[22rpx] leading-[1.7] text-[#5b5b7b]">
|
|
22
|
-
当前模板已全局开启组件 `virtualHost: true` 和 `styleIsolation: 'apply-shared'`。本页用最小组件对比 4 种写法的实际效果。
|
|
23
|
-
</text>
|
|
24
|
-
</view>
|
|
25
|
-
|
|
26
|
-
<view class="mt-[18rpx] rounded-[24rpx] bg-white p-[20rpx] shadow-[0_18rpx_40rpx_rgba(17,24,39,0.08)]">
|
|
27
|
-
<text class="text-[28rpx] font-semibold text-[#1f1a3f]">
|
|
28
|
-
1. 仅 `apply-shared`,不做 class 透传
|
|
29
|
-
</text>
|
|
30
|
-
<text class="mt-[8rpx] block text-[22rpx] leading-[1.7] text-[#6f6b8a]">
|
|
31
|
-
组件标签上写 `class` / `style`,但组件内部根节点没有接收这些 attrs。
|
|
32
|
-
</text>
|
|
33
|
-
<view class="mt-[14rpx] flex flex-col gap-[14rpx]">
|
|
34
|
-
<BrokenCard
|
|
35
|
-
:class="classCase"
|
|
36
|
-
title="BrokenCard"
|
|
37
|
-
subtitle="预期应变红并出现红色边框,但实际不会。"
|
|
38
|
-
/>
|
|
39
|
-
<BrokenCard
|
|
40
|
-
:style="inlineStyleCase"
|
|
41
|
-
title="BrokenCard style"
|
|
42
|
-
subtitle="预期应变蓝并出现蓝色背景/边框,但实际不会。"
|
|
43
|
-
/>
|
|
44
|
-
</view>
|
|
45
|
-
</view>
|
|
46
|
-
|
|
47
|
-
<view class="mt-[18rpx] rounded-[24rpx] bg-white p-[20rpx] shadow-[0_18rpx_40rpx_rgba(17,24,39,0.08)]">
|
|
48
|
-
<text class="text-[28rpx] font-semibold text-[#1f1a3f]">
|
|
49
|
-
2. `defineOptions({ externalClasses: ['class'] })`
|
|
50
|
-
</text>
|
|
51
|
-
<text class="mt-[8rpx] block text-[22rpx] leading-[1.7] text-[#6f6b8a]">
|
|
52
|
-
这是你问的那种“继续用组件标签上的 `class`”方案。组件内部根节点必须显式写上 `class` 占位。
|
|
53
|
-
</text>
|
|
54
|
-
<view class="mt-[14rpx]">
|
|
55
|
-
<FixedExternalClassCard
|
|
56
|
-
:class="classCase"
|
|
57
|
-
title="FixedExternalClassCard"
|
|
58
|
-
subtitle="这一块应该会变红,并出现红色边框和浅红背景。"
|
|
59
|
-
/>
|
|
60
|
-
</view>
|
|
61
|
-
</view>
|
|
62
|
-
|
|
63
|
-
<view class="mt-[18rpx] rounded-[24rpx] bg-white p-[20rpx] shadow-[0_18rpx_40rpx_rgba(17,24,39,0.08)]">
|
|
64
|
-
<text class="text-[28rpx] font-semibold text-[#1f1a3f]">
|
|
65
|
-
3. 推荐方案:`custom-class` + `rootStyle`
|
|
66
|
-
</text>
|
|
67
|
-
<text class="mt-[8rpx] block text-[22rpx] leading-[1.7] text-[#6f6b8a]">
|
|
68
|
-
`class` 和 `style` 分开设计,避免把组件标签 attrs 是否透传这件事变成隐式行为。
|
|
69
|
-
</text>
|
|
70
|
-
<view class="mt-[14rpx] flex flex-col gap-[14rpx]">
|
|
71
|
-
<RecommendedCard
|
|
72
|
-
custom-class="rounded-[20rpx] border border-emerald-500 bg-emerald-50 px-[20rpx] py-[16rpx] text-emerald-600"
|
|
73
|
-
title="RecommendedCard custom-class"
|
|
74
|
-
subtitle="通过 externalClasses 显式接收类名。"
|
|
75
|
-
/>
|
|
76
|
-
<RecommendedCard
|
|
77
|
-
:root-style="inlineStyleCase"
|
|
78
|
-
title="RecommendedCard rootStyle"
|
|
79
|
-
subtitle="通过显式 prop 接收内联样式。"
|
|
80
|
-
/>
|
|
81
|
-
</view>
|
|
82
|
-
</view>
|
|
83
|
-
|
|
84
|
-
<view class="mt-[18rpx] rounded-[24rpx] bg-[#1f1a3f] p-[20rpx] text-white">
|
|
85
|
-
<text class="text-[26rpx] font-semibold">
|
|
86
|
-
结论
|
|
87
|
-
</text>
|
|
88
|
-
<text class="mt-[10rpx] block text-[22rpx] leading-[1.8] text-white/80">
|
|
89
|
-
`virtualHost: true` 和 `styleIsolation: 'apply-shared'` 不会自动提供 Vue 式根节点 `class/style` fallthrough。
|
|
90
|
-
要么显式声明 `externalClasses` 并在根节点接入,要么把 `style` 做成显式 prop。
|
|
91
|
-
</text>
|
|
92
|
-
</view>
|
|
93
|
-
</view>
|
|
94
|
-
</template>
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
export type ActionTone = 'brand' | 'neutral'
|
|
2
|
-
export type ActionType = 'tab' | 'sub'
|
|
3
|
-
|
|
4
|
-
export interface QuickActionItem {
|
|
5
|
-
key: string
|
|
6
|
-
title: string
|
|
7
|
-
description?: string
|
|
8
|
-
icon?: string
|
|
9
|
-
tag?: string
|
|
10
|
-
tone?: ActionTone
|
|
11
|
-
disabled?: boolean
|
|
12
|
-
path?: string
|
|
13
|
-
type?: ActionType
|
|
14
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
export type ListStatus = 'processing' | 'pending' | 'done'
|
|
2
|
-
export type StatusFilterValue = 'all' | ListStatus
|
|
3
|
-
|
|
4
|
-
export interface ListItem {
|
|
5
|
-
id: number
|
|
6
|
-
title: string
|
|
7
|
-
owner: string
|
|
8
|
-
status: ListStatus
|
|
9
|
-
deadline: string
|
|
10
|
-
priority: string
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export interface StatusFilter {
|
|
14
|
-
value: StatusFilterValue
|
|
15
|
-
label: string
|
|
16
|
-
count?: number
|
|
17
|
-
}
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
type PrimitiveValue = string | number | boolean
|
|
2
|
-
|
|
3
|
-
function hasSameType<T extends PrimitiveValue>(value: unknown, fallback: T): value is T {
|
|
4
|
-
return typeof value === typeof fallback
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* @description 从小程序组件变更事件中提取值,兼容值直传、detail 直传和 detail.value 结构。
|
|
9
|
-
*/
|
|
10
|
-
export function resolveChangeValue<T extends PrimitiveValue>(event: unknown, fallback: T): T {
|
|
11
|
-
if (hasSameType(event, fallback)) {
|
|
12
|
-
return event
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
if (event && typeof event === 'object') {
|
|
16
|
-
const payload = event as Record<string, any>
|
|
17
|
-
if (hasSameType(payload.value, fallback)) {
|
|
18
|
-
return payload.value
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
const detail = payload.detail
|
|
22
|
-
if (hasSameType(detail, fallback)) {
|
|
23
|
-
return detail
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
if (detail && typeof detail === 'object' && hasSameType(detail.value, fallback)) {
|
|
27
|
-
return detail.value
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
return fallback
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* @description 从小程序组件变更事件中提取字符串值。
|
|
36
|
-
*/
|
|
37
|
-
export function resolveStringChangeValue(event: unknown, fallback = '') {
|
|
38
|
-
return resolveChangeValue(event, fallback)
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* @description 从小程序组件变更事件中提取数字值。
|
|
43
|
-
*/
|
|
44
|
-
export function resolveNumberChangeValue(event: unknown, fallback = 0) {
|
|
45
|
-
return Number(resolveChangeValue(event, fallback))
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* @description 从小程序组件变更事件中提取布尔值。
|
|
50
|
-
*/
|
|
51
|
-
export function resolveBooleanChangeValue(event: unknown, fallback = false) {
|
|
52
|
-
return Boolean(resolveChangeValue(event, fallback))
|
|
53
|
-
}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import type { ListItem, ListStatus, StatusFilter, StatusFilterValue } from '@/types/list'
|
|
2
|
-
|
|
3
|
-
export function buildStatusFilters(items: ListItem[]): StatusFilter[] {
|
|
4
|
-
const summary: Record<ListStatus, number> = {
|
|
5
|
-
processing: 0,
|
|
6
|
-
pending: 0,
|
|
7
|
-
done: 0,
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
for (const item of items) {
|
|
11
|
-
summary[item.status] += 1
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
return [
|
|
15
|
-
{ value: 'all', label: '全部', count: items.length },
|
|
16
|
-
{ value: 'processing', label: '进行中', count: summary.processing },
|
|
17
|
-
{ value: 'pending', label: '待启动', count: summary.pending },
|
|
18
|
-
{ value: 'done', label: '已完成', count: summary.done },
|
|
19
|
-
]
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export function filterListItems(
|
|
23
|
-
items: ListItem[],
|
|
24
|
-
query: string,
|
|
25
|
-
activeStatus: StatusFilterValue,
|
|
26
|
-
) {
|
|
27
|
-
const keyword = query.trim()
|
|
28
|
-
|
|
29
|
-
return items.filter((item) => {
|
|
30
|
-
const matchStatus = activeStatus === 'all' || item.status === activeStatus
|
|
31
|
-
const matchQuery = !keyword || item.title.includes(keyword) || item.owner.includes(keyword)
|
|
32
|
-
return matchStatus && matchQuery
|
|
33
|
-
})
|
|
34
|
-
}
|