@zhubangyun/lowcode-core 5.12.161 → 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.
Files changed (89) hide show
  1. package/es/components/load-materials/index.js +38 -22
  2. package/es/components/page-loading/index.js +4 -1
  3. package/es/index.d.ts +1 -1
  4. package/es/index.js +19 -2
  5. package/es/index.less +21 -0
  6. package/es/init/init.bar-height.d.ts +1 -0
  7. package/es/init/init.bar-height.js +37 -0
  8. package/es/init/init.mobile-class.d.ts +1 -0
  9. package/es/init/init.mobile-class.js +10 -0
  10. package/es/init/init.scroll-size.d.ts +5 -0
  11. package/es/init/init.scroll-size.js +26 -0
  12. package/es/style.js +3 -3
  13. package/es/utils/api/form-api.d.ts +2 -0
  14. package/es/utils/api/form-api.js +155 -34
  15. package/es/utils/api/index.d.ts +1 -1
  16. package/es/utils/api/index.js +4 -2
  17. package/es/utils/api/rest-api.d.ts +3 -1
  18. package/es/utils/api/rest-api.js +105 -23
  19. package/es/utils/api/schema.util.d.ts +3 -3
  20. package/es/utils/api/schema.util.js +17 -12
  21. package/es/utils/cache/index.js +57 -17
  22. package/es/utils/common/index.d.ts +3 -0
  23. package/es/utils/common/index.js +17 -3
  24. package/es/utils/page/index.js +10 -6
  25. package/es/utils/page/page-form-data-manager-group.js +10 -10
  26. package/es/utils/page/page-form-data-manager.d.ts +1 -0
  27. package/es/utils/page/page-form-data-manager.js +10 -10
  28. package/es/utils/page/page-form-group.d.ts +1 -0
  29. package/es/utils/page/page-form-group.js +2 -2
  30. package/es/utils/page/page-form.d.ts +1 -0
  31. package/es/utils/page/page-form.js +12 -4
  32. package/es/utils/page/page-layout.d.ts +3 -1
  33. package/es/utils/page/page-layout.js +44 -7
  34. package/es/utils/page/page-load-schema.js +20 -28
  35. package/es/utils/page/page-render.js +4 -5
  36. package/es/utils/page/page-show.d.ts +2 -0
  37. package/es/utils/page/page-show.js +9 -4
  38. package/es/utils/page/print-form.d.ts +3 -2
  39. package/es/utils/page/print-form.js +200 -61
  40. package/es/utils/uni-bridge.d.ts +20 -0
  41. package/es/utils/uni-bridge.js +172 -0
  42. package/es/utils/util.common.d.ts +1 -0
  43. package/es/utils/util.common.js +4 -0
  44. package/es/utils/utils.scrollbar-size.js +0 -0
  45. package/lib/components/load-materials/index.js +38 -22
  46. package/lib/components/page-loading/index.js +4 -1
  47. package/lib/index.d.ts +1 -1
  48. package/lib/index.js +22 -4
  49. package/lib/index.less +21 -0
  50. package/lib/init/init.bar-height.d.ts +1 -0
  51. package/lib/init/init.bar-height.js +42 -0
  52. package/lib/init/init.mobile-class.d.ts +1 -0
  53. package/lib/init/init.mobile-class.js +14 -0
  54. package/lib/init/init.scroll-size.d.ts +5 -0
  55. package/lib/init/init.scroll-size.js +31 -0
  56. package/lib/style.js +3 -3
  57. package/lib/utils/api/form-api.d.ts +2 -0
  58. package/lib/utils/api/form-api.js +155 -34
  59. package/lib/utils/api/index.d.ts +1 -1
  60. package/lib/utils/api/index.js +4 -2
  61. package/lib/utils/api/rest-api.d.ts +3 -1
  62. package/lib/utils/api/rest-api.js +105 -23
  63. package/lib/utils/api/schema.util.d.ts +3 -3
  64. package/lib/utils/api/schema.util.js +19 -13
  65. package/lib/utils/cache/index.js +56 -16
  66. package/lib/utils/common/index.d.ts +3 -0
  67. package/lib/utils/common/index.js +19 -2
  68. package/lib/utils/page/index.js +10 -6
  69. package/lib/utils/page/page-form-data-manager-group.js +10 -10
  70. package/lib/utils/page/page-form-data-manager.d.ts +1 -0
  71. package/lib/utils/page/page-form-data-manager.js +10 -10
  72. package/lib/utils/page/page-form-group.d.ts +1 -0
  73. package/lib/utils/page/page-form-group.js +2 -2
  74. package/lib/utils/page/page-form.d.ts +1 -0
  75. package/lib/utils/page/page-form.js +12 -4
  76. package/lib/utils/page/page-layout.d.ts +3 -1
  77. package/lib/utils/page/page-layout.js +44 -7
  78. package/lib/utils/page/page-load-schema.js +19 -27
  79. package/lib/utils/page/page-render.js +4 -5
  80. package/lib/utils/page/page-show.d.ts +2 -0
  81. package/lib/utils/page/page-show.js +9 -4
  82. package/lib/utils/page/print-form.d.ts +3 -2
  83. package/lib/utils/page/print-form.js +200 -61
  84. package/lib/utils/uni-bridge.d.ts +20 -0
  85. package/lib/utils/uni-bridge.js +177 -0
  86. package/lib/utils/util.common.d.ts +1 -0
  87. package/lib/utils/util.common.js +8 -0
  88. package/lib/utils/utils.scrollbar-size.js +1 -0
  89. package/package.json +2 -2
@@ -2,8 +2,9 @@ import _Drawer from "antd/es/drawer";
2
2
  import _Modal from "antd/es/modal";
3
3
  import _extends from "@babel/runtime/helpers/extends";
4
4
  import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/objectWithoutPropertiesLoose";
5
+ import _createClass from "@babel/runtime/helpers/createClass";
5
6
  import _inheritsLoose from "@babel/runtime/helpers/inheritsLoose";
6
- var _excluded = ["layout", "children"];
7
+ var _excluded = ["children"];
7
8
  import React, { Component } from "react";
8
9
  import { LoadMaterials } from "../../components/load-materials";
9
10
  export var PageLayout = /*#__PURE__*/function (_Component) {
@@ -22,7 +23,7 @@ export var PageLayout = /*#__PURE__*/function (_Component) {
22
23
  return Math.min(window.innerWidth, 1600);
23
24
  };
24
25
  _this.handleResize = function () {
25
- if (_this.props.layout == "drawer") {
26
+ if (_this.layout == "drawer") {
26
27
  _this.setState({
27
28
  width: _this.getWith()
28
29
  });
@@ -40,10 +41,11 @@ export var PageLayout = /*#__PURE__*/function (_Component) {
40
41
  window.removeEventListener("resize", this.handleResize);
41
42
  };
42
43
  _proto.render = function render() {
44
+ var _this2 = this;
43
45
  var _this$props = this.props,
44
- layout = _this$props.layout,
45
46
  children = _this$props.children,
46
47
  extraProps = _objectWithoutPropertiesLoose(_this$props, _excluded);
48
+ var layout = this.layout;
47
49
  var state = this.state;
48
50
  var restProps = _extends({}, extraProps, {
49
51
  children: undefined,
@@ -64,19 +66,54 @@ export var PageLayout = /*#__PURE__*/function (_Component) {
64
66
  padding: 0
65
67
  }
66
68
  },
67
- maskClosable: false
69
+ maskClosable: isMobile
68
70
  });
69
71
  var loadChildren = /*#__PURE__*/React.createElement(LoadMaterialChildren, null, children);
70
72
  if (layout == "modal") {
71
73
  restProps.style.top = 64;
72
74
  restProps.styles.body.height = "calc(100vh - 120px)";
73
- return /*#__PURE__*/React.createElement(_Modal, restProps, loadChildren);
75
+ return /*#__PURE__*/React.createElement(_Modal, _extends({}, restProps, {
76
+ getContainer: function getContainer() {
77
+ return _this2.props.container || window.document.body;
78
+ },
79
+ afterOpenChange: function afterOpenChange(open) {
80
+ if (!open) {
81
+ var _this2$props$onClose, _this2$props;
82
+ (_this2$props$onClose = (_this2$props = _this2.props).onClose) === null || _this2$props$onClose === void 0 ? void 0 : _this2$props$onClose.call(_this2$props);
83
+ }
84
+ }
85
+ }), loadChildren);
74
86
  } else if (layout == "drawer") {
75
- return /*#__PURE__*/React.createElement(_Drawer, restProps, loadChildren);
87
+ if (window.isMobile) {
88
+ restProps.placement = "bottom";
89
+ }
90
+ return /*#__PURE__*/React.createElement(_Drawer, _extends({}, restProps, {
91
+ getContainer: function getContainer() {
92
+ return _this2.props.container || window.document.body;
93
+ },
94
+ height: "75vh",
95
+ afterVisibleChange: function afterVisibleChange(open) {
96
+ if (!open) {
97
+ var _this2$props$onClose2, _this2$props2;
98
+ (_this2$props$onClose2 = (_this2$props2 = _this2.props).onClose) === null || _this2$props$onClose2 === void 0 ? void 0 : _this2$props$onClose2.call(_this2$props2);
99
+ }
100
+ }
101
+ }), loadChildren);
76
102
  }
77
103
  return loadChildren;
78
104
  };
79
- return PageLayout;
105
+ return _createClass(PageLayout, [{
106
+ key: "layout",
107
+ get: function get() {
108
+ var layout = this.props.layout;
109
+ if (window.isMobile) {
110
+ if (layout == "modal") {
111
+ return "drawer";
112
+ }
113
+ }
114
+ return layout;
115
+ }
116
+ }]);
80
117
  }(Component);
81
118
  function LoadMaterialChildren(props) {
82
119
  return /*#__PURE__*/React.createElement(LoadMaterials, null, props.children);
@@ -1,56 +1,48 @@
1
1
  import _Result from "antd/es/result";
2
2
  import _message from "antd/es/message";
3
- import { useEffect, useState } from "react";
3
+ import { Fragment, useEffect, useState } from "react";
4
4
  import { getSchema } from "../api";
5
- import { PageLoading } from "../../components/page-loading";
6
5
  import { getSchemaFromCache } from "../api/schema-api";
6
+ import { hideLoading, showLoading } from "./index";
7
7
  export function PageLoadSchema(props) {
8
8
  var pageId = props.pageId,
9
9
  children = props.children;
10
10
  var cache = getSchemaFromCache(pageId);
11
- var _useState = useState(!cache),
12
- loading = _useState[0],
13
- setLoading = _useState[1];
14
- var _useState2 = useState(cache === null || cache === void 0 ? void 0 : cache.data),
15
- schema = _useState2[0],
16
- setSchema = _useState2[1];
17
- var _useState3 = useState(),
18
- errorMsg = _useState3[0],
19
- setErrorMsg = _useState3[1];
11
+ var _useState = useState(cache === null || cache === void 0 ? void 0 : cache.data),
12
+ schema = _useState[0],
13
+ setSchema = _useState[1];
14
+ var _useState2 = useState(),
15
+ errorMsg = _useState2[0],
16
+ setErrorMsg = _useState2[1];
20
17
  useEffect(function () {
21
- if (cache) {
18
+ if (cache !== null && cache !== void 0 && cache.success) {
22
19
  return;
23
20
  }
24
21
  if (pageId) {
22
+ showLoading().then();
25
23
  getSchema(pageId).then(function (res) {
26
24
  if (res.success) {
27
- setLoading(false);
28
- setSchema(res.data);
25
+ setSchema(res === null || res === void 0 ? void 0 : res.data);
29
26
  } else {
30
- setErrorMsg(res.message);
27
+ setErrorMsg(res === null || res === void 0 ? void 0 : res.message);
31
28
  }
29
+ })["finally"](function () {
30
+ hideLoading().then();
32
31
  });
33
32
  } else {
34
- setLoading(false);
35
- setErrorMsg("页面id不可为空!");
36
- console.error("页面id不可为空!");
37
- _message.error("页面id不可为空!").then();
33
+ hideLoading().then();
34
+ setErrorMsg("参数错误:页面id不可为空!");
35
+ _message.error("参数错误:页面id不可为空!").then();
38
36
  }
39
37
  }, []);
40
- if (cache) {
38
+ if (schema) {
41
39
  return children(schema);
42
40
  }
43
- if (loading) {
44
- return /*#__PURE__*/React.createElement(PageLoading, {
45
- loading: true,
46
- background: "rgba(255, 255, 255, 0)"
47
- });
48
- }
49
- if (!schema) {
41
+ if (errorMsg) {
50
42
  return /*#__PURE__*/React.createElement(_Result, {
51
43
  status: 500,
52
44
  title: errorMsg
53
45
  });
54
46
  }
55
- return children(schema);
47
+ return /*#__PURE__*/React.createElement(Fragment, null);
56
48
  }
@@ -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, unmount, root, element;
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
- unmount = !container;
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 (unmount) {
30
+ if (needUnmount) {
31
31
  var _container;
32
- //移除
33
32
  (_container = container) === null || _container === void 0 ? void 0 : _container.remove();
34
33
  }
35
- }, 200);
34
+ }, 150);
36
35
  _onClose === null || _onClose === void 0 ? void 0 : _onClose();
37
36
  }
38
37
  }));
@@ -4,6 +4,8 @@ export interface ShowPageProps {
4
4
  pageId: string;
5
5
  layout?: PageLayoutType;
6
6
  onClose?: () => void | Promise<void>;
7
+ extraProps?: any;
8
+ afterLoadSchema?: (schema: any) => void;
7
9
  pageRef?: (page: any) => void;
8
10
  }
9
11
  export declare function show(options: ShowPageProps): Promise<any | any[]>;
@@ -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 = ["container", "onClose"];
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 container, onClose, props;
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
- container = options.container, onClose = options.onClose, props = _objectWithoutPropertiesLoose(options, _excluded2);
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,
@@ -44,6 +44,7 @@ var PageRender = /*#__PURE__*/function (_Component) {
44
44
  }
45
45
  _this = _Component.call.apply(_Component, [this].concat(args)) || this;
46
46
  _this.layoutRef = void 0;
47
+ _this.schema = void 0;
47
48
  return _this;
48
49
  }
49
50
  _inheritsLoose(PageRender, _Component);
@@ -72,6 +73,10 @@ var PageRender = /*#__PURE__*/function (_Component) {
72
73
  }, /*#__PURE__*/React.createElement(PageLoadSchema, {
73
74
  pageId: pageId
74
75
  }, function (schema) {
76
+ _this2.schema = schema;
77
+ if (_this2.props.pageRef) {
78
+ _this2.props.pageRef(_this2);
79
+ }
75
80
  return /*#__PURE__*/React.createElement(ReactRender, _extends({
76
81
  schema: schema,
77
82
  components: window._components || window.components || window.__components
@@ -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 _callee(formId) {
12
+ _getFormPrintTemplates = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2(formId) {
12
13
  var res;
13
- return _regeneratorRuntime.wrap(function (_context) {
14
- while (1) switch (_context.prev = _context.next) {
14
+ return _regeneratorRuntime.wrap(function (_context2) {
15
+ while (1) switch (_context2.prev = _context2.next) {
15
16
  case 0:
16
- _context.next = 1;
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 1:
29
- res = _context.sent;
35
+ case 2:
36
+ res = _context2.sent;
37
+ cache.set(formId, res.data || []);
30
38
  if (!res.success) {
31
- _context.next = 2;
39
+ _context2.next = 3;
32
40
  break;
33
41
  }
34
- return _context.abrupt("return", res.data);
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 _context.stop();
47
+ return _context2.stop();
40
48
  }
41
- }, _callee);
49
+ }, _callee2);
42
50
  }));
43
51
  return _getFormPrintTemplates.apply(this, arguments);
44
52
  }
@@ -46,102 +54,233 @@ export function print(_x2) {
46
54
  return _print.apply(this, arguments);
47
55
  }
48
56
  function _print() {
49
- _print = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2(options) {
57
+ _print = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee3(options) {
50
58
  var templateId, iw, _t;
51
- return _regeneratorRuntime.wrap(function (_context2) {
52
- while (1) switch (_context2.prev = _context2.next) {
59
+ return _regeneratorRuntime.wrap(function (_context3) {
60
+ while (1) switch (_context3.prev = _context3.next) {
53
61
  case 0:
54
- _context2.prev = 0;
55
- _context2.next = 1;
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
- _context2.next = 2;
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 _context2.abrupt("return");
76
+ return _context3.abrupt("return");
65
77
  case 2:
66
- _context2.next = 3;
67
- return openPrint(templateId);
78
+ _context3.next = 3;
79
+ return openPrint(templateId, options);
68
80
  case 3:
69
- iw = _context2.sent;
81
+ iw = _context3.sent;
70
82
  if (iw) {
71
- _context2.next = 4;
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 _context2.abrupt("return");
87
+ return _context3.abrupt("return");
76
88
  case 4:
77
- // @ts-ignore
78
- iw.printOptions = options;
79
- _context2.next = 6;
89
+ _context3.next = 6;
80
90
  break;
81
91
  case 5:
82
- _context2.prev = 5;
83
- _t = _context2["catch"](0);
92
+ _context3.prev = 5;
93
+ _t = _context3["catch"](0);
84
94
  console.log("打印失败", _t);
85
95
  case 6:
86
- _context2.prev = 6;
87
- return _context2.finish(6);
96
+ _context3.prev = 6;
97
+ return _context3.finish(6);
88
98
  case 7:
89
99
  case "end":
90
- return _context2.stop();
100
+ return _context3.stop();
91
101
  }
92
- }, _callee2, null, [[0, 5, 6, 7]]);
102
+ }, _callee3, null, [[0, 5, 6, 7]]);
93
103
  }));
94
104
  return _print.apply(this, arguments);
95
105
  }
96
- function openPrint(_x3) {
106
+ function openPrint(_x3, _x4) {
97
107
  return _openPrint.apply(this, arguments);
98
108
  }
99
109
  function _openPrint() {
100
- _openPrint = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee4(templateId) {
101
- return _regeneratorRuntime.wrap(function (_context4) {
102
- while (1) switch (_context4.prev = _context4.next) {
110
+ _openPrint = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee6(templateId, options) {
111
+ var url;
112
+ return _regeneratorRuntime.wrap(function (_context6) {
113
+ while (1) switch (_context6.prev = _context6.next) {
103
114
  case 0:
104
- return _context4.abrupt("return", new Promise(/*#__PURE__*/function () {
105
- var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee3(resolve, reject) {
106
- var iframe, iframeWindow;
107
- return _regeneratorRuntime.wrap(function (_context3) {
108
- while (1) switch (_context3.prev = _context3.next) {
115
+ url = "/print/" + templateId;
116
+ return _context6.abrupt("return", new Promise(/*#__PURE__*/function () {
117
+ var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee5(resolve, reject) {
118
+ var printWindow, iframe;
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
- iframe.src = "/print/" + templateId;
112
- iframe.style.display = "none";
123
+ iframe.src = url;
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
- iframeWindow = iframe.contentWindow;
115
- if (iframeWindow) {
116
- _context3.next = 1;
130
+ printWindow = iframe.contentWindow;
131
+ if (printWindow) {
132
+ _context5.next = 1;
117
133
  break;
118
134
  }
119
135
  reject("创建Iframe失败!");
120
- return _context3.abrupt("return");
136
+ return _context5.abrupt("return");
121
137
  case 1:
122
- iframeWindow.onload = function () {
123
- resolve(iframeWindow);
138
+ // @ts-ignore
139
+ window.printWindow = printWindow;
140
+ printWindow.onload = function () {
141
+ // @ts-ignore
142
+ printWindow.printOptions = options;
124
143
  };
125
- iframeWindow.addEventListener("beforeprint", function () {});
126
- iframeWindow.addEventListener("afterprint", function () {
127
- hideLoading();
128
- iframe.remove();
129
- });
144
+ printWindow.addEventListener("beforeprint", function () {});
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();
192
+ }
193
+ }, _callee4);
194
+ })));
130
195
  case 2:
131
196
  case "end":
132
- return _context3.stop();
197
+ return _context5.stop();
133
198
  }
134
- }, _callee3);
199
+ }, _callee5);
135
200
  }));
136
- return function (_x4, _x5) {
201
+ return function (_x6, _x7) {
137
202
  return _ref.apply(this, arguments);
138
203
  };
139
204
  }()));
140
205
  case 1:
141
206
  case "end":
142
- return _context4.stop();
207
+ return _context6.stop();
143
208
  }
144
- }, _callee4);
209
+ }, _callee6);
145
210
  }));
146
211
  return _openPrint.apply(this, arguments);
147
- }
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
+ }();
@@ -0,0 +1,20 @@
1
+ interface ScanCodeOptions {
2
+ onlyFromCamera?: boolean;
3
+ openUrl?: boolean;
4
+ scanType?: string[];
5
+ }
6
+ interface ScanCodeResult {
7
+ result: string;
8
+ }
9
+ declare class UniBridge {
10
+ private callbacks;
11
+ navigateTo(src: string): void;
12
+ scanCode(options: ScanCodeOptions): Promise<ScanCodeResult>;
13
+ getBarHeight(): Promise<unknown>;
14
+ scanCodeResult(): Promise<string>;
15
+ getLocation(options: {}): Promise<unknown>;
16
+ private doAction;
17
+ private receiveMessage;
18
+ }
19
+ export declare const uniBridge: UniBridge;
20
+ export {};