update
This commit is contained in:
353
src/views/document/index.vue
Normal file
353
src/views/document/index.vue
Normal file
@@ -0,0 +1,353 @@
|
||||
<template>
|
||||
<div class="app-container">
|
||||
<el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch">
|
||||
<el-form-item label="文档名称" prop="roleName">
|
||||
<el-input
|
||||
v-model="queryParams.docName"
|
||||
placeholder="请输入文档名称"
|
||||
clearable
|
||||
style="width: 240px"
|
||||
@keyup.enter.native="handleQuery"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
|
||||
<el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
|
||||
<el-row :gutter="10" class="mb8">
|
||||
<el-col :span="1.5">
|
||||
<el-button
|
||||
type="primary"
|
||||
plain
|
||||
icon="el-icon-upload2"
|
||||
size="mini"
|
||||
@click="handleAdd"
|
||||
>上传文档</el-button>
|
||||
</el-col>
|
||||
<right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
|
||||
</el-row>
|
||||
|
||||
<el-table v-loading="loading" :data="docList" @selection-change="handleSelectionChange">
|
||||
<el-table-column type="selection" width="55" align="center" />
|
||||
<el-table-column label="文档编号" prop="docCode" width="120" />
|
||||
<el-table-column label="文档名称" prop="docName" :show-overflow-tooltip="true" />
|
||||
<el-table-column label="类别" prop="docType" :show-overflow-tooltip="true" width="150" />
|
||||
<el-table-column label="负责人" prop="docPrincipals" :show-overflow-tooltip="true" width="150" />
|
||||
<el-table-column label="归属部门" prop="docRespDept" :show-overflow-tooltip="true" width="150" />
|
||||
<el-table-column label="来源" prop="docSource" width="100" />
|
||||
<el-table-column label="上传进度" prop="docUploadProgress" width="200" >
|
||||
<template slot-scope="scope">
|
||||
<el-tag type="success" v-if="scope.row.docStatus == 'ysc'">已上传</el-tag>
|
||||
<el-progress v-else :percentage="progress" status="success"></el-progress>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="关联工具" prop="roleSort" width="100" />
|
||||
<el-table-column label="创建时间" align="center" prop="createTime" width="180">
|
||||
<template slot-scope="scope">
|
||||
<span>{{ parseTime(scope.row.createTime) }}</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="操作" align="center" width="180">
|
||||
<template slot-scope="scope" v-if="scope.row.roleId !== 1">
|
||||
<el-button
|
||||
size="mini"
|
||||
type="text"
|
||||
icon="el-icon-view"
|
||||
@click="handlePriew(scope.row)"
|
||||
>预览</el-button>
|
||||
<el-button
|
||||
size="mini"
|
||||
type="text"
|
||||
icon="el-icon-delete"
|
||||
@click="handleDelete(scope.row)"
|
||||
>删除</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
|
||||
<pagination
|
||||
v-show="total>0"
|
||||
:total="total"
|
||||
:page.sync="queryParams.pageNum"
|
||||
:limit.sync="queryParams.pageSize"
|
||||
@pagination="getList"
|
||||
/>
|
||||
|
||||
<!-- 添加或修改文档资源信息对话框 -->
|
||||
<el-dialog :title="title" :visible.sync="open" width="800px" append-to-body>
|
||||
<el-form ref="form" :model="form" :rules="rules" label-width="100px">
|
||||
<el-form-item label="类别" prop="docType">
|
||||
<el-input v-model="form.docType" placeholder="请输入类别" />
|
||||
</el-form-item>
|
||||
<el-form-item label="负责人" prop="docPrincipals">
|
||||
<el-input v-model="form.docPrincipals" placeholder="请输入负责人" />
|
||||
</el-form-item>
|
||||
<el-form-item label="归属部门" prop="docRespDept">
|
||||
<el-input v-model="form.docRespDept" placeholder="请输入归属部门" />
|
||||
</el-form-item>
|
||||
<el-form-item label="文档来源" prop="docSource">
|
||||
<el-input v-model="form.docSource" placeholder="请输入文档来源" />
|
||||
</el-form-item>
|
||||
<el-form-item label="文件">
|
||||
<el-upload
|
||||
class="upload-component"
|
||||
ref="upload"
|
||||
:auto-upload="false"
|
||||
:file-list="fileList"
|
||||
:on-change="onChange"
|
||||
:on-remove="onRemove"
|
||||
:limit="1"
|
||||
action=""
|
||||
>
|
||||
<el-button size="small" type="primary">点击上传</el-button>
|
||||
<div slot="tip" class="el-upload__tip">只能上传jpg/png文件,且不超过500kb</div>
|
||||
</el-upload>
|
||||
</el-form-item>
|
||||
<el-form-item label="备注">
|
||||
<el-input v-model="form.remark" type="textarea" placeholder="请输入内容"></el-input>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<div slot="footer" class="dialog-footer">
|
||||
<el-button type="primary" @click="submitForm">确 定</el-button>
|
||||
<el-button @click="cancel">取 消</el-button>
|
||||
</div>
|
||||
</el-dialog>
|
||||
|
||||
<el-dialog :title="viewDialogTitle" :visible.sync="viewDialogOpen" fullscreen width="500px" append-to-body>
|
||||
<i-frame :src="previewUrl" />
|
||||
</el-dialog>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { listDocument, getDocument, delDocument, addDocument, updateDocument } from "@/api/document/document";
|
||||
import { Base64 } from 'js-base64';
|
||||
import iFrame from "@/components/iFrame/index";
|
||||
import { w3cwebsocket as WebSocket } from 'websocket';
|
||||
import axios from 'axios';
|
||||
import { getToken } from '@/utils/auth'
|
||||
|
||||
export default {
|
||||
name: "Document",
|
||||
components: { iFrame },
|
||||
data() {
|
||||
return {
|
||||
// 遮罩层
|
||||
loading: true,
|
||||
// 选中数组
|
||||
ids: [],
|
||||
// 非单个禁用
|
||||
single: true,
|
||||
// 非多个禁用
|
||||
multiple: true,
|
||||
// 显示搜索条件
|
||||
showSearch: true,
|
||||
// 总条数
|
||||
total: 0,
|
||||
// 表格数据
|
||||
docList: [],
|
||||
// 弹出层标题
|
||||
title: "",
|
||||
viewDialogTitle: "",
|
||||
// 是否显示弹出层
|
||||
open: false,
|
||||
viewDialogOpen: false,
|
||||
// 日期范围
|
||||
dateRange: [],
|
||||
previewUrl: '',
|
||||
progress: 0,
|
||||
fileList: [],
|
||||
websocket: null,
|
||||
// 查询参数
|
||||
queryParams: {
|
||||
pageNum: 1,
|
||||
pageSize: 10,
|
||||
docName: undefined
|
||||
},
|
||||
// 表单参数
|
||||
form: {
|
||||
docName: '',
|
||||
docType: '',
|
||||
docPrincipals: '',
|
||||
docRespDept: '',
|
||||
docSource: ''
|
||||
},
|
||||
// 表单校验
|
||||
rules: {
|
||||
docType: [
|
||||
{ required: true, message: "类别不能为空", trigger: "blur" }
|
||||
],
|
||||
docSource: [
|
||||
{ required: true, message: "文档来源不能为空", trigger: "blur" }
|
||||
]
|
||||
}
|
||||
};
|
||||
},
|
||||
created() {
|
||||
this.getList();
|
||||
this.initWebSocket();
|
||||
},
|
||||
methods: {
|
||||
generateUniqueID() {
|
||||
// 使用时间戳来生成唯一ID
|
||||
const timestamp = new Date().getTime();
|
||||
// 在ID前面添加一个前缀,以防止与其他ID冲突
|
||||
const uniqueID = 'file_' + timestamp;
|
||||
return uniqueID;
|
||||
},
|
||||
initWebSocket() {
|
||||
this.websocket = new WebSocket('ws://localhost:8080/tool-tech-admin/websocket');
|
||||
this.websocket.onmessage = (event) => {
|
||||
const msgStr = event.data;
|
||||
console.log('上传进度=' + msgStr);
|
||||
let progress = msgStr.substring(msgStr.indexOf("/") + 1, msgStr.length);
|
||||
this.progress = parseInt(progress)
|
||||
// if (progress === '100%') {
|
||||
// this.websocket.close();
|
||||
// }
|
||||
};
|
||||
this.websocket.onclose = () => {
|
||||
console.log('WebSocket connection closed');
|
||||
};
|
||||
},
|
||||
onChange(file, fileList) {
|
||||
// valid the suffix of file
|
||||
let validSuffix = ['pdf', 'docx', 'doc', 'txt', 'eml', 'mp4']
|
||||
let splits = file.name.split('.')
|
||||
let suffix = splits[splits.length - 1]
|
||||
if (!validSuffix.includes(suffix)) {
|
||||
this.$message.error(`只能上传 ${validSuffix.join(',')} 类型的文件!`)
|
||||
this.fileList = fileList.filter(item => item.uid !== file.uid)
|
||||
return
|
||||
}
|
||||
this.fileList = fileList
|
||||
},
|
||||
|
||||
onRemove(file, fileList) {
|
||||
this.fileList = fileList.filter(item => item.uid !== file.uid)
|
||||
},
|
||||
confirmSubmit(docId) {
|
||||
// 创建 formData 对象
|
||||
const formData = new FormData()
|
||||
// 将所有 的 upload 组件中的文件对象放入到 FormData 对象中
|
||||
this.fileList.forEach((file) => {
|
||||
formData.append('files', file.raw)
|
||||
})
|
||||
formData.append('docId', docId)
|
||||
formData.append('requestId', this.generateUniqueID())
|
||||
//自定义的接口也可以用ajax或者自己封装的接口
|
||||
axios.post('http://localhost:8080/tool-tech-admin/document/upload', formData, {
|
||||
headers: {
|
||||
'Content-Type': 'multipart/form-data',
|
||||
'Authorization': 'Bearer ' + getToken(),
|
||||
}
|
||||
}).then((response) => {
|
||||
if(response.data.code===200){
|
||||
this.getList()
|
||||
}else{
|
||||
// 弹框报错 response.data.message
|
||||
}
|
||||
this.initWebSocket();
|
||||
}).catch((error) => {
|
||||
console.error('Failed to upload file:', error);
|
||||
});
|
||||
},
|
||||
/** 查询列表 */
|
||||
getList() {
|
||||
this.loading = true;
|
||||
listDocument(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
|
||||
this.docList = response.rows;
|
||||
this.total = response.total;
|
||||
this.loading = false;
|
||||
}
|
||||
);
|
||||
},
|
||||
// 取消按钮
|
||||
cancel() {
|
||||
this.open = false;
|
||||
this.reset();
|
||||
},
|
||||
// 表单重置
|
||||
reset() {
|
||||
this.form = {
|
||||
docName: '',
|
||||
docType: '',
|
||||
docPrincipals: '',
|
||||
docRespDept: '',
|
||||
docSource: ''
|
||||
};
|
||||
this.fileList = []
|
||||
this.resetForm("form");
|
||||
},
|
||||
/** 搜索按钮操作 */
|
||||
handleQuery() {
|
||||
this.queryParams.pageNum = 1;
|
||||
this.getList();
|
||||
},
|
||||
/** 重置按钮操作 */
|
||||
resetQuery() {
|
||||
this.dateRange = [];
|
||||
this.resetForm("queryForm");
|
||||
this.handleQuery();
|
||||
},
|
||||
/** 新增按钮操作 */
|
||||
handleAdd() {
|
||||
this.reset();
|
||||
this.open = true;
|
||||
this.title = "上传文档";
|
||||
},
|
||||
handlePriew(row){
|
||||
console.log('mmmmmmmmmmm',process.env.VUE_APP_BASE_API + row.docUrl)
|
||||
this.previewUrl = process.env.VUE_APP_TOOL_TECH_FILE_VIEW_API + '/onlinePreview?url=' + encodeURIComponent(Base64.encode(process.env.VUE_APP_BASE_API + row.docUrl));
|
||||
this.viewDialogTitle = '文档在线预览'
|
||||
this.viewDialogOpen = true;
|
||||
},
|
||||
// 多选框选中数据
|
||||
handleSelectionChange(selection) {
|
||||
this.ids = selection.map(item => item.fileId)
|
||||
this.single = selection.length!=1
|
||||
this.multiple = !selection.length
|
||||
},
|
||||
/** 提交按钮 */
|
||||
submitForm: function() {
|
||||
//判断是否有文件再上传
|
||||
if (this.fileList.length === 0) {
|
||||
return this.$message.warning('请选取文件后再上传')
|
||||
}
|
||||
this.fileList.map(file =>{
|
||||
this.form.docName = file.name
|
||||
})
|
||||
this.$refs["form"].validate(valid => {
|
||||
if (valid) {
|
||||
if (this.form.id != undefined) {
|
||||
updateDocument(this.form).then(response => {
|
||||
this.$modal.msgSuccess("修改成功");
|
||||
this.open = false;
|
||||
this.getList();
|
||||
});
|
||||
} else {
|
||||
addDocument(this.form).then(response => {
|
||||
this.$modal.msgSuccess("新增成功");
|
||||
this.open = false;
|
||||
this.getList();
|
||||
this.confirmSubmit(response.data);
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
/** 删除按钮操作 */
|
||||
handleDelete(row) {
|
||||
const docIds = row.docId || this.ids;
|
||||
this.$modal.confirm('是否确认删除?').then(function() {
|
||||
return delDocument(docIds);
|
||||
}).then(() => {
|
||||
this.getList();
|
||||
this.$modal.msgSuccess("删除成功");
|
||||
}).catch(() => {});
|
||||
}
|
||||
}
|
||||
};
|
||||
</script>
|
||||
Reference in New Issue
Block a user