fix: office-viewer 链接地址时显示错误信息

This commit is contained in:
wuduoyi 2023-07-06 16:36:17 +08:00
parent 49cc16475a
commit 4da094c70f
10 changed files with 44 additions and 18 deletions

View File

@ -5,5 +5,5 @@
"packages/amis-ui",
"packages/amis"
],
"version": "3.2.0"
"version": "3.3.0-beta.3"
}

View File

@ -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",

View File

@ -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);

View File

@ -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",

View File

@ -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",

View File

@ -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',

View File

@ -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',

View File

@ -182,6 +182,7 @@ register('zh-CN', {
'Log.collapse': '收起工具栏',
'link': '链接',
'loading': '加载中',
'loadingFailed': '加载失败',
'LocationPicker.placeholder': '请选择位置',
'Month.placeholder': '请选择月份',
'Nav.sourceError': '获取链接错误',

View File

@ -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"
}
}

View File

@ -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 (
<div ref={this.rootElement} className={cx('office-viewer', className)}>
<div>
{/* 避免没内容时编辑器都选不了 */}
{display !== false && !src && !name && (
<svg width="100%" height="100" xmlns="http://www.w3.org/2000/svg">
@ -248,11 +263,15 @@ export default class OfficeViewer extends React.Component<
</text>
</svg>
)}
<div
ref={this.rootElement}
className={cx('office-viewer', className)}
></div>
<Spinner
overlay
key="info"
show={loading}
show={loading && this.state.loadding}
loadingConfig={loadingConfig}
/>
</div>