mirror of
https://github.com/501351981/vue-office.git
synced 2025-08-04 07:42:47 +08:00
Compare commits
2 Commits
fc22cf8995
...
6a3de18019
Author | SHA1 | Date | |
---|---|---|---|
|
6a3de18019 | ||
|
3995dfd781 |
5
.gitignore
vendored
5
.gitignore
vendored
@ -19,7 +19,4 @@ pnpm-debug.log*
|
|||||||
*.ntvs*
|
*.ntvs*
|
||||||
*.njsproj
|
*.njsproj
|
||||||
*.sln
|
*.sln
|
||||||
*.sw?
|
*.sw?
|
||||||
packages/**/lib
|
|
||||||
packages/**/README.md
|
|
||||||
pnpm-lock.yaml
|
|
0
.gitattributes → core/.gitattributes
vendored
0
.gitattributes → core/.gitattributes
vendored
24
examples/.gitignore → core/.gitignore
vendored
24
examples/.gitignore → core/.gitignore
vendored
@ -1,23 +1,25 @@
|
|||||||
# Logs
|
.DS_Store
|
||||||
logs
|
node_modules
|
||||||
*.log
|
|
||||||
|
|
||||||
|
# local env files
|
||||||
|
.env.local
|
||||||
|
.env.*.local
|
||||||
|
|
||||||
|
# Log files
|
||||||
npm-debug.log*
|
npm-debug.log*
|
||||||
yarn-debug.log*
|
yarn-debug.log*
|
||||||
yarn-error.log*
|
yarn-error.log*
|
||||||
pnpm-debug.log*
|
pnpm-debug.log*
|
||||||
lerna-debug.log*
|
|
||||||
|
|
||||||
node_modules
|
|
||||||
dist-ssr
|
|
||||||
*.local
|
|
||||||
|
|
||||||
# Editor directories and files
|
# Editor directories and files
|
||||||
.vscode/*
|
|
||||||
!.vscode/extensions.json
|
|
||||||
.idea
|
.idea
|
||||||
.DS_Store
|
.vscode
|
||||||
*.suo
|
*.suo
|
||||||
*.ntvs*
|
*.ntvs*
|
||||||
*.njsproj
|
*.njsproj
|
||||||
*.sln
|
*.sln
|
||||||
*.sw?
|
*.sw?
|
||||||
|
packages/**/lib
|
||||||
|
packages/**/README.md
|
||||||
|
pnpm-lock.yaml
|
@ -1,11 +1,16 @@
|
|||||||
{
|
{
|
||||||
"name": "vue-office",
|
"name": "vue-office",
|
||||||
"version": "0.1.4",
|
"version": "1.0.0",
|
||||||
"description": "通过Vue开发的办公文档预览组件,支持docx、pdf、ppt、excel(已实现)的预览",
|
"description": "通过Vue开发的办公文档预览组件,支持docx、pdf、ppt、excel(已实现)的预览",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
"dev": "node script/bak-vue.js && vite",
|
||||||
|
"build": "node script/bak-vue.js && vite build",
|
||||||
|
"lib": "node script/bak-vue.js bak && lerna run build",
|
||||||
"docs:build": "vuepress build docs"
|
"docs:build": "vuepress build docs"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@vue/compiler-sfc": "3.2.45",
|
||||||
|
"ant-design-vue": "^3.2.17",
|
||||||
"dayjs": "^1.11.7",
|
"dayjs": "^1.11.7",
|
||||||
"docx-preview": "^0.1.14",
|
"docx-preview": "^0.1.14",
|
||||||
"exceljs": "^4.3.0",
|
"exceljs": "^4.3.0",
|
||||||
@ -26,8 +31,8 @@
|
|||||||
"vite": "^4.0.0",
|
"vite": "^4.0.0",
|
||||||
"vite-plugin-require-transform": "^1.0.9",
|
"vite-plugin-require-transform": "^1.0.9",
|
||||||
"vite-plugin-vue2": "^2.0.3",
|
"vite-plugin-vue2": "^2.0.3",
|
||||||
"vitepress": "^1.0.0-alpha.61",
|
|
||||||
"vue-template-compiler": "2.6.14",
|
"vue-template-compiler": "2.6.14",
|
||||||
|
"vue": "3.2.45",
|
||||||
"vue2": "npm:vue@2.6.14",
|
"vue2": "npm:vue@2.6.14",
|
||||||
"vue3": "npm:vue@3.2.45"
|
"vue3": "npm:vue@3.2.45"
|
||||||
},
|
},
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@vue-office/docx",
|
"name": "@vue-office/docx",
|
||||||
"version": "0.2.4",
|
"version": "1.0.0",
|
||||||
"description": "",
|
"description": "",
|
||||||
"main": "lib/index.js",
|
"main": "lib/index.js",
|
||||||
"files": [
|
"files": [
|
||||||
@ -10,7 +10,7 @@
|
|||||||
"clean": "rimraf lib",
|
"clean": "rimraf lib",
|
||||||
"copyFile2": "cp lib/v2/vue-office-docx.umd.js lib/v2/index.js && cp lib/v2/style.css lib/v2/index.css",
|
"copyFile2": "cp lib/v2/vue-office-docx.umd.js lib/v2/index.js && cp lib/v2/style.css lib/v2/index.css",
|
||||||
"copyFile3": "cp lib/v3/vue-office-docx.umd.js lib/v3/index.js && cp lib/v3/style.css lib/v3/index.css",
|
"copyFile3": "cp lib/v3/vue-office-docx.umd.js lib/v3/index.js && cp lib/v3/style.css lib/v3/index.css",
|
||||||
"copyReadme": "cp ../../README.md README.md",
|
"copyReadme": "cp ../../../README.md README.md",
|
||||||
"copyType": "cp index.d.ts lib/index.d.ts",
|
"copyType": "cp index.d.ts lib/index.d.ts",
|
||||||
"copyScripts": "mkdir lib/script/ && cp ../../script/postinstall.js lib/script/postinstall.js && cp ../../script/switch-cli.js lib/script/switch-cli.js && cp ../../script/utils.js lib/script/utils.js",
|
"copyScripts": "mkdir lib/script/ && cp ../../script/postinstall.js lib/script/postinstall.js && cp ../../script/switch-cli.js lib/script/switch-cli.js && cp ../../script/utils.js lib/script/utils.js",
|
||||||
"build:2": "npx vue-demi-switch 2 vue2 && vite build && npm run copyFile2",
|
"build:2": "npx vue-demi-switch 2 vue2 && vite build && npm run copyFile2",
|
43
core/packages/docx/src/docx.js
Normal file
43
core/packages/docx/src/docx.js
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
/*eslint-disable*/
|
||||||
|
import {renderAsync} from 'docx-preview';
|
||||||
|
|
||||||
|
const defaultOptions = {
|
||||||
|
ignoreLastRenderedPageBreak: false
|
||||||
|
};
|
||||||
|
|
||||||
|
function getData(src, options = {}) {
|
||||||
|
if (typeof src === 'string') {
|
||||||
|
return fetchDocx(src, options);
|
||||||
|
}
|
||||||
|
return Promise.resolve(src);
|
||||||
|
}
|
||||||
|
|
||||||
|
function fetchDocx(src, options) {
|
||||||
|
return fetch(src, options).then(res => {
|
||||||
|
if (res.status !== 200) {
|
||||||
|
return Promise.reject(res);
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function render(data, container, options = {}) {
|
||||||
|
if (!data) {
|
||||||
|
container.innerHTML = '';
|
||||||
|
return Promise.resolve();
|
||||||
|
}
|
||||||
|
let blob;
|
||||||
|
if (data instanceof Blob) {
|
||||||
|
blob = data;
|
||||||
|
} else if (data instanceof Response) {
|
||||||
|
blob = data.blob();
|
||||||
|
} else if (data instanceof ArrayBuffer) {
|
||||||
|
blob = new Blob([data]);
|
||||||
|
}
|
||||||
|
return renderAsync(blob, container, container, {...defaultOptions, ...options});
|
||||||
|
}
|
||||||
|
|
||||||
|
export default {
|
||||||
|
getData,
|
||||||
|
render
|
||||||
|
};
|
89
core/packages/docx/src/main.vue
Normal file
89
core/packages/docx/src/main.vue
Normal file
@ -0,0 +1,89 @@
|
|||||||
|
<script>
|
||||||
|
import {defineComponent, ref, onMounted, watch} from 'vue-demi';
|
||||||
|
import docx from './docx';
|
||||||
|
|
||||||
|
export default defineComponent({
|
||||||
|
name: 'VueOfficeDocx',
|
||||||
|
props: {
|
||||||
|
src: [String, ArrayBuffer, Blob],
|
||||||
|
requestOptions: {
|
||||||
|
type: Object,
|
||||||
|
default: () => ({})
|
||||||
|
},
|
||||||
|
options:{
|
||||||
|
type: Object,
|
||||||
|
default: () => ({})
|
||||||
|
}
|
||||||
|
},
|
||||||
|
emits: ['rendered', 'error'],
|
||||||
|
setup(props, {emit}) {
|
||||||
|
const rootRef = ref(null);
|
||||||
|
|
||||||
|
function init() {
|
||||||
|
let container = rootRef.value;
|
||||||
|
docx.getData(props.src, props.requestOptions).then(res => {
|
||||||
|
docx.render(res, container, props.options).then(() => {
|
||||||
|
emit('rendered');
|
||||||
|
}).catch(e => {
|
||||||
|
docx.render('', container, props.options);
|
||||||
|
emit('error', e);
|
||||||
|
});
|
||||||
|
}).catch(e => {
|
||||||
|
docx.render('', container, props.options);
|
||||||
|
emit('error', e);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
if (props.src) {
|
||||||
|
init();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
watch(() => props.src, () => {
|
||||||
|
if (props.src) {
|
||||||
|
init();
|
||||||
|
} else {
|
||||||
|
docx.render('', rootRef.value, props.options).then(() => {
|
||||||
|
emit('rendered');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return {
|
||||||
|
rootRef
|
||||||
|
};
|
||||||
|
}
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div class="vue-office-docx">
|
||||||
|
<div class="vue-office-docx-main" ref="rootRef"></div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style lang="less">
|
||||||
|
.vue-office-docx {
|
||||||
|
height: 100%;
|
||||||
|
overflow-y: auto;
|
||||||
|
.docx-wrapper {
|
||||||
|
> section.docx {
|
||||||
|
margin-bottom: 5px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@media screen and (max-width: 800px) {
|
||||||
|
.vue-office-docx {
|
||||||
|
.docx-wrapper {
|
||||||
|
padding: 10px;
|
||||||
|
|
||||||
|
> section.docx {
|
||||||
|
padding: 10px !important;
|
||||||
|
width: 100% !important;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
</style>
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@vue-office/excel",
|
"name": "@vue-office/excel",
|
||||||
"version": "0.2.10",
|
"version": "1.0.0",
|
||||||
"description": "",
|
"description": "",
|
||||||
"main": "lib/index.js",
|
"main": "lib/index.js",
|
||||||
"files": [
|
"files": [
|
||||||
@ -10,7 +10,7 @@
|
|||||||
"clean": "rimraf lib",
|
"clean": "rimraf lib",
|
||||||
"copyFile2": "cp lib/v2/vue-office-excel.umd.js lib/v2/index.js && cp src/index.css lib/v2/index.css",
|
"copyFile2": "cp lib/v2/vue-office-excel.umd.js lib/v2/index.js && cp src/index.css lib/v2/index.css",
|
||||||
"copyFile3": "cp lib/v3/vue-office-excel.umd.js lib/v3/index.js && cp src/index.css lib/v3/index.css",
|
"copyFile3": "cp lib/v3/vue-office-excel.umd.js lib/v3/index.js && cp src/index.css lib/v3/index.css",
|
||||||
"copyReadme": "cp ../../README.md README.md",
|
"copyReadme": "cp ../../../README.md README.md",
|
||||||
"copyType": "cp index.d.ts lib/index.d.ts",
|
"copyType": "cp index.d.ts lib/index.d.ts",
|
||||||
"copyScripts": "mkdir lib/script/ && cp ../../script/postinstall.js lib/script/postinstall.js && cp ../../script/switch-cli.js lib/script/switch-cli.js && cp ../../script/utils.js lib/script/utils.js",
|
"copyScripts": "mkdir lib/script/ && cp ../../script/postinstall.js lib/script/postinstall.js && cp ../../script/switch-cli.js lib/script/switch-cli.js && cp ../../script/utils.js lib/script/utils.js",
|
||||||
"build:2": "npx vue-demi-switch 2 vue2 && vite build && npm run copyFile2",
|
"build:2": "npx vue-demi-switch 2 vue2 && vite build && npm run copyFile2",
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@vue-office/pdf",
|
"name": "@vue-office/pdf",
|
||||||
"version": "0.2.5",
|
"version": "1.0.0",
|
||||||
"description": "",
|
"description": "",
|
||||||
"main": "lib/index.js",
|
"main": "lib/index.js",
|
||||||
"files": [
|
"files": [
|
||||||
@ -10,7 +10,7 @@
|
|||||||
"clean": "rimraf lib",
|
"clean": "rimraf lib",
|
||||||
"copyFile2": "cp lib/v2/vue-office-pdf.umd.js lib/v2/index.js",
|
"copyFile2": "cp lib/v2/vue-office-pdf.umd.js lib/v2/index.js",
|
||||||
"copyFile3": "cp lib/v3/vue-office-pdf.umd.js lib/v3/index.js",
|
"copyFile3": "cp lib/v3/vue-office-pdf.umd.js lib/v3/index.js",
|
||||||
"copyReadme": "cp ../../README.md README.md",
|
"copyReadme": "cp ../../../README.md README.md",
|
||||||
"copyType": "cp index.d.ts lib/index.d.ts",
|
"copyType": "cp index.d.ts lib/index.d.ts",
|
||||||
"copyScripts": "mkdir lib/script/ && cp ../../script/postinstall.js lib/script/postinstall.js && cp ../../script/switch-cli.js lib/script/switch-cli.js && cp ../../script/utils.js lib/script/utils.js",
|
"copyScripts": "mkdir lib/script/ && cp ../../script/postinstall.js lib/script/postinstall.js && cp ../../script/switch-cli.js lib/script/switch-cli.js && cp ../../script/utils.js lib/script/utils.js",
|
||||||
"build:2": "npx vue-demi-switch 2 vue2 && vite build && npm run copyFile2",
|
"build:2": "npx vue-demi-switch 2 vue2 && vite build && npm run copyFile2",
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user