Skip to content

Commit 3ea6cc6

Browse files
committed
Merge branch 'gh-pages'
2 parents 784af10 + 0142c9a commit 3ea6cc6

File tree

10 files changed

+2481
-7
lines changed

10 files changed

+2481
-7
lines changed

build/bundle.js

Lines changed: 2403 additions & 0 deletions
Large diffs are not rendered by default.

build/pic/docx.png

39.2 KB
Loading

build/pic/pdf.png

66.5 KB
Loading

build/pic/xlsx.png

17.2 KB
Loading

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-office-viewer",
3-
"version": "1.1.0",
3+
"version": "1.0.3",
44
"description": "A React component to preview document of 'pdf,xls,xlsx,docx', which can automatically identify file types.",
55
"main": "build/bundle.js",
66
"scripts": {

src/components/DocxViewer/index.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export default function DocxViewer(props) {
99
const [fileName, setFileName] = useState('');
1010
const [showError, setShowError] = useState(false);
1111
const [errorInfo, setErrorInfo] = useState(t('formatInfoDocx'));
12+
const [scale, setScale] = useState(1);
1213
const [fileArrayBuffer, setFileArrayBuffer] = useState(); //ArrayBuffer类型的文件
1314
const [showLoading, setShowLoading] = useState(false);
1415
useEffect(() => {
@@ -86,14 +87,28 @@ export default function DocxViewer(props) {
8687
const onShowError = (status) => {
8788
setShowError(status);
8889
}
90+
const onZoom = direc => {
91+
if (direc == 'in') {
92+
//放大
93+
if (scale >= 1) return;
94+
let _scale = scale + 0.1;
95+
//console.log(_scale);
96+
setScale(_scale.toFixed(1) * 1);
97+
} else {
98+
if (scale <= 0.3) return;
99+
let _scale = scale - 0.1;
100+
//console.log(_scale);
101+
setScale(_scale.toFixed(1) * 1)
102+
}
103+
}
89104
return <div className={styles['pg-viewer-wrapper']} style={{ width: width || '100%', height: height || document.body.offsetHeight - 45 + 'px' }}>
90105
<Loading showLoading={showLoading} />
91106
<ErrorLine errorInfo={errorInfo} showError={showError} onShowError={onShowError} />
92-
<TitleWithDownload backgroundColor='rgba(35,100,155,0.9)' handleDownload={handleDownload} fileName={fileName} disabled={!fileArrayBuffer} />
107+
<TitleWithDownload backgroundColor='rgba(35,100,155,0.9)' handleDownload={handleDownload} fileName={fileName} disabled={!fileArrayBuffer} onZoom={onZoom} zoom={true} />
93108
<div
94109
className={styles['document-container']}
95110
style={{
96-
width: '100%',
111+
width: scale * 100 + '%',
97112
height: '85%',
98113
overflow: 'auto'
99114
}}

src/components/DocxViewer/style.less

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,4 @@
325325
}
326326
}
327327
}
328-
329-
330328
}

src/components/PdfViewer/Toolbar.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ export default forwardRef((props, ref) => {
248248
<div className={styles["splitToolbarButton"]}>
249249
<button className={`${styles["toolbarButton"]} ${styles["zoomOut"]}`} title={t("zoomOut")} onClick={onZoomOut} disabled={scaleOut === MIN_SCALE}>
250250
</button>
251-
<div className="splitToolbarButtonSeparator"></div>
251+
<div className={styles["splitToolbarButtonSeparator"]}></div>
252252
<button className={`${styles["toolbarButton"]} ${styles["zoomIn"]}`} title={t("zoomIn")} onClick={onZoomIn} disabled={scaleOut === MAX_SCALE}>
253253
</button>
254254
</div>

src/components/pageComps/TitleWithDownload/index.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,19 @@ import styles from '../style.less';
33
import downloadImg from "../../../assets/images/toolbarButton-download.svg"
44
export default function TitleWithDownload(props) {
55

6-
const { fileName, handleDownload, disabled = false, backgroundColor = '#1e8e3edb' } = props;
6+
const { fileName, handleDownload, disabled = false, backgroundColor = '#1e8e3edb', zoom, onZoom } = props;
77
return (
88
<div className={styles.title} style={{ backgroundColor: backgroundColor }}>
99
<span>{fileName}</span>
10+
{
11+
zoom && (
12+
<div style={{ display: 'flex' }}>
13+
<button className={`${styles["toolbarButton"]} ${styles["zoomOut"]}`} onClick={() => onZoom('out')}></button>
14+
<div className={styles["splitToolbarButtonSeparator"]}></div>
15+
<button className={`${styles["toolbarButton"]} ${styles["zoomIn"]}`} onClick={() => onZoom('in')}></button>
16+
</div>
17+
)
18+
}
1019
<button className={styles["download"]} title={t("download")} onClick={handleDownload} disabled={disabled}><img src={downloadImg} /></button>
1120
</div>
1221
)

src/components/pageComps/style.less

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
:root {
2+
--toolbarButton-zoomOut-icon: url(../../assets/images/toolbarButton-zoomOut.svg);
3+
--toolbarButton-zoomIn-icon: url(../../assets/images/toolbarButton-zoomIn.svg);
4+
--separator-color: rgba(0, 0, 0, 0.3);
5+
}
6+
17
.title {
28
display: flex;
39
justify-content: space-between;
@@ -53,4 +59,47 @@
5359
border-radius: 5px;
5460
cursor: pointer;
5561
}
62+
}
63+
64+
65+
.toolbarButton {
66+
border: 0 none;
67+
background: none;
68+
width: 28px;
69+
height: 28px;
70+
border: none;
71+
border-radius: 2px;
72+
color: #666;
73+
font-size: 12px;
74+
cursor: pointer;
75+
76+
}
77+
78+
.toolbarButton::before {
79+
/* All matching have a size of 16x16
80+
* All relevant containers have a size of 28x28 */
81+
position: absolute;
82+
top: 6px;
83+
left: 6px;
84+
width: 16px;
85+
height: 16px;
86+
content: "";
87+
// background-color: var(--toolbar-icon-bg-color);
88+
background-size: cover;
89+
}
90+
91+
.splitToolbarButtonSeparator {
92+
float: inline-start;
93+
margin: 4px 0;
94+
width: 1px;
95+
height: 20px;
96+
background-color: var(--separator-color);
97+
}
98+
99+
.zoomOut::before {
100+
background-image: var(--toolbarButton-zoomOut-icon);
101+
}
102+
103+
.zoomIn::before {
104+
background-image: var(--toolbarButton-zoomIn-icon);
56105
}

0 commit comments

Comments
 (0)