@solar-taro/ui-vant 4.0.1 → 4.2.0

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/index7.js CHANGED
@@ -1,273 +1,64 @@
1
- import { defineComponent as Z, ref as E, computed as ee, watch as te, onUnmounted as ne, Fragment as oe, vShow as se, openBlock as ie, createElementBlock as le, createElementVNode as re, unref as ce, createTextVNode as ae, toDisplayString as ue, normalizeClass as de, createVNode as pe, withDirectives as ve, withCtx as fe, renderList as me, normalizeStyle as we } from "vue";
2
- import { isOpperDevice as he } from "@opper/core";
3
- import { BluetoothLowEnergeyDevice as be } from "@opper/wx";
4
- import { checkBluetooth as U, bluetoothService as w, vibrator as ge, overlay as r, withLoading as ye } from "@solar-taro/core";
5
- import { SunIcon as _e, SunButton as q, SunList as De } from "@solar-taro/ui-sun";
6
- import { useDestroyed as K, useObservable as W } from "@solar-vue/core";
7
- import { getSystemInfo as Se, openSetting as xe } from "@tarojs/taro";
8
- import { filter as G, switchMap as f, combineLatest as Ce, map as B, of as $, catchError as D, tap as N, timer as ke, takeUntil as O, finalize as T, from as Ie } from "rxjs";
9
- import { dialog as Ee } from "./index10.js";
10
- const i = ce, o = re, p = ue, S = pe, Be = se, $e = ve, Ne = de, L = ae, M = fe, P = oe, h = ie, b = le, Oe = me, Te = we, Le = { class: "sun-opper-controller" }, Me = ["show"], Pe = { class: "sun-opper-controller-device" }, Re = { class: "sun-opper-controller-device-header" }, ze = { class: "sun-opper-controller-device-name" }, Ve = { class: "sun-opper-controller-device-infos" }, Ae = { class: "sun-opper-controller-device-info" }, je = { class: "sun-opper-controller-device-info" }, Fe = { class: "sun-opper-controller-device-info" }, Ue = { class: "sun-opper-controller-device-info" }, qe = { class: "van-button-container" }, Ke = ["title", "label", "onTap"], We = { class: "van-button-container" }, Ge = ["show"], ot = /* @__PURE__ */ Z({
1
+ import { defineComponent as y, computed as v, openBlock as V, createElementBlock as k, createElementVNode as w, mergeProps as B, unref as h, createBlock as C, isRef as b, createCommentVNode as g } from "vue";
2
+ import { useFilterList as x } from "@solar-taro/core";
3
+ import { SunSearchbar as K } from "@solar-taro/ui-sun";
4
+ const r = h, N = B, E = w, L = b, d = V, $ = C, q = g, P = k, R = ["show"], S = ["title", "value-key", "columns", "loading", "default-index"], U = /* @__PURE__ */ y({
5
+ inheritAttrs: !1,
11
6
  __name: "index",
12
7
  props: {
13
- show: { type: Boolean, default: !1 },
14
- mac: {},
15
- deviceId: {},
16
- opper: {}
8
+ show: { type: Boolean },
9
+ labelKey: { default: "fullName" },
10
+ valueKey: { default: "id" },
11
+ searchable: { type: Boolean, default: !0 },
12
+ title: {},
13
+ loading: { type: Boolean },
14
+ options: {},
15
+ modelValue: {},
16
+ required: { type: Boolean }
17
17
  },
18
- emits: ["update:show", "connect", "disconnect"],
19
- setup(R, { emit: H }) {
20
- const v = R, x = H, l = v.opper, z = K(), C = K(), a = E({}), u = E(!1), V = W(() => l.connected), g = E(!1), A = ee(() => Object.values(a.value)), d = W(() => l.connected.pipe(
21
- G(Boolean),
22
- f(() => {
23
- const n = l.device;
24
- return Ce({
25
- id: $(n.id),
26
- name: n.name,
27
- version: n.firmwareRevision,
28
- accuracy: l.accuracyChange,
29
- volt: l.batteryChange.pipe(
30
- B(([e]) => e)
31
- ),
32
- charging: l.batteryChange.pipe(
33
- B(([, e]) => !!e)
34
- ),
35
- serialNumber: n.serialNumber
36
- });
37
- })
38
- ), {}), J = [
39
- { id: 1, name: "断开连接" },
40
- { id: 2, name: "断开连接并关机", color: "var(--color-danger)" }
41
- ];
42
- let k = !1;
43
- function I() {
44
- if (!U()) return;
45
- let n = null;
46
- u.value = !0, w.openAdapter().pipe(
47
- D((e) => {
48
- var t, c;
49
- if ((c = (t = e.errMsg) == null ? void 0 : t.includes) != null && c.call(t, "already"))
50
- return $(null);
51
- throw e;
52
- }),
53
- f(
54
- () => w.startDevicesDiscovery({
55
- allowDuplicatesKey: !0,
56
- powerLevel: "high"
57
- })
58
- ),
59
- N(
60
- () => ke(0, 1250).pipe(
61
- O(C)
62
- ).subscribe(() => ge.short())
63
- ),
64
- f(() => w.devicesChange),
65
- B((e) => e.filter((t) => he({
66
- id: t.deviceId,
67
- name: t.name
68
- }))),
69
- O(C),
70
- D((e) => {
71
- var t, c, s;
72
- throw e.errno === 103 ? r.modal("温馨提示", "请先授予小程序蓝牙与位置权限").then(() => {
73
- xe();
74
- }) : (c = (t = e.errMsg) == null ? void 0 : t.includes) != null && c.call(t, "permission") ? r.tips("请先授予微信蓝牙与位置权限") : (s = e.errMsg) != null && s.includes("frequently") ? r.tips("操作频繁,请稍后再试") : r.tips(e.errMsg), m(), e;
75
- }),
76
- T(() => {
77
- u.value = !1, a.value = {}, w.stopDevicesDiscovery().subscribe();
78
- })
79
- ).subscribe((e) => {
80
- const t = v.mac || v.deviceId;
81
- if (t) {
82
- const s = t.slice(-5).replace(":", ""), _ = e.find(
83
- (F) => F.deviceId === t || // 由于 iOS 的 deviceId 不是 MAC,但是蓝牙名字上有 MAC 后四位,这里通过比对 MAC 来选择设备
84
- F.name.endsWith(s)
85
- );
86
- if (_)
87
- return y(_.deviceId);
88
- }
89
- if (e.length === 1) {
90
- if (n != null || (n = Date.now()), Date.now() - n > 5e3)
91
- return y(e[0].deviceId);
92
- } else e.length > 1 && (n = null);
93
- Object.keys(a.value).forEach((s) => {
94
- a.value[s].recommended = !1, Date.now() - a.value[s].discoveryTime > 5e3 && delete a.value[s];
95
- }), e.forEach((s) => {
96
- a.value[s.deviceId] = s, s.discoveryTime = Date.now();
97
- });
98
- const c = [...Object.values(a.value)].sort((s, _) => _.RSSI - s.RSSI)[0];
99
- c && (c.recommended = !0);
100
- });
18
+ emits: ["close", "cancel", "confirm", "update:show", "update:modelValue"],
19
+ setup(t, { emit: s }) {
20
+ const n = s, l = t, m = v(() => {
21
+ var o;
22
+ return (o = l.options.findIndex((e) => e[l.valueKey] === l.modelValue)) != null ? o : 0;
23
+ }), { keyword: u, filteredList: c } = x(
24
+ () => l.options,
25
+ (o, e) => o[l.labelKey].toLowerCase().includes(e.toLowerCase())
26
+ );
27
+ function f() {
28
+ l.required || n("update:modelValue", null), n("cancel", l.modelValue), i();
101
29
  }
102
- function m() {
103
- C.next();
30
+ function i() {
31
+ n("update:show", !1), n("close");
104
32
  }
105
- function y(n) {
106
- k || (r.loading("正在连接"), k = !0, z.next(), l.connect(new be(n)).pipe(
107
- N(() => {
108
- m(), x("connect", n), r.success("连接成功"), setTimeout(j, 600);
109
- }),
110
- D((e) => {
111
- throw e.errCode === 10003 ? r.tips("连接超时,请重试") : r.tips(`连接失败:${e.errCode}:${e.errMsg}`), e;
112
- }),
113
- T(() => k = !1),
114
- f(() => l.connected.pipe(G((e) => !e))),
115
- // 监听断开
116
- O(z)
117
- ).subscribe(() => {
118
- x("disconnect", n), r.error("连接断开");
119
- }));
33
+ function p({ detail: o }) {
34
+ n("update:modelValue", o.value[l.valueKey]), n("confirm", o.value), n("update:show", !1);
120
35
  }
121
- function Q(n) {
122
- U() && (u.value = !0, w.openAdapter().pipe(
123
- T(() => {
124
- u.value = !1;
125
- })
126
- ).subscribe(() => {
127
- y(n);
128
- }));
129
- }
130
- function X() {
131
- var n;
132
- (n = l.disconnect()) == null || n.pipe(
133
- ye("正在断开")
134
- ).subscribe();
135
- }
136
- function Y({ detail: n }) {
137
- switch (n.id) {
138
- case 1:
139
- X();
140
- break;
141
- case 2:
142
- Ie(Ee.confirm("温馨提示", "您确定要关闭设备电源吗?")).pipe(
143
- N(() => r.loading("正在关机")),
144
- f(() => l.shutdown()),
145
- D(() => $(null)),
146
- // 关机后距离信号丢失还有一段时间,这里主动断开连接,改进用户体验
147
- f(() => l.disconnect())
148
- ).subscribe(() => {
149
- r.success("设备已关机");
150
- });
151
- break;
152
- }
153
- }
154
- function j() {
155
- x("update:show", !1);
156
- }
157
- return te(() => v.show, async (n) => {
158
- if (n) {
159
- if (!V.value)
160
- if (v.mac) {
161
- const { platform: e } = await Se();
162
- e === "ios" ? I() : Q(v.mac);
163
- } else
164
- I();
165
- } else
166
- u.value && m();
167
- }), ne(() => {
168
- m();
169
- }), (n, e) => (h(), b("view", Le, [
170
- o("van-action-sheet", {
171
- show: R.show,
172
- title: "OPPER",
173
- "close-on-click-overlay": !0,
174
- onClose: e[2] || (e[2] = (t) => j())
175
- }, [
176
- i(V) ? (h(), b(P, { key: 0 }, [
177
- o("view", Pe, [
178
- o("view", Re, [
179
- e[6] || (e[6] = o("view", { class: "sun-opper-controller-device-title" }, "设备已连接", -1)),
180
- o("view", ze, [
181
- L(p(i(d).name || "OPPER") + " ", 1),
182
- o("view", {
183
- class: Ne(["sun-opper-controller-device-battery", { "sun-opper-controller-device-battery-active": i(d).charging }])
184
- }, [
185
- S(i(_e), { name: "flash" }),
186
- $e(o("text", null, p(i(d).volt) + "%", 513), [
187
- [Be, i(d).volt]
188
- ])
189
- ], 2)
190
- ])
191
- ]),
192
- o("view", Ve, [
193
- o("view", Ae, [
194
- e[7] || (e[7] = o("view", null, "设备号", -1)),
195
- o("view", null, p(i(d).id), 1)
196
- ]),
197
- o("view", je, [
198
- e[8] || (e[8] = o("view", null, "秤台精度", -1)),
199
- o("view", null, p(i(d).accuracy || 1) + "克", 1)
200
- ]),
201
- o("view", Fe, [
202
- e[9] || (e[9] = o("view", null, "固件版本", -1)),
203
- o("view", null, p(i(d).version), 1)
204
- ]),
205
- o("view", Ue, [
206
- e[10] || (e[10] = o("view", null, "序列号", -1)),
207
- o("view", null, p(i(d).serialNumber), 1)
208
- ])
209
- ])
210
- ]),
211
- o("view", qe, [
212
- S(i(q), {
213
- color: "danger",
214
- expand: "block",
215
- onTap: e[0] || (e[0] = (t) => g.value = !0)
216
- }, {
217
- default: M(() => [...e[11] || (e[11] = [
218
- L("断开连接", -1)
219
- ])]),
220
- _: 1
221
- })
222
- ])
223
- ], 64)) : (h(), b(P, { key: 1 }, [
224
- S(i(De), {
225
- class: "sun-opper-controller-device-list",
226
- refresher: !1,
227
- data: A.value,
228
- loading: u.value,
229
- "loading-text": "正在扫描"
230
- }, {
231
- default: M(() => [
232
- (h(!0), b(P, null, Oe(A.value, (t) => (h(), b("van-cell", {
233
- key: t.deviceId,
234
- title: t.name,
235
- label: t.deviceId,
236
- size: "large",
237
- clickable: !0,
238
- onTap: (c) => y(t.deviceId)
239
- }, [
240
- o("text", {
241
- style: Te({ color: t.recommended ? "var(--color-success)" : "inherit" })
242
- }, p(t.RSSI) + "dBm", 5)
243
- ], 40, Ke))), 128))
244
- ]),
245
- _: 1
246
- }, 8, ["data", "loading"]),
247
- o("view", We, [
248
- S(i(q), {
249
- expand: "block",
250
- onTap: e[1] || (e[1] = (t) => u.value ? m() : I())
251
- }, {
252
- default: M(() => [
253
- L(p(u.value ? "停止扫描" : "扫描 OPPER 设备"), 1)
254
- ]),
255
- _: 1
256
- })
257
- ])
258
- ], 64))
259
- ], 40, Me),
260
- o("van-action-sheet", {
261
- show: g.value,
262
- actions: J,
263
- "cancel-text": "取消",
264
- onSelect: e[3] || (e[3] = (t) => Y(t)),
265
- onCancel: e[4] || (e[4] = (t) => g.value = !1),
266
- onClose: e[5] || (e[5] = (t) => g.value = !1)
267
- }, null, 40, Ge)
268
- ]));
36
+ return (o, e) => (d(), P("van-popup", {
37
+ show: t.show,
38
+ position: "bottom",
39
+ round: !0,
40
+ "close-on-click-overlay": !0,
41
+ onClose: e[3] || (e[3] = (a) => i())
42
+ }, [
43
+ E("van-picker", N(o.$attrs, {
44
+ title: t.title,
45
+ "show-toolbar": !0,
46
+ "value-key": t.labelKey,
47
+ columns: r(c),
48
+ loading: t.loading,
49
+ "default-index": m.value,
50
+ onCancel: e[0] || (e[0] = (a) => f()),
51
+ onConfirm: e[1] || (e[1] = (a) => p(a))
52
+ }), null, 16, S),
53
+ t.searchable && t.options.length ? (d(), $(r(K), {
54
+ key: 0,
55
+ modelValue: r(u),
56
+ "onUpdate:modelValue": e[2] || (e[2] = (a) => L(u) ? u.value = a : null),
57
+ placeholder: "输入关键字搜索"
58
+ }, null, 8, ["modelValue"])) : q("", !0)
59
+ ], 40, R));
269
60
  }
270
61
  });
271
62
  export {
272
- ot as default
63
+ U as default
273
64
  };