mirror of
https://gitee.com/baidu/amis.git
synced 2024-12-02 03:58:07 +08:00
fix: 修复 office-viewer 本地文件加载出错;numbering 每个层级重置计数 (#6421)
* 修复 office-viewer 本地文件加载出错 * 尝试修复 coverage 报错 * 去掉 console.log * numbering 每个层级重置 * 忽略 cnfStyle
This commit is contained in:
parent
a6ca69af6f
commit
4f4ca56008
@ -8,6 +8,8 @@ icon:
|
|||||||
order: 23
|
order: 23
|
||||||
---
|
---
|
||||||
|
|
||||||
|
> 2.9.0 及以上版本
|
||||||
|
|
||||||
用于渲染 office 文档,目前只支持 docx 格式,通过前端转成 HTML 的方式进行渲染,支持以下功能:
|
用于渲染 office 文档,目前只支持 docx 格式,通过前端转成 HTML 的方式进行渲染,支持以下功能:
|
||||||
|
|
||||||
- 基础文本样式
|
- 基础文本样式
|
||||||
@ -30,7 +32,10 @@ order: 23
|
|||||||
```schema: scope="body"
|
```schema: scope="body"
|
||||||
{
|
{
|
||||||
"type": "office-viewer",
|
"type": "office-viewer",
|
||||||
"src": "/examples/static/example.docx"
|
"src": "https://suda.cdn.bcebos.com/docx/simple.docx",
|
||||||
|
"wordOptions": {
|
||||||
|
"padding": "8px"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -111,7 +116,7 @@ order: 23
|
|||||||
{
|
{
|
||||||
"type": "office-viewer",
|
"type": "office-viewer",
|
||||||
"id": "office-viewer",
|
"id": "office-viewer",
|
||||||
"src": "/examples/static/info.docx",
|
"src": "https://suda.cdn.bcebos.com/docx/info.docx",
|
||||||
"wordOptions": {
|
"wordOptions": {
|
||||||
"enableVar": true,
|
"enableVar": true,
|
||||||
"padding": "8px"
|
"padding": "8px"
|
||||||
@ -127,7 +132,7 @@ order: 23
|
|||||||
{
|
{
|
||||||
"type": "office-viewer",
|
"type": "office-viewer",
|
||||||
"id": "office-viewer",
|
"id": "office-viewer",
|
||||||
"src": "/examples/static/info.docx",
|
"src": "https://suda.cdn.bcebos.com/docx/info.docx",
|
||||||
"wordOptions": {
|
"wordOptions": {
|
||||||
"padding": "8px"
|
"padding": "8px"
|
||||||
}
|
}
|
||||||
@ -168,7 +173,7 @@ order: 23
|
|||||||
"type": "office-viewer",
|
"type": "office-viewer",
|
||||||
"id": "office-viewer-download",
|
"id": "office-viewer-download",
|
||||||
"display": false,
|
"display": false,
|
||||||
"src": "/examples/static/example.docx"
|
"src": "https://suda.cdn.bcebos.com/docx/simple.docx"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
```
|
```
|
||||||
@ -197,7 +202,7 @@ order: 23
|
|||||||
"type": "office-viewer",
|
"type": "office-viewer",
|
||||||
"id": "office-viewer-print",
|
"id": "office-viewer-print",
|
||||||
"display": false,
|
"display": false,
|
||||||
"src": "/examples/static/example.docx"
|
"src": "https://suda.cdn.bcebos.com/docx/simple.docx"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
```
|
```
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
/>
|
/>
|
||||||
<meta http-equiv="X-UA-Compatible" content="IE=Edge" />
|
<meta http-equiv="X-UA-Compatible" content="IE=Edge" />
|
||||||
<link rel="stylesheet" href="../static/iconfont.css" />
|
<link rel="stylesheet" href="../static/iconfont.css" />
|
||||||
|
<link rel="stylesheet" href="../static/officefont.css" />
|
||||||
<link
|
<link
|
||||||
rel="stylesheet"
|
rel="stylesheet"
|
||||||
href="../../node_modules/@fortawesome/fontawesome-free/css/all.css"
|
href="../../node_modules/@fortawesome/fontawesome-free/css/all.css"
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
/>
|
/>
|
||||||
<meta http-equiv="X-UA-Compatible" content="IE=Edge" />
|
<meta http-equiv="X-UA-Compatible" content="IE=Edge" />
|
||||||
<link rel="stylesheet" href="../static/iconfont.css" />
|
<link rel="stylesheet" href="../static/iconfont.css" />
|
||||||
|
<link rel="stylesheet" href="../static/officefont.css" />
|
||||||
<link rel="stylesheet" href="@fortawesome/fontawesome-free/css/all.css" />
|
<link rel="stylesheet" href="@fortawesome/fontawesome-free/css/all.css" />
|
||||||
<link
|
<link
|
||||||
rel="stylesheet"
|
rel="stylesheet"
|
||||||
|
@ -1,16 +1,22 @@
|
|||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="zh">
|
<html lang="zh">
|
||||||
|
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8" />
|
<meta charset="UTF-8" />
|
||||||
<title>amis - 低代码前端框架</title>
|
<title>amis - 低代码前端框架</title>
|
||||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||||
<link type="image/x-icon" rel="shortcut icon" href="./static/favicon.png" />
|
<link type="image/x-icon" rel="shortcut icon" href="./static/favicon.png" />
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
|
<meta
|
||||||
|
name="viewport"
|
||||||
|
content="width=device-width, initial-scale=1, maximum-scale=1"
|
||||||
|
/>
|
||||||
<meta http-equiv="X-UA-Compatible" content="IE=Edge" />
|
<meta http-equiv="X-UA-Compatible" content="IE=Edge" />
|
||||||
<link rel="stylesheet" href="./static/iconfont.css" />
|
<link rel="stylesheet" href="./static/iconfont.css" />
|
||||||
|
<link rel="stylesheet" href="./static/officefont.css" />
|
||||||
<link rel="stylesheet" href="@fortawesome/fontawesome-free/css/all.css" />
|
<link rel="stylesheet" href="@fortawesome/fontawesome-free/css/all.css" />
|
||||||
<link rel="stylesheet" href="@fortawesome/fontawesome-free/css/v4-shims.css" />
|
<link
|
||||||
|
rel="stylesheet"
|
||||||
|
href="@fortawesome/fontawesome-free/css/v4-shims.css"
|
||||||
|
/>
|
||||||
<link rel="stylesheet" href="prismjs/themes/prism.css" />
|
<link rel="stylesheet" href="prismjs/themes/prism.css" />
|
||||||
<!--DEPENDENCIES_INJECT_PLACEHOLDER-->
|
<!--DEPENDENCIES_INJECT_PLACEHOLDER-->
|
||||||
<link rel="stylesheet" href="./doc.css" />
|
<link rel="stylesheet" href="./doc.css" />
|
||||||
@ -112,5 +118,4 @@
|
|||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
</html>
|
</html>
|
@ -13,7 +13,7 @@
|
|||||||
'classnames': __moduleId('classnames'),
|
'classnames': __moduleId('classnames'),
|
||||||
'axios': __moduleId('axios'),
|
'axios': __moduleId('axios'),
|
||||||
'exceljs': __moduleId('exceljs'),
|
'exceljs': __moduleId('exceljs'),
|
||||||
'office-viewer': __moduleId('office-viewer'),
|
'fflate': __moduleId('fflate'),
|
||||||
'moment': __moduleId('moment'),
|
'moment': __moduleId('moment'),
|
||||||
'mobx': __moduleId('mobx'),
|
'mobx': __moduleId('mobx'),
|
||||||
'mobx-state-tree': __moduleId('mobx-state-tree'),
|
'mobx-state-tree': __moduleId('mobx-state-tree'),
|
||||||
|
BIN
examples/static/font/symbol.ttf
Executable file
BIN
examples/static/font/symbol.ttf
Executable file
Binary file not shown.
BIN
examples/static/font/wingding.ttf
Executable file
BIN
examples/static/font/wingding.ttf
Executable file
Binary file not shown.
9
examples/static/officefont.css
Normal file
9
examples/static/officefont.css
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
@font-face {
|
||||||
|
font-family: Wingdings;
|
||||||
|
src: url(font/wingding.ttf);
|
||||||
|
}
|
||||||
|
|
||||||
|
@font-face {
|
||||||
|
font-family: Symbol;
|
||||||
|
src: url(font/symbol.ttf);
|
||||||
|
}
|
Binary file not shown.
@ -73,6 +73,7 @@ fis.set('project.files', [
|
|||||||
'/examples/static/photo/*.png',
|
'/examples/static/photo/*.png',
|
||||||
'/examples/static/audio/*.mp3',
|
'/examples/static/audio/*.mp3',
|
||||||
'/examples/static/video/*.mp4',
|
'/examples/static/video/*.mp4',
|
||||||
|
'/examples/static/font/*.ttf',
|
||||||
'mock/**'
|
'mock/**'
|
||||||
]);
|
]);
|
||||||
|
|
||||||
@ -862,7 +863,8 @@ if (fis.project.currentMedia() === 'publish-sdk') {
|
|||||||
'!mdurl/**',
|
'!mdurl/**',
|
||||||
'!uc.micro/**',
|
'!uc.micro/**',
|
||||||
'!markdown-it/**',
|
'!markdown-it/**',
|
||||||
'!markdown-it-html5-media/**'
|
'!markdown-it-html5-media/**',
|
||||||
|
'!fflate/**'
|
||||||
],
|
],
|
||||||
|
|
||||||
'pkg/npm.css': ['node_modules/*/**.css', '!monaco-editor/**'],
|
'pkg/npm.css': ['node_modules/*/**.css', '!monaco-editor/**'],
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
/>
|
/>
|
||||||
<meta http-equiv="X-UA-Compatible" content="IE=Edge" />
|
<meta http-equiv="X-UA-Compatible" content="IE=Edge" />
|
||||||
<link rel="stylesheet" href="./examples/static/iconfont.css" />
|
<link rel="stylesheet" href="./examples/static/iconfont.css" />
|
||||||
|
<link rel="stylesheet" href="./examples/static/officefont.css" />
|
||||||
<link
|
<link
|
||||||
rel="stylesheet"
|
rel="stylesheet"
|
||||||
href="./node_modules/@fortawesome/fontawesome-free/css/all.css"
|
href="./node_modules/@fortawesome/fontawesome-free/css/all.css"
|
||||||
|
@ -38,6 +38,7 @@
|
|||||||
"@types/js-yaml": "^4.0.5",
|
"@types/js-yaml": "^4.0.5",
|
||||||
"@types/marked": "^4.0.7",
|
"@types/marked": "^4.0.7",
|
||||||
"@types/prismjs": "^1.26.0",
|
"@types/prismjs": "^1.26.0",
|
||||||
|
"@types/react": "^18.0.24",
|
||||||
"@types/react-dom": "^18.0.8",
|
"@types/react-dom": "^18.0.8",
|
||||||
"@vitejs/plugin-react": "^2.2.0",
|
"@vitejs/plugin-react": "^2.2.0",
|
||||||
"copy-to-clipboard": "3.3.1",
|
"copy-to-clipboard": "3.3.1",
|
||||||
|
@ -17,8 +17,8 @@
|
|||||||
"@types/file-saver": "^2.0.1",
|
"@types/file-saver": "^2.0.1",
|
||||||
"@types/hoist-non-react-statics": "^3.3.1",
|
"@types/hoist-non-react-statics": "^3.3.1",
|
||||||
"@types/jest": "^28.1.0",
|
"@types/jest": "^28.1.0",
|
||||||
"@types/react": "^17.0.39",
|
"@types/react": "^18.0.24",
|
||||||
"@types/react-dom": "^17.0.11",
|
"@types/react-dom": "^18.0.8",
|
||||||
"immutable": "^4.1.0",
|
"immutable": "^4.1.0",
|
||||||
"jest": "^29.0.3",
|
"jest": "^29.0.3",
|
||||||
"jest-environment-jsdom": "^29.0.3",
|
"jest-environment-jsdom": "^29.0.3",
|
||||||
|
3
packages/amis-editor-core/.gitignore
vendored
Normal file
3
packages/amis-editor-core/.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
/coverage
|
||||||
|
/lib
|
||||||
|
/esm
|
3
packages/amis-editor/.gitignore
vendored
Normal file
3
packages/amis-editor/.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
/coverage
|
||||||
|
/lib
|
||||||
|
/esm
|
@ -80,8 +80,8 @@
|
|||||||
"@testing-library/jest-dom": "^5.16.4",
|
"@testing-library/jest-dom": "^5.16.4",
|
||||||
"@types/babel__core": "^7.1.19",
|
"@types/babel__core": "^7.1.19",
|
||||||
"@types/jest": "^28.1.0",
|
"@types/jest": "^28.1.0",
|
||||||
"@types/react": "^17.0.39",
|
"@types/react": "^18.0.24",
|
||||||
"@types/react-dom": "^17.0.11",
|
"@types/react-dom": "^18.0.8",
|
||||||
"autoprefixer": "^10.4.12",
|
"autoprefixer": "^10.4.12",
|
||||||
"jest": "^29.0.3",
|
"jest": "^29.0.3",
|
||||||
"jest-environment-jsdom": "^29.0.3",
|
"jest-environment-jsdom": "^29.0.3",
|
||||||
|
@ -100,9 +100,9 @@
|
|||||||
"@types/papaparse": "^5.2.2",
|
"@types/papaparse": "^5.2.2",
|
||||||
"@types/prop-types": "^15.5.2",
|
"@types/prop-types": "^15.5.2",
|
||||||
"@types/qs": "^6.5.1",
|
"@types/qs": "^6.5.1",
|
||||||
"@types/react": "^17.0.39",
|
"@types/react": "^18.0.24",
|
||||||
"@types/react-color": "^3.0.5",
|
"@types/react-color": "^3.0.5",
|
||||||
"@types/react-dom": "^17.0.11",
|
"@types/react-dom": "^18.0.8",
|
||||||
"@types/react-onclickoutside": "^6.0.2",
|
"@types/react-onclickoutside": "^6.0.2",
|
||||||
"@types/react-router-dom": "^5.3.3",
|
"@types/react-router-dom": "^5.3.3",
|
||||||
"@types/react-test-renderer": "^17.0.1",
|
"@types/react-test-renderer": "^17.0.1",
|
||||||
|
@ -29,7 +29,6 @@ const external = id => {
|
|||||||
'react-dom',
|
'react-dom',
|
||||||
'rc-input-number',
|
'rc-input-number',
|
||||||
'@rc-component/mini-decimal',
|
'@rc-component/mini-decimal',
|
||||||
'fflate',
|
|
||||||
'@babel/runtime'
|
'@babel/runtime'
|
||||||
])
|
])
|
||||||
.map(value =>
|
.map(value =>
|
||||||
|
@ -11,9 +11,9 @@ import {
|
|||||||
Renderer,
|
Renderer,
|
||||||
RendererProps,
|
RendererProps,
|
||||||
resolveVariableAndFilter,
|
resolveVariableAndFilter,
|
||||||
ScopedContext,
|
ScopedContext
|
||||||
ServiceStore
|
|
||||||
} from 'amis-core';
|
} from 'amis-core';
|
||||||
|
import type {Word} from 'office-viewer';
|
||||||
|
|
||||||
export interface OfficeViewerSchema extends BaseSchema {
|
export interface OfficeViewerSchema extends BaseSchema {
|
||||||
type: 'office-viewer';
|
type: 'office-viewer';
|
||||||
@ -154,6 +154,7 @@ export default class OfficeViewer extends React.Component<
|
|||||||
const data = reader.result as ArrayBuffer;
|
const data = reader.result as ArrayBuffer;
|
||||||
|
|
||||||
import('office-viewer').then(async (officeViewer: any) => {
|
import('office-viewer').then(async (officeViewer: any) => {
|
||||||
|
const Word = officeViewer.Word;
|
||||||
const word = new Word(data, {
|
const word = new Word(data, {
|
||||||
...wordOptions,
|
...wordOptions,
|
||||||
replaceText: this.replaceText.bind(this)
|
replaceText: this.replaceText.bind(this)
|
||||||
@ -162,7 +163,6 @@ export default class OfficeViewer extends React.Component<
|
|||||||
word.render(this.rootElement?.current!);
|
word.render(this.rootElement?.current!);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
};
|
};
|
||||||
reader.readAsArrayBuffer(file);
|
reader.readAsArrayBuffer(file);
|
||||||
}
|
}
|
||||||
|
8
packages/office-viewer/.gitignore
vendored
8
packages/office-viewer/.gitignore
vendored
@ -1,9 +1,3 @@
|
|||||||
/dist
|
|
||||||
lib
|
|
||||||
sdk
|
|
||||||
/public
|
|
||||||
/gh-pages
|
|
||||||
/output
|
|
||||||
/coverage
|
/coverage
|
||||||
/npm
|
/lib
|
||||||
/esm
|
/esm
|
||||||
|
@ -53,7 +53,6 @@ test('font hint', async () => {
|
|||||||
|
|
||||||
const word = await createWord();
|
const word = await createWord();
|
||||||
mergeRun(word, xmlDoc);
|
mergeRun(word, xmlDoc);
|
||||||
console.log(buildXML(xmlDoc));
|
|
||||||
expect(xmlDoc.getElementsByTagName('w:t')[0]?.innerHTML).toBe('B6');
|
expect(xmlDoc.getElementsByTagName('w:t')[0]?.innerHTML).toBe('B6');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Binary file not shown.
@ -27,6 +27,7 @@ body {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.file-list {
|
.file-list {
|
||||||
|
flex: none;
|
||||||
width: 140px;
|
width: 140px;
|
||||||
padding-top: 4px;
|
padding-top: 4px;
|
||||||
padding-left: 4px;
|
padding-left: 4px;
|
||||||
|
@ -189,6 +189,10 @@ export class Tc {
|
|||||||
parseTextDirection(child, style);
|
parseTextDirection(child, style);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'w:cnfStyle':
|
||||||
|
// 目前是自动计算的,所以不需要这个了
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
console.warn('parseTcPr: ignore', tagName, child);
|
console.warn('parseTcPr: ignore', tagName, child);
|
||||||
}
|
}
|
||||||
|
@ -54,6 +54,10 @@ export class Tr {
|
|||||||
parseTblCellSpacing(child, tcStyle);
|
parseTblCellSpacing(child, tcStyle);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'w:cnfStyle':
|
||||||
|
// 目前是自动计算的,所以不需要这个了
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
console.warn(`Tr: Unknown tag `, tagName, child);
|
console.warn(`Tr: Unknown tag `, tagName, child);
|
||||||
}
|
}
|
||||||
|
@ -339,6 +339,10 @@ export function parsePr(word: Word, element: Element, type: 'r' | 'p' = 'p') {
|
|||||||
parseTextDirection(child, style);
|
parseTextDirection(child, style);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'w:cnfStyle':
|
||||||
|
// 目前是自动计算的,所以不需要这个了
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
console.warn('parsePr Unknown tagName', tagName, child);
|
console.warn('parsePr Unknown tagName', tagName, child);
|
||||||
}
|
}
|
||||||
|
@ -109,6 +109,12 @@ export function renderNumbering(
|
|||||||
ilvlData[ilvl] = lvl.start;
|
ilvlData[ilvl] = lvl.start;
|
||||||
} else {
|
} else {
|
||||||
ilvlData[ilvl] += 1;
|
ilvlData[ilvl] += 1;
|
||||||
|
// 加一之后,将比它大的都清空,这样才能每个级别重置
|
||||||
|
for (const ilvIndex in ilvlData) {
|
||||||
|
if (parseInt(ilvIndex) > parseInt(ilvl)) {
|
||||||
|
ilvlData[ilvIndex] = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const element = createElement('span');
|
const element = createElement('span');
|
||||||
|
@ -84,10 +84,6 @@ export default defineConfig({
|
|||||||
{
|
{
|
||||||
find: 'office-viewer',
|
find: 'office-viewer',
|
||||||
replacement: path.resolve(__dirname, './packages/office-viewer/src')
|
replacement: path.resolve(__dirname, './packages/office-viewer/src')
|
||||||
},
|
|
||||||
{
|
|
||||||
find: 'office-viewer/lib',
|
|
||||||
replacement: path.resolve(__dirname, './packages/office-viewer/src')
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user