diff --git a/docs/zh-CN/components/office-viewer.md b/docs/zh-CN/components/office-viewer.md index bdaa11d52..ebe69484d 100644 --- a/docs/zh-CN/components/office-viewer.md +++ b/docs/zh-CN/components/office-viewer.md @@ -8,6 +8,8 @@ icon: order: 23 --- +> 2.9.0 及以上版本 + 用于渲染 office 文档,目前只支持 docx 格式,通过前端转成 HTML 的方式进行渲染,支持以下功能: - 基础文本样式 @@ -30,7 +32,10 @@ order: 23 ```schema: scope="body" { "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", "id": "office-viewer", - "src": "/examples/static/info.docx", + "src": "https://suda.cdn.bcebos.com/docx/info.docx", "wordOptions": { "enableVar": true, "padding": "8px" @@ -127,7 +132,7 @@ order: 23 { "type": "office-viewer", "id": "office-viewer", - "src": "/examples/static/info.docx", + "src": "https://suda.cdn.bcebos.com/docx/info.docx", "wordOptions": { "padding": "8px" } @@ -168,7 +173,7 @@ order: 23 "type": "office-viewer", "id": "office-viewer-download", "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", "id": "office-viewer-print", "display": false, - "src": "/examples/static/example.docx" + "src": "https://suda.cdn.bcebos.com/docx/simple.docx" } ] ``` diff --git a/examples/app/index-vite.html b/examples/app/index-vite.html index 194fdfa81..cf43d7561 100644 --- a/examples/app/index-vite.html +++ b/examples/app/index-vite.html @@ -15,6 +15,7 @@ /> + + + + + amis - 低代码前端框架 + + + + + + + + + + + - - - amis - 低代码前端框架 - - - - - - - - - - - - - - - - - - - + + + + - -
- - + - - - \ No newline at end of file + /* @require ./index.jsx 标记为同步依赖,提前加载 */ + amis.require(['./index.jsx'], function (app) { + var initialState = {}; + app.bootstrap(document.getElementById('root'), initialState); + }); + + + diff --git a/examples/loader.ts b/examples/loader.ts index ff7a6c50b..d7929f6ae 100644 --- a/examples/loader.ts +++ b/examples/loader.ts @@ -13,7 +13,7 @@ 'classnames': __moduleId('classnames'), 'axios': __moduleId('axios'), 'exceljs': __moduleId('exceljs'), - 'office-viewer': __moduleId('office-viewer'), + 'fflate': __moduleId('fflate'), 'moment': __moduleId('moment'), 'mobx': __moduleId('mobx'), 'mobx-state-tree': __moduleId('mobx-state-tree'), diff --git a/examples/static/font/symbol.ttf b/examples/static/font/symbol.ttf new file mode 100755 index 000000000..897384ab5 Binary files /dev/null and b/examples/static/font/symbol.ttf differ diff --git a/examples/static/font/wingding.ttf b/examples/static/font/wingding.ttf new file mode 100755 index 000000000..6e38f7fdd Binary files /dev/null and b/examples/static/font/wingding.ttf differ diff --git a/examples/static/officefont.css b/examples/static/officefont.css new file mode 100644 index 000000000..d2f071405 --- /dev/null +++ b/examples/static/officefont.css @@ -0,0 +1,9 @@ +@font-face { + font-family: Wingdings; + src: url(font/wingding.ttf); +} + +@font-face { + font-family: Symbol; + src: url(font/symbol.ttf); +} diff --git a/examples/static/example.docx b/examples/static/simple.docx similarity index 83% rename from examples/static/example.docx rename to examples/static/simple.docx index 8294aa13d..1574460b6 100644 Binary files a/examples/static/example.docx and b/examples/static/simple.docx differ diff --git a/fis-conf.js b/fis-conf.js index 92836b540..dd0eb78fd 100644 --- a/fis-conf.js +++ b/fis-conf.js @@ -73,6 +73,7 @@ fis.set('project.files', [ '/examples/static/photo/*.png', '/examples/static/audio/*.mp3', '/examples/static/video/*.mp4', + '/examples/static/font/*.ttf', 'mock/**' ]); @@ -862,7 +863,8 @@ if (fis.project.currentMedia() === 'publish-sdk') { '!mdurl/**', '!uc.micro/**', '!markdown-it/**', - '!markdown-it-html5-media/**' + '!markdown-it-html5-media/**', + '!fflate/**' ], 'pkg/npm.css': ['node_modules/*/**.css', '!monaco-editor/**'], diff --git a/index.html b/index.html index ec5f8809c..599515299 100644 --- a/index.html +++ b/index.html @@ -15,6 +15,7 @@ /> + { 'react-dom', 'rc-input-number', '@rc-component/mini-decimal', - 'fflate', '@babel/runtime' ]) .map(value => diff --git a/packages/amis/src/renderers/OfficeViewer.tsx b/packages/amis/src/renderers/OfficeViewer.tsx index d01029a09..fe94e6469 100644 --- a/packages/amis/src/renderers/OfficeViewer.tsx +++ b/packages/amis/src/renderers/OfficeViewer.tsx @@ -11,9 +11,9 @@ import { Renderer, RendererProps, resolveVariableAndFilter, - ScopedContext, - ServiceStore + ScopedContext } from 'amis-core'; +import type {Word} from 'office-viewer'; export interface OfficeViewerSchema extends BaseSchema { type: 'office-viewer'; @@ -154,6 +154,7 @@ export default class OfficeViewer extends React.Component< const data = reader.result as ArrayBuffer; import('office-viewer').then(async (officeViewer: any) => { + const Word = officeViewer.Word; const word = new Word(data, { ...wordOptions, replaceText: this.replaceText.bind(this) @@ -162,7 +163,6 @@ export default class OfficeViewer extends React.Component< word.render(this.rootElement?.current!); } }); - }; reader.readAsArrayBuffer(file); } diff --git a/packages/office-viewer/.gitignore b/packages/office-viewer/.gitignore index 21ba09598..955d7bb36 100644 --- a/packages/office-viewer/.gitignore +++ b/packages/office-viewer/.gitignore @@ -1,9 +1,3 @@ -/dist -lib -sdk -/public -/gh-pages -/output /coverage -/npm +/lib /esm diff --git a/packages/office-viewer/__tests__/OpenXML.test.ts b/packages/office-viewer/__tests__/OpenXML.test.ts index e1ed9872c..e25c73d81 100644 --- a/packages/office-viewer/__tests__/OpenXML.test.ts +++ b/packages/office-viewer/__tests__/OpenXML.test.ts @@ -53,7 +53,6 @@ test('font hint', async () => { const word = await createWord(); mergeRun(word, xmlDoc); - console.log(buildXML(xmlDoc)); expect(xmlDoc.getElementsByTagName('w:t')[0]?.innerHTML).toBe('B6'); }); diff --git a/packages/office-viewer/__tests__/docx/simple/helloworld.docx b/packages/office-viewer/__tests__/docx/simple/helloworld.docx index 3ec70b090..5ad73c1d8 100644 Binary files a/packages/office-viewer/__tests__/docx/simple/helloworld.docx and b/packages/office-viewer/__tests__/docx/simple/helloworld.docx differ diff --git a/packages/office-viewer/examples/static/css/app.css b/packages/office-viewer/examples/static/css/app.css index a443acdf2..25a8589d4 100644 --- a/packages/office-viewer/examples/static/css/app.css +++ b/packages/office-viewer/examples/static/css/app.css @@ -27,6 +27,7 @@ body { } .file-list { + flex: none; width: 140px; padding-top: 4px; padding-left: 4px; diff --git a/packages/office-viewer/src/openxml/word/table/Tc.ts b/packages/office-viewer/src/openxml/word/table/Tc.ts index 0143afffc..72bcd3a5d 100644 --- a/packages/office-viewer/src/openxml/word/table/Tc.ts +++ b/packages/office-viewer/src/openxml/word/table/Tc.ts @@ -189,6 +189,10 @@ export class Tc { parseTextDirection(child, style); break; + case 'w:cnfStyle': + // 目前是自动计算的,所以不需要这个了 + break; + default: console.warn('parseTcPr: ignore', tagName, child); } diff --git a/packages/office-viewer/src/openxml/word/table/Tr.ts b/packages/office-viewer/src/openxml/word/table/Tr.ts index 0403c86c6..4342dc26f 100644 --- a/packages/office-viewer/src/openxml/word/table/Tr.ts +++ b/packages/office-viewer/src/openxml/word/table/Tr.ts @@ -54,6 +54,10 @@ export class Tr { parseTblCellSpacing(child, tcStyle); break; + case 'w:cnfStyle': + // 目前是自动计算的,所以不需要这个了 + break; + default: console.warn(`Tr: Unknown tag `, tagName, child); } diff --git a/packages/office-viewer/src/parse/parsePr.ts b/packages/office-viewer/src/parse/parsePr.ts index 4d29f6e1d..209cebed9 100644 --- a/packages/office-viewer/src/parse/parsePr.ts +++ b/packages/office-viewer/src/parse/parsePr.ts @@ -339,6 +339,10 @@ export function parsePr(word: Word, element: Element, type: 'r' | 'p' = 'p') { parseTextDirection(child, style); break; + case 'w:cnfStyle': + // 目前是自动计算的,所以不需要这个了 + break; + default: console.warn('parsePr Unknown tagName', tagName, child); } diff --git a/packages/office-viewer/src/render/renderNumbering.ts b/packages/office-viewer/src/render/renderNumbering.ts index eeb1e05c5..6e817e2c5 100644 --- a/packages/office-viewer/src/render/renderNumbering.ts +++ b/packages/office-viewer/src/render/renderNumbering.ts @@ -109,6 +109,12 @@ export function renderNumbering( ilvlData[ilvl] = lvl.start; } else { ilvlData[ilvl] += 1; + // 加一之后,将比它大的都清空,这样才能每个级别重置 + for (const ilvIndex in ilvlData) { + if (parseInt(ilvIndex) > parseInt(ilvl)) { + ilvlData[ilvIndex] = 0; + } + } } const element = createElement('span'); diff --git a/vite.config.ts b/vite.config.ts index e0913a4c6..b5763cef2 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -84,10 +84,6 @@ export default defineConfig({ { find: 'office-viewer', replacement: path.resolve(__dirname, './packages/office-viewer/src') - }, - { - find: 'office-viewer/lib', - replacement: path.resolve(__dirname, './packages/office-viewer/src') } ] }