@4399ywkf/design 1.3.9 → 1.3.10

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.
@@ -35,7 +35,7 @@ export var useDownloadImage = function useDownloadImage() {
35
35
  // 单张图片下载
36
36
  var downloadImage = useCallback( /*#__PURE__*/function () {
37
37
  var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(url, options) {
38
- var _abortControllerRef$c, _response$headers$get, _response$headers$get2, _options$onSuccess, response, _options$onError, filename, blob, finalBlob, objectUrl, link, _options$onError2, err;
38
+ var _abortControllerRef$c, _response$headers$get, _response$headers$get2, _options$onSuccess, response, _options$onError, errMsg, filename, blob, finalBlob, objectUrl, link, _options$onError2, err;
39
39
  return _regeneratorRuntime().wrap(function _callee$(_context) {
40
40
  while (1) switch (_context.prev = _context.next) {
41
41
  case 0:
@@ -44,37 +44,55 @@ export var useDownloadImage = function useDownloadImage() {
44
44
  setError(null);
45
45
  setProgress(0);
46
46
  abortControllerRef.current = new AbortController();
47
- _context.next = 7;
47
+ console.log('🟩 [downloadImage] 发起请求...', url, options);
48
+ _context.next = 8;
48
49
  return fetch(url, _objectSpread(_objectSpread({}, options === null || options === void 0 ? void 0 : options.fetchOptions), {}, {
49
50
  signal: (_abortControllerRef$c = abortControllerRef.current) === null || _abortControllerRef$c === void 0 ? void 0 : _abortControllerRef$c.signal
50
51
  }));
51
- case 7:
52
+ case 8:
52
53
  response = _context.sent;
54
+ console.log('🟩 [downloadImage] 响应状态:', response.status, response.statusText);
55
+ console.log('🟩 [downloadImage] 响应类型:', response.type);
56
+ console.log('🟩 [downloadImage] Content-Type:', response.headers.get('content-type'));
57
+ console.log('🟩 [downloadImage] Content-Disposition:', response.headers.get('content-disposition'));
53
58
  if (response.ok) {
54
- _context.next = 11;
59
+ _context.next = 18;
55
60
  break;
56
61
  }
57
- options === null || options === void 0 || (_options$onError = options.onError) === null || _options$onError === void 0 || _options$onError.call(options, new Error("\u4E0B\u8F7D\u5931\u8D25: ".concat(response.status, " ").concat(response.statusText)));
58
- throw new Error("\u4E0B\u8F7D\u5931\u8D25: ".concat(response.status, " ").concat(response.statusText));
59
- case 11:
62
+ errMsg = "\u4E0B\u8F7D\u5931\u8D25: ".concat(response.status, " ").concat(response.statusText);
63
+ console.error('❌ [downloadImage] 响应非 200:', errMsg);
64
+ options === null || options === void 0 || (_options$onError = options.onError) === null || _options$onError === void 0 || _options$onError.call(options, new Error(errMsg));
65
+ throw new Error(errMsg);
66
+ case 18:
60
67
  // // 检查内容类型
61
68
  filename = (_response$headers$get = (_response$headers$get2 = response.headers.get('Content-Disposition')) === null || _response$headers$get2 === void 0 || (_response$headers$get2 = _response$headers$get2.split('filename=')) === null || _response$headers$get2 === void 0 ? void 0 : _response$headers$get2[1]) !== null && _response$headers$get !== void 0 ? _response$headers$get : 'image.png';
62
- _context.next = 14;
69
+ console.log('🟩 [downloadImage] 解析文件名:', filename);
70
+ _context.next = 22;
63
71
  return response.blob();
64
- case 14:
72
+ case 22:
65
73
  blob = _context.sent;
74
+ console.log('🟩 [downloadImage] Blob 大小:', blob.size, '字节');
75
+
76
+ // 检查 blob 是否为空
77
+ if (blob.size === 0) {
78
+ console.warn('⚠️ [downloadImage] Blob 内容为空,可能是资源无效或被拦截。');
79
+ }
80
+
66
81
  // 处理图片压缩(如果需要)
67
82
  finalBlob = blob;
68
83
  if (!(options !== null && options !== void 0 && options.compress && options.quality)) {
69
- _context.next = 20;
84
+ _context.next = 32;
70
85
  break;
71
86
  }
72
- _context.next = 19;
87
+ console.log('🟨 [downloadImage] 启用压缩, 质量:', options.quality);
88
+ _context.next = 30;
73
89
  return compressImage(blob, options.quality);
74
- case 19:
90
+ case 30:
75
91
  finalBlob = _context.sent;
76
- case 20:
92
+ console.log('🟨 [downloadImage] 压缩后大小:', finalBlob.size);
93
+ case 32:
77
94
  objectUrl = URL.createObjectURL(finalBlob);
95
+ console.log('🟩 [downloadImage] 生成 Object URL:', objectUrl);
78
96
  link = document.createElement('a');
79
97
  link.href = objectUrl;
80
98
  // 如果没有提供文件名,则使用默认名称
@@ -87,29 +105,31 @@ export var useDownloadImage = function useDownloadImage() {
87
105
  URL.revokeObjectURL(objectUrl);
88
106
  setProgress(100);
89
107
  options === null || options === void 0 || (_options$onSuccess = options.onSuccess) === null || _options$onSuccess === void 0 || _options$onSuccess.call(options);
108
+ console.log('✅ [downloadImage] 下载完成:', filename);
90
109
  return _context.abrupt("return", {
91
110
  success: true
92
111
  });
93
- case 33:
94
- _context.prev = 33;
112
+ case 47:
113
+ _context.prev = 47;
95
114
  _context.t0 = _context["catch"](0);
96
115
  err = _context.t0 instanceof Error ? _context.t0 : new Error('未知错误');
97
- console.error('下载图片失败:', err);
116
+ console.error('❌ [downloadImage] 下载图片失败:', err);
98
117
  setError(err);
99
118
  options === null || options === void 0 || (_options$onError2 = options.onError) === null || _options$onError2 === void 0 || _options$onError2.call(options, err);
100
119
  return _context.abrupt("return", {
101
120
  success: false,
102
121
  error: err
103
122
  });
104
- case 40:
105
- _context.prev = 40;
123
+ case 54:
124
+ _context.prev = 54;
106
125
  setLoading(false);
107
- return _context.finish(40);
108
- case 43:
126
+ console.log('🧹 [downloadImage] 状态重置完成。');
127
+ return _context.finish(54);
128
+ case 58:
109
129
  case "end":
110
130
  return _context.stop();
111
131
  }
112
- }, _callee, null, [[0, 33, 40, 43]]);
132
+ }, _callee, null, [[0, 47, 54, 58]]);
113
133
  }));
114
134
  return function (_x, _x2) {
115
135
  return _ref.apply(this, arguments);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@4399ywkf/design",
3
- "version": "1.3.9",
3
+ "version": "1.3.10",
4
4
  "description": "4399ywkf Design React UI Library.",
5
5
  "license": "MIT",
6
6
  "module": "dist/index.js",