@solar-taro/ui-vant 1.0.0 → 1.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/CHANGELOG.md +3 -0
- package/cascader-picker/index.vue.d.ts +73 -0
- package/date-range-picker/index.vue.d.ts +75 -0
- package/directives/bind-function.d.ts +5 -0
- package/directives/datetime-picker.d.ts +5 -0
- package/directives/readonly.d.ts +3 -0
- package/index.js +1764 -0
- package/item/index.vue.d.ts +44 -0
- package/list/index.vue.d.ts +105 -0
- package/modal/index.vue.d.ts +56 -0
- package/opper-controller/index.vue.d.ts +45 -0
- package/overlay/overlay.d.ts +37 -0
- package/package.json +1 -1
- package/plugin.d.ts +9 -0
- package/select-picker/index.vue.d.ts +66 -0
- package/selector/index.vue.d.ts +126 -0
- package/tabbar/index.vue.d.ts +58 -0
- package/vant.interface.d.ts +91 -0
- package/eslint.config.cjs +0 -22
- package/project.json +0 -29
- package/src/cascader-picker/index.vue +0 -210
- package/src/date-range-picker/index.vue +0 -201
- package/src/directives/bind-function.ts +0 -22
- package/src/directives/datetime-picker.ts +0 -33
- package/src/directives/readonly.ts +0 -5
- package/src/item/index.vue +0 -34
- package/src/list/index.vue +0 -86
- package/src/modal/index.vue +0 -55
- package/src/opper-controller/index.vue +0 -365
- package/src/overlay/overlay.ts +0 -76
- package/src/plugin.ts +0 -14
- package/src/select-picker/index.vue +0 -80
- package/src/selector/index.vue +0 -252
- package/src/tabbar/index.vue +0 -56
- package/src/vant.interface.ts +0 -96
- package/tsconfig.json +0 -21
- package/tsconfig.lib.json +0 -24
- package/tsconfig.spec.json +0 -28
- package/vite.config.ts +0 -130
- /package/{src/cascader-picker/index.ts → cascader-picker/index.d.ts} +0 -0
- /package/{src/date-range-picker/index.ts → date-range-picker/index.d.ts} +0 -0
- /package/{src/date-range-picker → date-range-picker}/index.scss +0 -0
- /package/{src/directives/index.ts → directives/index.d.ts} +0 -0
- /package/{src/index.ts → index.d.ts} +0 -0
- /package/{src/index.scss → index.scss} +0 -0
- /package/{src/item/index.ts → item/index.d.ts} +0 -0
- /package/{src/item → item}/index.scss +0 -0
- /package/{src/list/index.ts → list/index.d.ts} +0 -0
- /package/{src/modal/index.ts → modal/index.d.ts} +0 -0
- /package/{src/opper-controller/index.ts → opper-controller/index.d.ts} +0 -0
- /package/{src/opper-controller → opper-controller}/index.scss +0 -0
- /package/{src/overlay/index.ts → overlay/index.d.ts} +0 -0
- /package/{src/select-picker/index.ts → select-picker/index.d.ts} +0 -0
- /package/{src/selector/index.ts → selector/index.d.ts} +0 -0
- /package/{src/selector → selector}/index.scss +0 -0
- /package/{src/tabbar/index.ts → tabbar/index.d.ts} +0 -0
- /package/{src/tabbar → tabbar}/index.scss +0 -0
|
@@ -1,365 +0,0 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<view class="sun-opper-controller">
|
|
3
|
-
<van-action-sheet :show="show" title="OPPER" :close-on-click-overlay="true" @close="hide()">
|
|
4
|
-
<block v-if="connected">
|
|
5
|
-
<view class="sun-opper-controller-device">
|
|
6
|
-
<view class="sun-opper-controller-device-header">
|
|
7
|
-
<view class="sun-opper-controller-device-title">设备已连接</view>
|
|
8
|
-
<view class="sun-opper-controller-device-name">
|
|
9
|
-
{{ currentDevice.name || 'OPPER' }}
|
|
10
|
-
<view :class="currentDevice.charging ? 'color-success' : 'color-primary'">
|
|
11
|
-
<van-icon class-prefix="iconfont" name="lightning" />
|
|
12
|
-
<text v-show="currentDevice.volt">{{ currentDevice.volt }}%</text>
|
|
13
|
-
</view>
|
|
14
|
-
</view>
|
|
15
|
-
</view>
|
|
16
|
-
|
|
17
|
-
<view class="sun-opper-controller-device-infos">
|
|
18
|
-
<view class="sun-opper-controller-device-info">
|
|
19
|
-
<view class="color-gray">设备号</view>
|
|
20
|
-
<view class="color-secondary">{{ currentDevice.id }}</view>
|
|
21
|
-
</view>
|
|
22
|
-
<view class="sun-opper-controller-device-info">
|
|
23
|
-
<view class="color-gray">秤台精度</view>
|
|
24
|
-
<view class="color-secondary">{{ currentDevice.accuracy || 1 }}克</view>
|
|
25
|
-
</view>
|
|
26
|
-
<view class="sun-opper-controller-device-info">
|
|
27
|
-
<view class="color-gray">固件版本</view>
|
|
28
|
-
<view class="color-secondary">{{ currentDevice.version }}</view>
|
|
29
|
-
</view>
|
|
30
|
-
<view class="sun-opper-controller-device-info">
|
|
31
|
-
<view class="color-gray">序列号</view>
|
|
32
|
-
<view class="color-secondary">{{ currentDevice.serialNumber }}</view>
|
|
33
|
-
</view>
|
|
34
|
-
</view>
|
|
35
|
-
</view>
|
|
36
|
-
|
|
37
|
-
<view class="van-button-container">
|
|
38
|
-
<van-button type="danger" round="true" block="true" @tap="disconnectActionShow = true"> 断开连接 </van-button>
|
|
39
|
-
</view>
|
|
40
|
-
</block>
|
|
41
|
-
|
|
42
|
-
<block v-else>
|
|
43
|
-
<sun-list
|
|
44
|
-
class="sun-opper-controller-device-list"
|
|
45
|
-
:refresher="false"
|
|
46
|
-
:data="devices"
|
|
47
|
-
:loading="discovering"
|
|
48
|
-
loading-text="正在扫描"
|
|
49
|
-
empty-type="search"
|
|
50
|
-
empty-text="暂无设备">
|
|
51
|
-
<van-cell
|
|
52
|
-
v-for="device in devices"
|
|
53
|
-
:key="device.deviceId"
|
|
54
|
-
:title="device.localName || device.name"
|
|
55
|
-
:label="device.deviceId"
|
|
56
|
-
size="large"
|
|
57
|
-
:clickable="true"
|
|
58
|
-
@tap="connect(device.deviceId)">
|
|
59
|
-
<text :class="{ 'color-success': device.recommended }">{{ device.RSSI }}dBm</text>
|
|
60
|
-
</van-cell>
|
|
61
|
-
</sun-list>
|
|
62
|
-
|
|
63
|
-
<view class="van-button-container">
|
|
64
|
-
<van-button type="primary" round="true" block="true" @tap="discovering ? stopDiscovery() : startDiscovery()">
|
|
65
|
-
{{ discovering ? '停止扫描' : '扫描 OPPER 设备' }}
|
|
66
|
-
</van-button>
|
|
67
|
-
</view>
|
|
68
|
-
</block>
|
|
69
|
-
</van-action-sheet>
|
|
70
|
-
|
|
71
|
-
<van-action-sheet
|
|
72
|
-
:show="disconnectActionShow"
|
|
73
|
-
:actions="disconnectActions"
|
|
74
|
-
cancel-text="取消"
|
|
75
|
-
@select="onDisconnectAction($event)"
|
|
76
|
-
@cancel="disconnectActionShow = false"
|
|
77
|
-
@close="disconnectActionShow = false" />
|
|
78
|
-
</view>
|
|
79
|
-
</template>
|
|
80
|
-
|
|
81
|
-
<script lang="ts" setup>
|
|
82
|
-
import { isOpperDevice, Opper } from '@opper/core';
|
|
83
|
-
import { BluetoothLowEnergeDevice } from '@opper/wx';
|
|
84
|
-
import { BlueToothDevice, bluetoothService, checkBluetooth, overlay, vibrator, withLoading } from '@solar-taro/core';
|
|
85
|
-
import { useDestroyed, useObservable } from '@solar-vue/core';
|
|
86
|
-
import { getSystemInfo, openSetting } from '@tarojs/taro';
|
|
87
|
-
import { catchError, combineLatest, filter, finalize, from, map, of, switchMap, takeUntil, tap, timer } from 'rxjs';
|
|
88
|
-
import { computed, onUnmounted, ref, watch } from 'vue';
|
|
89
|
-
import { SunList } from '../list';
|
|
90
|
-
import { dialog } from '../overlay';
|
|
91
|
-
|
|
92
|
-
const props = withDefaults(
|
|
93
|
-
defineProps<{
|
|
94
|
-
show?: boolean,
|
|
95
|
-
/** 自动连接设备,MAC */
|
|
96
|
-
autoconnect?: string
|
|
97
|
-
opper: Opper
|
|
98
|
-
}>(),
|
|
99
|
-
{
|
|
100
|
-
show: false
|
|
101
|
-
}
|
|
102
|
-
);
|
|
103
|
-
|
|
104
|
-
const emit = defineEmits<{
|
|
105
|
-
'update:show': [boolean],
|
|
106
|
-
'connect': [deviceId: string],
|
|
107
|
-
'disconnect': [deviceId: string],
|
|
108
|
-
}>();
|
|
109
|
-
|
|
110
|
-
const opper = props.opper;
|
|
111
|
-
|
|
112
|
-
const connect$ = useDestroyed();
|
|
113
|
-
const discovery$ = useDestroyed();
|
|
114
|
-
|
|
115
|
-
const deviceMap = ref<Record<string, BlueToothDevice & { discoveryTime?: number, recommended?: boolean }>>({});
|
|
116
|
-
const discovering = ref(false);
|
|
117
|
-
const connected = useObservable(() => opper.connected);
|
|
118
|
-
const disconnectActionShow = ref(false);
|
|
119
|
-
|
|
120
|
-
const devices = computed(() => Object.values(deviceMap.value));
|
|
121
|
-
|
|
122
|
-
const currentDevice = useObservable(() => opper.connected.pipe(
|
|
123
|
-
filter(Boolean),
|
|
124
|
-
switchMap(() => {
|
|
125
|
-
const device = opper.device!;
|
|
126
|
-
|
|
127
|
-
return combineLatest({
|
|
128
|
-
id: of(device.id),
|
|
129
|
-
name: device.name,
|
|
130
|
-
version: device.firmwareRevision,
|
|
131
|
-
accuracy: opper.accuracyChange,
|
|
132
|
-
volt: opper.batteryChange.pipe(
|
|
133
|
-
map(([volt]) => volt)
|
|
134
|
-
),
|
|
135
|
-
charging: opper.batteryChange.pipe(
|
|
136
|
-
map(([, state]) => !!state)
|
|
137
|
-
),
|
|
138
|
-
serialNumber: device.serialNumber
|
|
139
|
-
});
|
|
140
|
-
})
|
|
141
|
-
), {} as { id: string, name: string, version: string, accuracy: number, volt: number, charging: boolean, serialNumber: string });
|
|
142
|
-
|
|
143
|
-
const disconnectActions = [
|
|
144
|
-
{ id: 1, name: '断开连接' },
|
|
145
|
-
{ id: 2, name: '断开连接并关机', color: 'var(--color-danger)' },
|
|
146
|
-
];
|
|
147
|
-
|
|
148
|
-
let connecting = false;
|
|
149
|
-
|
|
150
|
-
function startDiscovery() {
|
|
151
|
-
if (!checkBluetooth()) return;
|
|
152
|
-
|
|
153
|
-
let discoverDeviceTime: number | null = null;
|
|
154
|
-
|
|
155
|
-
discovering.value = true;
|
|
156
|
-
|
|
157
|
-
bluetoothService.openAdapter().pipe(
|
|
158
|
-
catchError(error => {
|
|
159
|
-
if (error.errMsg?.includes?.('already')) { // filter out the error of openBluetoothAdapter 'already' opened
|
|
160
|
-
return of(null);
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
throw error;
|
|
164
|
-
}),
|
|
165
|
-
switchMap(() =>
|
|
166
|
-
bluetoothService.startDevicesDiscovery({
|
|
167
|
-
allowDuplicatesKey: true,
|
|
168
|
-
powerLevel: 'high',
|
|
169
|
-
})
|
|
170
|
-
),
|
|
171
|
-
tap(() =>
|
|
172
|
-
timer(0, 1250).pipe(
|
|
173
|
-
takeUntil(discovery$)
|
|
174
|
-
).subscribe(() => vibrator.short())
|
|
175
|
-
),
|
|
176
|
-
switchMap(() => bluetoothService.devicesChange),
|
|
177
|
-
map(devices => devices.filter(device => isOpperDevice({
|
|
178
|
-
id: device.deviceId,
|
|
179
|
-
localName: device.localName,
|
|
180
|
-
name: device.name,
|
|
181
|
-
}))),
|
|
182
|
-
takeUntil(discovery$),
|
|
183
|
-
catchError(error => {
|
|
184
|
-
// 用户之前拒绝了授权
|
|
185
|
-
if (error.errno === 103) {
|
|
186
|
-
overlay.modal('温馨提示', '请先授予小程序蓝牙与位置权限').then(() => {
|
|
187
|
-
openSetting();
|
|
188
|
-
});
|
|
189
|
-
} else if (error.errMsg?.includes?.('permission')) { // startBluetoothDevicesDiscovery:fail:location permission is denied: 系统没给微信开启位置权限
|
|
190
|
-
overlay.tips('请先授予微信蓝牙与位置权限');
|
|
191
|
-
} else if (error.errMsg?.includes('frequently')) { // {"errno": 1500104, "errCode": 10008, "errMsg": "startBluetoothDevicesDiscovery:fail:system error, scanning too frequently", "isDiscovering": false}
|
|
192
|
-
overlay.tips('操作频繁,请稍后再试');
|
|
193
|
-
} else {
|
|
194
|
-
overlay.tips(error.errMsg);
|
|
195
|
-
}
|
|
196
|
-
stopDiscovery();
|
|
197
|
-
throw error;
|
|
198
|
-
}),
|
|
199
|
-
finalize(() => {
|
|
200
|
-
discovering.value = false;
|
|
201
|
-
deviceMap.value = {};
|
|
202
|
-
bluetoothService.stopDevicesDiscovery().subscribe();
|
|
203
|
-
})
|
|
204
|
-
).subscribe((devices: (BlueToothDevice & { discoveryTime?: number, recommended?: boolean })[]) => {
|
|
205
|
-
// 如果有,代表我就自动连接这一台设备
|
|
206
|
-
const mac = props.autoconnect;
|
|
207
|
-
if (mac) {
|
|
208
|
-
// MAC 后四位:aa:bb:cc:dd:ee:ff -> ee:ff -> eeff */
|
|
209
|
-
const macPart = mac.slice(-5).replace(':', '');
|
|
210
|
-
|
|
211
|
-
const device = devices.find(o =>
|
|
212
|
-
o.deviceId === props.autoconnect ||
|
|
213
|
-
// 由于 iOS 的 deviceId 不是 MAC,但是蓝牙名字上有 MAC 后四位,这里通过比对 MAC 来选择设备
|
|
214
|
-
o.name.endsWith(macPart)
|
|
215
|
-
);
|
|
216
|
-
|
|
217
|
-
if (device) {
|
|
218
|
-
return connect(device.deviceId);
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
// 如果没有自动连接设备,且三秒后只有一台设备,则自动连接
|
|
223
|
-
if (devices.length === 1) {
|
|
224
|
-
discoverDeviceTime ??= Date.now();
|
|
225
|
-
if (Date.now() - discoverDeviceTime > 3000) {
|
|
226
|
-
return connect(devices[0].deviceId);
|
|
227
|
-
}
|
|
228
|
-
} else if (devices.length > 1) {
|
|
229
|
-
discoverDeviceTime = null;
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
Object.keys(deviceMap.value).forEach(key => {
|
|
233
|
-
deviceMap.value[key].recommended = false;
|
|
234
|
-
// 五秒内没有发现该设备,则将其淘汰
|
|
235
|
-
if (Date.now() - deviceMap.value[key]!.discoveryTime! > 5000) {
|
|
236
|
-
delete deviceMap.value[key];
|
|
237
|
-
}
|
|
238
|
-
});
|
|
239
|
-
|
|
240
|
-
devices.forEach(device => {
|
|
241
|
-
deviceMap.value[device.deviceId] = device;
|
|
242
|
-
device.discoveryTime = Date.now();
|
|
243
|
-
});
|
|
244
|
-
|
|
245
|
-
const recommendDevice = [...Object.values(deviceMap.value)].sort((a, b) => b.RSSI - a.RSSI)[0];
|
|
246
|
-
if (recommendDevice) recommendDevice.recommended = true;
|
|
247
|
-
});
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
function stopDiscovery() {
|
|
251
|
-
discovery$.next();
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
function connect(deviceId: string) {
|
|
255
|
-
if (connecting) return;
|
|
256
|
-
|
|
257
|
-
overlay.loading('正在连接');
|
|
258
|
-
|
|
259
|
-
connecting = true;
|
|
260
|
-
connect$.next();
|
|
261
|
-
|
|
262
|
-
opper.connect(new BluetoothLowEnergeDevice(deviceId)).pipe(
|
|
263
|
-
takeUntil(connect$),
|
|
264
|
-
finalize(() => connecting = false)
|
|
265
|
-
).subscribe({
|
|
266
|
-
next: () => {
|
|
267
|
-
stopDiscovery();
|
|
268
|
-
},
|
|
269
|
-
error: error => {
|
|
270
|
-
if (error.errCode === 10003) {
|
|
271
|
-
overlay.tips('连接超时,请重试');
|
|
272
|
-
} else {
|
|
273
|
-
overlay.tips(`连接失败,原因:${error.errCode}:${error.errMsg}`);
|
|
274
|
-
console.error('连接失败', error);
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
});
|
|
278
|
-
|
|
279
|
-
opper.device!.connectedChange.pipe(
|
|
280
|
-
takeUntil(connect$),
|
|
281
|
-
).subscribe(value => {
|
|
282
|
-
if (value) {
|
|
283
|
-
emit('connect', deviceId);
|
|
284
|
-
setTimeout(hide, 600);
|
|
285
|
-
} else {
|
|
286
|
-
emit('disconnect', deviceId);
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
if (value) {
|
|
290
|
-
overlay.success('连接成功');
|
|
291
|
-
} else {
|
|
292
|
-
overlay.error('连接断开');
|
|
293
|
-
}
|
|
294
|
-
});
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
/** 跳过发现设备,直接连接设备 */
|
|
298
|
-
function directConnect() {
|
|
299
|
-
if (!checkBluetooth()) return;
|
|
300
|
-
|
|
301
|
-
discovering.value = true;
|
|
302
|
-
|
|
303
|
-
bluetoothService.openAdapter().pipe(
|
|
304
|
-
finalize(() => {
|
|
305
|
-
discovering.value = false;
|
|
306
|
-
})
|
|
307
|
-
).subscribe(() => {
|
|
308
|
-
connect(props.autoconnect!);
|
|
309
|
-
});
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
function disconnect() {
|
|
313
|
-
opper.disconnect().pipe(
|
|
314
|
-
withLoading('正在断开')
|
|
315
|
-
).subscribe();
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
function onDisconnectAction({ detail }: { detail: { id: number } }) {
|
|
319
|
-
switch (detail.id) {
|
|
320
|
-
case 1:
|
|
321
|
-
disconnect();
|
|
322
|
-
break;
|
|
323
|
-
|
|
324
|
-
case 2:
|
|
325
|
-
from(dialog.confirm('温馨提示', '您确定要关闭设备电源吗?')).pipe(
|
|
326
|
-
tap(() => overlay.loading('正在关机')),
|
|
327
|
-
switchMap(() => opper.shutdown()),
|
|
328
|
-
catchError(() => of(null)),
|
|
329
|
-
// 关机后距离信号丢失还有一段时间,这里主动断开连接,改进用户体验
|
|
330
|
-
switchMap(() => opper.disconnect())
|
|
331
|
-
).subscribe(() => {
|
|
332
|
-
overlay.success('设备已关机');
|
|
333
|
-
});
|
|
334
|
-
break;
|
|
335
|
-
}
|
|
336
|
-
}
|
|
337
|
-
|
|
338
|
-
function hide() {
|
|
339
|
-
emit('update:show', false);
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
watch(() => props.show, async value => {
|
|
343
|
-
if (value) {
|
|
344
|
-
if (!connected.value) {
|
|
345
|
-
if (props.autoconnect) {
|
|
346
|
-
const { platform } = await getSystemInfo();
|
|
347
|
-
// 由于在 ios 中,mac != deviceId,所以 ios 不支持直连,需要先发现设备
|
|
348
|
-
if (platform === 'ios') {
|
|
349
|
-
startDiscovery();
|
|
350
|
-
} else {
|
|
351
|
-
directConnect();
|
|
352
|
-
}
|
|
353
|
-
} else {
|
|
354
|
-
startDiscovery();
|
|
355
|
-
}
|
|
356
|
-
}
|
|
357
|
-
} else {
|
|
358
|
-
discovering.value && stopDiscovery();
|
|
359
|
-
}
|
|
360
|
-
});
|
|
361
|
-
|
|
362
|
-
onUnmounted(() => {
|
|
363
|
-
stopDiscovery();
|
|
364
|
-
});
|
|
365
|
-
</script>
|
package/src/overlay/overlay.ts
DELETED
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import type { VanDialog, VanDialogOptions, VanNotify } from '../vant.interface';
|
|
2
|
-
|
|
3
|
-
export interface OverlayConfig {
|
|
4
|
-
dialog: VanDialog;
|
|
5
|
-
notify: VanNotify;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
const config = {} as OverlayConfig;
|
|
9
|
-
|
|
10
|
-
export function setupOverlay(cfg: OverlayConfig) {
|
|
11
|
-
Object.assign(config, cfg);
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export class Notify {
|
|
15
|
-
private readonly duration = 2000;
|
|
16
|
-
|
|
17
|
-
primary(message: string, selector = '#van-notify') {
|
|
18
|
-
return config.notify({ type: 'primary', message, duration: this.duration, selector });
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
success(message: string, selector = '#van-notify') {
|
|
22
|
-
return config.notify({ type: 'success', message, duration: this.duration, selector })
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
warning(message: string, selector = '#van-notify') {
|
|
26
|
-
return config.notify({ type: 'warning', message, duration: this.duration, selector })
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
danger(message: string, selector = '#van-notify') {
|
|
30
|
-
return config.notify({ type: 'danger', message, duration: this.duration, selector });
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
dismiss() {
|
|
34
|
-
return config.notify.clear();
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export class Dialog {
|
|
39
|
-
/**
|
|
40
|
-
* 展示确认对话框
|
|
41
|
-
* @param title
|
|
42
|
-
* @param message
|
|
43
|
-
* @param options 其他 dialog 选项
|
|
44
|
-
*/
|
|
45
|
-
confirm(title: string, message: string, options?: VanDialogOptions) {
|
|
46
|
-
return config.dialog.confirm({
|
|
47
|
-
title,
|
|
48
|
-
message,
|
|
49
|
-
...options
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* 展示警告对话框
|
|
55
|
-
* @param title
|
|
56
|
-
* @param message
|
|
57
|
-
* @param options 其他 dialog 选项
|
|
58
|
-
*/
|
|
59
|
-
alert(title: string, message: string, options?: VanDialogOptions) {
|
|
60
|
-
return config.dialog.alert({
|
|
61
|
-
title,
|
|
62
|
-
message,
|
|
63
|
-
...options
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* 关闭对话框
|
|
69
|
-
*/
|
|
70
|
-
dismiss() {
|
|
71
|
-
return config.dialog.close();
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
export const dialog = new Dialog();
|
|
76
|
-
export const notify = new Notify();
|
package/src/plugin.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import type { App, Plugin } from 'vue';
|
|
2
|
-
import { vReadonly } from './directives';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* sun-core vue plugin
|
|
6
|
-
*
|
|
7
|
-
* Directives:
|
|
8
|
-
* - `v-readonly`: https://github.com/NervJS/taro/issues/10337#issuecomment-989641124
|
|
9
|
-
*/
|
|
10
|
-
export const SolarVant: Plugin = {
|
|
11
|
-
install(app: App) {
|
|
12
|
-
app.directive('readonly', vReadonly);
|
|
13
|
-
}
|
|
14
|
-
}
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<van-popup :show="show" position="bottom" :round="true" :close-on-click-overlay="true" @close="close()">
|
|
3
|
-
<van-picker
|
|
4
|
-
v-bind="$attrs"
|
|
5
|
-
:title="title"
|
|
6
|
-
:show-toolbar="true"
|
|
7
|
-
:value-key="labelKey"
|
|
8
|
-
:columns="filteredList"
|
|
9
|
-
:loading="loading"
|
|
10
|
-
:default-index="index"
|
|
11
|
-
@cancel="cancel()"
|
|
12
|
-
@confirm="onConfirm($event)" />
|
|
13
|
-
<van-search
|
|
14
|
-
v-if="searchable && options.length"
|
|
15
|
-
shape="round"
|
|
16
|
-
input-align="center"
|
|
17
|
-
placeholder="请输入搜索关键词"
|
|
18
|
-
@change="keyword = $event.detail" />
|
|
19
|
-
</van-popup>
|
|
20
|
-
</template>
|
|
21
|
-
|
|
22
|
-
<script lang="ts" setup>
|
|
23
|
-
import { useFilterList } from '@solar-taro/core';
|
|
24
|
-
import { computed } from 'vue';
|
|
25
|
-
|
|
26
|
-
interface Option {
|
|
27
|
-
[key: string]: any;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
defineOptions({
|
|
31
|
-
inheritAttrs: false
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
const emit = defineEmits<{
|
|
35
|
-
close: [],
|
|
36
|
-
cancel: [model: any],
|
|
37
|
-
confirm: [options: any],
|
|
38
|
-
'update:show': [boolean],
|
|
39
|
-
'update:modelValue': [model: any]
|
|
40
|
-
}>();
|
|
41
|
-
|
|
42
|
-
const props = withDefaults(
|
|
43
|
-
defineProps<{
|
|
44
|
-
show: boolean
|
|
45
|
-
labelKey?: string
|
|
46
|
-
valueKey?: string
|
|
47
|
-
searchable?: boolean
|
|
48
|
-
title: string
|
|
49
|
-
loading?: boolean
|
|
50
|
-
options: Option[]
|
|
51
|
-
modelValue: string | number | undefined
|
|
52
|
-
required?: boolean
|
|
53
|
-
}>(),
|
|
54
|
-
{
|
|
55
|
-
labelKey: 'fullName',
|
|
56
|
-
valueKey: 'id',
|
|
57
|
-
searchable: true,
|
|
58
|
-
}
|
|
59
|
-
)
|
|
60
|
-
|
|
61
|
-
const index = computed(() => props.options.findIndex(option => option[props.valueKey] === props.modelValue) ?? 0);
|
|
62
|
-
const { keyword, filteredList } = useFilterList(() => props.options, (item, keyword) =>
|
|
63
|
-
item[props.labelKey].toLowerCase().includes(keyword.value.toLowerCase())
|
|
64
|
-
);
|
|
65
|
-
|
|
66
|
-
function cancel() {
|
|
67
|
-
props.required || emit('update:modelValue', null);
|
|
68
|
-
emit('cancel', props.modelValue);
|
|
69
|
-
close();
|
|
70
|
-
}
|
|
71
|
-
function close() {
|
|
72
|
-
emit('update:show', false);
|
|
73
|
-
emit('close');
|
|
74
|
-
}
|
|
75
|
-
function onConfirm({ detail }: any) {
|
|
76
|
-
emit('update:modelValue', detail.value[props.valueKey]);
|
|
77
|
-
emit('confirm', detail.value);
|
|
78
|
-
emit('update:show', false);
|
|
79
|
-
}
|
|
80
|
-
</script>
|