Skip to content

Commit bac5999

Browse files
committed
fix: toolbar 浮动
1 parent 5adfe86 commit bac5999

File tree

4 files changed

+55
-9
lines changed

4 files changed

+55
-9
lines changed

README.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@
1919

2020
#### 通过引入 js 文件进行
2121
```html
22-
<div id="container"></div>
22+
<div id="container" style="
23+
height: 100%;
24+
overflow: hidden;
25+
/* 这里的样式可以自定义 */
26+
"></div>
2327
<script>
2428
// prepare 等待后端请求返回之后的函数
2529
window.shimo.prepare().then(function() {

document.ts

+31-6
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,17 @@ const historyCSSClassTemplate = `
3636
}
3737
`;
3838

39+
const toolbarCSSClassTemplate = `
40+
.sm-editor-scroller {
41+
height: calc(100% - 46px);
42+
overflow: auto;
43+
}
44+
45+
.sm-toolbar-wrapper.active {
46+
border-bottom: 1px solid #F7F7F7;
47+
}
48+
`;
49+
3950
export default class ShimoDocumentCabinet extends CabinetBase {
4051
public editor: ShimoSDK.Document.Editor;
4152
private sdkCommon: any;
@@ -82,8 +93,16 @@ export default class ShimoDocumentCabinet extends CabinetBase {
8293
}
8394

8495
const toolbarContainer = this.getDom("toolbar-wrapper");
96+
const editorScroller = this.getDom("sm-editor-scroller");
97+
toolbarContainer.className += "sm-toolbar-wrapper";
98+
editorScroller.className += "sm-editor-scroller";
8599

86-
editor.render(this.getDom("sm-editor"), {
100+
const style = document.createElement("style");
101+
style.type = "text/css";
102+
style.innerHTML = historyCSSClassTemplate + toolbarCSSClassTemplate;
103+
document.getElementsByTagName("head")[0].appendChild(style);
104+
105+
editor.render(this.getDom("sm-editor", editorScroller), {
87106
readOnly: !this.editorOptions.editable,
88107
id: this.user.id,
89108
localeConfig,
@@ -92,6 +111,17 @@ export default class ShimoDocumentCabinet extends CabinetBase {
92111
},
93112
});
94113
editor.setContent(this.file.content);
114+
115+
editorScroller.addEventListener("scroll", () => {
116+
setTimeout(() => {
117+
if (editorScroller.scrollTop === 0) {
118+
toolbarContainer.classList.remove("active");
119+
} else {
120+
toolbarContainer.classList.add("active");
121+
}
122+
}, 0);
123+
});
124+
95125
for (const plugin of this.plugins) {
96126
this[`init${plugin}`](editor);
97127
}
@@ -137,11 +167,6 @@ export default class ShimoDocumentCabinet extends CabinetBase {
137167
};
138168

139169
if (!document.querySelector("history-sidebar")) {
140-
const style = document.createElement("style");
141-
style.type = "text/css";
142-
style.innerHTML = historyCSSClassTemplate;
143-
document.getElementsByTagName("head")[0].appendChild(style);
144-
145170
this.rootDom.insertAdjacentHTML("afterend", historyContainerTemplate);
146171
}
147172

example/document/index.html

+4-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,10 @@
4747
<script src="<path>/shimo.sdk.document.plugins.uploader.min.js"></script>
4848

4949
<body>
50-
<div id="container"></div>
50+
<div id="container" style="
51+
height: 100%;
52+
overflow: hidden;
53+
"></div>
5154
</body>
5255

5356
<script>

sheet.ts

+15-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import CabinetBase from "./base";
44

55
export default class ShimoSheetCabinet extends CabinetBase {
6-
public editor: ShimoSDK.Document.Editor;
6+
public editor: ShimoSDK.Sheet.Editor;
77
private sdkSheet: any;
88
private sdkCommon: any;
99
private user: ShimoSDK.User;
@@ -55,6 +55,20 @@ export default class ShimoSheetCabinet extends CabinetBase {
5555
this.insertAfter(referenceNode, this.getDom("editor"));
5656
}
5757

58+
editor.on(this.sdkSheet.sheets.Events, (msg) => {
59+
this.sdkSheet.sheets.utils.confirm({
60+
title: "表格异常",
61+
description: '表格出现异常,无法编辑,请刷新后继续使用。<br /><i style="font-size:12px;color:#ccc;">' + msg + "</i>",
62+
buttons: [
63+
{
64+
type: "button",
65+
buttonLabel: "确定",
66+
customClass: "btn-ok",
67+
closeAfterClick: true,
68+
}],
69+
});
70+
});
71+
5872
return editor;
5973
}
6074

0 commit comments

Comments
 (0)