From 4da094c70f532b2d8effd668ae256c48ae3c6050 Mon Sep 17 00:00:00 2001 From: wuduoyi Date: Thu, 6 Jul 2023 16:36:17 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20office-viewer=20=E9=93=BE=E6=8E=A5?= =?UTF-8?q?=E5=9C=B0=E5=9D=80=E6=97=B6=E6=98=BE=E7=A4=BA=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lerna.json | 2 +- packages/amis-core/package.json | 4 +-- packages/amis-core/src/utils/dataMapping.ts | 6 +++- packages/amis-formula/package.json | 2 +- packages/amis-ui/package.json | 6 ++-- packages/amis-ui/src/locale/de-DE.ts | 1 + packages/amis-ui/src/locale/en-US.ts | 1 + packages/amis-ui/src/locale/zh-CN.ts | 1 + packages/amis/package.json | 8 ++--- packages/amis/src/renderers/OfficeViewer.tsx | 31 ++++++++++++++++---- 10 files changed, 44 insertions(+), 18 deletions(-) diff --git a/lerna.json b/lerna.json index aa3bed475..547171ece 100644 --- a/lerna.json +++ b/lerna.json @@ -5,5 +5,5 @@ "packages/amis-ui", "packages/amis" ], - "version": "3.2.0" + "version": "3.3.0-beta.3" } diff --git a/packages/amis-core/package.json b/packages/amis-core/package.json index 4d3dbca4a..25deb0e20 100644 --- a/packages/amis-core/package.json +++ b/packages/amis-core/package.json @@ -1,6 +1,6 @@ { "name": "amis-core", - "version": "3.2.0", + "version": "3.3.0-beta.3", "description": "amis-core", "main": "lib/index.js", "module": "esm/index.js", @@ -45,7 +45,7 @@ "esm" ], "dependencies": { - "amis-formula": "^3.2.0", + "amis-formula": "^3.3.0-beta.3", "classnames": "2.3.1", "file-saver": "^2.0.2", "hoist-non-react-statics": "^3.3.2", diff --git a/packages/amis-core/src/utils/dataMapping.ts b/packages/amis-core/src/utils/dataMapping.ts index 64b2f1e25..06bc9cbb9 100644 --- a/packages/amis-core/src/utils/dataMapping.ts +++ b/packages/amis-core/src/utils/dataMapping.ts @@ -155,7 +155,11 @@ export function dataMapping( setVariable(ret, key, value, convertKeyToPath); } else if (value === '$$') { setVariable(ret, key, from, convertKeyToPath); - } else if (value && value[0] === '$') { + } else if ( + typeof value === 'string' && + value.length > 0 && + value[0] === '$' + ) { const v = resolveMapping(value, from, undefined, ignoreIfNotMatch); setVariable(ret, key, v, convertKeyToPath); diff --git a/packages/amis-formula/package.json b/packages/amis-formula/package.json index 6d2b88d53..e876f1540 100644 --- a/packages/amis-formula/package.json +++ b/packages/amis-formula/package.json @@ -1,6 +1,6 @@ { "name": "amis-formula", - "version": "3.2.0", + "version": "3.3.0-beta.3", "description": "负责 amis 里面的表达式实现,内置公式,编辑器等", "main": "lib/index.js", "module": "esm/index.js", diff --git a/packages/amis-ui/package.json b/packages/amis-ui/package.json index d201257d9..94743bfcd 100644 --- a/packages/amis-ui/package.json +++ b/packages/amis-ui/package.json @@ -3,7 +3,7 @@ "main": "lib/index.js", "module": "esm/index.js", "types": "lib/index.d.ts", - "version": "3.2.0", + "version": "3.3.0-beta.3", "description": "", "scripts": { "build": "npm run clean-dist && NODE_ENV=production rollup -c ", @@ -35,8 +35,8 @@ }, "dependencies": { "@rc-component/mini-decimal": "^1.0.1", - "amis-core": "^3.2.0", - "amis-formula": "^3.2.0", + "amis-core": "^3.3.0-beta.3", + "amis-formula": "^3.3.0-beta.3", "classnames": "2.3.1", "codemirror": "^5.63.0", "downshift": "6.1.12", diff --git a/packages/amis-ui/src/locale/de-DE.ts b/packages/amis-ui/src/locale/de-DE.ts index 7cc807c2b..36d12f8d7 100644 --- a/packages/amis-ui/src/locale/de-DE.ts +++ b/packages/amis-ui/src/locale/de-DE.ts @@ -184,6 +184,7 @@ register('de-DE', { 'Log.collapse': 'Falten', 'link': 'Link', 'loading': 'Wird geladen...', + 'loadingFailed': 'Das Laden ist fehlgeschlagen', 'LocationPicker.placeholder': 'Wählen Sie einen Ort', 'Month.placeholder': 'Wählen Sie einen Monat', 'Nav.sourceError': 'Fehler beim Abrufen des Links', diff --git a/packages/amis-ui/src/locale/en-US.ts b/packages/amis-ui/src/locale/en-US.ts index 65c83aba0..da859a7bc 100644 --- a/packages/amis-ui/src/locale/en-US.ts +++ b/packages/amis-ui/src/locale/en-US.ts @@ -177,6 +177,7 @@ register('en-US', { 'Log.collapse': 'Collapse Operation', 'link': 'Link', 'loading': 'Loading', + 'loadingFailed': 'Loading failed', 'LocationPicker.placeholder': 'Pick location', 'Month.placeholder': 'Select a month', 'Nav.sourceError': 'Fetch link error', diff --git a/packages/amis-ui/src/locale/zh-CN.ts b/packages/amis-ui/src/locale/zh-CN.ts index 2a290418a..0ea0ac65b 100644 --- a/packages/amis-ui/src/locale/zh-CN.ts +++ b/packages/amis-ui/src/locale/zh-CN.ts @@ -182,6 +182,7 @@ register('zh-CN', { 'Log.collapse': '收起工具栏', 'link': '链接', 'loading': '加载中', + 'loadingFailed': '加载失败', 'LocationPicker.placeholder': '请选择位置', 'Month.placeholder': '请选择月份', 'Nav.sourceError': '获取链接错误', diff --git a/packages/amis/package.json b/packages/amis/package.json index efb778467..d0ec42e0f 100644 --- a/packages/amis/package.json +++ b/packages/amis/package.json @@ -1,6 +1,6 @@ { "name": "amis", - "version": "3.2.0", + "version": "3.3.0-beta.3", "description": "一种MIS页面生成工具", "main": "lib/index.js", "module": "esm/index.js", @@ -36,8 +36,8 @@ } ], "dependencies": { - "amis-core": "^3.2.0", - "amis-ui": "^3.2.0", + "amis-core": "^3.3.0-beta.3", + "amis-ui": "^3.3.0-beta.3", "attr-accept": "2.2.2", "blueimp-canvastoblob": "2.1.0", "classnames": "2.3.1", @@ -242,4 +242,4 @@ "react-dom": ">=16.8.6" }, "gitHead": "37d23b4a8eb1c663bc38e8dd9040889ea1526ec4" -} \ No newline at end of file +} diff --git a/packages/amis/src/renderers/OfficeViewer.tsx b/packages/amis/src/renderers/OfficeViewer.tsx index 416726c57..bead297b5 100644 --- a/packages/amis/src/renderers/OfficeViewer.tsx +++ b/packages/amis/src/renderers/OfficeViewer.tsx @@ -44,7 +44,9 @@ export interface OfficeViewerProps columnsCount: number; } -export interface OfficeViewerState {} +export interface OfficeViewerState { + loadding: boolean; +} export default class OfficeViewer extends React.Component< OfficeViewerProps, @@ -138,7 +140,7 @@ export default class OfficeViewer extends React.Component< * 渲染远端文件 */ async renderRemoteWord() { - const {wordOptions, env, src, data, display} = this.props; + const {wordOptions, env, src, data, display, translate: __} = this.props; const finalSrc = src ? resolveVariableAndFilter(src, data, '| raw') @@ -154,13 +156,22 @@ export default class OfficeViewer extends React.Component< } let response: Payload; - + this.setState({ + loadding: true + }); try { response = await env.fetcher(finalSrc, data, { responseType: 'arraybuffer' }); } catch (error) { - env.alert(error); + // 显示一下报错信息避免没法选中组件 + if (this.rootElement?.current) { + this.rootElement.current.innerHTML = + __('loadingFailed') + ' url:' + finalSrc; + } + this.setState({ + loadding: false + }); return; } @@ -180,6 +191,10 @@ export default class OfficeViewer extends React.Component< } this.word = word; + + this.setState({ + loadding: false + }); }); } @@ -224,7 +239,7 @@ export default class OfficeViewer extends React.Component< loadingConfig } = this.props; return ( -
+
{/* 避免没内容时编辑器都选不了 */} {display !== false && !src && !name && ( @@ -248,11 +263,15 @@ export default class OfficeViewer extends React.Component< )} +