@binblink/wasmnest-plugin-sdk-mobile 0.0.0-stage → 0.0.2
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/README.md +439 -2
- package/README_en.md +415 -0
- package/bin/build.js +271 -0
- package/bin/cli.js +96 -0
- package/bin/lib.js +349 -0
- package/bin/manifest-gen.js +327 -0
- package/bin/package.js +151 -0
- package/bin/scaffold.js +299 -0
- package/dev-shell/README.md +151 -0
- package/dev-shell/index.html +27 -0
- package/dev-shell/package.json +27 -0
- package/dev-shell/pnpm-workspace.yaml +9 -0
- package/dev-shell/postcss.config.js +6 -0
- package/dev-shell/src/App.vue +90 -0
- package/dev-shell/src/apps/mock-terminal/MockTerminalSlotCard.vue +43 -0
- package/dev-shell/src/apps/mock-terminal/MockTerminalView.vue +168 -0
- package/dev-shell/src/apps/mock-terminal/index.ts +50 -0
- package/dev-shell/src/components/DevToolbar.vue +100 -0
- package/dev-shell/src/components/DialogHost.vue +119 -0
- package/dev-shell/src/components/LogPanel.vue +80 -0
- package/dev-shell/src/i18n.ts +22 -0
- package/dev-shell/src/loader.ts +239 -0
- package/dev-shell/src/locale.ts +29 -0
- package/dev-shell/src/locales/en-shell.ts +332 -0
- package/dev-shell/src/locales/index.ts +70 -0
- package/dev-shell/src/locales/shell.ts +331 -0
- package/dev-shell/src/main.ts +58 -0
- package/dev-shell/src/mock/dialog-service.ts +58 -0
- package/dev-shell/src/mock/file-transfer.ts +390 -0
- package/dev-shell/src/mock/mobile-api.ts +369 -0
- package/dev-shell/src/mock/preset-tasks.ts +186 -0
- package/dev-shell/src/mock/session.ts +121 -0
- package/dev-shell/src/mock-context.ts +374 -0
- package/dev-shell/src/registry.ts +151 -0
- package/dev-shell/src/shared-runtime.ts +44 -0
- package/dev-shell/src/shell/ShellView.vue +52 -0
- package/dev-shell/src/shell/adapters/devAppSource.ts +144 -0
- package/dev-shell/src/shell/components/PluginContextHost.vue +40 -0
- package/dev-shell/src/shell/components/ShellAppCell.vue +75 -0
- package/dev-shell/src/shell/components/ShellAppIcon.vue +111 -0
- package/dev-shell/src/shell/components/ShellAppSurface.vue +46 -0
- package/dev-shell/src/shell/components/ShellBrandTile.vue +27 -0
- package/dev-shell/src/shell/components/ShellCapsuleMenu.vue +123 -0
- package/dev-shell/src/shell/components/ShellChip.vue +49 -0
- package/dev-shell/src/shell/components/ShellGroupCard.vue +17 -0
- package/dev-shell/src/shell/components/ShellHost.vue +75 -0
- package/dev-shell/src/shell/components/ShellNotificationShade.vue +501 -0
- package/dev-shell/src/shell/components/ShellPermissionPrompt.vue +127 -0
- package/dev-shell/src/shell/components/ShellPlaceholderSurface.vue +33 -0
- package/dev-shell/src/shell/components/ShellSection.vue +27 -0
- package/dev-shell/src/shell/components/ShellSheet.vue +74 -0
- package/dev-shell/src/shell/components/ShellStatusbar.vue +84 -0
- package/dev-shell/src/shell/components/screens/PluginRoutePage.vue +98 -0
- package/dev-shell/src/shell/components/screens/ShellAppDetailScreen.vue +359 -0
- package/dev-shell/src/shell/components/screens/ShellAppRunScreen.vue +90 -0
- package/dev-shell/src/shell/components/screens/ShellAppsScreen.vue +195 -0
- package/dev-shell/src/shell/components/screens/ShellHomeScreen.vue +357 -0
- package/dev-shell/src/shell/components/screens/ShellPermissionsScreen.vue +376 -0
- package/dev-shell/src/shell/components/screens/ShellSettingsScreen.vue +240 -0
- package/dev-shell/src/shell/components/screens/ShellSwitcherScreen.vue +559 -0
- package/dev-shell/src/shell/components/ui/ConfirmDialog.vue +137 -0
- package/dev-shell/src/shell/components/ui/Toggle.vue +53 -0
- package/dev-shell/src/shell/composables/useShellApps.ts +417 -0
- package/dev-shell/src/shell/composables/useShellNavigation.ts +197 -0
- package/dev-shell/src/shell/composables/useShellNotifications.ts +115 -0
- package/dev-shell/src/shell/composables/useShellOpen.ts +44 -0
- package/dev-shell/src/shell/composables/useShellOverlays.ts +101 -0
- package/dev-shell/src/shell/composables/useShellPreferences.ts +143 -0
- package/dev-shell/src/shell/composables/useShellRecent.ts +84 -0
- package/dev-shell/src/shell/composables/useSlotCarousel.ts +238 -0
- package/dev-shell/src/shell/composables/useToast.ts +33 -0
- package/dev-shell/src/shell/index.ts +88 -0
- package/dev-shell/src/shell/logger.ts +45 -0
- package/dev-shell/src/shell/permissions.ts +145 -0
- package/dev-shell/src/shell/registry.ts +220 -0
- package/dev-shell/src/shell/slotCards.ts +47 -0
- package/dev-shell/src/shell/styles/shell.css +1155 -0
- package/dev-shell/src/shell/surfaceIntent.ts +107 -0
- package/dev-shell/src/shell/types.ts +152 -0
- package/dev-shell/src/shell/utils.ts +54 -0
- package/dev-shell/src/styles/main.css +153 -0
- package/dev-shell/src/styles/mobile.css +981 -0
- package/dev-shell/src/styles/wallpaper.css +130 -0
- package/dev-shell/src/theme.ts +71 -0
- package/dev-shell/src/vite-env.d.ts +20 -0
- package/dev-shell/tailwind.config.js +101 -0
- package/dev-shell/tsconfig.json +16 -0
- package/dev-shell/vite.config.ts +130 -0
- package/dist/index.d.ts +124 -0
- package/dist/index.js +229 -0
- package/dist/types.d.ts +738 -0
- package/dist/types.js +0 -0
- package/dist/vite-plugin.d.ts +16 -0
- package/dist/vite-plugin.js +95 -0
- package/package.json +88 -3
- package/src/constants.ts +6 -0
- package/src/global-dialog.ts +168 -0
- package/src/index.ts +96 -0
- package/src/runtime.ts +44 -0
- package/src/types.ts +822 -0
- package/src/ui/AppUpdateSection.d.ts +44 -0
- package/src/ui/AppUpdateSection.vue +253 -0
- package/src/ui/PluginGlobalDialog.vue +388 -0
- package/src/ui/QuickCard.d.ts +33 -0
- package/src/ui/QuickCard.vue +167 -0
- package/src/ui/Select.d.ts +37 -0
- package/src/ui/Select.vue +307 -0
- package/src/ui/plugin-global-dialog.d.ts +11 -0
- package/src/ui/useSwipeTabs.d.ts +20 -0
- package/src/ui/useSwipeTabs.ts +53 -0
- package/src/update.ts +123 -0
- package/src/vite-plugin.ts +132 -0
- package/template/.gitignore +4 -0
- package/template/README.md +46 -0
- package/template/package.json +23 -0
- package/template/plugin.json +13 -0
- package/template/rust/Cargo.toml +19 -0
- package/template/rust/src/lib.rs +33 -0
- package/template/src/env.d.ts +24 -0
- package/template/src/index.ts +37 -0
- package/template/tsconfig.json +17 -0
- package/template/vite.config.ts +21 -0
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { DefineComponent } from 'vue'
|
|
2
|
+
|
|
3
|
+
/** 卡片状态点语义(neutral 不显示) */
|
|
4
|
+
export type QuickCardTone = 'neutral' | 'success' | 'warning' | 'danger'
|
|
5
|
+
|
|
6
|
+
/** QuickCard 组件 props */
|
|
7
|
+
export interface QuickCardProps {
|
|
8
|
+
/** 顶部标签(如「活跃会话」);留空则只显示主体 */
|
|
9
|
+
label?: string
|
|
10
|
+
/** 主体数值 / 主文案(等宽数字排版) */
|
|
11
|
+
value?: string | number
|
|
12
|
+
/** 数值下方的一行状态说明(零值提示、补充信息等) */
|
|
13
|
+
hint?: string
|
|
14
|
+
/** 右上角装饰图标:24×24 视框的 SVG path d,可多条 */
|
|
15
|
+
iconPath?: string | string[]
|
|
16
|
+
/** 状态点语义:neutral 不显示;其余取对应语义色 */
|
|
17
|
+
tone?: QuickCardTone
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* 移动端公共快捷卡片(宿主壳首页)
|
|
22
|
+
*
|
|
23
|
+
* 用法(应用 activate 期注册,宿主壳首页渲染并负责点击跳转):
|
|
24
|
+
* ```vue
|
|
25
|
+
* <QuickCard label="活跃会话" :value="count" :hint="count ? '正在运行' : '暂无会话'" />
|
|
26
|
+
* ```
|
|
27
|
+
* - 卡片内容由应用自持;宿主管布局、滚动与点击打开本应用,应用不处理导航
|
|
28
|
+
* - 卡片内不得再放按钮 / 链接(整卡已是宿主按钮,嵌套交互会互相抢点击)
|
|
29
|
+
* - 外观由 --mobile-* / --shell-radius-* token 驱动,跟随宿主主题与字号偏好
|
|
30
|
+
*/
|
|
31
|
+
export declare const QuickCard: DefineComponent<QuickCardProps>
|
|
32
|
+
|
|
33
|
+
export default QuickCard
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<!--
|
|
3
|
+
快捷卡片(应用贡献给宿主壳首页的公共卡片外观)
|
|
4
|
+
|
|
5
|
+
只负责「卡片长什么样」:应用填内容(label / value / hint 或默认插槽),
|
|
6
|
+
点击与跳转由宿主壳接管——宿主把整张卡渲染成按钮并打开贡献方应用。
|
|
7
|
+
因此卡片内不得再放按钮 / 链接等交互控件(会与宿主按钮形成嵌套交互)。
|
|
8
|
+
-->
|
|
9
|
+
<article class="quick-card" :data-tone="tone">
|
|
10
|
+
<header v-if="label || iconPaths.length > 0 || tone !== 'neutral'" class="quick-card__head">
|
|
11
|
+
<span
|
|
12
|
+
v-if="tone !== 'neutral'"
|
|
13
|
+
class="quick-card__tone"
|
|
14
|
+
:data-tone="tone"
|
|
15
|
+
aria-hidden="true"
|
|
16
|
+
/>
|
|
17
|
+
<span v-if="label" class="quick-card__label">{{ label }}</span>
|
|
18
|
+
<span v-if="iconPaths.length > 0" class="quick-card__icon" aria-hidden="true">
|
|
19
|
+
<svg
|
|
20
|
+
width="18"
|
|
21
|
+
height="18"
|
|
22
|
+
viewBox="0 0 24 24"
|
|
23
|
+
fill="none"
|
|
24
|
+
stroke="currentColor"
|
|
25
|
+
stroke-width="1.7"
|
|
26
|
+
stroke-linecap="round"
|
|
27
|
+
stroke-linejoin="round"
|
|
28
|
+
>
|
|
29
|
+
<path v-for="d in iconPaths" :key="d" :d="d" />
|
|
30
|
+
</svg>
|
|
31
|
+
</span>
|
|
32
|
+
</header>
|
|
33
|
+
|
|
34
|
+
<div class="quick-card__body">
|
|
35
|
+
<slot>
|
|
36
|
+
<span v-if="hasValue" class="quick-card__value">{{ value }}</span>
|
|
37
|
+
<span v-if="hint" class="quick-card__hint">{{ hint }}</span>
|
|
38
|
+
</slot>
|
|
39
|
+
</div>
|
|
40
|
+
</article>
|
|
41
|
+
</template>
|
|
42
|
+
|
|
43
|
+
<script setup lang="ts">
|
|
44
|
+
/**
|
|
45
|
+
* QuickCard — SDK 公共快捷卡片
|
|
46
|
+
*
|
|
47
|
+
* 内容由应用自持(活跃会话数 / 传输任务数 / 最近对话……),宿主不解释字段语义;
|
|
48
|
+
* 卡片固定外观由 --mobile-* + --shell-radius-* token 驱动,随宿主主题 / 明暗 /
|
|
49
|
+
* 用户字号偏好自动适配。跨应用等宽靠宿主轨道 item 的定宽约束,本组件铺满 item。
|
|
50
|
+
*/
|
|
51
|
+
import { computed } from 'vue'
|
|
52
|
+
|
|
53
|
+
type QuickCardTone = 'neutral' | 'success' | 'warning' | 'danger'
|
|
54
|
+
|
|
55
|
+
const props = withDefaults(
|
|
56
|
+
defineProps<{
|
|
57
|
+
/** 顶部标签(如「活跃会话」);留空则只显示主体 */
|
|
58
|
+
label?: string
|
|
59
|
+
/** 主体数值 / 主文案(等宽数字排版) */
|
|
60
|
+
value?: string | number
|
|
61
|
+
/** 数值下方的一行状态说明(零值提示、补充信息等) */
|
|
62
|
+
hint?: string
|
|
63
|
+
/** 右上角装饰图标:24×24 视框的 SVG path d,可多条 */
|
|
64
|
+
iconPath?: string | string[]
|
|
65
|
+
/** 状态点语义:neutral 不显示;其余取对应语义色 */
|
|
66
|
+
tone?: QuickCardTone
|
|
67
|
+
}>(),
|
|
68
|
+
{ tone: 'neutral', label: '', value: '', hint: '', iconPath: '' },
|
|
69
|
+
)
|
|
70
|
+
|
|
71
|
+
const iconPaths = computed(() => {
|
|
72
|
+
const raw = props.iconPath
|
|
73
|
+
if (!raw) return []
|
|
74
|
+
return Array.isArray(raw) ? raw : [raw]
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
const hasValue = computed(() => props.value !== undefined && props.value !== null && props.value !== '')
|
|
78
|
+
</script>
|
|
79
|
+
|
|
80
|
+
<style scoped>
|
|
81
|
+
.quick-card {
|
|
82
|
+
box-sizing: border-box;
|
|
83
|
+
display: flex;
|
|
84
|
+
flex-direction: column;
|
|
85
|
+
gap: 8px;
|
|
86
|
+
width: 100%;
|
|
87
|
+
height: 100%;
|
|
88
|
+
min-width: 0;
|
|
89
|
+
padding: 14px;
|
|
90
|
+
border: 1px solid var(--mobile-border);
|
|
91
|
+
border-radius: var(--shell-radius-card, 12px);
|
|
92
|
+
background: var(--mobile-bg-card);
|
|
93
|
+
box-shadow: var(--mobile-card-shadow);
|
|
94
|
+
color: var(--mobile-text-primary);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
.quick-card__head {
|
|
98
|
+
display: flex;
|
|
99
|
+
align-items: center;
|
|
100
|
+
gap: 6px;
|
|
101
|
+
min-width: 0;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
.quick-card__label {
|
|
105
|
+
min-width: 0;
|
|
106
|
+
overflow: hidden;
|
|
107
|
+
color: var(--mobile-text-secondary);
|
|
108
|
+
font-size: var(--font-size-xs);
|
|
109
|
+
line-height: 1.4;
|
|
110
|
+
text-overflow: ellipsis;
|
|
111
|
+
white-space: nowrap;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
.quick-card__icon {
|
|
115
|
+
display: flex;
|
|
116
|
+
flex-shrink: 0;
|
|
117
|
+
margin-left: auto;
|
|
118
|
+
color: var(--mobile-accent);
|
|
119
|
+
opacity: 0.85;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
.quick-card__tone {
|
|
123
|
+
flex-shrink: 0;
|
|
124
|
+
width: 6px;
|
|
125
|
+
height: 6px;
|
|
126
|
+
border-radius: 999px;
|
|
127
|
+
background: var(--mobile-text-secondary);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
.quick-card__tone[data-tone='success'] {
|
|
131
|
+
background: var(--mobile-success);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
.quick-card__tone[data-tone='warning'] {
|
|
135
|
+
background: var(--mobile-warning);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
.quick-card__tone[data-tone='danger'] {
|
|
139
|
+
background: var(--mobile-error);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
.quick-card__body {
|
|
143
|
+
display: flex;
|
|
144
|
+
flex-direction: column;
|
|
145
|
+
gap: 4px;
|
|
146
|
+
min-width: 0;
|
|
147
|
+
margin-top: auto;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
.quick-card__value {
|
|
151
|
+
font-size: var(--font-size-2xl);
|
|
152
|
+
font-variant-numeric: tabular-nums;
|
|
153
|
+
font-weight: 600;
|
|
154
|
+
line-height: 1.15;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
.quick-card__hint {
|
|
158
|
+
display: -webkit-box;
|
|
159
|
+
overflow: hidden;
|
|
160
|
+
color: var(--mobile-text-secondary);
|
|
161
|
+
font-size: var(--font-size-xs);
|
|
162
|
+
line-height: 1.45;
|
|
163
|
+
overflow-wrap: anywhere;
|
|
164
|
+
-webkit-box-orient: vertical;
|
|
165
|
+
-webkit-line-clamp: 2;
|
|
166
|
+
}
|
|
167
|
+
</style>
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { DefineComponent } from 'vue'
|
|
2
|
+
|
|
3
|
+
/** 下拉选项(value 同时作为 v-model 绑定值) */
|
|
4
|
+
export interface SelectOption {
|
|
5
|
+
value: string | number
|
|
6
|
+
label: string
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/** Select 组件 props */
|
|
10
|
+
export interface SelectProps {
|
|
11
|
+
modelValue: string | number
|
|
12
|
+
/** 顶部标签文本(可选) */
|
|
13
|
+
label?: string
|
|
14
|
+
options: SelectOption[]
|
|
15
|
+
/** 未选中时的占位文本;设置后下拉顶部出现"清除选择"行 */
|
|
16
|
+
placeholder?: string
|
|
17
|
+
disabled?: boolean
|
|
18
|
+
required?: boolean
|
|
19
|
+
error?: string
|
|
20
|
+
/** md:宿主表单默认(44px/14px 触摸目标);sm:插件紧凑布局(36px/12px) */
|
|
21
|
+
size?: 'md' | 'sm'
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* 移动端共享下拉选择组件(替代原生 <select>)
|
|
26
|
+
*
|
|
27
|
+
* 用法:
|
|
28
|
+
* ```vue
|
|
29
|
+
* <Select v-model="value" :options="options" size="sm" @open="refresh" />
|
|
30
|
+
* ```
|
|
31
|
+
* - 触发 `update:modelValue`(选中/清除)
|
|
32
|
+
* - 触发 `open`(下拉展开时,可用于静默刷新选项)
|
|
33
|
+
* - 面板 Teleport 到 body,safe-stack overlay 层,样式由 --mobile-* token 驱动
|
|
34
|
+
*/
|
|
35
|
+
export declare const Select: DefineComponent<SelectProps>
|
|
36
|
+
|
|
37
|
+
export default Select
|
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div class="select-root">
|
|
3
|
+
<label v-if="label" :for="id" class="block text-xs font-medium mb-1.5 text-mobile-secondary select-label">
|
|
4
|
+
{{ label }}
|
|
5
|
+
<span v-if="required" class="text-mobile-error">*</span>
|
|
6
|
+
</label>
|
|
7
|
+
|
|
8
|
+
<div ref="triggerRef" class="relative">
|
|
9
|
+
<!-- Trigger -->
|
|
10
|
+
<button
|
|
11
|
+
:id="id"
|
|
12
|
+
type="button"
|
|
13
|
+
:disabled="disabled"
|
|
14
|
+
class="select-trigger"
|
|
15
|
+
:class="[
|
|
16
|
+
triggerSizeCls,
|
|
17
|
+
error ? 'select-trigger--error' : 'select-trigger--normal',
|
|
18
|
+
{ 'select-trigger--disabled': disabled },
|
|
19
|
+
]"
|
|
20
|
+
@click="toggle"
|
|
21
|
+
@keydown.down.prevent="open"
|
|
22
|
+
@keydown.up.prevent="open"
|
|
23
|
+
@keydown.escape="close"
|
|
24
|
+
>
|
|
25
|
+
<span
|
|
26
|
+
class="min-w-0 truncate"
|
|
27
|
+
:class="selectedLabel ? 'text-mobile-primary' : 'text-[var(--mobile-input-placeholder)]'"
|
|
28
|
+
>
|
|
29
|
+
{{ selectedLabel || placeholder || '' }}
|
|
30
|
+
</span>
|
|
31
|
+
<svg
|
|
32
|
+
class="w-4 h-4 flex-shrink-0 text-mobile-muted transition-transform duration-200"
|
|
33
|
+
:class="{ 'rotate-180': isOpen }"
|
|
34
|
+
fill="none"
|
|
35
|
+
stroke="currentColor"
|
|
36
|
+
viewBox="0 0 24 24"
|
|
37
|
+
>
|
|
38
|
+
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 9l-7 7-7-7" />
|
|
39
|
+
</svg>
|
|
40
|
+
</button>
|
|
41
|
+
|
|
42
|
+
<!-- 下拉面板:Teleport 到 body 规避 overflow 裁剪,safe-stack overlay 层 z-50 -->
|
|
43
|
+
<Teleport to="body">
|
|
44
|
+
<div
|
|
45
|
+
v-show="isOpen"
|
|
46
|
+
ref="panelRef"
|
|
47
|
+
class="select-panel fixed z-50"
|
|
48
|
+
:style="panelStyle"
|
|
49
|
+
>
|
|
50
|
+
<ul class="py-1 max-h-[45vh] overflow-y-auto">
|
|
51
|
+
<li
|
|
52
|
+
v-if="placeholder"
|
|
53
|
+
class="select-option select-option--placeholder"
|
|
54
|
+
:class="optionRowCls"
|
|
55
|
+
@click="select('')"
|
|
56
|
+
>
|
|
57
|
+
{{ placeholder }}
|
|
58
|
+
</li>
|
|
59
|
+
<li
|
|
60
|
+
v-for="(option, index) in options"
|
|
61
|
+
:key="option.value"
|
|
62
|
+
class="select-option"
|
|
63
|
+
:class="[
|
|
64
|
+
optionRowCls,
|
|
65
|
+
option.value === modelValue ? 'select-option--selected' : '',
|
|
66
|
+
hoveredIndex === index ? 'select-option--hover' : '',
|
|
67
|
+
]"
|
|
68
|
+
@mouseenter="hoveredIndex = index"
|
|
69
|
+
@mouseleave="hoveredIndex = -1"
|
|
70
|
+
@click="select(option.value)"
|
|
71
|
+
>
|
|
72
|
+
<span class="min-w-0 truncate">{{ option.label }}</span>
|
|
73
|
+
</li>
|
|
74
|
+
</ul>
|
|
75
|
+
</div>
|
|
76
|
+
</Teleport>
|
|
77
|
+
</div>
|
|
78
|
+
|
|
79
|
+
<!-- Error Message -->
|
|
80
|
+
<p v-if="error" class="mt-1 text-xs text-mobile-error">{{ error }}</p>
|
|
81
|
+
</div>
|
|
82
|
+
</template>
|
|
83
|
+
|
|
84
|
+
<script setup lang="ts">
|
|
85
|
+
/**
|
|
86
|
+
* Select - 移动端共享自定义下拉选择组件
|
|
87
|
+
*
|
|
88
|
+
* 替代原生 <select>,外观完全由 --mobile-* token 控制,适配深浅主题。
|
|
89
|
+
* 宿主与插件共享(@binblink/wasmnest-plugin-sdk-mobile/ui)。
|
|
90
|
+
*
|
|
91
|
+
* - 默认 md:触发器与选项行 44px 触摸目标、字号 14px;面板空间不足时自动向上展开
|
|
92
|
+
* - size="sm":插件紧凑布局(36px/12px,如聊天头部工具条)
|
|
93
|
+
* - open 事件:下拉展开时触发(插件可借此静默刷新选项,无原生组件禁用打断问题)
|
|
94
|
+
*/
|
|
95
|
+
import { ref, computed, onMounted, onUnmounted, nextTick } from 'vue'
|
|
96
|
+
|
|
97
|
+
export interface SelectOption {
|
|
98
|
+
value: string | number
|
|
99
|
+
label: string
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export interface Props {
|
|
103
|
+
modelValue: string | number
|
|
104
|
+
label?: string
|
|
105
|
+
options: SelectOption[]
|
|
106
|
+
placeholder?: string
|
|
107
|
+
disabled?: boolean
|
|
108
|
+
required?: boolean
|
|
109
|
+
error?: string
|
|
110
|
+
/** md:宿主表单默认(44px/14px);sm:插件紧凑布局(36px/12px) */
|
|
111
|
+
size?: 'md' | 'sm'
|
|
112
|
+
/** 面板弹出方向:auto=空间不足自动向上(默认);top/bottom=固定方向(输入栏等贴底场景用 top) */
|
|
113
|
+
placement?: 'auto' | 'top' | 'bottom'
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const props = withDefaults(defineProps<Props>(), {
|
|
117
|
+
disabled: false,
|
|
118
|
+
required: false,
|
|
119
|
+
size: 'md',
|
|
120
|
+
placement: 'auto',
|
|
121
|
+
})
|
|
122
|
+
|
|
123
|
+
const emit = defineEmits(['update:modelValue', 'open'])
|
|
124
|
+
|
|
125
|
+
const id = `select-${Math.random().toString(36).slice(2, 9)}`
|
|
126
|
+
const isOpen = ref(false)
|
|
127
|
+
const hoveredIndex = ref(-1)
|
|
128
|
+
const triggerRef = ref<HTMLElement | null>(null)
|
|
129
|
+
const panelRef = ref<HTMLElement | null>(null)
|
|
130
|
+
const panelStyle = ref<Record<string, string>>({})
|
|
131
|
+
|
|
132
|
+
const selectedLabel = computed(() => {
|
|
133
|
+
const opt = props.options.find(o => o.value === props.modelValue)
|
|
134
|
+
return opt?.label ?? ''
|
|
135
|
+
})
|
|
136
|
+
|
|
137
|
+
const triggerSizeCls = computed(() =>
|
|
138
|
+
props.size === 'sm' ? 'select-trigger--sm' : 'select-trigger--md',
|
|
139
|
+
)
|
|
140
|
+
const optionRowCls = computed(() =>
|
|
141
|
+
props.size === 'sm' ? 'select-option--sm' : 'select-option--md',
|
|
142
|
+
)
|
|
143
|
+
|
|
144
|
+
/** 面板与触发器的间距 */
|
|
145
|
+
const PANEL_GAP = 4
|
|
146
|
+
|
|
147
|
+
function computePosition() {
|
|
148
|
+
const trigger = triggerRef.value
|
|
149
|
+
const panel = panelRef.value
|
|
150
|
+
if (!trigger || !panel) return
|
|
151
|
+
const rect = trigger.getBoundingClientRect()
|
|
152
|
+
const panelHeight = panel.offsetHeight
|
|
153
|
+
// 下方空间不足时向上展开,避免面板超出视口底部(移动端小屏常见);
|
|
154
|
+
// placement 显式指定时优先:输入栏贴容器底部等场景固定向上,不受视口高度误判影响
|
|
155
|
+
const openUpward =
|
|
156
|
+
props.placement === 'top' ||
|
|
157
|
+
(props.placement === 'auto' && rect.bottom + PANEL_GAP + panelHeight > window.innerHeight)
|
|
158
|
+
const top = openUpward
|
|
159
|
+
? Math.max(PANEL_GAP, rect.top - panelHeight - PANEL_GAP)
|
|
160
|
+
: rect.bottom + PANEL_GAP
|
|
161
|
+
panelStyle.value = {
|
|
162
|
+
top: `${top}px`,
|
|
163
|
+
left: `${rect.left}px`,
|
|
164
|
+
width: `${rect.width}px`,
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
function toggle() {
|
|
169
|
+
if (props.disabled) return
|
|
170
|
+
isOpen.value ? close() : open()
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
function open() {
|
|
174
|
+
if (props.disabled) return
|
|
175
|
+
isOpen.value = true
|
|
176
|
+
hoveredIndex.value = -1
|
|
177
|
+
emit('open')
|
|
178
|
+
nextTick(computePosition)
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
function close() {
|
|
182
|
+
isOpen.value = false
|
|
183
|
+
hoveredIndex.value = -1
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
function select(value: string | number) {
|
|
187
|
+
emit('update:modelValue', value)
|
|
188
|
+
close()
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
function onClickOutside(e: MouseEvent) {
|
|
192
|
+
const target = e.target as HTMLElement
|
|
193
|
+
if (
|
|
194
|
+
isOpen.value &&
|
|
195
|
+
!triggerRef.value?.contains(target) &&
|
|
196
|
+
!panelRef.value?.contains(target)
|
|
197
|
+
) {
|
|
198
|
+
close()
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
onMounted(() => {
|
|
203
|
+
document.addEventListener('mousedown', onClickOutside)
|
|
204
|
+
window.addEventListener('resize', close)
|
|
205
|
+
window.addEventListener('scroll', close, true)
|
|
206
|
+
})
|
|
207
|
+
|
|
208
|
+
onUnmounted(() => {
|
|
209
|
+
document.removeEventListener('mousedown', onClickOutside)
|
|
210
|
+
window.removeEventListener('resize', close)
|
|
211
|
+
window.removeEventListener('scroll', close, true)
|
|
212
|
+
})
|
|
213
|
+
</script>
|
|
214
|
+
|
|
215
|
+
<style scoped>
|
|
216
|
+
/* 触发器:44px 触摸目标,字号 14px,随屏幕宽度 flow 缩放 */
|
|
217
|
+
.select-trigger {
|
|
218
|
+
width: 100%;
|
|
219
|
+
display: flex;
|
|
220
|
+
align-items: center;
|
|
221
|
+
justify-content: space-between;
|
|
222
|
+
gap: 0.5rem;
|
|
223
|
+
text-align: left;
|
|
224
|
+
background: var(--mobile-input-bg);
|
|
225
|
+
transition: border-color 0.15s ease;
|
|
226
|
+
cursor: pointer;
|
|
227
|
+
outline: none;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
.select-trigger--normal {
|
|
231
|
+
border: 1px solid var(--mobile-input-border);
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
.select-trigger--normal:focus-visible,
|
|
235
|
+
.select-trigger--normal:focus {
|
|
236
|
+
border-color: var(--mobile-input-focus);
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
.select-trigger--error {
|
|
240
|
+
border: 1px solid var(--mobile-error);
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
.select-trigger--disabled {
|
|
244
|
+
opacity: 0.5;
|
|
245
|
+
cursor: not-allowed;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
.select-trigger--md {
|
|
249
|
+
min-height: clamp(2.75rem, 2.75rem + (100vw - 400px) / 800 * 8, 3.25rem);
|
|
250
|
+
padding: 0 0.75rem;
|
|
251
|
+
font-size: var(--font-size-base); /* 14px */
|
|
252
|
+
border-radius: 0.625rem;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
/* sm:插件紧凑布局(聊天头部工具条等) */
|
|
256
|
+
.select-trigger--sm {
|
|
257
|
+
min-height: clamp(2.25rem, 2.25rem + (100vw - 400px) / 800 * 4, 2.5rem);
|
|
258
|
+
padding: 0 0.5rem;
|
|
259
|
+
font-size: var(--font-size-sm);
|
|
260
|
+
border-radius: 0.5rem;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
/* 面板:卡片底色 + 边框 + 阴影,overlay 层浮于页面内容之上 */
|
|
264
|
+
.select-panel {
|
|
265
|
+
background: var(--mobile-bg-card);
|
|
266
|
+
border: 1px solid var(--mobile-border);
|
|
267
|
+
border-radius: 0.75rem;
|
|
268
|
+
box-shadow: var(--mobile-card-shadow);
|
|
269
|
+
overflow: hidden;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
/* 选项行:44px 触摸目标,字号 14px */
|
|
273
|
+
.select-option {
|
|
274
|
+
display: flex;
|
|
275
|
+
align-items: center;
|
|
276
|
+
padding: 0 0.75rem;
|
|
277
|
+
cursor: pointer;
|
|
278
|
+
user-select: none;
|
|
279
|
+
color: var(--mobile-text-primary);
|
|
280
|
+
transition: background-color 0.15s ease, color 0.15s ease;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
.select-option--md {
|
|
284
|
+
min-height: 2.75rem; /* 44px */
|
|
285
|
+
font-size: var(--font-size-base); /* 14px */
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
.select-option--sm {
|
|
289
|
+
min-height: 2.25rem; /* 36px */
|
|
290
|
+
font-size: var(--font-size-sm);
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
.select-option--hover {
|
|
294
|
+
background: var(--mobile-accent-muted);
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
/* 当前选中项以 accent 高亮,方便移动端快速识别 */
|
|
298
|
+
.select-option--selected {
|
|
299
|
+
color: var(--mobile-accent);
|
|
300
|
+
font-weight: 500;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
.select-option--placeholder {
|
|
304
|
+
color: var(--mobile-text-muted);
|
|
305
|
+
cursor: default;
|
|
306
|
+
}
|
|
307
|
+
</style>
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { DefineComponent } from 'vue'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* PluginGlobalDialog — 移动端宿主全局弹窗(通用能力)
|
|
5
|
+
*
|
|
6
|
+
* 与桌面端同构,仅在应用根挂载一次(宿主 App.vue / dev-shell App);
|
|
7
|
+
* 渲染完全由全局弹窗控制器(global-dialog.ts)驱动。
|
|
8
|
+
*/
|
|
9
|
+
export declare const PluginGlobalDialog: DefineComponent<Record<string, never>>
|
|
10
|
+
|
|
11
|
+
export default PluginGlobalDialog
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/** 手势跳过选项:排除不应作为切页手势的触摸起点 */
|
|
2
|
+
export interface SwipeTabsOptions {
|
|
3
|
+
/** 返回 true 时该轮触摸跳过手势判定(touchstart 的目标元素入参) */
|
|
4
|
+
shouldSkip?: (target: EventTarget | null) => boolean
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* 弹窗/页签内容区横向滑动切换(插件侧通用)
|
|
9
|
+
*
|
|
10
|
+
* 水平主导滑动超阈值(48px)触发 onSwitch('left' | 'right');
|
|
11
|
+
* 垂直主导不干扰内容滚动。返回绑定到模板的 touchstart/touchmove/touchend 处理器。
|
|
12
|
+
*/
|
|
13
|
+
export declare function useSwipeTabs(
|
|
14
|
+
onSwitch: (dir: 'left' | 'right') => void,
|
|
15
|
+
options?: SwipeTabsOptions
|
|
16
|
+
): {
|
|
17
|
+
onTouchStart: (e: TouchEvent) => void
|
|
18
|
+
onTouchMove: (e: TouchEvent) => void
|
|
19
|
+
onTouchEnd: () => void
|
|
20
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 弹窗/页签内容区横向滑动切换(插件侧通用)
|
|
3
|
+
*
|
|
4
|
+
* 与宿主 src/composables/useSwipeTabs 同语义:内容区水平主导滑动超阈值触发
|
|
5
|
+
* onSwitch;垂直主导(内容区上下滚动)时不记录位移,不干扰自身滚动。
|
|
6
|
+
* 水平方向不调用 preventDefault,避免阻断滚动容器行为。
|
|
7
|
+
*
|
|
8
|
+
* options.shouldSkip 用于排除不应作为切页手势的触摸起点(如输入控件、
|
|
9
|
+
* 可横向滚动容器),在 touchstart 时以事件目标判定一次,整轮手势生效。
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
export interface SwipeTabsOptions {
|
|
13
|
+
/** 返回 true 时该轮触摸跳过手势判定(touchstart 的目标元素入参) */
|
|
14
|
+
shouldSkip?: (target: EventTarget | null) => boolean
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function useSwipeTabs(onSwitch: (dir: 'left' | 'right') => void, options?: SwipeTabsOptions) {
|
|
18
|
+
let startX = 0
|
|
19
|
+
let startY = 0
|
|
20
|
+
let deltaX = 0
|
|
21
|
+
let skipped = false
|
|
22
|
+
|
|
23
|
+
/** 滑动方向判定阈值(px),低于阈值视为点按/轻微移动 */
|
|
24
|
+
const THRESHOLD = 48
|
|
25
|
+
|
|
26
|
+
function onTouchStart(e: TouchEvent) {
|
|
27
|
+
const t = e.touches[0]
|
|
28
|
+
startX = t.clientX
|
|
29
|
+
startY = t.clientY
|
|
30
|
+
deltaX = 0
|
|
31
|
+
skipped = options?.shouldSkip?.(e.target) ?? false
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function onTouchMove(e: TouchEvent) {
|
|
35
|
+
if (skipped) return
|
|
36
|
+
const t = e.touches[0]
|
|
37
|
+
const dx = t.clientX - startX
|
|
38
|
+
const dy = t.clientY - startY
|
|
39
|
+
// 仅水平主导时记录位移,垂直主导(内容区上下滚动)时清零
|
|
40
|
+
deltaX = Math.abs(dx) > Math.abs(dy) ? dx : 0
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function onTouchEnd() {
|
|
44
|
+
if (!skipped) {
|
|
45
|
+
if (deltaX < -THRESHOLD) onSwitch('left')
|
|
46
|
+
else if (deltaX > THRESHOLD) onSwitch('right')
|
|
47
|
+
}
|
|
48
|
+
deltaX = 0
|
|
49
|
+
skipped = false
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return { onTouchStart, onTouchMove, onTouchEnd }
|
|
53
|
+
}
|