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