@zhubangyun/lowcode-core 6.1.90 → 6.2.30
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/es/index.js +12 -34
- package/es/index.less +11 -0
- package/es/init/init.bar-height.d.ts +1 -0
- package/es/init/init.bar-height.js +37 -0
- package/es/init/init.mobile-class.d.ts +1 -0
- package/es/init/init.mobile-class.js +10 -0
- package/es/init/init.scroll-size.d.ts +5 -0
- package/es/init/init.scroll-size.js +26 -0
- package/es/style.js +1 -1
- package/es/utils/api/form-api.d.ts +1 -0
- package/es/utils/api/form-api.js +101 -19
- package/es/utils/api/index.js +3 -2
- package/es/utils/common/index.d.ts +1 -1
- package/es/utils/common/index.js +5 -1
- package/es/utils/page/index.js +10 -6
- package/es/utils/page/page-form-data-manager-group.js +8 -8
- package/es/utils/page/page-form-data-manager.js +8 -8
- package/es/utils/page/page-form.js +4 -6
- package/es/utils/page/page-layout.d.ts +2 -1
- package/es/utils/page/page-layout.js +23 -3
- package/es/utils/page/page-render.js +4 -5
- package/es/utils/page/page-show.js +4 -4
- package/es/utils/page/print-form.d.ts +3 -2
- package/es/utils/page/print-form.js +184 -54
- package/es/utils/uni-bridge.d.ts +2 -0
- package/es/utils/uni-bridge.js +78 -36
- package/es/utils/utils.scrollbar-size.js +0 -0
- package/lib/index.js +12 -34
- package/lib/index.less +11 -0
- package/lib/init/init.bar-height.d.ts +1 -0
- package/lib/init/init.bar-height.js +42 -0
- package/lib/init/init.mobile-class.d.ts +1 -0
- package/lib/init/init.mobile-class.js +14 -0
- package/lib/init/init.scroll-size.d.ts +5 -0
- package/lib/init/init.scroll-size.js +31 -0
- package/lib/style.js +1 -1
- package/lib/utils/api/form-api.d.ts +1 -0
- package/lib/utils/api/form-api.js +100 -18
- package/lib/utils/api/index.js +3 -2
- package/lib/utils/common/index.d.ts +1 -1
- package/lib/utils/common/index.js +5 -1
- package/lib/utils/page/index.js +10 -6
- package/lib/utils/page/page-form-data-manager-group.js +8 -8
- package/lib/utils/page/page-form-data-manager.js +8 -8
- package/lib/utils/page/page-form.js +4 -6
- package/lib/utils/page/page-layout.d.ts +2 -1
- package/lib/utils/page/page-layout.js +23 -3
- package/lib/utils/page/page-render.js +4 -5
- package/lib/utils/page/page-show.js +4 -4
- package/lib/utils/page/print-form.d.ts +3 -2
- package/lib/utils/page/print-form.js +184 -54
- package/lib/utils/uni-bridge.d.ts +2 -0
- package/lib/utils/uni-bridge.js +78 -36
- package/lib/utils/utils.scrollbar-size.js +1 -0
- package/package.json +1 -1
|
@@ -6,13 +6,13 @@ import { createRoot } from "react-dom/client";
|
|
|
6
6
|
export function renderElement(options) {
|
|
7
7
|
return new Promise(/*#__PURE__*/function () {
|
|
8
8
|
var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(resolve, reject) {
|
|
9
|
-
var container, _onClose, _options$element, component, props,
|
|
9
|
+
var container, _onClose, _options$element, component, props, needUnmount, root, element;
|
|
10
10
|
return _regeneratorRuntime.wrap(function (_context) {
|
|
11
11
|
while (1) switch (_context.prev = _context.next) {
|
|
12
12
|
case 0:
|
|
13
13
|
container = options.container, _onClose = options.onClose;
|
|
14
14
|
_options$element = options.element, component = _options$element.component, props = _options$element.props;
|
|
15
|
-
|
|
15
|
+
needUnmount = !container;
|
|
16
16
|
if (!container) {
|
|
17
17
|
container = document.createElement("div");
|
|
18
18
|
document.body.append(container);
|
|
@@ -27,12 +27,11 @@ export function renderElement(options) {
|
|
|
27
27
|
//等待动画结束
|
|
28
28
|
setTimeout(function () {
|
|
29
29
|
root.unmount();
|
|
30
|
-
if (
|
|
30
|
+
if (needUnmount) {
|
|
31
31
|
var _container;
|
|
32
|
-
//移除
|
|
33
32
|
(_container = container) === null || _container === void 0 ? void 0 : _container.remove();
|
|
34
33
|
}
|
|
35
|
-
},
|
|
34
|
+
}, 150);
|
|
36
35
|
_onClose === null || _onClose === void 0 ? void 0 : _onClose();
|
|
37
36
|
}
|
|
38
37
|
}));
|
|
@@ -3,7 +3,7 @@ import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/objectWithoutP
|
|
|
3
3
|
import _inheritsLoose from "@babel/runtime/helpers/inheritsLoose";
|
|
4
4
|
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
5
5
|
var _excluded = ["layout", "pageId", "onClose"],
|
|
6
|
-
_excluded2 = ["
|
|
6
|
+
_excluded2 = ["onClose"];
|
|
7
7
|
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
8
8
|
import { renderElement } from "./page-render";
|
|
9
9
|
import React, { Component } from "react";
|
|
@@ -15,13 +15,13 @@ export function show(_x) {
|
|
|
15
15
|
}
|
|
16
16
|
function _show() {
|
|
17
17
|
_show = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(options) {
|
|
18
|
-
var
|
|
18
|
+
var onClose, props;
|
|
19
19
|
return _regeneratorRuntime.wrap(function (_context) {
|
|
20
20
|
while (1) switch (_context.prev = _context.next) {
|
|
21
21
|
case 0:
|
|
22
|
-
|
|
22
|
+
onClose = options.onClose, props = _objectWithoutPropertiesLoose(options, _excluded2);
|
|
23
23
|
return _context.abrupt("return", renderElement({
|
|
24
|
-
container: container,
|
|
24
|
+
container: props.container,
|
|
25
25
|
onClose: onClose,
|
|
26
26
|
element: {
|
|
27
27
|
component: PageRender,
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
interface PrintOptions {
|
|
2
|
+
showLoading?: boolean;
|
|
2
3
|
templateId: string;
|
|
3
|
-
mode?: "print" | "export";
|
|
4
|
+
mode?: "print" | "export" | "cloud_print";
|
|
4
5
|
data: any;
|
|
5
6
|
}
|
|
6
|
-
export declare function getFormPrintTemplates(formId: string): Promise<any
|
|
7
|
+
export declare function getFormPrintTemplates(formId: string): Promise<any>;
|
|
7
8
|
export declare function print(options: PrintOptions): Promise<void>;
|
|
8
9
|
export {};
|
|
@@ -4,16 +4,23 @@ import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
|
4
4
|
import { apiRequest } from "../api";
|
|
5
5
|
import { FormIds } from "../formIds";
|
|
6
6
|
import { hideLoading, showLoading } from "./index";
|
|
7
|
+
var cache = new Map();
|
|
7
8
|
export function getFormPrintTemplates(_x) {
|
|
8
9
|
return _getFormPrintTemplates.apply(this, arguments);
|
|
9
10
|
}
|
|
10
11
|
function _getFormPrintTemplates() {
|
|
11
|
-
_getFormPrintTemplates = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function
|
|
12
|
+
_getFormPrintTemplates = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2(formId) {
|
|
12
13
|
var res;
|
|
13
|
-
return _regeneratorRuntime.wrap(function (
|
|
14
|
-
while (1) switch (
|
|
14
|
+
return _regeneratorRuntime.wrap(function (_context2) {
|
|
15
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
15
16
|
case 0:
|
|
16
|
-
|
|
17
|
+
if (!cache.has(formId)) {
|
|
18
|
+
_context2.next = 1;
|
|
19
|
+
break;
|
|
20
|
+
}
|
|
21
|
+
return _context2.abrupt("return", cache.get(formId));
|
|
22
|
+
case 1:
|
|
23
|
+
_context2.next = 2;
|
|
17
24
|
return apiRequest.get("forms/search", {
|
|
18
25
|
params: {
|
|
19
26
|
formId: FormIds.printTemplate,
|
|
@@ -25,20 +32,21 @@ function _getFormPrintTemplates() {
|
|
|
25
32
|
pageSize: 1000
|
|
26
33
|
}
|
|
27
34
|
});
|
|
28
|
-
case
|
|
29
|
-
res =
|
|
35
|
+
case 2:
|
|
36
|
+
res = _context2.sent;
|
|
37
|
+
cache.set(formId, res.data || []);
|
|
30
38
|
if (!res.success) {
|
|
31
|
-
|
|
39
|
+
_context2.next = 3;
|
|
32
40
|
break;
|
|
33
41
|
}
|
|
34
|
-
return
|
|
35
|
-
case 2:
|
|
36
|
-
return _context.abrupt("return", []);
|
|
42
|
+
return _context2.abrupt("return", res.data);
|
|
37
43
|
case 3:
|
|
44
|
+
return _context2.abrupt("return", []);
|
|
45
|
+
case 4:
|
|
38
46
|
case "end":
|
|
39
|
-
return
|
|
47
|
+
return _context2.stop();
|
|
40
48
|
}
|
|
41
|
-
},
|
|
49
|
+
}, _callee2);
|
|
42
50
|
}));
|
|
43
51
|
return _getFormPrintTemplates.apply(this, arguments);
|
|
44
52
|
}
|
|
@@ -46,48 +54,52 @@ export function print(_x2) {
|
|
|
46
54
|
return _print.apply(this, arguments);
|
|
47
55
|
}
|
|
48
56
|
function _print() {
|
|
49
|
-
_print = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function
|
|
57
|
+
_print = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee3(options) {
|
|
50
58
|
var templateId, iw, _t;
|
|
51
|
-
return _regeneratorRuntime.wrap(function (
|
|
52
|
-
while (1) switch (
|
|
59
|
+
return _regeneratorRuntime.wrap(function (_context3) {
|
|
60
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
53
61
|
case 0:
|
|
54
|
-
|
|
55
|
-
|
|
62
|
+
_context3.prev = 0;
|
|
63
|
+
if (!(options.showLoading != false)) {
|
|
64
|
+
_context3.next = 1;
|
|
65
|
+
break;
|
|
66
|
+
}
|
|
67
|
+
_context3.next = 1;
|
|
56
68
|
return showLoading();
|
|
57
69
|
case 1:
|
|
58
70
|
templateId = options === null || options === void 0 ? void 0 : options.templateId;
|
|
59
71
|
if (templateId) {
|
|
60
|
-
|
|
72
|
+
_context3.next = 2;
|
|
61
73
|
break;
|
|
62
74
|
}
|
|
63
75
|
_message.error("\u6253\u5370\u5931\u8D25!\u6A21\u677Fid\u4E0D\u53EF\u4E3A\u7A7A!");
|
|
64
|
-
return
|
|
76
|
+
return _context3.abrupt("return");
|
|
65
77
|
case 2:
|
|
66
|
-
|
|
78
|
+
_context3.next = 3;
|
|
67
79
|
return openPrint(templateId, options);
|
|
68
80
|
case 3:
|
|
69
|
-
iw =
|
|
81
|
+
iw = _context3.sent;
|
|
70
82
|
if (iw) {
|
|
71
|
-
|
|
83
|
+
_context3.next = 4;
|
|
72
84
|
break;
|
|
73
85
|
}
|
|
74
86
|
_message.error("\u6253\u5370\u5931\u8D25!\u6253\u5370\u7A97\u53E3\u4E0D\u53EF\u4E3A\u7A7A!");
|
|
75
|
-
return
|
|
87
|
+
return _context3.abrupt("return");
|
|
76
88
|
case 4:
|
|
77
|
-
|
|
89
|
+
_context3.next = 6;
|
|
78
90
|
break;
|
|
79
91
|
case 5:
|
|
80
|
-
|
|
81
|
-
_t =
|
|
92
|
+
_context3.prev = 5;
|
|
93
|
+
_t = _context3["catch"](0);
|
|
82
94
|
console.log("打印失败", _t);
|
|
83
95
|
case 6:
|
|
84
|
-
|
|
85
|
-
return
|
|
96
|
+
_context3.prev = 6;
|
|
97
|
+
return _context3.finish(6);
|
|
86
98
|
case 7:
|
|
87
99
|
case "end":
|
|
88
|
-
return
|
|
100
|
+
return _context3.stop();
|
|
89
101
|
}
|
|
90
|
-
},
|
|
102
|
+
}, _callee3, null, [[0, 5, 6, 7]]);
|
|
91
103
|
}));
|
|
92
104
|
return _print.apply(this, arguments);
|
|
93
105
|
}
|
|
@@ -95,29 +107,33 @@ function openPrint(_x3, _x4) {
|
|
|
95
107
|
return _openPrint.apply(this, arguments);
|
|
96
108
|
}
|
|
97
109
|
function _openPrint() {
|
|
98
|
-
_openPrint = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function
|
|
110
|
+
_openPrint = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee6(templateId, options) {
|
|
99
111
|
var url;
|
|
100
|
-
return _regeneratorRuntime.wrap(function (
|
|
101
|
-
while (1) switch (
|
|
112
|
+
return _regeneratorRuntime.wrap(function (_context6) {
|
|
113
|
+
while (1) switch (_context6.prev = _context6.next) {
|
|
102
114
|
case 0:
|
|
103
115
|
url = "/print/" + templateId;
|
|
104
|
-
return
|
|
105
|
-
var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function
|
|
116
|
+
return _context6.abrupt("return", new Promise(/*#__PURE__*/function () {
|
|
117
|
+
var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee5(resolve, reject) {
|
|
106
118
|
var printWindow, iframe;
|
|
107
|
-
return _regeneratorRuntime.wrap(function (
|
|
108
|
-
while (1) switch (
|
|
119
|
+
return _regeneratorRuntime.wrap(function (_context5) {
|
|
120
|
+
while (1) switch (_context5.prev = _context5.next) {
|
|
109
121
|
case 0:
|
|
110
122
|
iframe = document.createElement("iframe");
|
|
111
123
|
iframe.src = url;
|
|
112
124
|
iframe.className = "print-iframe";
|
|
125
|
+
iframe.onload = function () {
|
|
126
|
+
// @ts-ignore
|
|
127
|
+
iframe.contentWindow.printOptions = options;
|
|
128
|
+
};
|
|
113
129
|
document.body.appendChild(iframe);
|
|
114
130
|
printWindow = iframe.contentWindow;
|
|
115
131
|
if (printWindow) {
|
|
116
|
-
|
|
132
|
+
_context5.next = 1;
|
|
117
133
|
break;
|
|
118
134
|
}
|
|
119
135
|
reject("创建Iframe失败!");
|
|
120
|
-
return
|
|
136
|
+
return _context5.abrupt("return");
|
|
121
137
|
case 1:
|
|
122
138
|
// @ts-ignore
|
|
123
139
|
window.printWindow = printWindow;
|
|
@@ -126,31 +142,145 @@ function _openPrint() {
|
|
|
126
142
|
printWindow.printOptions = options;
|
|
127
143
|
};
|
|
128
144
|
printWindow.addEventListener("beforeprint", function () {});
|
|
129
|
-
printWindow.addEventListener("afterprint", function () {
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
145
|
+
printWindow.addEventListener("afterprint", /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee4() {
|
|
146
|
+
var _printWindow, printer, _printWindow2, doc, html;
|
|
147
|
+
return _regeneratorRuntime.wrap(function (_context4) {
|
|
148
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
149
|
+
case 0:
|
|
150
|
+
if (window.__debug) {
|
|
151
|
+
console.debug((_printWindow = printWindow) === null || _printWindow === void 0 ? void 0 : _printWindow.document.documentElement.outerHTML);
|
|
152
|
+
}
|
|
153
|
+
_context4.next = 1;
|
|
154
|
+
return hideLoading();
|
|
155
|
+
case 1:
|
|
156
|
+
if (!(options.mode == "cloud_print")) {
|
|
157
|
+
_context4.next = 5;
|
|
158
|
+
break;
|
|
159
|
+
}
|
|
160
|
+
_context4.next = 2;
|
|
161
|
+
return getCloudPrinter();
|
|
162
|
+
case 2:
|
|
163
|
+
printer = _context4.sent;
|
|
164
|
+
if (!printer) {
|
|
165
|
+
_context4.next = 4;
|
|
166
|
+
break;
|
|
167
|
+
}
|
|
168
|
+
doc = (_printWindow2 = printWindow) === null || _printWindow2 === void 0 ? void 0 : _printWindow2.document;
|
|
169
|
+
if (!doc) {
|
|
170
|
+
_context4.next = 3;
|
|
171
|
+
break;
|
|
172
|
+
}
|
|
173
|
+
doc.querySelectorAll("script").forEach(function (item) {
|
|
174
|
+
return item.remove();
|
|
175
|
+
});
|
|
176
|
+
html = doc.documentElement.outerHTML;
|
|
177
|
+
_context4.next = 3;
|
|
178
|
+
return printer.post("<!doctype html>" + html);
|
|
179
|
+
case 3:
|
|
180
|
+
_context4.next = 5;
|
|
181
|
+
break;
|
|
182
|
+
case 4:
|
|
183
|
+
_message.error("\u6253\u5370\u5931\u8D25\uFF01\u8BF7\u5148\u7ED1\u5B9A\u4E91\u6253\u5370\u673A");
|
|
184
|
+
case 5:
|
|
185
|
+
resolve(printWindow);
|
|
186
|
+
setTimeout(function () {
|
|
187
|
+
return iframe.remove();
|
|
188
|
+
}, 100);
|
|
189
|
+
case 6:
|
|
190
|
+
case "end":
|
|
191
|
+
return _context4.stop();
|
|
135
192
|
}
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
});
|
|
193
|
+
}, _callee4);
|
|
194
|
+
})));
|
|
139
195
|
case 2:
|
|
140
196
|
case "end":
|
|
141
|
-
return
|
|
197
|
+
return _context5.stop();
|
|
142
198
|
}
|
|
143
|
-
},
|
|
199
|
+
}, _callee5);
|
|
144
200
|
}));
|
|
145
|
-
return function (
|
|
201
|
+
return function (_x6, _x7) {
|
|
146
202
|
return _ref.apply(this, arguments);
|
|
147
203
|
};
|
|
148
204
|
}()));
|
|
149
205
|
case 1:
|
|
150
206
|
case "end":
|
|
151
|
-
return
|
|
207
|
+
return _context6.stop();
|
|
152
208
|
}
|
|
153
|
-
},
|
|
209
|
+
}, _callee6);
|
|
154
210
|
}));
|
|
155
211
|
return _openPrint.apply(this, arguments);
|
|
156
|
-
}
|
|
212
|
+
}
|
|
213
|
+
function getCloudPrinter() {
|
|
214
|
+
return _getCloudPrinter.apply(this, arguments);
|
|
215
|
+
}
|
|
216
|
+
function _getCloudPrinter() {
|
|
217
|
+
_getCloudPrinter = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee7() {
|
|
218
|
+
var itemValue;
|
|
219
|
+
return _regeneratorRuntime.wrap(function (_context7) {
|
|
220
|
+
while (1) switch (_context7.prev = _context7.next) {
|
|
221
|
+
case 0:
|
|
222
|
+
itemValue = localStorage.getItem("default:cloud-printer");
|
|
223
|
+
if (!(itemValue == null)) {
|
|
224
|
+
_context7.next = 1;
|
|
225
|
+
break;
|
|
226
|
+
}
|
|
227
|
+
return _context7.abrupt("return", null);
|
|
228
|
+
case 1:
|
|
229
|
+
return _context7.abrupt("return", new CloudPrinter(JSON.parse(itemValue)));
|
|
230
|
+
case 2:
|
|
231
|
+
case "end":
|
|
232
|
+
return _context7.stop();
|
|
233
|
+
}
|
|
234
|
+
}, _callee7);
|
|
235
|
+
}));
|
|
236
|
+
return _getCloudPrinter.apply(this, arguments);
|
|
237
|
+
}
|
|
238
|
+
var CloudPrinter = /*#__PURE__*/function () {
|
|
239
|
+
function CloudPrinter(options) {
|
|
240
|
+
this.deviceName = void 0;
|
|
241
|
+
this.serverIp = void 0;
|
|
242
|
+
this.port = void 0;
|
|
243
|
+
Object.assign(this, options);
|
|
244
|
+
}
|
|
245
|
+
var _proto = CloudPrinter.prototype;
|
|
246
|
+
_proto.post = /*#__PURE__*/function () {
|
|
247
|
+
var _post = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(html) {
|
|
248
|
+
var baseUrl, baseRes, res;
|
|
249
|
+
return _regeneratorRuntime.wrap(function (_context) {
|
|
250
|
+
while (1) switch (_context.prev = _context.next) {
|
|
251
|
+
case 0:
|
|
252
|
+
baseUrl = "http://" + this.serverIp + ":" + this.port;
|
|
253
|
+
_context.next = 1;
|
|
254
|
+
return apiRequest.get(baseUrl);
|
|
255
|
+
case 1:
|
|
256
|
+
baseRes = _context.sent;
|
|
257
|
+
if (baseRes !== null && baseRes !== void 0 && baseRes.success) {
|
|
258
|
+
_context.next = 2;
|
|
259
|
+
break;
|
|
260
|
+
}
|
|
261
|
+
_message.error("云打印服务不可用");
|
|
262
|
+
return _context.abrupt("return");
|
|
263
|
+
case 2:
|
|
264
|
+
_context.next = 3;
|
|
265
|
+
return apiRequest.post(baseUrl + "/print", {
|
|
266
|
+
deviceName: this.deviceName,
|
|
267
|
+
data: html
|
|
268
|
+
});
|
|
269
|
+
case 3:
|
|
270
|
+
res = _context.sent;
|
|
271
|
+
if (!res.success) {
|
|
272
|
+
_message.error(res.message);
|
|
273
|
+
}
|
|
274
|
+
case 4:
|
|
275
|
+
case "end":
|
|
276
|
+
return _context.stop();
|
|
277
|
+
}
|
|
278
|
+
}, _callee, this);
|
|
279
|
+
}));
|
|
280
|
+
function post(_x5) {
|
|
281
|
+
return _post.apply(this, arguments);
|
|
282
|
+
}
|
|
283
|
+
return post;
|
|
284
|
+
}();
|
|
285
|
+
return CloudPrinter;
|
|
286
|
+
}();
|
package/es/utils/uni-bridge.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
interface ScanCodeOptions {
|
|
2
2
|
onlyFromCamera?: boolean;
|
|
3
3
|
openUrl?: boolean;
|
|
4
|
+
scanType?: string[];
|
|
4
5
|
}
|
|
5
6
|
interface ScanCodeResult {
|
|
6
7
|
result: string;
|
|
@@ -10,6 +11,7 @@ declare class UniBridge {
|
|
|
10
11
|
navigateTo(src: string): void;
|
|
11
12
|
scanCode(options: ScanCodeOptions): Promise<ScanCodeResult>;
|
|
12
13
|
getBarHeight(): Promise<unknown>;
|
|
14
|
+
scanCodeResult(): Promise<string>;
|
|
13
15
|
getLocation(options: {}): Promise<unknown>;
|
|
14
16
|
private doAction;
|
|
15
17
|
private receiveMessage;
|
package/es/utils/uni-bridge.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import _message from "antd/es/message";
|
|
2
2
|
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
3
3
|
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
4
|
-
|
|
4
|
+
import { v7 } from "uuid";
|
|
5
5
|
var UniBridge = /*#__PURE__*/function () {
|
|
6
6
|
function UniBridge() {
|
|
7
7
|
this.callbacks = {};
|
|
@@ -12,9 +12,13 @@ var UniBridge = /*#__PURE__*/function () {
|
|
|
12
12
|
if (!src.startsWith("http")) {
|
|
13
13
|
url = new URL(url, window.location.href).href;
|
|
14
14
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
if (window.plus) {
|
|
16
|
+
uni.navigateTo({
|
|
17
|
+
url: "/pages/web-page/index?url=" + encodeURIComponent(url)
|
|
18
|
+
});
|
|
19
|
+
} else {
|
|
20
|
+
window.open(url);
|
|
21
|
+
}
|
|
18
22
|
};
|
|
19
23
|
_proto.scanCode = /*#__PURE__*/function () {
|
|
20
24
|
var _scanCode = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(options) {
|
|
@@ -22,21 +26,21 @@ var UniBridge = /*#__PURE__*/function () {
|
|
|
22
26
|
return _regeneratorRuntime.wrap(function (_context) {
|
|
23
27
|
while (1) switch (_context.prev = _context.next) {
|
|
24
28
|
case 0:
|
|
25
|
-
|
|
26
|
-
_context.
|
|
29
|
+
options.scanType = ['qrCode', 'barCode'];
|
|
30
|
+
_context.prev = 1;
|
|
31
|
+
_context.next = 2;
|
|
27
32
|
return this.doAction("scanCode", options);
|
|
28
|
-
case 1:
|
|
29
|
-
return _context.abrupt("return", _context.sent);
|
|
30
33
|
case 2:
|
|
31
|
-
_context.
|
|
32
|
-
_t = _context["catch"](0);
|
|
33
|
-
_message.error("");
|
|
34
|
-
throw _t;
|
|
34
|
+
return _context.abrupt("return", _context.sent);
|
|
35
35
|
case 3:
|
|
36
|
+
_context.prev = 3;
|
|
37
|
+
_t = _context["catch"](1);
|
|
38
|
+
throw _t;
|
|
39
|
+
case 4:
|
|
36
40
|
case "end":
|
|
37
41
|
return _context.stop();
|
|
38
42
|
}
|
|
39
|
-
}, _callee, this, [[
|
|
43
|
+
}, _callee, this, [[1, 3]]);
|
|
40
44
|
}));
|
|
41
45
|
function scanCode(_x) {
|
|
42
46
|
return _scanCode.apply(this, arguments);
|
|
@@ -60,53 +64,90 @@ var UniBridge = /*#__PURE__*/function () {
|
|
|
60
64
|
}
|
|
61
65
|
return getBarHeight;
|
|
62
66
|
}();
|
|
63
|
-
_proto.
|
|
64
|
-
var
|
|
67
|
+
_proto.scanCodeResult = /*#__PURE__*/function () {
|
|
68
|
+
var _scanCodeResult = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee3() {
|
|
69
|
+
var res;
|
|
65
70
|
return _regeneratorRuntime.wrap(function (_context3) {
|
|
66
71
|
while (1) switch (_context3.prev = _context3.next) {
|
|
67
72
|
case 0:
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
73
|
+
_context3.next = 1;
|
|
74
|
+
return this.scanCode({
|
|
75
|
+
onlyFromCamera: false,
|
|
76
|
+
openUrl: false
|
|
77
|
+
});
|
|
71
78
|
case 1:
|
|
79
|
+
res = _context3.sent;
|
|
80
|
+
return _context3.abrupt("return", res.result);
|
|
81
|
+
case 2:
|
|
72
82
|
case "end":
|
|
73
83
|
return _context3.stop();
|
|
74
84
|
}
|
|
75
85
|
}, _callee3, this);
|
|
76
86
|
}));
|
|
87
|
+
function scanCodeResult() {
|
|
88
|
+
return _scanCodeResult.apply(this, arguments);
|
|
89
|
+
}
|
|
90
|
+
return scanCodeResult;
|
|
91
|
+
}();
|
|
92
|
+
_proto.getLocation = /*#__PURE__*/function () {
|
|
93
|
+
var _getLocation = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee4(options) {
|
|
94
|
+
return _regeneratorRuntime.wrap(function (_context4) {
|
|
95
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
96
|
+
case 0:
|
|
97
|
+
return _context4.abrupt("return", this.doAction("getLocation", {
|
|
98
|
+
type: 'wgs84'
|
|
99
|
+
}));
|
|
100
|
+
case 1:
|
|
101
|
+
case "end":
|
|
102
|
+
return _context4.stop();
|
|
103
|
+
}
|
|
104
|
+
}, _callee4, this);
|
|
105
|
+
}));
|
|
77
106
|
function getLocation(_x2) {
|
|
78
107
|
return _getLocation.apply(this, arguments);
|
|
79
108
|
}
|
|
80
109
|
return getLocation;
|
|
81
110
|
}();
|
|
82
111
|
_proto.doAction = /*#__PURE__*/function () {
|
|
83
|
-
var _doAction = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function
|
|
112
|
+
var _doAction = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee5(action, options) {
|
|
84
113
|
var _this = this;
|
|
85
114
|
var messageId;
|
|
86
|
-
return _regeneratorRuntime.wrap(function (
|
|
87
|
-
while (1) switch (
|
|
115
|
+
return _regeneratorRuntime.wrap(function (_context5) {
|
|
116
|
+
while (1) switch (_context5.prev = _context5.next) {
|
|
88
117
|
case 0:
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
118
|
+
if (window.uni) {
|
|
119
|
+
_context5.next = 1;
|
|
120
|
+
break;
|
|
121
|
+
}
|
|
122
|
+
_message.error("\u6267\u884C\u5931\u8D25\uFF01\u7F3A\u5C11uni\u63D2\u4EF6");
|
|
123
|
+
return _context5.abrupt("return");
|
|
124
|
+
case 1:
|
|
125
|
+
messageId = v7();
|
|
126
|
+
return _context5.abrupt("return", new Promise(function (resolve, reject) {
|
|
127
|
+
console.log("UniBridge.doAction", messageId, action, options);
|
|
92
128
|
_this.callbacks[messageId] = {
|
|
93
129
|
resolve: resolve,
|
|
94
130
|
reject: reject
|
|
95
131
|
};
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
132
|
+
try {
|
|
133
|
+
console.log("postMessage", messageId, action, options);
|
|
134
|
+
uni.postMessage({
|
|
135
|
+
data: {
|
|
136
|
+
action: action,
|
|
137
|
+
messageId: messageId,
|
|
138
|
+
options: options
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
} catch (e) {
|
|
142
|
+
console.log("UniBridge.doAction 异常", e);
|
|
143
|
+
delete _this.callbacks[messageId];
|
|
144
|
+
}
|
|
104
145
|
}));
|
|
105
|
-
case
|
|
146
|
+
case 2:
|
|
106
147
|
case "end":
|
|
107
|
-
return
|
|
148
|
+
return _context5.stop();
|
|
108
149
|
}
|
|
109
|
-
},
|
|
150
|
+
}, _callee5);
|
|
110
151
|
}));
|
|
111
152
|
function doAction(_x3, _x4) {
|
|
112
153
|
return _doAction.apply(this, arguments);
|
|
@@ -114,8 +155,9 @@ var UniBridge = /*#__PURE__*/function () {
|
|
|
114
155
|
return doAction;
|
|
115
156
|
}();
|
|
116
157
|
_proto.receiveMessage = function receiveMessage(message) {
|
|
117
|
-
console.log('收到 UniApp 消息:', message);
|
|
118
158
|
var callback = this.callbacks[message.messageId];
|
|
159
|
+
console.log('客户端收到 UniApp 消息:', JSON.stringify(message));
|
|
160
|
+
console.log('客户端收到 UniApp 消息:callbacks', this.callbacks);
|
|
119
161
|
if (callback) {
|
|
120
162
|
if (message.success) {
|
|
121
163
|
callback.resolve(message.data);
|
|
File without changes
|
package/lib/index.js
CHANGED
|
@@ -3,8 +3,7 @@
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
4
|
exports.__esModule = true;
|
|
5
5
|
exports.lodash = exports.apiRequest = exports.RestFormApi = exports.RestApi = exports.PageLoading = exports.LoadMaterials = exports.Layout = void 0;
|
|
6
|
-
var
|
|
7
|
-
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
6
|
+
var _message2 = _interopRequireDefault(require("antd/lib/message"));
|
|
8
7
|
require("./index.less");
|
|
9
8
|
var _reactRender = require("./components/react-render");
|
|
10
9
|
exports.ReactRender = _reactRender.ReactRender;
|
|
@@ -23,6 +22,9 @@ exports.Layout = _layout.Layout;
|
|
|
23
22
|
var _index2 = _interopRequireDefault(require("./utils/index"));
|
|
24
23
|
exports.utils = _index2["default"];
|
|
25
24
|
var _uniBridge = require("./utils/uni-bridge");
|
|
25
|
+
var _init = require("./init/init.bar-height");
|
|
26
|
+
var _init2 = require("./init/init.scroll-size");
|
|
27
|
+
var _init3 = require("./init/init.mobile-class");
|
|
26
28
|
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, "default": e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
|
|
27
29
|
// @ts-ignore
|
|
28
30
|
window.__ReactRender = _reactRender.ReactRender;
|
|
@@ -36,40 +38,16 @@ if (!window.utils) {
|
|
|
36
38
|
// @ts-ignore
|
|
37
39
|
window.utils = _index2["default"];
|
|
38
40
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
var classList = window.document.body.classList;
|
|
42
|
-
if (!classList.contains("mobile")) {
|
|
43
|
-
classList.add("mobile");
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
var bar_height_key = "bar_height";
|
|
41
|
+
(0, _init3.initMobileClass)();
|
|
42
|
+
|
|
47
43
|
// @ts-ignore
|
|
48
44
|
_index2["default"].uniBridge = _uniBridge.uniBridge;
|
|
49
45
|
// @ts-ignore
|
|
50
46
|
window.uniBridge = _uniBridge.uniBridge;
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
while (1) switch (_context.prev = _context.next) {
|
|
56
|
-
case 0:
|
|
57
|
-
_context.next = 1;
|
|
58
|
-
return _uniBridge.uniBridge.getBarHeight();
|
|
59
|
-
case 1:
|
|
60
|
-
height = _context.sent;
|
|
61
|
-
localStorage.setItem(bar_height_key, height);
|
|
62
|
-
updateBarHeight();
|
|
63
|
-
case 2:
|
|
64
|
-
case "end":
|
|
65
|
-
return _context.stop();
|
|
66
|
-
}
|
|
67
|
-
}, _callee);
|
|
68
|
-
})), 100);
|
|
47
|
+
_message2["default"].config({
|
|
48
|
+
top: 150,
|
|
49
|
+
duration: 5,
|
|
50
|
+
maxCount: 3
|
|
69
51
|
});
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
document.documentElement.style.setProperty('--bar-height', localStorage.getItem(bar_height_key));
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
updateBarHeight();
|
|
52
|
+
(0, _init.initBarHeight)();
|
|
53
|
+
(0, _init2.initScrollSize)();
|