@myun/gimi-chat 0.9.36 → 0.9.37

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.
@@ -16,7 +16,6 @@ import styles from "./index.module.css";
16
16
  import { Spin } from '@douyinfe/semi-ui';
17
17
  import GdPlayer from '@gaodun.com/gplayer';
18
18
  import ChatContext from "../templates/chatContext";
19
- import AiLoading from "../ai-loading";
20
19
  import { getFieldConfigsByType } from "./config";
21
20
  var SUPPORT_PREVIEW_FILE_TYPE = ['doc', 'docx', 'xls', 'xlsx', 'ppt', 'pptx'];
22
21
  var SUPPORT_WEB_PREVIEW = ['pdf', 'svg', 'png', 'jpg', 'jpeg', 'gif'];
@@ -153,99 +152,10 @@ var DocumentPlayer = function DocumentPlayer(_ref5) {
153
152
  onViewFull = _ref5.onViewFull;
154
153
  var _useTranslation2 = useTranslation(),
155
154
  t = _useTranslation2.t;
156
- var _useContext2 = useContext(ChatContext),
157
- apiService = _useContext2.apiService;
158
- var _ref6 = apiService,
159
- getDocumentTrialUrl = _ref6.getDocumentTrialUrl;
160
155
 
161
- // trialUrl: 试看地址;error: 失败文案 key(null 表示无错误);loading: 加载中
162
- var _useState3 = useState(''),
163
- _useState4 = _slicedToArray(_useState3, 2),
164
- trialUrl = _useState4[0],
165
- setTrialUrl = _useState4[1];
166
- var _useState5 = useState(null),
167
- _useState6 = _slicedToArray(_useState5, 2),
168
- errorKey = _useState6[0],
169
- setErrorKey = _useState6[1];
170
- var _useState7 = useState(false),
171
- _useState8 = _slicedToArray(_useState7, 2),
172
- loading = _useState8[0],
173
- setLoading = _useState8[1];
174
-
175
- // Office 文档与 Web 可预览类型(pdf/svg/图片)均通过试看接口获取试看地址
156
+ // Office 文档与 Web 可预览类型(pdf/svg/图片)支持试看
176
157
  var canPreview = SUPPORT_PREVIEW_FILE_TYPE.includes(item.suffix) || SUPPORT_WEB_PREVIEW.includes(item.suffix);
177
158
 
178
- // 业务码 -> i18n key
179
- var mapTrialError = function mapTrialError(status) {
180
- switch (status) {
181
- case 4001:
182
- return 'trace.document.trialUnsupportedType';
183
- case 4002:
184
- return 'trace.document.trialFileTooLarge';
185
- case 4003:
186
- return 'trace.document.trialInvalidDoc';
187
- default:
188
- return 'trace.document.trialFailed';
189
- }
190
- };
191
- useEffect(function () {
192
- if (!canPreview) return;
193
- var cancelled = false;
194
- var fetchTrial = /*#__PURE__*/function () {
195
- var _ref7 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
196
- var _res$result, res, isOfficeType;
197
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
198
- while (1) switch (_context2.prev = _context2.next) {
199
- case 0:
200
- setLoading(true);
201
- setErrorKey(null);
202
- setTrialUrl('');
203
- _context2.prev = 3;
204
- _context2.next = 6;
205
- return getDocumentTrialUrl({
206
- resourceUrl: item.url
207
- });
208
- case 6:
209
- res = _context2.sent;
210
- if (!cancelled) {
211
- _context2.next = 9;
212
- break;
213
- }
214
- return _context2.abrupt("return");
215
- case 9:
216
- if (res.status === 0 && (_res$result = res.result) !== null && _res$result !== void 0 && _res$result.trialUrl) {
217
- // Office 文档:用 Office 在线预览嵌入地址;Web 类型(pdf/图片)直接用 trialUrl
218
- isOfficeType = SUPPORT_PREVIEW_FILE_TYPE.includes(item.suffix);
219
- setTrialUrl(isOfficeType ? "https://view.officeapps.live.com/op/embed.aspx?src=".concat(encodeURIComponent(res.result.trialUrl)) : res.result.trialUrl);
220
- } else {
221
- setErrorKey(mapTrialError(res.status));
222
- }
223
- _context2.next = 15;
224
- break;
225
- case 12:
226
- _context2.prev = 12;
227
- _context2.t0 = _context2["catch"](3);
228
- if (!cancelled) setErrorKey('trace.document.trialFailed');
229
- case 15:
230
- _context2.prev = 15;
231
- if (!cancelled) setLoading(false);
232
- return _context2.finish(15);
233
- case 18:
234
- case "end":
235
- return _context2.stop();
236
- }
237
- }, _callee2, null, [[3, 12, 15, 18]]);
238
- }));
239
- return function fetchTrial() {
240
- return _ref7.apply(this, arguments);
241
- };
242
- }();
243
- fetchTrial();
244
- return function () {
245
- cancelled = true;
246
- };
247
- }, [item.url, canPreview]);
248
-
249
159
  // 不支持预览的类型:直接提示并下载
250
160
  if (!canPreview) {
251
161
  return /*#__PURE__*/React.createElement(UnsupportedView, {
@@ -255,33 +165,21 @@ var DocumentPlayer = function DocumentPlayer(_ref5) {
255
165
  });
256
166
  }
257
167
 
258
- // 加载中
259
- if (loading) {
260
- return /*#__PURE__*/React.createElement("div", {
261
- className: styles.docLoading
262
- }, /*#__PURE__*/React.createElement(AiLoading, null));
263
- }
264
- // 试看接口失败
265
- if (errorKey) {
266
- return /*#__PURE__*/React.createElement(UnsupportedView, {
267
- tipKey: errorKey,
268
- downloadUrl: item.url,
269
- onViewFull: onViewFull
270
- });
271
- }
272
- // 试看地址
273
- return trialUrl ? /*#__PURE__*/React.createElement("iframe", {
168
+ // item.url 即试看地址:Office 文档用 Office 在线预览嵌入地址;Web 类型(pdf/图片)直接用 url
169
+ var isOfficeType = SUPPORT_PREVIEW_FILE_TYPE.includes(item.suffix);
170
+ var previewUrl = isOfficeType ? "https://view.officeapps.live.com/op/embed.aspx?src=".concat(encodeURIComponent(item.url)) : item.url;
171
+ return /*#__PURE__*/React.createElement("iframe", {
274
172
  className: styles.docFrame,
275
- src: trialUrl,
173
+ src: previewUrl,
276
174
  style: {
277
175
  border: 0
278
176
  },
279
177
  title: item.name || t('file.previewTitle')
280
- }) : null;
178
+ });
281
179
  };
282
- var NewsPlayer = function NewsPlayer(_ref8) {
180
+ var NewsPlayer = function NewsPlayer(_ref6) {
283
181
  var _item$regulationType;
284
- var item = _ref8.item;
182
+ var item = _ref6.item;
285
183
  var _useTranslation3 = useTranslation(),
286
184
  t = _useTranslation3.t;
287
185
  var html = item.htmlContent || item.content || '';
@@ -330,12 +228,12 @@ var NewsPlayer = function NewsPlayer(_ref8) {
330
228
  className: styles.newsMaskText
331
229
  }, t('trace.information.unsupportedTips')))));
332
230
  };
333
- var TryWatch = function TryWatch(_ref9) {
334
- var item = _ref9.item,
335
- type = _ref9.type,
336
- visible = _ref9.visible,
337
- onCancel = _ref9.onCancel,
338
- onCurrentTraceVideoClick = _ref9.onCurrentTraceVideoClick;
231
+ var TryWatch = function TryWatch(_ref7) {
232
+ var item = _ref7.item,
233
+ type = _ref7.type,
234
+ visible = _ref7.visible,
235
+ onCancel = _ref7.onCancel,
236
+ onCurrentTraceVideoClick = _ref7.onCurrentTraceVideoClick;
339
237
  var platform = useAppSelector(function (state) {
340
238
  return state.gimiMenu.platform;
341
239
  });