修改项目结构,doc预览增加配置

This commit is contained in:
liyulin 2023-04-21 12:59:52 +08:00
parent fc22cf8995
commit 3995dfd781
300 changed files with 1869 additions and 12656 deletions

5
.idea/.gitignore generated vendored Normal file
View File

@ -0,0 +1,5 @@
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/

View File

@ -0,0 +1,6 @@
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="Eslint" enabled="true" level="WARNING" enabled_by_default="true" />
</profile>
</component>

8
.idea/modules.xml generated Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/vue-office.iml" filepath="$PROJECT_DIR$/.idea/vue-office.iml" />
</modules>
</component>
</project>

6
.idea/vcs.xml generated Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

12
.idea/vue-office.iml generated Normal file
View File

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="WEB_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/temp" />
<excludeFolder url="file://$MODULE_DIR$/.tmp" />
<excludeFolder url="file://$MODULE_DIR$/tmp" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

View File

View File

View File

@ -3,9 +3,14 @@
"version": "0.1.4",
"description": "通过Vue开发的办公文档预览组件支持docx、pdf、ppt、excel(已实现)的预览",
"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"
},
"dependencies": {
"@vue/compiler-sfc": "3.2.45",
"ant-design-vue": "^3.2.17",
"dayjs": "^1.11.7",
"docx-preview": "^0.1.14",
"exceljs": "^4.3.0",
@ -26,8 +31,8 @@
"vite": "^4.0.0",
"vite-plugin-require-transform": "^1.0.9",
"vite-plugin-vue2": "^2.0.3",
"vitepress": "^1.0.0-alpha.61",
"vue-template-compiler": "2.6.14",
"vue": "3.2.45",
"vue2": "npm:vue@2.6.14",
"vue3": "npm:vue@3.2.45"
},

View File

@ -1,6 +1,6 @@
{
"name": "@vue-office/docx",
"version": "0.2.4",
"version": "1.0.0",
"description": "",
"main": "lib/index.js",
"files": [
@ -10,7 +10,7 @@
"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",
"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",
"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",

View 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
};

View 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>

View File

@ -1,6 +1,6 @@
{
"name": "@vue-office/excel",
"version": "0.2.10",
"version": "1.0.0",
"description": "",
"main": "lib/index.js",
"files": [
@ -10,7 +10,7 @@
"clean": "rimraf lib",
"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",
"copyReadme": "cp ../../README.md README.md",
"copyReadme": "cp ../../../README.md README.md",
"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",
"build:2": "npx vue-demi-switch 2 vue2 && vite build && npm run copyFile2",

View File

@ -1,6 +1,6 @@
{
"name": "@vue-office/pdf",
"version": "0.2.5",
"version": "1.0.0",
"description": "",
"main": "lib/index.js",
"files": [
@ -10,7 +10,7 @@
"clean": "rimraf lib",
"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",
"copyReadme": "cp ../../README.md README.md",
"copyReadme": "cp ../../../README.md README.md",
"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",
"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