@solar-taro/ui-vant 4.5.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/index6.js CHANGED
@@ -1,286 +1,64 @@
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 = {
10
- key: 0,
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({
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,
16
6
  __name: "index",
17
- props: /* @__PURE__ */ F({
18
- mac: {},
19
- deviceId: {},
20
- opper: {}
21
- }, {
22
- show: { type: Boolean, default: !1 },
23
- showModifiers: {}
24
- }),
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
- });
107
- }
108
- function h() {
109
- x.next();
110
- }
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
- }));
126
- }
127
- function Y(o) {
128
- q() && (d.value = !0, g.openAdapter().pipe(
129
- O(() => {
130
- d.value = !1;
131
- })
132
- ).subscribe(() => {
133
- _(o);
134
- }));
135
- }
136
- function Z() {
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(() => {
137
21
  var o;
138
- (o = i.disconnect()) == null || o.pipe(
139
- ke("正在断开")
140
- ).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");
141
32
  }
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
- }
33
+ function p({ detail: o }) {
34
+ n("update:modelValue", o.value[l.valueKey]), n("confirm", o.value), n("update:show", !1);
159
35
  }
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"]))
270
- ]),
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
- ]));
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));
282
60
  }
283
61
  });
284
62
  export {
285
- ct as default
63
+ U as default
286
64
  };
package/index7.js CHANGED
@@ -1,64 +1,30 @@
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,
6
- __name: "index",
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(() => {
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();
29
- }
30
- function i() {
31
- n("update:show", !1), n("close");
32
- }
33
- function p({ detail: o }) {
34
- n("update:modelValue", o.value[l.valueKey]), n("confirm", o.value), n("update:show", !1);
35
- }
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));
1
+ const i = {};
2
+ function a(r) {
3
+ Object.assign(i, r);
4
+ }
5
+ class o {
6
+ constructor() {
7
+ this.duration = 2e3;
60
8
  }
61
- });
9
+ primary(n, t = "#van-notify") {
10
+ return i.notify({ type: "primary", message: n, duration: this.duration, selector: t });
11
+ }
12
+ success(n, t = "#van-notify") {
13
+ return i.notify({ type: "success", message: n, duration: this.duration, selector: t });
14
+ }
15
+ warning(n, t = "#van-notify") {
16
+ return i.notify({ type: "warning", message: n, duration: this.duration, selector: t });
17
+ }
18
+ danger(n, t = "#van-notify") {
19
+ return i.notify({ type: "danger", message: n, duration: this.duration, selector: t });
20
+ }
21
+ dismiss() {
22
+ return i.notify.clear();
23
+ }
24
+ }
25
+ const s = new o();
62
26
  export {
63
- U as default
27
+ o as Notify,
28
+ s as notify,
29
+ a as setupOverlay
64
30
  };