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