amis/packages/office-viewer/examples/app.ts
吴多益 85bae586a9
feat: office-viewer Word 文档渲染 (#6412)
* init

* theme

* 基础文本渲染

* 基础文本样式

* 支持简单链接和图片

* 修复 jc 解析不正确问题

* 解析和渲染分离

* 初步支持列表渲染

* 完善样式表的实现

* 表格解析初步

* 避免解析顺序不一致

* 避免解析顺序不一致导致的问题

* 基于 DOMParser 来实现解析; 初步实现表格渲染

* 修复行高解析不正确问题

* 修复变量替换不正确问题

* 补充注释

* 用 fflate 替换 jszip, 支持同步使用

* 支持渲染 tab

* 支持表格条件渲染

* 优化表格样式适配

* 完善背景色支持

* 支持 ruby

* 支持简单 inserttext

* 修复表格合并不正确问题

* amis 渲染初步

* 整合 amis 初步

* 支持 input-file 上传预览

* styles: 优化button组件单icon情况的样式 (#6269)

Co-authored-by: qinhaoyan <30946345+qinhaoyan@users.noreply.github.com>

* fix: Badge设置overflowCount不生效问题修复 (#6267)

Co-authored-by: wanglinfang <wanglinfang@baidu.com>

* feat: InputGroup报错展示优化 (#5803)

* feat:增加DATETOWEEK表达式

* feat:增加DATETOWEEK表达式

* feat:增加WEEKDAY和WEEK表达式

* feat:增加WEEKDAY和WEEK表达式

* feat:增加WEEKDAY和WEEK表达式

* feat:增加WEEKDAY和WEEK表达式

* feat:增加WEEKDAY和WEEK表达式

* chore: 2.7.3版本改为2.8.0 (#6272)

* styles: 输入框附加组件样式 (#6271)

Co-authored-by: qinhaoyan <30946345+qinhaoyan@users.noreply.github.com>

* styles: 优化checkbox组件选中态样式 (#6277)

Co-authored-by: qinhaoyan <30946345+qinhaoyan@users.noreply.github.com>

* feat:增加判断日期范围的表达式BETWEENRANGE&&优化STARTOF和ENDOF

* docs:表达式文档 (#6282)

* fix: Nav样式问题、性能优化 (#6280)

Co-authored-by: wanglinfang <wanglinfang@baidu.com>

* chore: 还原几个 antd 导航及表格的颜色 (#6276)

* chore: Action倒计时key添加id避免冲突 (#5943)

* fix: nav同层拖拽问题修复 (#6285)

Co-authored-by: wanglinfang <wanglinfang@baidu.com>

* v2.8.0

* chore: 删除在 ts 编译后永远都不会成立的代码 (#6291)

* styles: 将组件透明背景颜色改为白色 (#6289)

* styles: 将组件透明背景颜色改为白色

* styles: 将组件透明背景颜色改为白色

---------

Co-authored-by: qinhaoyan <30946345+qinhaoyan@users.noreply.github.com>

* fix: Select组件overlay属性在popOverContainer时宽度错误问题 (#6284)

* fix:Select组件overlay属性在popOverContainer时宽度错误问题

* 问题修改

* styles: 优化link组件svg图标样式 (#6292)

Co-authored-by: qinhaoyan <30946345+qinhaoyan@users.noreply.github.com>

* chore: Tree 组件中使用 value 替换 key (#6194)

* fix: 单选选项值包含逗号时获取选项错误问题 (#6258)

* fix: 单选选项值包含逗号时获取选项错误问题

* 加个单测

* 单测问题

* 在WrapControl 中使渲染器默认 multiple 生效

* 修改

* fix: select 各种模式支持 checkAll (#5941)

* feat(页面交互行为跟踪): 新增pageLoaded事件 (#6299)

* fix: nav拖拽卡顿、更多操作打开定位等问题修复 (#6304)

Co-authored-by: wanglinfang <wanglinfang@baidu.com>

* fix: toast组件css变量拼错 (#6302)

Co-authored-by: renjianhua <renjianhua@zuoshouyisheng.com>

* fix: CRUD2 加载更多时接口page传参始终为1 (#6298)

* fix: 日期范围底部按钮居中 (#6301)

* 调整 saveAs  fileName 优先级

* feat: 移动端人员选择增加确定按钮

* Update UserSelect.tsx

* fix: 人员选择ts 类型错误

* fix: 城市选择组件移动端回显问题

* fix: 移动端级联选择器选中值bug修复

* Update Cascader.tsx

* fix: 城市选择香港、澳门不能选择市

* fix: 删除错误城市数据

* feat: 移动端人员选择支持字段配置

* feat: 人员选择组件支持字段配置

* Update UserSelect.tsx

* fix: 移动端人员选择静态展示头像url回显

* fix: 日期时间选择器底部按钮居中

---------

Co-authored-by: zhangxulong <zhangxulong@baidu.com>

* fix: table2全选、嵌套展开等问题修复 (#6313)

Co-authored-by: wanglinfang <wanglinfang@baidu.com>

* docs(API 适配器): 调整文档细节 (#6314)

* styles: 优化清除图标样式 (#6312)

Co-authored-by: qinhaoyan <30946345+qinhaoyan@users.noreply.github.com>

* fix: 修复 Tree 在传入 pathSeparator 时,非根节点无法选中 (#6315)

* Update README.md

* fix: 解决因部分组件默认配置,导致编辑器配置面板宽度溢出问题 (#6328)

Co-authored-by: zhangzhulei <zhangzhulei@baidu.com>

* chore: svg 瘦身 (#6320)

* chore: svg 瘦身

* chore: svg 瘦身

* chore: svg 瘦身

* feat: mapping 的 source 接口支持 select 选项类接口 (#6326)

* fix: 调整 spinner-overlay 和 dialog 的 z-index,使关闭按钮不会被 spinner 遮挡 (#6321)

* feat: 新增 number 组件用来展示数字 (#6330)

* feat: 新增 number 组件用来展示数字

* feat: 新增 number 组件用来展示数字

* chore: tableCell 内部属性换个名字,以免跟已有其他组件组合使用时冲突

* fix: 注销renderer问题 (#6327)

Co-authored-by: liujintao03 <liujintao03@baidu.com>

* feat: InputExcel支持placeholder (#6295)

* feat: button-group-select支持角标 (#6309)

Co-authored-by: yanglu19 <yanglu19@baidu.com>

* chore: 暴露 InputBoxWithSuggestion (#6337)

* fix: 注销renderer问题 (#6338)

Co-authored-by: liujintao03 <liujintao03@baidu.com>

* docs: 补充trackExpression用法示例 (#6286)

* fix: 解决monaco环境变量和monaco插件的冲突 (#6283)

Co-authored-by: renjianhua <renjianhua@zuoshouyisheng.com>

* fix: Cards嵌套List组件时, props透传导致Schema不生效问题 (#6110)

* styles: 优化带单位的number组件样式 (#6054)

* styles: 优化待单位的number组件样式

* 更新快照

---------

Co-authored-by: qinhaoyan <30946345+qinhaoyan@users.noreply.github.com>

* fix(Table): #2978 嵌套表格如何设置默认全部展开 (#6028)

* fix(Table): #2978 嵌套表格如何设置默认全部展开

* fix(Table): #2978 更改函数命名

* fix: now表达式作为form组件默认值时,增加特殊逻辑,处理数据更新 (#5783)

* fix: 解决公式编辑器 搜索变量失效bug (#6345)

Co-authored-by: zhangzhulei <zhangzhulei@baidu.com>

* fix: nav角标、悬浮展开子菜单、更多操作不可点击等问题修复 (#6346)

Co-authored-by: wanglinfang <wanglinfang@baidu.com>

* feat:config动作优化

* fix: 修复卡片的 checkOnItemClick 配置问题 (#6365)

* fix: 修复弹窗中 form 配置 closeDialogOnSubmit 无效的问题 (#6368)

* fix: Transfer tree mode 支持 onlyChildren;两个值为undefined的Option不相等 (#6342)

* fix:transfer tree 支持 onlyChildren;两个值为undefined的Option不相等

* 修改

* 修改

* feat:carousel支持卡片动画模式 (#6354)

* feat:carousel支持多图配置

* Update carousel.md

---------

Co-authored-by: zhaowenli <zhaowenli@baidu.com>
Co-authored-by: RUNZE LU <36724300+lurunze1226@users.noreply.github.com>

* fix: inputTable 组件value依赖别的字段时,不同步数据域的问题 (#6360)

* fix: inputTable 组件value依赖别的字段时,不同步数据域的问题

* 修改

* 修改

* feat: 添加input-table子表单校验 (#6357)

* feat: 添加input-table子表单校验

* feat: 添加input-table snapshots更新

* feat: 添加input-table子表单校验

* feat: 添加input-table子表单校验

* feat: 添加input-table子表单校验

* feat: input-table snapshots更新

* feat: 添加input-table子表单校验

* feat: 添加input-table子表单校验

* feat: Steps source支持动态获取value status (#6370)

* fix: 修复 drawer reload 目标可能找不到的问题 (#6373)

* fix: 修复 crud 嵌套会触发多次快速保存接口问题 (#6374)

* fix: 修复 this.model.validated 可能读取不到的报错 (#6375)

* chore: alert 支持多个实例

* feat: Tag支持事件动作 (#6325)

* feat: reload 支持动态目标, 解决目标在循环中场景 (#6372)

* chore: Select组件checkAllBySearch默认为true (#6347)

* fix: Nav切换数据源实时更新、点击分组卡顿、横向模式排序等问题修复 (#6371)

Co-authored-by: wanglinfang <wanglinfang@baidu.com>

* fix: table单元格支持自定义样式、crud支持本地数据快速过滤 (#6353)

Co-authored-by: wanglinfang <wanglinfang@baidu.com>

* fix: 修改角标样式 (#6383)

Co-authored-by: yanglu19 <yanglu19@baidu.com>

* fix: 图标选择器,如果图标不属于saas项目中的,则默认显示schema配置的内容 (#6394)

Co-authored-by: zhangzhulei <zhangzhulei@baidu.com>

* feat: icon支持自定义样式 (#6379)

Co-authored-by: sarding <hongfuquan@baidu.com>

* fix: 解决input-table某些场景下无法新增的bug (#6400)

Co-authored-by: zhangzhulei <zhangzhulei@baidu.com>

* fix: 解决input-table某些场景下无法新增的bug (#6404)

Co-authored-by: zhangzhulei <zhangzhulei@baidu.com>

* fix: input-table内columns为下拉框时,删掉下拉框的选中值,发现input-table的数据域更新错误 (#6402)

* fix: input-table内columns为下拉框时,删掉下拉框的选中值,发现input-table的数据域更新错误

* fix: input-table内columns为下拉框时,删掉下拉框的选中值,发现input-table的数据域更新错误

* 修复示例文档错误

* 修复用例报错

* 修复 fis 报错

---------

Co-authored-by: qkiroc <30946345+qkiroc@users.noreply.github.com>
Co-authored-by: qinhaoyan <30946345+qinhaoyan@users.noreply.github.com>
Co-authored-by: wanglinfang2014 <w.l.fang@foxmail.com>
Co-authored-by: wanglinfang <wanglinfang@baidu.com>
Co-authored-by: RUNZE LU <36724300+lurunze1226@users.noreply.github.com>
Co-authored-by: lvxiaojiao <lvxiaojiao@baidu.com>
Co-authored-by: hsm-lv <80095014+hsm-lv@users.noreply.github.com>
Co-authored-by: lurunze1226 <lurunze1226@foxmail.com>
Co-authored-by: liaoxuezhi <2betop.cn@gmail.com>
Co-authored-by: sansiro <sansiro@sansiro.me>
Co-authored-by: meerkat <kit_hack@outlook.com>
Co-authored-by: 刘丹 <365533093@qq.com>
Co-authored-by: backpast <agileago@gmail.com>
Co-authored-by: renjianhua <renjianhua@zuoshouyisheng.com>
Co-authored-by: ls <1769057083@qq.com>
Co-authored-by: zhangxulong <zhangxulong@baidu.com>
Co-authored-by: zhangzhulei <30931358+DynaZhang@users.noreply.github.com>
Co-authored-by: zhangzhulei <zhangzhulei@baidu.com>
Co-authored-by: gooolh <57032082+gooolh@users.noreply.github.com>
Co-authored-by: liujintao03 <liujintao03@baidu.com>
Co-authored-by: Dora <53067150+Dora-boots@users.noreply.github.com>
Co-authored-by: yanglu19 <yanglu19@baidu.com>
Co-authored-by: TommyShao <tomieric@gmail.com>
Co-authored-by: pianruijie <13522335863@163.com>
Co-authored-by: xiangwaner <1186355501@qq.com>
Co-authored-by: zhaowenli <zhaowenli@baidu.com>
Co-authored-by: zhou999 <zhousq809@163.com>
Co-authored-by: Allen <yupeng.fe@qq.com>
Co-authored-by: sarding <37691952+sarding@users.noreply.github.com>
Co-authored-by: sarding <hongfuquan@baidu.com>
2023-03-20 20:09:13 +08:00

119 lines
2.8 KiB
TypeScript

/**
* 本地测试例子
*/
import XMLPackageParser from '../src/package/XMLPackageParser';
import Word from '../src/Word';
const viewerElement = document.getElementById('viewer') as HTMLElement;
const testDir = '__tests__/docx';
const fileLists = {
simple: [
'helloworld.docx',
'list.docx',
'tableborder.docx',
'tablestyle.docx',
'pinyin.docx'
],
docx4j: [
'ArialUnicodeMS.docx',
'DOCPROP_builtin.docx',
'FontEmbedded.docx',
'Headers.docx',
'Images.docx',
'Symbols.docx',
'Word2007-fonts.docx',
'chart.docx',
'chunk.docx',
'decracdiscrim1.docx',
'docProps.docx',
'fonts-modesOfApplication.docx',
'hyperlinks-internal.docx',
'sample-docx.docx',
'sample-docxv2.docx',
'tableborder.docx',
'tables.docx',
'toc.docx',
'unmarshallFromTemplateDirtyExample.docx',
'unmarshallFromTemplateExample.docx',
'numberingrestart.xml',
'sample-docx.xml',
'table-features.xml',
'table-spans.xml'
]
};
/**
* 生成左侧文件列表
*/
(function genFileList() {
const fileListElement = document.getElementById('fileList')!;
for (const dirName in fileLists) {
fileListElement.innerHTML += `<h2 class="dir">${dirName}</h2>`;
const dir = dirName as keyof typeof fileLists;
for (const file of fileLists[dir]) {
const fileName = file.split('.')[0];
fileListElement.innerHTML += `<div class="file" data-path="${dirName}/${file}" title="${file}">${fileName}</div>`;
}
}
document.querySelectorAll('.file').forEach(file => {
file.addEventListener('click', elm => {
const fileName = (elm.target as Element).getAttribute('data-path')!;
history.pushState({fileName}, fileName, `?file=${fileName}`);
renderDocx(fileName);
});
});
})();
const data = {
var: 'amis'
};
function replaceText(text: string) {
// 将 {{xxx}} 替换成 ${xxx},为啥要这样呢,因为输入 $ 可能会变成两段文本
text = text.replace(/{{/g, '${').replace(/}}/g, '}');
return text;
}
async function renderDocx(fileName: string) {
const filePath = `${testDir}/${fileName}`;
const file = await (await fetch(filePath)).arrayBuffer();
let word: Word;
const renderOptions = {
debug: true
// replaceText
};
if (filePath.endsWith('.xml')) {
word = new Word(file, renderOptions, new XMLPackageParser());
} else {
word = new Word(file, renderOptions);
}
const fileNameSplit = fileName.split('/');
const downloadName = fileNameSplit[fileNameSplit.length - 1].replace(
'.xml',
'.docx'
);
(window as any).downloadDocx = () => {
word.download(downloadName);
};
(window as any).printDocx = () => {
word.print();
};
word.render(viewerElement);
}
const url = new URL(location.href);
const initFile = url.searchParams.get('file');
if (initFile) {
renderDocx(initFile);
}