提交 b62a6c4d authored 作者: 龙菲's avatar 龙菲

完善通过模板新建文件

上级 1de03282
......@@ -69,6 +69,14 @@ export const getFoldTreeByPath = (params) => {
})
}
// 获取文件目录树by path
export const getTemplateFiletreeByPath = (params) => {
return request({
url: baseUrl + '/file/getTemplateFiletreeByPath',
method: 'get',
params
})
}
/**
* 单文件操作相关接口
......
/**
* WPS相关接口
*/
import qs from 'qs'
import request from '@/utils/request'
const baseUrl = '/v1/api'
......@@ -18,7 +19,9 @@ export const newfile = data => {
return request({
url: baseUrl + '/wps/newfile',
method: 'post',
data
// data
data: qs.stringify(data),
headers: { 'content-type': 'application/x-www-form-urlencoded' }
})
}
......
<?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="1693905752136" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="1677" width="80" height="80" xmlns:xlink="http://www.w3.org/1999/xlink"><path d="M918.673 883H104.327C82.578 883 65 867.368 65 848.027V276.973C65 257.632 82.578 242 104.327 242h814.346C940.422 242 958 257.632 958 276.973v571.054C958 867.28 940.323 883 918.673 883z" fill="#FFE9B4" p-id="1678"></path><path d="M512 411H65V210.37C65 188.597 82.598 171 104.371 171h305.92c17.4 0 32.71 11.334 37.681 28.036L512 411z" fill="#FFB02C" p-id="1679"></path><path d="M918.673 883H104.327C82.578 883 65 865.42 65 843.668V335.332C65 313.58 82.578 296 104.327 296h814.346C940.422 296 958 313.58 958 335.332v508.336C958 865.32 940.323 883 918.673 883z" fill="#FFCA28" p-id="1680"></path></svg>
\ No newline at end of file
<?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="1648199299550" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="3869" width="24" height="24" xmlns:xlink="http://www.w3.org/1999/xlink"><defs><style type="text/css">@font-face { font-family: feedback-iconfont; src: url("//at.alicdn.com/t/font_1031158_u69w8yhxdu.woff2?t=1630033759944") format("woff2"), url("//at.alicdn.com/t/font_1031158_u69w8yhxdu.woff?t=1630033759944") format("woff"), url("//at.alicdn.com/t/font_1031158_u69w8yhxdu.ttf?t=1630033759944") format("truetype"); }
</style></defs><path d="M535.119473 0h69.599248v95.247413C729.226717 96.331138 853.614299 93.92286 977.881468 96.331138a40.459078 40.459078 0 0 1 44.914393 45.516463c2.047037 234.566322 0 469.614299 1.204139 703.819379-1.204139 24.082785 2.287865 50.694262-11.318909 72.248354-16.978363 12.041392-38.893697 10.837253-58.761994 12.041392h-349.200376V1023.518344h-72.248354C354.980245 990.886171 177.490122 960.541863 0 928.752587V95.488241C178.33302 63.578551 356.786453 32.511759 535.119473 0z" fill="#2A5699" p-id="3870"></path><path d="M604.718721 131.010348H988.598307v761.979304H604.718721v-95.247413h302.479774v-48.165569H604.718721v-59.002822h302.479774v-48.16557H604.718721v-59.002822h302.479774v-48.165569H604.718721v-60.206961h302.479774V428.673565H604.718721v-60.206961h302.479774v-46.96143H604.718721v-59.604892h302.479774V214.336783H604.718721zM240.827846 341.373471c22.156162-1.324553 44.19191-2.287865 66.348071-3.492003 15.533396 80.4365 31.30762 160.632173 48.165569 240.827845 13.125118-82.724365 27.695202-165.087488 41.783632-247.571025 23.239887-0.842897 46.479774-2.167451 69.719661-3.612418-26.370649 115.356538-49.369708 231.796802-78.148636 346.430856-19.386642 10.355597-48.165569 0-71.52587 1.204139C301.034807 596.169332 283.093133 517.779868 269.245532 438.667921c-13.606773 76.944497-31.30762 153.16651-46.841016 229.508937-22.39699-1.204139-44.793979-2.528692-67.311383-4.094073-19.266228-104.760113-42.024459-208.918156-60.206962-313.919097 19.868297-0.963311 39.857008-1.806209 60.206962-2.528693 12.041392 75.860771 25.648166 151.360301 36.124177 227.341487 16.135466-77.907808 32.873001-155.695202 49.610536-233.603011z" fill="#FFFFFF" p-id="3871"></path></svg>
\ No newline at end of file
......@@ -584,15 +584,17 @@ export default {
* @description 调用新建 office 文件服务,并在弹窗确认回调事件中刷新文件列表
* @param {string} 文件扩展名 docx xlsx pptx
*/
handleCreateFile(extendName) {
this.$openDialog
.addFile({
extendName: extendName,
})
.then((res) => {
this.callback(res);
});
},
// handleCreateFile(extendName) {
// const isShowTemplateRatio = this.fileType != this.TEMPLATE_MANAGE;
// this.$openDialog
// .addFileByTemplate({
// extendName,
// isShowTemplateRatio
// })
// .then((res) => {
// this.callback(res);
// });
// },
/**
* 新建 office 文件——通过模板导入
......@@ -600,9 +602,11 @@ export default {
* @param {string} 文件扩展名 docx xlsx pptx
*/
handleCreateFileByTemplate(extendName) {
const isShowTemplateRatio = this.fileType != this.TEMPLATE_MANAGE;
this.$openDialog
.addFileByTemplate({
extendName: extendName,
extendName,
isShowTemplateRatio
})
.then((res) => {
this.callback(res);
......
......@@ -384,58 +384,20 @@ export default {
}
});
},
// 新建文件按钮
handleCreateFile() {
// 模板管理处不能够通过模板新建文件,我的创作处可以
if (this.fileType == this.TEMPLATE_MANAGE) {
this.createFile("docx");
} else {
this.createFileByTemplate("docx");
}
},
/**
* 新建 office 文件
* @description 调用新建 office 文件服务,并在弹窗确认回调事件中刷新文件列表
* @param {string} 文件扩展名 docx xlsx pptx
*/
createFile(extendName) {
this.$openDialog
.addFile({
extendName: extendName,
})
.then((res) => {
if (res === "confirm") {
this.$emit("getTableDataByType");
}
});
},
/**
* 新建 office 文件(支持可通过模板)
* @description 调用新建 office 文件服务,并在弹窗确认回调事件中刷新文件列表
* @param {string} 文件扩展名 docx xlsx pptx
*/
createFileByTemplate(extendName) {
this.$openDialog
.addFileByTemplate({
extendName: extendName,
})
.then((res) => {
if (res === "confirm") {
this.$emit("getTableDataByType");
}
});
},
/**
* 新建 office 文件(支持可通过模板)
* @description 调用新建 office 文件服务,并在弹窗确认回调事件中刷新文件列表
* @param {string} 文件扩展名 docx xlsx pptx
* @param {string} extendName 文件扩展名 docx xlsx pptx
*/
handleCreateFileByTemplate(extendName) {
handleCreateFile(extendName) {
let isShowTemplateRatio = this.fileType != this.TEMPLATE_MANAGE; //是否要展示模板选项,我的创作展示,模板管理不展示
console.log('isShowTemplateRatio',isShowTemplateRatio);
this.$openDialog
.addFileByTemplate({
extendName: extendName,
extendName,
isShowTemplateRatio,
})
.then((res) => {
if (res === "confirm") {
......
<template>
<!-- 新建文件ByTemplate对话框(可以新增模板) -->
<el-dialog
title="新建文档"
:title="isShowTemplateRatio ? '新建文档' : '新建模板'"
:visible.sync="visible"
:close-on-click-modal="false"
width="550px"
......@@ -15,40 +15,49 @@
label-width="100px"
label-position="top"
>
<el-form-item label="选择新建方式" prop="addNewFileWay" >
<el-radio-group v-model="form.addNewFileWay">
<el-radio label="1">新建空白文档</el-radio>
<el-radio label="2">从模板导入</el-radio>
<el-form-item
label="选择新建方式"
prop="isTemplate"
v-if="isShowTemplateRatio"
>
<el-radio-group v-model="form.isTemplate" size="mini">
<el-radio :label="IS_NOT_TEMPLATE">新建空白文档</el-radio>
<el-radio :label="IS_TEMPLATE">从模板导入</el-radio>
</el-radio-group>
</el-form-item>
<el-form-item
label="选择模板"
prop="template"
v-if="form.addNewFileWay == 2"
prop="templateId"
v-if="form.isTemplate == IS_TEMPLATE"
style="width: 100%"
>
<el-select
v-model="templateId"
placeholder="请选择"
v-if="templateList.w_list && templateList.w_list.length > 0"
<el-cascader
v-model="form.templateId"
style="width: 100%"
size="mini"
v-if="templateList.length > 0"
placeholder="请选择模板(可搜索)"
:options="templateList"
filterable
:props="{
value: 'nodeId',
label: 'label',
}"
>
<el-option
v-for="item in templateList.w_list"
:key="item.id"
:label="item.name"
:value="item.id"
>
</el-option>
</el-select>
<div class="empty">暂无模板,如要添加请联系管理员</div>
<template slot-scope="{ node, data }">
<svg-icon style="margin-right:4px" icon-class="dir" v-if="data.isDir"></svg-icon>
<svg-icon style="margin-right:4px" icon-class="file_word" v-if="!data.isDir"></svg-icon>
<span>{{ data.label }}</span>
<span v-if="!node.isLeaf"> ({{ data.children.length }}) </span>
</template>
</el-cascader>
<div class="empty" v-else>暂无模板,如要添加请联系管理员</div>
</el-form-item>
<el-form-item label="文件名称" prop="fileName">
<el-form-item label="文件名称" prop="fileName" size="mini">
<el-input
v-model="form.fileName"
placeholder="请输入文件名称"
type="textarea"
autosize
maxlength="255"
show-word-limit
></el-input>
</el-form-item>
......@@ -66,29 +75,38 @@
</template>
<script>
import { newfile, getTemplateList } from "@/api/wps";
import { newfile } from "@/api/wps";
import { getTemplateFiletreeByPath } from "@/api/qwFile";
export default {
name: "AddFileDialog",
data() {
return {
visible: false, // 对话框是否可见
form: {
addNewFileWay: "1", //新建文件的方式,1-新建空白文件 2-从模板导入
isTemplate: "0", //新建文件的方式,0-新建空白文件 1-从模板导入
fileName: "",
templateId: "", //模板ID
},
templateList: {}, //模板文件对象,包含p_list(PPT模板)/s_list(表格模板)/w_list(文档模板)三个数组,暂时只用文档模板
formRules: {
fileName: [
{ required: true, message: "请输入文件名称", trigger: "blur" },
],
isTemplate: [
{ required: true, message: "请选择新建方式", trigger: "blur" },
],
templateId: [
{ required: true, message: "请选择模板", trigger: "blur" },
],
},
sureBtnLoading: false,
templateList: [],
IS_TEMPLATE: "1",
IS_NOT_TEMPLATE: "0",
};
},
watch: {
"form.addNewFileWay"(value) {
if (value == 2) {
"form.isTemplate"(value) {
if (value == this.IS_TEMPLATE) {
this.loadTemplateList();
}
},
......@@ -113,18 +131,24 @@ export default {
this.$refs[formName].validate((valid) => {
if (valid) {
const formData = new FormData();
let fileType = "w";
let filetype = "w";
const WORD = ["docx", "doc"]; //暂时只考虑新建word的情况
// const PDF = ["pdf", "doc"];
// const EXCEL = ["xlsx", "xls"];
if (WORD.includes(this.extendName)) {
fileType = "w";
filetype = "w";
}
formData.append("filetype", fileType);
formData.append("extendName", this.extendName);
formData.append("filePath", this.filePath);
formData.append("fileName", this.form.fileName);
newfile(formData)
const { extendName, filePath } = this;
const { fileName, isTemplate, templateId } = this.form;
const params = {
filetype,
extendName,
filePath,
fileName,
isTemplate,
templateId:templateId[0] || '',
};
newfile(params)
.then((res) => {
this.sureBtnLoading = false;
if (res.code == 200) {
......@@ -151,9 +175,18 @@ export default {
if (this.templateList.length > 0) {
return;
}
let res = await getTemplateList();
const params = {
path: "/模板管理",
};
let res = await getTemplateFiletreeByPath(params);
if (res.code == 200) {
this.templateList = res.data;
// 获取根目录下的模板管理下的所有
this.templateList = res.data.children[0].children;
this.templateList.forEach((item) => {
if (!item.isDir && item.children && item.children.length == 0) {
delete item.children; //刪除没有文件夹的
}
});
}
},
// /**
......
......@@ -9,10 +9,12 @@ let addFileByTemplateInstance = null
/**
* 初始化新建文件实例
* @param {string} extendName office 文件扩展名
* @param {string} isShowTemplateRatio 是否要展示模板选项按钮 我的创作需要展示,模板管理处不需要展示
* @param {string} filePath 新建文件夹的父路径
*/
const initInstanceAddFileByTemplate = (
extendName,
isShowTemplateRatio,//默认不展示
filePath = router.currentRoute.query.filePath || '/'
) => {
addFileByTemplateInstance = new AddFileConstructor({
......@@ -20,6 +22,7 @@ const initInstanceAddFileByTemplate = (
data() {
return {
extendName,
isShowTemplateRatio,
filePath
}
}
......@@ -34,9 +37,9 @@ const showAddFileByTemplateDialog = (obj) => {
if (addFileByTemplateInstance !== null) {
document.body.removeChild(addFileByTemplateInstance.$el)
}
let { extendName, filePath } = obj
let { extendName, isShowTemplateRatio,filePath } = obj
return new Promise((reslove) => {
initInstanceAddFileByTemplate(extendName, filePath)
initInstanceAddFileByTemplate(extendName,isShowTemplateRatio, filePath)
addFileByTemplateInstance.callback = (res) => {
reslove(res)
// 服务取消时卸载 DOM
......
......@@ -7,7 +7,7 @@
width="550px"
@close="handleDialogClose"
>
<div v-if="deleteMode === 1">删除后可在回收站查看, 是否继续删除?</div>
<div v-if="deleteMode === 1">是否继续删除?</div>
<div v-else-if="deleteMode === 2">此操作将永久删除该文件, 是否继续?</div>
<div slot="footer" class="dialog-footer">
<el-button @click="handleDialogClose">取 消</el-button>
......
......@@ -67,6 +67,7 @@
style="margin-right: 8px"
type="warning"
v-for="(v, i) in item.tagName.split(',')"
:key="i"
>{{ v }}
</el-tag>
</div>
......
......@@ -35,9 +35,9 @@ module.exports = {
proxy: {
// detail: https://cli.vuejs.org/config/#devserver-proxy
[process.env.VUE_APP_BASE_API]: {
target: `http://222.85.214.245:9600`,
// target: `http://222.85.214.245:9600`,
// target: `http://222.85.214.245:9558`,
// target: `http://172.24.100.246:9600`,
target: `http://172.24.100.246:9600`,
changeOrigin: true,
pathRewrite: {
['^' + process.env.VUE_APP_BASE_API]: ''
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论