@pisell/materials 6.0.16 → 6.0.17

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 (40) hide show
  1. package/build/lowcode/assets-daily.json +11 -11
  2. package/build/lowcode/assets-dev.json +2 -2
  3. package/build/lowcode/assets-prod.json +11 -11
  4. package/build/lowcode/index.js +1 -1
  5. package/build/lowcode/meta.js +2 -2
  6. package/build/lowcode/preview.js +13 -21
  7. package/build/lowcode/render/default/view.css +1 -1
  8. package/build/lowcode/render/default/view.js +21 -35
  9. package/build/lowcode/view.css +1 -1
  10. package/build/lowcode/view.js +21 -35
  11. package/dist/umd/materials.min.css +1 -0
  12. package/dist/umd/materials.min.js +1 -0
  13. package/dist/umd/static/DotsSix.57d66266.svg +1 -0
  14. package/dist/umd/static/arrow-left.e542294f.svg +1 -0
  15. package/dist/umd/static/arrow-right.763f03e0.svg +1 -0
  16. package/dist/umd/static/filter-lines.04a54ae9.svg +1 -0
  17. package/dist/umd/static/help-circle.31c9be40.svg +1 -0
  18. package/dist/umd/static/switch-vertical-01.7ebe3ba8.svg +1 -0
  19. package/es/components/Pagination/index.d.ts +1 -1
  20. package/es/components/dataSourceComponents/dataSourceTable/hooks/useTableProps.d.ts +3 -3
  21. package/es/components/dataSourceComponents/fields/Input/WithMode.d.ts +1 -0
  22. package/es/components/dataSourceComponents/fields/Input/WithMode.js +605 -5
  23. package/es/components/dataSourceComponents/fields/Input/WithMode.less +96 -0
  24. package/es/components/dataSourceComponents/fields/Input/type.d.ts +1 -0
  25. package/es/components/dataSourceComponents/fields/index.d.ts +1 -1
  26. package/es/components/iconfont/index.d.ts +1 -0
  27. package/es/components/iconfont/index.js +1 -1
  28. package/lib/components/Pagination/index.d.ts +1 -1
  29. package/lib/components/dataSourceComponents/dataSourceTable/hooks/useTableProps.d.ts +3 -3
  30. package/lib/components/dataSourceComponents/fields/Input/WithMode.d.ts +1 -0
  31. package/lib/components/dataSourceComponents/fields/Input/WithMode.js +383 -1
  32. package/lib/components/dataSourceComponents/fields/Input/WithMode.less +96 -0
  33. package/lib/components/dataSourceComponents/fields/Input/type.d.ts +1 -0
  34. package/lib/components/dataSourceComponents/fields/index.d.ts +1 -1
  35. package/lib/components/iconfont/index.d.ts +1 -0
  36. package/lib/components/iconfont/index.js +1 -1
  37. package/lowcode/_utils/defaultSchema.ts +18 -0
  38. package/lowcode/form-item-input/meta.ts +1 -0
  39. package/lowcode/form-item-input/snippets.ts +1 -0
  40. package/package.json +3 -3
@@ -1,12 +1,612 @@
1
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
2
+ var _excluded = ["enableQRScanner", "value", "onChange"];
1
3
  function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
2
- import { Input as AntInput } from 'antd';
3
- import React from 'react';
4
+ function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return exports; }; var exports = {}, Op = Object.prototype, hasOwn = Op.hasOwnProperty, defineProperty = Object.defineProperty || function (obj, key, desc) { obj[key] = desc.value; }, $Symbol = "function" == typeof Symbol ? Symbol : {}, iteratorSymbol = $Symbol.iterator || "@@iterator", asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; function define(obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: !0, configurable: !0, writable: !0 }), obj[key]; } try { define({}, ""); } catch (err) { define = function define(obj, key, value) { return obj[key] = value; }; } function wrap(innerFn, outerFn, self, tryLocsList) { var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, generator = Object.create(protoGenerator.prototype), context = new Context(tryLocsList || []); return defineProperty(generator, "_invoke", { value: makeInvokeMethod(innerFn, self, context) }), generator; } function tryCatch(fn, obj, arg) { try { return { type: "normal", arg: fn.call(obj, arg) }; } catch (err) { return { type: "throw", arg: err }; } } exports.wrap = wrap; var ContinueSentinel = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var IteratorPrototype = {}; define(IteratorPrototype, iteratorSymbol, function () { return this; }); var getProto = Object.getPrototypeOf, NativeIteratorPrototype = getProto && getProto(getProto(values([]))); NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype); function defineIteratorMethods(prototype) { ["next", "throw", "return"].forEach(function (method) { define(prototype, method, function (arg) { return this._invoke(method, arg); }); }); } function AsyncIterator(generator, PromiseImpl) { function invoke(method, arg, resolve, reject) { var record = tryCatch(generator[method], generator, arg); if ("throw" !== record.type) { var result = record.arg, value = result.value; return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { invoke("next", value, resolve, reject); }, function (err) { invoke("throw", err, resolve, reject); }) : PromiseImpl.resolve(value).then(function (unwrapped) { result.value = unwrapped, resolve(result); }, function (error) { return invoke("throw", error, resolve, reject); }); } reject(record.arg); } var previousPromise; defineProperty(this, "_invoke", { value: function value(method, arg) { function callInvokeWithMethodAndArg() { return new PromiseImpl(function (resolve, reject) { invoke(method, arg, resolve, reject); }); } return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(innerFn, self, context) { var state = "suspendedStart"; return function (method, arg) { if ("executing" === state) throw new Error("Generator is already running"); if ("completed" === state) { if ("throw" === method) throw arg; return doneResult(); } for (context.method = method, context.arg = arg;;) { var delegate = context.delegate; if (delegate) { var delegateResult = maybeInvokeDelegate(delegate, context); if (delegateResult) { if (delegateResult === ContinueSentinel) continue; return delegateResult; } } if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { if ("suspendedStart" === state) throw state = "completed", context.arg; context.dispatchException(context.arg); } else "return" === context.method && context.abrupt("return", context.arg); state = "executing"; var record = tryCatch(innerFn, self, context); if ("normal" === record.type) { if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; return { value: record.arg, done: context.done }; } "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); } }; } function maybeInvokeDelegate(delegate, context) { var methodName = context.method, method = delegate.iterator[methodName]; if (undefined === method) return context.delegate = null, "throw" === methodName && delegate.iterator.return && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method) || "return" !== methodName && (context.method = "throw", context.arg = new TypeError("The iterator does not provide a '" + methodName + "' method")), ContinueSentinel; var record = tryCatch(method, delegate.iterator, context.arg); if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; var info = record.arg; return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel); } function pushTryEntry(locs) { var entry = { tryLoc: locs[0] }; 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry); } function resetTryEntry(entry) { var record = entry.completion || {}; record.type = "normal", delete record.arg, entry.completion = record; } function Context(tryLocsList) { this.tryEntries = [{ tryLoc: "root" }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0); } function values(iterable) { if (iterable) { var iteratorMethod = iterable[iteratorSymbol]; if (iteratorMethod) return iteratorMethod.call(iterable); if ("function" == typeof iterable.next) return iterable; if (!isNaN(iterable.length)) { var i = -1, next = function next() { for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; return next.value = undefined, next.done = !0, next; }; return next.next = next; } } return { next: doneResult }; } function doneResult() { return { value: undefined, done: !0 }; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), defineProperty(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { var ctor = "function" == typeof genFun && genFun.constructor; return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); }, exports.mark = function (genFun) { return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun; }, exports.awrap = function (arg) { return { __await: arg }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () { return this; }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { void 0 === PromiseImpl && (PromiseImpl = Promise); var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { return result.done ? result.value : iter.next(); }); }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () { return this; }), define(Gp, "toString", function () { return "[object Generator]"; }), exports.keys = function (val) { var object = Object(val), keys = []; for (var key in object) keys.push(key); return keys.reverse(), function next() { for (; keys.length;) { var key = keys.pop(); if (key in object) return next.value = key, next.done = !1, next; } return next.done = !0, next; }; }, exports.values = values, Context.prototype = { constructor: Context, reset: function reset(skipTempReset) { if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined); }, stop: function stop() { this.done = !0; var rootRecord = this.tryEntries[0].completion; if ("throw" === rootRecord.type) throw rootRecord.arg; return this.rval; }, dispatchException: function dispatchException(exception) { if (this.done) throw exception; var context = this; function handle(loc, caught) { return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught; } for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i], record = entry.completion; if ("root" === entry.tryLoc) return handle("end"); if (entry.tryLoc <= this.prev) { var hasCatch = hasOwn.call(entry, "catchLoc"), hasFinally = hasOwn.call(entry, "finallyLoc"); if (hasCatch && hasFinally) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } else if (hasCatch) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); } else { if (!hasFinally) throw new Error("try statement without catch or finally"); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } } } }, abrupt: function abrupt(type, arg) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { var finallyEntry = entry; break; } } finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); var record = finallyEntry ? finallyEntry.completion : {}; return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); }, complete: function complete(record, afterLoc) { if ("throw" === record.type) throw record.arg; return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel; }, finish: function finish(finallyLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel; } }, catch: function _catch(tryLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc === tryLoc) { var record = entry.completion; if ("throw" === record.type) { var thrown = record.arg; resetTryEntry(entry); } return thrown; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(iterable, resultName, nextLoc) { return this.delegate = { iterator: values(iterable), resultName: resultName, nextLoc: nextLoc }, "next" === this.method && (this.arg = undefined), ContinueSentinel; } }, exports; }
5
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
6
+ function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
7
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
8
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
9
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
10
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
11
+ function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
12
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
13
+ function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
14
+ function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
15
+ import { Input as AntInput, message } from 'antd';
16
+ import React, { useState, useRef, useEffect } from 'react';
17
+ import { BrowserMultiFormatReader } from '@zxing/library';
18
+ import IconFont from "./../../../../components/iconfont";
4
19
  import ReadPretty from "./ReadPretty";
5
20
  import { withMode } from "../../dataSourceForm/utils";
21
+ import "./WithMode.less";
6
22
  var Input = function Input(props) {
7
- return /*#__PURE__*/React.createElement(AntInput, _extends({}, props, {
8
- ref: props.innerRef || undefined
9
- }));
23
+ var enableQRScanner = props.enableQRScanner,
24
+ propValue = props.value,
25
+ onChange = props.onChange,
26
+ restProps = _objectWithoutProperties(props, _excluded);
27
+
28
+ // 使用内部状态来管理输入值
29
+ var _useState = useState(propValue || ''),
30
+ _useState2 = _slicedToArray(_useState, 2),
31
+ inputValue = _useState2[0],
32
+ setInputValue = _useState2[1];
33
+
34
+ // 当props.value变化时更新内部状态
35
+ useEffect(function () {
36
+ if (propValue !== undefined && propValue !== inputValue) {
37
+ setInputValue(propValue);
38
+ }
39
+ }, [propValue]);
40
+ var _useState3 = useState(false),
41
+ _useState4 = _slicedToArray(_useState3, 2),
42
+ scanVisible = _useState4[0],
43
+ setScanVisible = _useState4[1];
44
+ var _useState5 = useState(false),
45
+ _useState6 = _slicedToArray(_useState5, 2),
46
+ uploading = _useState6[0],
47
+ setUploading = _useState6[1];
48
+ var videoRef = useRef(null);
49
+ var fileInputRef = useRef(null);
50
+ var codeReaderRef = useRef(null);
51
+
52
+ // 创建一个用于设置输入框值的函数
53
+ var setValue = function setValue(value) {
54
+ console.log('设置输入框值:', value);
55
+
56
+ // 1. 更新内部状态
57
+ setInputValue(value);
58
+
59
+ // 2. 通知父组件值已变化
60
+ if (typeof onChange === 'function') {
61
+ try {
62
+ // 创建模拟事件
63
+ var syntheticEvent = {
64
+ target: {
65
+ value: value
66
+ },
67
+ currentTarget: {
68
+ value: value
69
+ },
70
+ preventDefault: function preventDefault() {},
71
+ stopPropagation: function stopPropagation() {}
72
+ };
73
+ onChange(syntheticEvent);
74
+ } catch (err) {
75
+ console.error('调用onChange失败:', err);
76
+ }
77
+ }
78
+ };
79
+
80
+ // 处理输入变化
81
+ var handleInputChange = function handleInputChange(e) {
82
+ var newValue = e.target.value;
83
+
84
+ // 更新内部状态
85
+ setInputValue(newValue);
86
+
87
+ // 调用原始onChange
88
+ if (typeof onChange === 'function') {
89
+ onChange(e);
90
+ }
91
+ };
92
+
93
+ // 处理扫码按钮点击
94
+ var handleScanClick = function handleScanClick() {
95
+ setScanVisible(true);
96
+ };
97
+
98
+ // 处理关闭扫码界面
99
+ var handleScanClose = function handleScanClose() {
100
+ var _codeReaderRef$curren;
101
+ setScanVisible(false);
102
+ // 关闭摄像头
103
+ (_codeReaderRef$curren = codeReaderRef.current) === null || _codeReaderRef$curren === void 0 ? void 0 : _codeReaderRef$curren.reset();
104
+
105
+ // 停止视频流
106
+ if (videoRef.current && videoRef.current.srcObject) {
107
+ var stream = videoRef.current.srcObject;
108
+ var tracks = stream.getTracks();
109
+ tracks.forEach(function (track) {
110
+ track.stop();
111
+ });
112
+ videoRef.current.srcObject = null;
113
+ }
114
+ };
115
+
116
+ // 清理资源
117
+ useEffect(function () {
118
+ return function () {
119
+ var _codeReaderRef$curren2;
120
+ (_codeReaderRef$curren2 = codeReaderRef.current) === null || _codeReaderRef$curren2 === void 0 ? void 0 : _codeReaderRef$curren2.reset();
121
+ };
122
+ }, []);
123
+
124
+ // 处理上传按钮点击
125
+ var handleUploadClick = function handleUploadClick() {
126
+ var _fileInputRef$current;
127
+ (_fileInputRef$current = fileInputRef.current) === null || _fileInputRef$current === void 0 ? void 0 : _fileInputRef$current.click();
128
+ };
129
+
130
+ // 处理文件上传
131
+ var handleFileChange = /*#__PURE__*/function () {
132
+ var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(event) {
133
+ var files, file, reader;
134
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
135
+ while (1) switch (_context2.prev = _context2.next) {
136
+ case 0:
137
+ files = event.target.files;
138
+ if (!(!files || files.length === 0)) {
139
+ _context2.next = 3;
140
+ break;
141
+ }
142
+ return _context2.abrupt("return");
143
+ case 3:
144
+ setUploading(true);
145
+ _context2.prev = 4;
146
+ file = files[0]; // 检查文件类型
147
+ if (file.type.startsWith('image/')) {
148
+ _context2.next = 10;
149
+ break;
150
+ }
151
+ message.error('请上传图片文件');
152
+ setUploading(false);
153
+ return _context2.abrupt("return");
154
+ case 10:
155
+ reader = new FileReader();
156
+ reader.onload = /*#__PURE__*/function () {
157
+ var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(e) {
158
+ var img, canvas, hints, result, width, height, ctx, imageData, data, i, dataUrl, canvasImg, newImg, text;
159
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
160
+ while (1) switch (_context.prev = _context.next) {
161
+ case 0:
162
+ if (!(!e.target || !e.target.result)) {
163
+ _context.next = 2;
164
+ break;
165
+ }
166
+ return _context.abrupt("return");
167
+ case 2:
168
+ _context.prev = 2;
169
+ // 创建一个img元素并添加到DOM中(使用隐藏样式)
170
+ img = document.createElement('img');
171
+ img.style.position = 'absolute';
172
+ img.style.top = '-9999px';
173
+ img.style.left = '-9999px';
174
+
175
+ // 创建canvas用于图像处理
176
+ canvas = document.createElement('canvas');
177
+ canvas.style.position = 'absolute';
178
+ canvas.style.top = '-9999px';
179
+ canvas.style.left = '-9999px';
180
+ document.body.appendChild(img);
181
+ document.body.appendChild(canvas);
182
+
183
+ // 等待图片加载完成
184
+ _context.next = 15;
185
+ return new Promise(function (resolve, reject) {
186
+ var _e$target;
187
+ img.onload = resolve;
188
+ img.onerror = reject;
189
+ img.src = ((_e$target = e.target) === null || _e$target === void 0 ? void 0 : _e$target.result) || '';
190
+ });
191
+ case 15:
192
+ _context.prev = 15;
193
+ // 创建多种解码器配置,提高成功率
194
+ hints = new Map();
195
+ hints.set(2, true); // 尝试较慢但更强大的算法 (TRY_HARDER)
196
+
197
+ if (!codeReaderRef.current) {
198
+ // 创建解码器实例
199
+ codeReaderRef.current = new BrowserMultiFormatReader(hints, 500);
200
+ }
201
+
202
+ // 尝试直接从图像元素解码
203
+ _context.prev = 19;
204
+ _context.next = 22;
205
+ return codeReaderRef.current.decodeFromImageElement(img);
206
+ case 22:
207
+ result = _context.sent;
208
+ _context.next = 63;
209
+ break;
210
+ case 25:
211
+ _context.prev = 25;
212
+ _context.t0 = _context["catch"](19);
213
+ console.log('直接解码失败,尝试预处理图像...');
214
+
215
+ // 获取图像尺寸
216
+ width = img.naturalWidth || img.width;
217
+ height = img.naturalHeight || img.height; // 设置canvas尺寸
218
+ canvas.width = width;
219
+ canvas.height = height;
220
+
221
+ // 获取上下文
222
+ ctx = canvas.getContext('2d');
223
+ if (ctx) {
224
+ _context.next = 35;
225
+ break;
226
+ }
227
+ throw new Error('无法创建Canvas上下文');
228
+ case 35:
229
+ // 绘制原始图像
230
+ ctx.drawImage(img, 0, 0, width, height);
231
+
232
+ // 尝试提高对比度
233
+ imageData = ctx.getImageData(0, 0, width, height);
234
+ data = imageData.data; // 简单对比度增强
235
+ for (i = 0; i < data.length; i += 4) {
236
+ data[i] = data[i] < 128 ? 0 : 255; // R
237
+ data[i + 1] = data[i + 1] < 128 ? 0 : 255; // G
238
+ data[i + 2] = data[i + 2] < 128 ? 0 : 255; // B
239
+ }
240
+
241
+ ctx.putImageData(imageData, 0, 0);
242
+
243
+ // 从处理后的canvas尝试解码
244
+ _context.prev = 40;
245
+ // 将canvas转为dataURL,创建新的image元素
246
+ dataUrl = canvas.toDataURL('image/png');
247
+ canvasImg = document.createElement('img');
248
+ document.body.appendChild(canvasImg);
249
+
250
+ // 等待图像加载
251
+ _context.next = 46;
252
+ return new Promise(function (resolve, reject) {
253
+ canvasImg.onload = resolve;
254
+ canvasImg.onerror = reject;
255
+ canvasImg.src = dataUrl;
256
+ });
257
+ case 46:
258
+ _context.next = 48;
259
+ return codeReaderRef.current.decodeFromImageElement(canvasImg);
260
+ case 48:
261
+ result = _context.sent;
262
+ // 清理
263
+ document.body.removeChild(canvasImg);
264
+ _context.next = 63;
265
+ break;
266
+ case 52:
267
+ _context.prev = 52;
268
+ _context.t1 = _context["catch"](40);
269
+ console.log('Canvas增强解码失败,尝试最后方法...');
270
+
271
+ // 创建新的Image实例,尝试不同的图像加载方式
272
+ newImg = document.createElement('img');
273
+ document.body.appendChild(newImg);
274
+
275
+ // 等待新图像加载
276
+ _context.next = 59;
277
+ return new Promise(function (resolve, reject) {
278
+ newImg.onload = resolve;
279
+ newImg.onerror = reject;
280
+ // 使用canvas的dataURL
281
+ newImg.src = canvas.toDataURL('image/png');
282
+ });
283
+ case 59:
284
+ _context.next = 61;
285
+ return codeReaderRef.current.decodeFromImageElement(newImg);
286
+ case 61:
287
+ result = _context.sent;
288
+ // 清理
289
+ document.body.removeChild(newImg);
290
+ case 63:
291
+ if (!(result && result.getText)) {
292
+ _context.next = 69;
293
+ break;
294
+ }
295
+ text = result.getText(); // 使用setValue函数设置值
296
+ setValue(text);
297
+ handleScanClose();
298
+ _context.next = 70;
299
+ break;
300
+ case 69:
301
+ throw new Error('未能获取有效的二维码文本');
302
+ case 70:
303
+ _context.next = 76;
304
+ break;
305
+ case 72:
306
+ _context.prev = 72;
307
+ _context.t2 = _context["catch"](15);
308
+ console.error('二维码识别失败', _context.t2);
309
+ message.error('无法识别二维码,请上传清晰的二维码图片');
310
+ case 76:
311
+ _context.prev = 76;
312
+ // 移除临时创建的DOM元素
313
+ if (document.body.contains(img)) {
314
+ document.body.removeChild(img);
315
+ }
316
+ if (document.body.contains(canvas)) {
317
+ document.body.removeChild(canvas);
318
+ }
319
+ return _context.finish(76);
320
+ case 80:
321
+ _context.next = 86;
322
+ break;
323
+ case 82:
324
+ _context.prev = 82;
325
+ _context.t3 = _context["catch"](2);
326
+ console.error('图片加载失败', _context.t3);
327
+ message.error('图片加载失败');
328
+ case 86:
329
+ _context.prev = 86;
330
+ setUploading(false);
331
+ // 重置文件输入以允许再次选择相同文件
332
+ if (fileInputRef.current) {
333
+ fileInputRef.current.value = '';
334
+ }
335
+ return _context.finish(86);
336
+ case 90:
337
+ case "end":
338
+ return _context.stop();
339
+ }
340
+ }, _callee, null, [[2, 82, 86, 90], [15, 72, 76, 80], [19, 25], [40, 52]]);
341
+ }));
342
+ return function (_x3) {
343
+ return _ref2.apply(this, arguments);
344
+ };
345
+ }();
346
+ reader.onerror = function () {
347
+ message.error('读取文件失败');
348
+ setUploading(false);
349
+ };
350
+ reader.readAsDataURL(file);
351
+ _context2.next = 21;
352
+ break;
353
+ case 16:
354
+ _context2.prev = 16;
355
+ _context2.t0 = _context2["catch"](4);
356
+ console.error('处理图片出错', _context2.t0);
357
+ setUploading(false);
358
+ message.error('处理图片时出错');
359
+ case 21:
360
+ case "end":
361
+ return _context2.stop();
362
+ }
363
+ }, _callee2, null, [[4, 16]]);
364
+ }));
365
+ return function handleFileChange(_x2) {
366
+ return _ref.apply(this, arguments);
367
+ };
368
+ }();
369
+ useEffect(function () {
370
+ if (scanVisible && videoRef.current) {
371
+ initCamera();
372
+ }
373
+ }, [scanVisible]);
374
+ var initCamera = /*#__PURE__*/function () {
375
+ var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
376
+ var constraints, stream;
377
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
378
+ while (1) switch (_context3.prev = _context3.next) {
379
+ case 0:
380
+ _context3.prev = 0;
381
+ // 停止之前的实例
382
+ if (codeReaderRef.current) {
383
+ try {
384
+ codeReaderRef.current.reset();
385
+ } catch (err) {
386
+ console.log('重置之前的实例出错', err);
387
+ }
388
+ }
389
+
390
+ // 创建新的BrowserMultiFormatReader实例,使用100ms的扫描间隔(更频繁扫描)
391
+ codeReaderRef.current = new BrowserMultiFormatReader(undefined, 100);
392
+ console.log('创建二维码阅读器实例成功');
393
+
394
+ // 最简单的相机约束
395
+ constraints = {
396
+ video: {
397
+ facingMode: 'environment'
398
+ }
399
+ };
400
+ console.log('正在请求摄像头权限...');
401
+
402
+ // 获取视频流
403
+ _context3.next = 8;
404
+ return navigator.mediaDevices.getUserMedia(constraints);
405
+ case 8:
406
+ stream = _context3.sent;
407
+ console.log('获取摄像头流成功');
408
+ if (!videoRef.current) {
409
+ _context3.next = 18;
410
+ break;
411
+ }
412
+ // 设置视频源
413
+ videoRef.current.srcObject = stream;
414
+
415
+ // 等待视频加载
416
+ _context3.next = 14;
417
+ return new Promise(function (resolve) {
418
+ if (!videoRef.current) {
419
+ resolve();
420
+ return;
421
+ }
422
+ videoRef.current.onloadedmetadata = function () {
423
+ if (!videoRef.current) return;
424
+ console.log('视频元数据加载完成');
425
+ videoRef.current.play().then(function () {
426
+ console.log('视频开始播放成功');
427
+ resolve();
428
+ }).catch(function (err) {
429
+ console.error('视频播放失败', err);
430
+ message.error('摄像头播放失败');
431
+ resolve();
432
+ });
433
+ };
434
+
435
+ // 设置超时,防止卡住
436
+ setTimeout(resolve, 3000);
437
+ });
438
+ case 14:
439
+ console.log('准备开始扫描...');
440
+
441
+ // 最简单的解码方式
442
+ if (codeReaderRef.current && videoRef.current) {
443
+ try {
444
+ // 基础解码
445
+ codeReaderRef.current.decodeFromVideoDevice(null, videoRef.current, function (result, error) {
446
+ if (result) {
447
+ var text = result.getText();
448
+ console.log('扫描成功:', text);
449
+
450
+ // 使用更简单直接的方式更新输入
451
+ try {
452
+ // 直接通知组件
453
+ setValue(text);
454
+
455
+ // 给用户反馈
456
+ setTimeout(function () {
457
+ return handleScanClose();
458
+ }, 500);
459
+ } catch (e) {
460
+ console.error('设置值出错', e);
461
+ handleScanClose();
462
+ }
463
+ }
464
+ });
465
+ console.log('扫描器初始化完成,等待二维码...');
466
+ } catch (e) {
467
+ console.error('初始化扫描器失败', e);
468
+ message.error('初始化二维码扫描失败');
469
+ handleScanClose();
470
+ }
471
+ }
472
+ _context3.next = 19;
473
+ break;
474
+ case 18:
475
+ throw new Error('视频元素不存在');
476
+ case 19:
477
+ _context3.next = 26;
478
+ break;
479
+ case 21:
480
+ _context3.prev = 21;
481
+ _context3.t0 = _context3["catch"](0);
482
+ console.error('摄像头初始化错误', _context3.t0);
483
+ message.error('无法启动摄像头,请确保已授权');
484
+ handleScanClose();
485
+ case 26:
486
+ case "end":
487
+ return _context3.stop();
488
+ }
489
+ }, _callee3, null, [[0, 21]]);
490
+ }));
491
+ return function initCamera() {
492
+ return _ref3.apply(this, arguments);
493
+ };
494
+ }();
495
+
496
+ // 仅在启用扫码功能时显示扫码图标,不再限制设备类型
497
+ var scanSuffix = enableQRScanner ? /*#__PURE__*/React.createElement(IconFont, {
498
+ type: "pisell2-scan2",
499
+ className: "scan-button-icon",
500
+ style: {
501
+ fontSize: 24,
502
+ color: '#fff',
503
+ cursor: 'pointer'
504
+ },
505
+ onClick: handleScanClick
506
+ }) : null;
507
+
508
+ // 全屏容器样式
509
+ var fullscreenStyle = {
510
+ position: 'fixed',
511
+ top: 0,
512
+ left: 0,
513
+ width: '100vw',
514
+ height: '100vh',
515
+ backgroundColor: '#000',
516
+ zIndex: 9999,
517
+ overflow: 'hidden',
518
+ display: 'flex',
519
+ justifyContent: 'center',
520
+ alignItems: 'center'
521
+ };
522
+
523
+ // 视频容器样式
524
+ var videoContainerStyle = {
525
+ position: 'relative',
526
+ width: '100%',
527
+ height: '100%',
528
+ overflow: 'hidden'
529
+ };
530
+
531
+ // 视频样式
532
+ var videoStyle = {
533
+ width: '100%',
534
+ height: '100%',
535
+ objectFit: 'cover'
536
+ };
537
+
538
+ // 关闭按钮样式
539
+ var closeButtonStyle = {
540
+ position: 'fixed',
541
+ top: 20,
542
+ left: 20,
543
+ zIndex: 9999,
544
+ fontSize: 24,
545
+ color: '#fff',
546
+ cursor: 'pointer',
547
+ backgroundColor: 'rgba(255, 255, 255, 0.15)',
548
+ width: 44,
549
+ height: 44,
550
+ display: 'flex',
551
+ alignItems: 'center',
552
+ justifyContent: 'center',
553
+ borderRadius: '50%'
554
+ };
555
+
556
+ // 上传按钮样式
557
+ var uploadButtonStyle = {
558
+ position: 'fixed',
559
+ right: 30,
560
+ bottom: 60,
561
+ width: 88,
562
+ height: 88,
563
+ display: 'flex',
564
+ alignItems: 'center',
565
+ justifyContent: 'center',
566
+ zIndex: 9999,
567
+ fontSize: 48,
568
+ color: '#fff',
569
+ backgroundColor: 'rgba(255, 255, 255, 0.15)',
570
+ borderRadius: '50%',
571
+ cursor: 'pointer'
572
+ };
573
+ return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(AntInput, _extends({}, restProps, {
574
+ ref: props.innerRef || undefined,
575
+ addonAfter: scanSuffix,
576
+ value: inputValue,
577
+ onChange: handleInputChange
578
+ })), scanVisible && /*#__PURE__*/React.createElement("div", {
579
+ className: "pisell-scan-fullscreen",
580
+ style: fullscreenStyle
581
+ }, /*#__PURE__*/React.createElement("div", {
582
+ style: videoContainerStyle
583
+ }, /*#__PURE__*/React.createElement("video", {
584
+ ref: videoRef,
585
+ className: "scan-video",
586
+ style: videoStyle,
587
+ autoPlay: true,
588
+ playsInline: true,
589
+ muted: true
590
+ })), /*#__PURE__*/React.createElement(IconFont, {
591
+ type: "pisell2-arrow-left",
592
+ className: "scan-close-left",
593
+ style: closeButtonStyle,
594
+ onClick: handleScanClose
595
+ }), /*#__PURE__*/React.createElement(IconFont, {
596
+ type: "pisell2-image-01",
597
+ className: "scan-upload",
598
+ style: uploadButtonStyle,
599
+ onClick: handleUploadClick
600
+ }), /*#__PURE__*/React.createElement("input", {
601
+ type: "file",
602
+ ref: fileInputRef,
603
+ onChange: handleFileChange,
604
+ accept: "image/*",
605
+ className: "scan-file-input",
606
+ style: {
607
+ display: 'none'
608
+ }
609
+ })));
10
610
  };
11
611
  var InputWithMode = withMode(Input, ReadPretty);
12
612
  export default InputWithMode;