ydb-components-material 0.1.209 → 0.1.210

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.
@@ -224,6 +224,8 @@ var FileItem = function FileItem(_ref) {
224
224
  // 预览/下载在 loading 期间的提示语,区分「文件加载」与「签批结果轮询」
225
225
  var loadingTip = signPolling ? '签批结果获取中,请稍后' : '数据获取中,请稍后';
226
226
  var timerRef = useRef(null);
227
+ // 签批结果轮询是否已启动(幂等标记,避免 loading 变化导致重复起轮询)
228
+ var pollingRef = useRef(false);
227
229
  var originalUrlRef = useRef('');
228
230
  var rootRef = useRef(null);
229
231
  var getSignedFile = /*#__PURE__*/function () {
@@ -1092,60 +1094,68 @@ var FileItem = function FileItem(_ref) {
1092
1094
  onCloseSignerInfo && onCloseSignerInfo();
1093
1095
  }
1094
1096
  }, [autoShowSignerInfo, onCloseSignerInfo]);
1097
+
1098
+ // 轮询签批结果:
1099
+ // - 外层组件会修改 file.loading,需要在 loading 变为 false 时启动轮询
1100
+ // - 轮询自身会把 loading 置为 true,所以必须幂等,且不能在依赖变化时清理定时器
1095
1101
  useEffect(function () {
1102
+ if (loading || pollingRef.current) return;
1096
1103
  try {
1097
1104
  var stored = localStorage.getItem(fileId);
1098
- // 当前文件已处于 loading 中时,不再重复发起签批结果轮询
1099
- // 注意:loading 不进依赖数组,否则轮询把 loading 置为 true 后 effect 重跑会清掉定时器
1100
- if (stored && !loading) {
1101
- console.log('stored---', stored);
1102
- var _JSON$parse = JSON.parse(stored),
1103
- contrId = _JSON$parse.contractId,
1104
- docId = _JSON$parse.documentId,
1105
- nameVal = _JSON$parse.fileName,
1106
- originalUrl = _JSON$parse.fileUrl;
1107
- console.log('docId', docId, contrId, nameVal);
1108
- localStorage.removeItem(fileId);
1109
- originalUrlRef.current = originalUrl || '';
1110
- if (docId && contrId && nameVal) {
1111
- // openLoading()
1112
- setSignPolling(true);
1113
- // 轮询期间把 loading 标记到 file 对象上,沿用统一的 loading 展示逻辑
1114
- valChange(_extends({}, file, {
1115
- loading: true
1116
- }), fileIndex, index, subIndex);
1117
- // 兜底:连续 10 次轮询仍未成功则结束轮询,避免无限请求
1118
- var pollCount = 0;
1119
- timerRef.current = setInterval(function () {
1120
- getSignedFile(docId, contrId, nameVal).then(function (success) {
1121
- // 成功时 getSignedFile 内部会清除轮询并关闭 loading
1122
- if (!success) {
1123
- pollCount += 1;
1124
- if (pollCount >= 10) {
1125
- clearInterval(timerRef.current);
1126
- timerRef.current = null;
1127
- closeLoading();
1128
- setSignPolling(false);
1129
- valChange(_extends({}, file, {
1130
- loading: false
1131
- }), fileIndex, index, subIndex);
1132
- _Message.error('签批结果获取失败,请重试');
1133
- }
1134
- } else {
1135
- setSignPolling(false);
1136
- }
1137
- });
1138
- }, 3000);
1139
- }
1140
- }
1105
+ if (!stored) return;
1106
+ console.log('stored---', stored);
1107
+ var _JSON$parse = JSON.parse(stored),
1108
+ contrId = _JSON$parse.contractId,
1109
+ docId = _JSON$parse.documentId,
1110
+ nameVal = _JSON$parse.fileName,
1111
+ originalUrl = _JSON$parse.fileUrl;
1112
+ console.log('docId', docId, contrId, nameVal);
1113
+ localStorage.removeItem(fileId);
1114
+ originalUrlRef.current = originalUrl || '';
1115
+ if (!(docId && contrId && nameVal)) return;
1116
+ pollingRef.current = true;
1117
+ // openLoading()
1118
+ setSignPolling(true);
1119
+ // 轮询期间把 loading 标记到 file 对象上,沿用统一的 loading 展示逻辑
1120
+ valChange(_extends({}, file, {
1121
+ loading: true
1122
+ }), fileIndex, index, subIndex);
1123
+ // 兜底:连续 10 次轮询仍未成功则结束轮询,避免无限请求
1124
+ var pollCount = 0;
1125
+ timerRef.current = setInterval(function () {
1126
+ getSignedFile(docId, contrId, nameVal).then(function (success) {
1127
+ // 成功时 getSignedFile 内部会清除轮询并关闭 loading
1128
+ if (!success) {
1129
+ pollCount += 1;
1130
+ if (pollCount >= 10) {
1131
+ clearInterval(timerRef.current);
1132
+ timerRef.current = null;
1133
+ pollingRef.current = false;
1134
+ closeLoading();
1135
+ setSignPolling(false);
1136
+ valChange(_extends({}, file, {
1137
+ loading: false
1138
+ }), fileIndex, index, subIndex);
1139
+ _Message.error('签批结果获取失败,请重试');
1140
+ }
1141
+ } else {
1142
+ pollingRef.current = false;
1143
+ setSignPolling(false);
1144
+ }
1145
+ });
1146
+ }, 3000);
1141
1147
  } catch (e) {}
1148
+ }, [fileId, loading]);
1149
+
1150
+ // 仅在卸载时清理定时器;不能放进上面的 effect,否则 loading 变化会清掉正在进行的轮询
1151
+ useEffect(function () {
1142
1152
  return function () {
1143
1153
  if (timerRef.current) {
1144
1154
  clearInterval(timerRef.current);
1145
1155
  timerRef.current = null;
1146
1156
  }
1147
1157
  };
1148
- }, [fileId]);
1158
+ }, []);
1149
1159
  return /*#__PURE__*/React.createElement("div", {
1150
1160
  className: "file_item",
1151
1161
  style: style,
@@ -230,6 +230,8 @@ var FileItem = function FileItem(_ref) {
230
230
  // 预览/下载在 loading 期间的提示语,区分「文件加载」与「签批结果轮询」
231
231
  var loadingTip = signPolling ? '签批结果获取中,请稍后' : '数据获取中,请稍后';
232
232
  var timerRef = (0, _react.useRef)(null);
233
+ // 签批结果轮询是否已启动(幂等标记,避免 loading 变化导致重复起轮询)
234
+ var pollingRef = (0, _react.useRef)(false);
233
235
  var originalUrlRef = (0, _react.useRef)('');
234
236
  var rootRef = (0, _react.useRef)(null);
235
237
  var getSignedFile = /*#__PURE__*/function () {
@@ -1098,60 +1100,68 @@ var FileItem = function FileItem(_ref) {
1098
1100
  onCloseSignerInfo && onCloseSignerInfo();
1099
1101
  }
1100
1102
  }, [autoShowSignerInfo, onCloseSignerInfo]);
1103
+
1104
+ // 轮询签批结果:
1105
+ // - 外层组件会修改 file.loading,需要在 loading 变为 false 时启动轮询
1106
+ // - 轮询自身会把 loading 置为 true,所以必须幂等,且不能在依赖变化时清理定时器
1101
1107
  (0, _react.useEffect)(function () {
1108
+ if (loading || pollingRef.current) return;
1102
1109
  try {
1103
1110
  var stored = localStorage.getItem(fileId);
1104
- // 当前文件已处于 loading 中时,不再重复发起签批结果轮询
1105
- // 注意:loading 不进依赖数组,否则轮询把 loading 置为 true 后 effect 重跑会清掉定时器
1106
- if (stored && !loading) {
1107
- console.log('stored---', stored);
1108
- var _JSON$parse = JSON.parse(stored),
1109
- contrId = _JSON$parse.contractId,
1110
- docId = _JSON$parse.documentId,
1111
- nameVal = _JSON$parse.fileName,
1112
- originalUrl = _JSON$parse.fileUrl;
1113
- console.log('docId', docId, contrId, nameVal);
1114
- localStorage.removeItem(fileId);
1115
- originalUrlRef.current = originalUrl || '';
1116
- if (docId && contrId && nameVal) {
1117
- // openLoading()
1118
- setSignPolling(true);
1119
- // 轮询期间把 loading 标记到 file 对象上,沿用统一的 loading 展示逻辑
1120
- valChange((0, _extends3["default"])({}, file, {
1121
- loading: true
1122
- }), fileIndex, index, subIndex);
1123
- // 兜底:连续 10 次轮询仍未成功则结束轮询,避免无限请求
1124
- var pollCount = 0;
1125
- timerRef.current = setInterval(function () {
1126
- getSignedFile(docId, contrId, nameVal).then(function (success) {
1127
- // 成功时 getSignedFile 内部会清除轮询并关闭 loading
1128
- if (!success) {
1129
- pollCount += 1;
1130
- if (pollCount >= 10) {
1131
- clearInterval(timerRef.current);
1132
- timerRef.current = null;
1133
- closeLoading();
1134
- setSignPolling(false);
1135
- valChange((0, _extends3["default"])({}, file, {
1136
- loading: false
1137
- }), fileIndex, index, subIndex);
1138
- _message["default"].error('签批结果获取失败,请重试');
1139
- }
1140
- } else {
1141
- setSignPolling(false);
1142
- }
1143
- });
1144
- }, 3000);
1145
- }
1146
- }
1111
+ if (!stored) return;
1112
+ console.log('stored---', stored);
1113
+ var _JSON$parse = JSON.parse(stored),
1114
+ contrId = _JSON$parse.contractId,
1115
+ docId = _JSON$parse.documentId,
1116
+ nameVal = _JSON$parse.fileName,
1117
+ originalUrl = _JSON$parse.fileUrl;
1118
+ console.log('docId', docId, contrId, nameVal);
1119
+ localStorage.removeItem(fileId);
1120
+ originalUrlRef.current = originalUrl || '';
1121
+ if (!(docId && contrId && nameVal)) return;
1122
+ pollingRef.current = true;
1123
+ // openLoading()
1124
+ setSignPolling(true);
1125
+ // 轮询期间把 loading 标记到 file 对象上,沿用统一的 loading 展示逻辑
1126
+ valChange((0, _extends3["default"])({}, file, {
1127
+ loading: true
1128
+ }), fileIndex, index, subIndex);
1129
+ // 兜底:连续 10 次轮询仍未成功则结束轮询,避免无限请求
1130
+ var pollCount = 0;
1131
+ timerRef.current = setInterval(function () {
1132
+ getSignedFile(docId, contrId, nameVal).then(function (success) {
1133
+ // 成功时 getSignedFile 内部会清除轮询并关闭 loading
1134
+ if (!success) {
1135
+ pollCount += 1;
1136
+ if (pollCount >= 10) {
1137
+ clearInterval(timerRef.current);
1138
+ timerRef.current = null;
1139
+ pollingRef.current = false;
1140
+ closeLoading();
1141
+ setSignPolling(false);
1142
+ valChange((0, _extends3["default"])({}, file, {
1143
+ loading: false
1144
+ }), fileIndex, index, subIndex);
1145
+ _message["default"].error('签批结果获取失败,请重试');
1146
+ }
1147
+ } else {
1148
+ pollingRef.current = false;
1149
+ setSignPolling(false);
1150
+ }
1151
+ });
1152
+ }, 3000);
1147
1153
  } catch (e) {}
1154
+ }, [fileId, loading]);
1155
+
1156
+ // 仅在卸载时清理定时器;不能放进上面的 effect,否则 loading 变化会清掉正在进行的轮询
1157
+ (0, _react.useEffect)(function () {
1148
1158
  return function () {
1149
1159
  if (timerRef.current) {
1150
1160
  clearInterval(timerRef.current);
1151
1161
  timerRef.current = null;
1152
1162
  }
1153
1163
  };
1154
- }, [fileId]);
1164
+ }, []);
1155
1165
  return /*#__PURE__*/_react["default"].createElement("div", {
1156
1166
  className: "file_item",
1157
1167
  style: style,
@@ -101,7 +101,7 @@ function fillRealVersion(meta, packageName, version, basicLibraryVersion) {
101
101
  packageName = 'ydb-components-material';
102
102
  }
103
103
  if (version === void 0) {
104
- version = '0.1.209';
104
+ version = '0.1.210';
105
105
  }
106
106
  if (basicLibraryVersion === void 0) {
107
107
  basicLibraryVersion = {
@@ -106,7 +106,7 @@ function fillRealVersion(meta, packageName, version, basicLibraryVersion) {
106
106
  packageName = 'ydb-components-material';
107
107
  }
108
108
  if (version === void 0) {
109
- version = '0.1.209';
109
+ version = '0.1.210';
110
110
  }
111
111
  if (basicLibraryVersion === void 0) {
112
112
  basicLibraryVersion = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ydb-components-material",
3
- "version": "0.1.209",
3
+ "version": "0.1.210",
4
4
  "description": "ydb-components-material",
5
5
  "main": "lib/index.js",
6
6
  "module": "es/index.js",
@@ -103,10 +103,10 @@
103
103
  },
104
104
  "componentConfig": {
105
105
  "isComponentLibrary": true,
106
- "materialSchema": "https://unpkg.com/ydb-components-material@0.1.209/build/lowcode/assets-prod.json"
106
+ "materialSchema": "https://unpkg.com/ydb-components-material@0.1.210/build/lowcode/assets-prod.json"
107
107
  },
108
108
  "lcMeta": {
109
109
  "type": "component"
110
110
  },
111
- "homepage": "https://unpkg.com/ydb-components-material@0.1.209/build/index.html"
111
+ "homepage": "https://unpkg.com/ydb-components-material@0.1.210/build/index.html"
112
112
  }