Browse Source

change word

master
godo 7 months ago
parent
commit
320b55418f
  1. 1
      frontend/public/docx/assets/index.6dcf988b.css
  2. 107
      frontend/public/docx/assets/index.bae472f7.js
  3. 1
      frontend/public/docx/assets/save.5057a734.svg
  4. 1
      frontend/public/docx/assets/table-border-dash.8cfd45a5.svg
  5. 1
      frontend/public/docx/assets/table-border-internal.78ae9ca1.svg
  6. 415
      frontend/public/docx/assets/vendor.d13e5cc9.js
  7. 95
      frontend/public/docx/index.html
  8. 4
      frontend/src/system/applist.ts
  9. 38
      frontend/src/system/notification/Notification.ts
  10. 20
      packages/word/src/main.ts
  11. 3
      packages/word/src/plugins/barcode2d/index.ts
  12. 16
      packages/word/src/plugins/docx/exportDocx.ts
  13. 2
      packages/word/src/plugins/docx/importDocx.ts
  14. 2
      packages/word/src/plugins/floatingToolbar/interface/index.ts

1
frontend/public/docx/assets/index.6dcf988b.css

File diff suppressed because one or more lines are too long

107
frontend/public/docx/assets/index.bae472f7.js

File diff suppressed because one or more lines are too long

1
frontend/public/docx/assets/save.5057a734.svg

@ -0,0 +1 @@
<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg t="1731468009721" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="4260" width="32" height="32" xmlns:xlink="http://www.w3.org/1999/xlink"><path d="M877.141333 0.938667H146.773333c-80.810667 0-145.92 65.109333-145.92 145.92v730.282666c0 80.810667 65.706667 145.92 145.92 145.92h730.282667c80.810667 0 145.92-65.706667 145.92-145.92V146.773333c0-80.810667-65.109333-145.92-145.92-145.92z m-581.12 75.178666h433.237334V363.52H295.936V76.117333z m654.336 801.024c0 19.626667-7.594667 37.888-21.418666 51.797334a72.618667 72.618667 0 0 1-51.797334 21.418666H146.773333a72.618667 72.618667 0 0 1-51.797333-21.418666 71.594667 71.594667 0 0 1-21.418667-51.797334V146.773333A73.386667 73.386667 0 0 1 146.773333 73.642667h73.386667v291.84c0 19.626667 7.509333 37.888 21.333333 51.797333a72.277333 72.277333 0 0 0 51.2 21.418667H731.306667c19.626667 0 37.888-7.594667 51.797333-21.418667a72.618667 72.618667 0 0 0 21.418667-51.797333V74.24h72.704c19.626667 0 37.888 7.594667 51.797333 21.504a72.618667 72.618667 0 0 1 21.418667 51.797333v729.6z" fill="#13227a" p-id="4261"></path><path d="M582.826667 140.544c-20.906667 0-37.973333 17.066667-37.973334 37.973333v73.216c0 20.821333 17.066667 37.888 37.888 37.888 10.154667 0 19.626667-3.754667 26.538667-11.349333a38.997333 38.997333 0 0 0 11.349333-26.453333v-73.386667c0-20.821333-17.066667-37.888-37.888-37.888z" fill="#13227a" p-id="4262"></path></svg>

After

Width:  |  Height:  |  Size: 1.5 KiB

1
frontend/public/docx/assets/table-border-dash.8cfd45a5.svg

@ -0,0 +1 @@
<svg width="16" height="16" fill="none" xmlns="http://www.w3.org/2000/svg"><path fill-rule="evenodd" clip-rule="evenodd" d="M13 3h-1V2h1a1 1 0 011 1v1h-1V3zm-3-1v1H8.5v2h-1V3H6V2h4zM4 2v1H3v1H2V3a1 1 0 011-1h1zM2 6h1v1.5h2v1H3V10H2V6zm0 6h1v1h1v1H3a1 1 0 01-1-1v-1zm4 2v-1h1.5v-2h1v2H10v1H6zm6 0v-1h1v-1h1v1a1 1 0 01-1 1h-1zm2-4h-1V8.5h-2v-1h2V6h1v4zM8.5 7.5v-1h-1v1h-1v1h1v1h1v-1h1v-1h-1z" fill="#000000"/></svg>

After

Width:  |  Height:  |  Size: 413 B

1
frontend/public/docx/assets/table-border-internal.78ae9ca1.svg

@ -0,0 +1 @@
<svg width="16" height="16" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M2.5 3a.5.5 0 01.5-.5h11a.5.5 0 01.5.5v11a.5.5 0 01-.5.5H3a.5.5 0 01-.5-.5V3z" stroke="#AAACB0"/><path fill-rule="evenodd" clip-rule="evenodd" d="M9 5V3H8v2h1zm0 9v-2H8v2h1zM5 8H3v1h2V8zm9 0h-2v1h2V8zM9 7v1h1v1H9v1H8V9H7V8h1V7h1z" fill="#3D4757"/></svg>

After

Width:  |  Height:  |  Size: 337 B

415
frontend/public/docx/assets/vendor.d13e5cc9.js

File diff suppressed because one or more lines are too long

95
frontend/public/docx/index.html

@ -5,69 +5,14 @@
<meta charset="UTF-8" /> <meta charset="UTF-8" />
<link rel="icon" type="image/png" href="./assets/favicon.fbfa22e6.png" /> <link rel="icon" type="image/png" href="./assets/favicon.fbfa22e6.png" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>docx</title> <title>word</title>
<style> <script type="module" crossorigin src="./assets/index.bae472f7.js"></script>
.first-screen-loading { <link rel="modulepreload" href="./assets/vendor.d13e5cc9.js">
width: 200px; <link rel="stylesheet" href="./assets/index.6dcf988b.css">
height: 200px;
position: fixed;
top: 50%;
left: 50%;
margin-top: -100px;
margin-left: -100px;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
.first-screen-loading-spinner {
width: 36px;
height: 36px;
border: 3px solid #d14424;
border-top-color: transparent;
border-radius: 50%;
animation: spinner .8s linear infinite;
}
.first-screen-loading-text {
margin-top: 20px;
color: #d14424;
}
@keyframes spinner {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}
</style>
<script>
// 假设加载动画持续2秒,2秒后隐藏加载动画并显示.menu
setTimeout(function () {
var loading = document.querySelector('.first-screen-loading');
var menu = document.querySelector('#app');
// 隐藏加载动画
loading.style.display = 'none';
// 显示菜单
menu.style.display = 'block';
}, 3000); // 2000毫秒后执行,根据实际情况调整
</script>
<script type="module" crossorigin src="./assets/index.82ba8f6a.js"></script>
<link rel="stylesheet" href="./assets/index.ea630926.css">
</head> </head>
<body> <body>
<div class="first-screen-loading"> <div id="app">
<div class="first-screen-loading-spinner"></div>
<div class="first-screen-loading-text">正在加载中,请稍等 ...</div>
</div>
<div id="app" style="display: none;">
<div class="menu" editor-component="menu"> <div class="menu" editor-component="menu">
<div class="menu-item"> <div class="menu-item">
<div class="menu-item__undo"> <div class="menu-item__undo">
@ -90,11 +35,10 @@
<div class="options"> <div class="options">
<ul> <ul>
<li data-family="Microsoft YaHei" style="font-family:'Microsoft YaHei';">微软雅黑</li> <li data-family="Microsoft YaHei" style="font-family:'Microsoft YaHei';">微软雅黑</li>
<li data-family="宋体" style="font-family:'宋体';">宋体</li> <li data-family="华文宋体" style="font-family:'华文宋体';">华文宋体</li>
<li data-family="黑体" style="font-family:'黑体';">黑体</li> <li data-family="华文黑体" style="font-family:'华文黑体';">华文黑体</li>
<li data-family="仿宋" style="font-family:'仿宋';">仿宋</li> <li data-family="华文仿宋" style="font-family:'华文仿宋';">华文仿宋</li>
<li data-family="楷体" style="font-family:'楷体';">楷体</li> <li data-family="华文楷体" style="font-family:'华文楷体';">华文楷体</li>
<li data-family="等线" style="font-family:'等线';">等线</li>
<li data-family="华文琥珀" style="font-family:'华文琥珀';">华文琥珀</li> <li data-family="华文琥珀" style="font-family:'华文琥珀';">华文琥珀</li>
<li data-family="华文楷体" style="font-family:'华文楷体';">华文楷体</li> <li data-family="华文楷体" style="font-family:'华文楷体';">华文楷体</li>
<li data-family="华文隶书" style="font-family:'华文隶书';">华文隶书</li> <li data-family="华文隶书" style="font-family:'华文隶书';">华文隶书</li>
@ -266,7 +210,7 @@
</li> </li>
<li data-list-type="ul" data-list-style='square'> <li data-list-type="ul" data-list-style='square'>
<label>空心方块列表:</label> <label>空心方块列表:</label>
<ul style="list-style-type: square;"> <ul style="list-style-type: '☐ ';">
<li>________</li> <li>________</li>
</ul> </ul>
</li> </li>
@ -390,21 +334,12 @@
<button>替换</button> <button>替换</button>
</div> </div>
</div> </div>
<div class="menu-item__print" data-menu="print" title="打印"> <div class="menu-item__print" data-menu="print">
<i></i> <i></i>
</div> </div>
<div class="menu-item__save" data-menu="save">
<div class="menu-item__import" data-menu="import" title="导入">
<i></i> <i></i>
<input type="file" id="file-docx" style="display: none; width: 0; height: 0" accept=".docx" />
</div> </div>
<div class="menu-item__export" data-menu="export" title="导出">
<i></i>
</div>
<div class="menu-item__save" data-menu="save" title="保存">
<i></i>
</div>
</div> </div>
</div> </div>
<div class="catalog" editor-component="catalog"> <div class="catalog" editor-component="catalog">
@ -436,7 +371,7 @@
<span>页面:<span class="page-no">1</span>/<span class="page-size">1</span></span> <span>页面:<span class="page-no">1</span>/<span class="page-size">1</span></span>
<span>字数:<span class="word-count">0</span></span> <span>字数:<span class="word-count">0</span></span>
</div> </div>
<div class="editor-mode" title="编辑模式(编辑、清洁、只读、表单)">编辑模式</div> <div class="editor-mode" title="编辑模式(编辑、清洁、只读、表单、设计)">编辑模式</div>
<div> <div>
<div class="page-scale-minus" title="缩小(Ctrl+-)"> <div class="page-scale-minus" title="缩小(Ctrl+-)">
<i></i> <i></i>
@ -483,6 +418,10 @@
</div> </div>
</div> </div>
</div> </div>
<div style="display: none;">
<input type="file" name="file-docx" id="file-docx" accept=".docx" />
<input type="file" name="file-excel" id="file-excel" accept=".xlsx" />
</div>
</body> </body>

4
frontend/src/system/applist.ts

@ -80,8 +80,8 @@ export const appList = [
{ {
name: "document", name: "document",
appIcon: "word", appIcon: "word",
//url: "/docx/index.html", url: "/docx/index.html",
url:"http://localhost:3000/", //url:"http://localhost:3000/",
width: 800, width: 800,
frame: true, frame: true,
height: 600, height: 600,

38
frontend/src/system/notification/Notification.ts

@ -21,26 +21,26 @@ export class Notify {
}, option.timeout || 5000); }, option.timeout || 5000);
// 检查浏览器是否支持通知 // 检查浏览器是否支持通知
if ('Notification' in window) { // if ('Notification' in window) {
// 请求通知权限 // // 请求通知权限
Notification.requestPermission().then(function (permission) { // Notification.requestPermission().then(function (permission) {
if (permission === 'granted') { // if (permission === 'granted') {
// 创建通知 // // 创建通知
const notification = new Notification(option.title, { // const notification = new Notification(option.title, {
body: option.content, // body: option.content,
}); // });
// 点击通知时触发的事件 // // 点击通知时触发的事件
notification.onclick = function () { // notification.onclick = function () {
// console.log('通知被点击了'); // // console.log('通知被点击了');
}; // };
} else { // } else {
// console.warn('用户拒绝了通知权限'); // // console.warn('用户拒绝了通知权限');
} // }
}); // });
} else { // } else {
// console.error('浏览器不支持通知'); // // console.error('浏览器不支持通知');
} // }
} }
close() { close() {
const sys = useSystem(); const sys = useSystem();

20
packages/word/src/main.ts

@ -30,7 +30,6 @@ import barcode2dPlugin from "./plugins/barcode2d"
import floatingToolbarPlugin from "./plugins/floatingToolbar" import floatingToolbarPlugin from "./plugins/floatingToolbar"
import excelPlugin from "./plugins/excel" import excelPlugin from "./plugins/excel"
import docxPlugin from './plugins/docx' import docxPlugin from './plugins/docx'
import { workerData } from 'worker_threads'
window.onload = function () { window.onload = function () {
const isApple = const isApple =
typeof navigator !== 'undefined' && /Mac OS X/.test(navigator.userAgent) typeof navigator !== 'undefined' && /Mac OS X/.test(navigator.userAgent)
@ -1806,7 +1805,7 @@ window.onload = function () {
}, },
{ {
name: "导出文档", name: "导出文档",
when: (payload) => true, when: () => true,
callback: (command) => { callback: (command) => {
if (wordTitle == '') { if (wordTitle == '') {
wordTitle = window.prompt("请输入文档标题"); wordTitle = window.prompt("请输入文档标题");
@ -1819,15 +1818,15 @@ window.onload = function () {
}, },
{ {
name: "导入文档", name: "导入文档",
when: (payload) => true, when: () => true,
callback: (command) => { callback: () => {
docxFileInput.click(); docxFileInput.click();
}, },
}, },
{ {
name: "导入excel", name: "导入excel",
when: (payload) => true, when: () => true,
callback: (command) => { callback: () => {
excelFileInput.click(); excelFileInput.click();
}, },
}, },
@ -1943,13 +1942,6 @@ window.onload = function () {
instance.command.executeExportDocx({ instance.command.executeExportDocx({
fileName: wordTitle, fileName: wordTitle,
isFile: false isFile: false
}).then((base64:any) => {
const save = {
data: JSON.stringify({ content: base64, title: wordTitle }),
type: 'exportDocx'
}
//console.log(save)
window.parent.postMessage(save, '*')
}) })
}; };
@ -1959,7 +1951,7 @@ window.onload = function () {
key: KeyMap.S, key: KeyMap.S,
mod: true, mod: true,
isGlobal: true, isGlobal: true,
callback: (command: Command) => { callback: () => {
saveData() saveData()
} }
}, },

3
packages/word/src/plugins/barcode2d/index.ts

@ -25,8 +25,7 @@ export interface IBarcode2DOption {
} }
export default function barcode2DPlugin( export default function barcode2DPlugin(
editor: Editor, editor: Editor
options: IBarcode2DOption = {}
) { ) {
const command = editor.command const command = editor.command

16
packages/word/src/plugins/docx/exportDocx.ts

@ -39,14 +39,11 @@ const titleLevelToHeadingLevel = {
function convertElementToParagraphChild(element: IElement): ParagraphChild { function convertElementToParagraphChild(element: IElement): ParagraphChild {
if (element.type === ElementType.IMAGE) { if (element.type === ElementType.IMAGE) {
return new ImageRun({ return new ImageRun({
type: 'png',
data: element.value, data: element.value,
transformation: { transformation: {
width: element.width!, width: element.width!,
height: element.height! height: element.height!
},
SvgMediaOptions:{
width: element.width!,
height: element.height!
} }
}) })
} }
@ -77,7 +74,7 @@ function convertElementToParagraphChild(element: IElement): ParagraphChild {
color: Color(element.color).hex() || '#000000', color: Color(element.color).hex() || '#000000',
italics: element.italic, italics: element.italic,
strike: element.strikeout, strike: element.strikeout,
highlight: element.highlight ? Color(element.highlight).hex() : undefined, // highlight: element.highlight ? Color(element.highlight).hex() : undefined,
superScript: element.type === ElementType.SUPERSCRIPT, superScript: element.type === ElementType.SUPERSCRIPT,
subScript: element.type === ElementType.SUBSCRIPT, subScript: element.type === ElementType.SUBSCRIPT,
underline: element.underline ? {} : undefined underline: element.underline ? {} : undefined
@ -230,7 +227,14 @@ export default function (command: Command) {
saveAs(blob, `${fileName}.docx`) saveAs(blob, `${fileName}.docx`)
}) })
}else{ }else{
return Packer.toBase64String(doc) Packer.toBase64String(doc).then((base64:any) => {
const save = {
data: JSON.stringify({ content: base64, title: fileName }),
type: 'exportDocx'
}
//console.log(save)
window.parent.postMessage(save, '*')
})
} }
} }

2
packages/word/src/plugins/docx/importDocx.ts

@ -12,7 +12,7 @@ export interface IImportDocxOption {
} }
function transformElement(element:any) { function transformElement(element:any) {
if (element.children) { if (element.children) {
var children = _.map(element.children, transformElement); const children = _.map(element.children, transformElement);
element = {...element, children: children}; element = {...element, children: children};
} }

2
packages/word/src/plugins/floatingToolbar/interface/index.ts

@ -1,4 +1,4 @@
import Editor from '@hufe921/canvas-editor' import Editor from '../../../editor'
export interface IToolbarRegister { export interface IToolbarRegister {
key?: string key?: string

Loading…
Cancel
Save