<template>
|
<div class="app-container">
|
<el-form
|
:model="queryParams"
|
ref="queryForm"
|
:inline="true"
|
v-show="showSearch"
|
label-width="68px"
|
>
|
<el-form-item label="文档分类" prop="doctype">
|
<el-select
|
v-model="queryParams.doctype"
|
placeholder="请选择文档归类"
|
clearable
|
size="small"
|
>
|
<el-option
|
v-for="dict in dict.type.sys_doctype"
|
:key="dict.value"
|
:label="dict.label"
|
:value="dict.value"
|
/>
|
</el-select>
|
</el-form-item>
|
<el-form-item label="文件名称" prop="filename">
|
<el-input
|
v-model="queryParams.filename"
|
placeholder="请输入文件名称"
|
clearable
|
size="small"
|
@keyup.enter.native="handleQuery"
|
/>
|
</el-form-item>
|
<el-form-item label="文件类型" prop="filetype">
|
<el-select
|
v-model="queryParams.filetype"
|
placeholder="请选择文件类型"
|
clearable
|
size="small"
|
>
|
<el-option
|
v-for="dict in dict.type.sys_filetype"
|
:key="dict.value"
|
:label="dict.label"
|
:value="dict.value"
|
/>
|
</el-select>
|
</el-form-item>
|
<!-- <el-form-item label="文件地址" prop="fileurl">
|
<el-input
|
v-model="queryParams.fileurl"
|
placeholder="请输入文件地址"
|
clearable
|
size="small"
|
@keyup.enter.native="handleQuery"
|
/>
|
</el-form-item> -->
|
<el-form-item label="状态" prop="status">
|
<!-- <el-select v-model="queryParams.status" placeholder="请选择状态" clearable size="small">
|
<el-option label="请选择字典生成" value="" />
|
</el-select> -->
|
<el-select v-model="queryParams.status" clearable size="small">
|
<el-option
|
v-for="dict in dict.type.sys_normal_disable"
|
:key="dict.value"
|
:label="dict.label"
|
:value="dict.value"
|
/>
|
</el-select>
|
</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-plus"
|
size="mini"
|
@click="handleAdd"
|
v-hasPermi="['product:documentfiles:add']"
|
>新增</el-button
|
>
|
</el-col>
|
<el-col :span="1.5">
|
<el-button
|
type="success"
|
plain
|
icon="el-icon-edit"
|
size="mini"
|
:disabled="single"
|
v-hasPermi="['product:documentfiles:update']"
|
@click="handleUpdate"
|
>修改</el-button
|
>
|
</el-col>
|
<el-col :span="1.5">
|
<el-button
|
type="danger"
|
plain
|
icon="el-icon-delete"
|
size="mini"
|
:disabled="multiple"
|
@click="handleDelete"
|
v-hasPermi="['product:documentfiles:delete']"
|
>删除</el-button
|
>
|
</el-col>
|
<!-- <el-col :span="1.5">
|
<el-button
|
type="warning"
|
plain
|
icon="el-icon-download"
|
size="mini"
|
:loading="exportLoading"
|
@click="handleExport"
|
v-hasPermi="['project:documentfiles:export']"
|
>导出</el-button>
|
</el-col> -->
|
<right-toolbar
|
:showSearch.sync="showSearch"
|
@queryTable="getList"
|
></right-toolbar>
|
</el-row>
|
<el-row>
|
|
<el-table
|
border
|
v-loading="loading"
|
:data="documentfilesList"
|
@selection-change="handleSelectionChange"
|
>
|
<el-table-column type="selection" width="55" align="center" />
|
<el-table-column
|
label="文档归类"
|
width="120"
|
align="center"
|
prop="doctype"
|
>
|
<template slot-scope="scope">
|
<dict-tag
|
:options="dict.type.sys_doctype"
|
:value="scope.row.doctype"
|
/>
|
</template>
|
</el-table-column>
|
<el-table-column
|
label="文件名称"
|
width="400"
|
align="center"
|
prop="filename"
|
/>
|
<el-table-column
|
label="文件类型"
|
width="120"
|
align="center"
|
prop="filetype"
|
>
|
<template slot-scope="scope">
|
<dict-tag
|
:options="dict.type.sys_filetype"
|
:value="scope.row.filetype"
|
/>
|
</template>
|
</el-table-column>
|
<el-table-column
|
label="录入人"
|
width="120"
|
align="center"
|
prop="createBy"
|
/>
|
<el-table-column label="状态" align="center" width="60" prop="status">
|
<template slot-scope="scope">
|
<dict-tag
|
:options="dict.type.sys_normal_disable"
|
:value="scope.row.status"
|
/>
|
</template>
|
</el-table-column>
|
<el-table-column label="备注" width="400" align="center" prop="remark" />
|
<!-- <el-table-column label="文件名" width="620" align="center" prop="fileurl">
|
<template slot-scope="scope">
|
<span>{{ getFileName(scope.row.fileurl) }}</span>
|
</template>
|
</el-table-column> -->
|
<!-- fixed="right" -->
|
<el-table-column
|
label="操作"
|
align="center"
|
class-name="small-padding fixed-width"
|
width="300"
|
>
|
<template slot-scope="scope">
|
<el-button
|
size="mini"
|
type="text"
|
icon="el-icon-edit"
|
@click="handleUpdate(scope.row)"
|
>修改</el-button
|
>
|
<!-- v-hasPermi="['project:documentfiles:edit']" -->
|
<el-button
|
size="mini"
|
type="text"
|
icon="el-icon-delete"
|
@click="handleDelete(scope.row)"
|
>删除</el-button
|
>
|
<!-- v-hasPermi="['project:documentfiles:remove']" -->
|
<el-button
|
size="mini"
|
type="text"
|
icon="el-icon-download"
|
@click="handleDownload(scope.row)"
|
>下载</el-button
|
>
|
<!-- v-hasPermi="['project:documentfiles:remove']" -->
|
</template>
|
</el-table-column>
|
</el-table>
|
</el-row>
|
|
<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="80px"
|
><el-row>
|
<el-col :span="12">
|
<el-form-item label="文件名称" prop="filename">
|
<el-input
|
style="width: 220px"
|
v-model="form.filename"
|
placeholder="请输入文件名称"
|
/>
|
</el-form-item>
|
</el-col>
|
<el-col :span="12">
|
<el-form-item label="文件归类" prop="doctype">
|
<el-select v-model="form.doctype" placeholder="请选择文档归类">
|
<el-option
|
v-for="dict in dict.type.sys_doctype"
|
:key="dict.value"
|
:label="dict.label"
|
:value="dict.value"
|
></el-option>
|
</el-select> </el-form-item
|
></el-col>
|
</el-row>
|
<el-row>
|
<el-col :span="12">
|
<el-form-item label="上传时间" prop="uploadtime">
|
<el-date-picker
|
clearable
|
size="small"
|
style="width: 220px"
|
v-model="form.uploadtime"
|
type="datetime" format="yyyy-MM-dd HH:mm"
|
value-format="yyyy-MM-dd HH:mm"
|
>
|
</el-date-picker>
|
</el-form-item>
|
</el-col>
|
<el-col :span="12">
|
<el-form-item label="录入人" prop="createBy">
|
<el-select
|
v-model="form.createBy"
|
placeholder="录入人"
|
clearable
|
filterable
|
allow-create
|
>
|
<el-option
|
v-for="dict in userlist"
|
:key="dict.index"
|
:label="dict.nickname"
|
:value="dict.nickname"
|
></el-option>
|
</el-select> </el-form-item
|
></el-col> </el-row
|
><el-row>
|
<el-col :span="12">
|
<el-form-item label="文件格式" prop="filetype">
|
<el-select
|
v-model="form.filetype"
|
clearable
|
size="small"
|
style="width: 220px"
|
>
|
<el-option
|
v-for="dict in dict.type.sys_filetype"
|
:key="dict.value"
|
:label="dict.label"
|
:value="dict.value"
|
/>
|
</el-select>
|
</el-form-item>
|
</el-col>
|
<el-col :span="12">
|
<el-form-item label="是否有效">
|
<el-select v-model="form.status" placeholder="请选择文档归类">
|
<el-option
|
v-for="dict in dict.type.sys_normal_disable"
|
:key="dict.value"
|
:label="dict.label"
|
:value="dict.value"
|
></el-option>
|
</el-select>
|
</el-form-item> </el-col></el-row
|
><el-row>
|
<el-col :span="24">
|
<!-- <el-form-item label="文件地址" prop="fileurl">
|
<el-input v-model="form.fileurl" placeholder="请输入文件地址" />
|
</el-form-item> -->
|
<el-form-item label="文件上传" align="left" prop="fileurl">
|
<el-upload
|
size="mini"
|
class="upload-demo"
|
:action="uploadFileUrl"
|
:file-list="fileList"
|
multiple
|
:limit="1"
|
:headers="headers"
|
:on-success="
|
(response, file, fileList) =>
|
uploadSccess(response, file, fileList)
|
"
|
:on-error="handleUploadError"
|
:on-exceed="handleExceed"
|
:on-remove="(file, fileList) => removeFile(file, fileList)"
|
>
|
<el-button size="small" type="primary">上传</el-button>
|
</el-upload>
|
</el-form-item>
|
</el-col>
|
</el-row>
|
<el-row>
|
<el-col :span="24">
|
<el-form-item label="地区" prop="addresss" v-show="false">
|
<div>
|
<li_area_select
|
ref="addSelect"
|
v-model="address"
|
></li_area_select>
|
<!-- <div>{{defultAddress}}</div> -->
|
</div>
|
</el-form-item>
|
</el-col>
|
</el-row>
|
<el-row>
|
<el-col :span="24">
|
<el-form-item label="来源" prop="source">
|
<el-input v-model="form.source" placeholder="请输入附件来源" />
|
</el-form-item>
|
</el-col>
|
</el-row>
|
<el-row>
|
<el-col :span="24">
|
<el-form-item label="备注" prop="remark">
|
<el-input v-model="form.remark" placeholder="请输入备注" />
|
</el-form-item>
|
</el-col>
|
</el-row>
|
</el-form>
|
<div slot="footer" class="dialog-footer">
|
<el-button type="warning" @click="download">文件下载</el-button>
|
<el-button type="primary" @click="submitForm">确 定</el-button>
|
<el-button @click="cancel">取 消</el-button>
|
</div>
|
</el-dialog>
|
</div>
|
</template>
|
|
<script>
|
import {
|
listDocumentfiles,
|
getDocumentfiles,
|
delDocumentfiles,
|
addDocumentfiles,
|
updateDocumentfiles,
|
exportDocumentfiles,
|
} from "@/api/project/documentfiles";
|
import AnnexUpload from "@/views/project/components/annexupload";
|
import FileUpload from "@/components/FileUpload";
|
import { listUser } from "@/api/project/organization";
|
import Li_area_select from "@/components/Address";
|
import { getUserProfile } from "@/api/system/user";
|
import { getToken } from "@/utils/auth";
|
|
export default {
|
components: {
|
AnnexUpload,
|
FileUpload,
|
Li_area_select,
|
},
|
name: "Documentfiles",
|
dicts: [
|
"sys_doctype",
|
"filetype",
|
"sys_yes_no",
|
"sys_0_1",
|
"sys_normal_disable",
|
"sys_filetype",
|
],
|
data() {
|
return {
|
userlist: [],
|
// 遮罩层
|
loading: true,
|
// 导出遮罩层
|
exportLoading: false,
|
// 选中数组
|
ids: [],
|
// 非单个禁用
|
single: true,
|
// 非多个禁用
|
multiple: true,
|
// 显示搜索条件
|
showSearch: true,
|
// 总条数
|
total: 0,
|
// 文件表格数据
|
documentfilesList: [],
|
// 弹出层标题
|
title: "",
|
// 是否显示弹出层
|
open: false,
|
address: {
|
sheng: "浙江省",
|
shi: "",
|
qu: "",
|
},
|
baseUrl: process.env.VUE_APP_BASE_API,
|
// 查询参数
|
queryParams: {
|
pageNum: 1,
|
pageSize: 10,
|
doctype: null,
|
filename: null,
|
filetype: null,
|
fileurl: null,
|
status: null,
|
},
|
// 表单参数
|
form: {},
|
// 表单校验
|
rules: {},
|
nickName: "",
|
//文件列表
|
fileList: [],
|
baseUrl: process.env.VUE_APP_BASE_API,
|
// 政策文件上传接口(2026-10-09:改用模块专属接口,允许任意文件类型;
|
// 通用 /common/upload 仍按扩展名白名单校验,不适用于本模块)
|
uploadFileUrl: process.env.VUE_APP_BASE_API + "/project/documentfiles/upload",
|
//上传附件请求头
|
headers: {
|
Authorization: "Bearer " + getToken(),
|
},
|
};
|
},
|
created() {
|
this.getList();
|
},
|
mounted() {
|
this.getlistUser();
|
getUserProfile().then((response) => {
|
this.nickName = response.data.nickName;
|
});
|
},
|
methods: {
|
getlistUser() {
|
listUser().then((res) => {
|
this.userlist = res.data;
|
});
|
},
|
/** 查询文件列表 */
|
getList() {
|
this.loading = true;
|
listDocumentfiles(this.queryParams).then((response) => {
|
this.documentfilesList = response.rows;
|
this.total = response.total;
|
this.loading = false;
|
});
|
},
|
// 取消按钮
|
cancel() {
|
this.open = false;
|
this.reset();
|
},
|
// 表单重置
|
reset() {
|
this.form = {
|
id: null,
|
doctype: null,
|
filename: null,
|
filetype: null,
|
fileurl: null,
|
status: "0",
|
remark: null,
|
delFlag: null,
|
createBy: null,
|
createTime: null,
|
updateBy: null,
|
updateTime: null,
|
province: null,
|
provincename: null,
|
city: null,
|
cityname: null,
|
town: null,
|
townname: null,
|
uploadtime: null,
|
};
|
this.address.sheng = "浙江省";
|
this.address.shi = "";
|
this.address.qu = "";
|
|
this.resetForm("form");
|
},
|
/** 搜索按钮操作 */
|
handleQuery() {
|
this.queryParams.pageNum = 1;
|
this.getList();
|
},
|
/** 重置按钮操作 */
|
resetQuery() {
|
this.resetForm("queryForm");
|
this.handleQuery();
|
},
|
// 多选框选中数据
|
handleSelectionChange(selection) {
|
this.ids = selection.map((item) => item.id);
|
this.single = selection.length !== 1;
|
this.multiple = !selection.length;
|
},
|
/** 新增按钮操作 */
|
handleAdd() {
|
this.reset();
|
// this.$nextTick(() => {
|
// this.$refs.fileUpload.clearFileUrl();
|
// });
|
this.fileList = [];
|
(this.form.uploadtime = this.$moment().format("YYYY-MM-DD HH:mm:ss")),
|
(this.form.createBy = this.nickName);
|
this.open = true;
|
this.title = "添加文件";
|
},
|
/** 修改按钮操作 */
|
handleUpdate(row) {
|
this.reset();
|
const id = row.id || this.ids;
|
this.fileList = [];
|
getDocumentfiles(id)
|
.then((response) => {
|
this.form = response.data;
|
this.address.sheng = response.data.provincename;
|
this.address.shi = response.data.cityname;
|
this.address.qu = response.data.townname;
|
this.open = true;
|
this.title = "修改文件";
|
})
|
.finally(() => {
|
this.$nextTick(() => {
|
console.log(this.form)
|
if (this.form.filename) {
|
this.fileList.push(
|
{
|
name: this.form.filename,
|
url: this.form.fileurl,
|
});
|
} else {
|
//this.$refs.fileUpload.clearFileUrl();
|
}
|
});
|
});
|
},
|
/** 提交按钮 */
|
submitForm() {
|
this.$refs["form"].validate((valid) => {
|
if (valid) {
|
this.form.province = this.$refs.addSelect.getSheng();
|
this.form.provincename = this.address.sheng;
|
|
this.form.city = this.$refs.addSelect.getShi();
|
this.form.cityname = this.address.shi;
|
|
this.form.town = this.$refs.addSelect.getQu();
|
this.form.townname = this.address.qu;
|
|
//let list = this.$refs.fileUpload.getFileUrl();
|
let list = this.fileList;
|
if (list.length > 0) {
|
this.form.fileurl = list[0].url;
|
}
|
|
if (this.form.id != null) {
|
updateDocumentfiles(this.form).then((response) => {
|
this.$modal.msgSuccess("修改成功");
|
this.open = false;
|
this.getList();
|
});
|
} else {
|
addDocumentfiles(this.form).then((response) => {
|
this.$modal.msgSuccess("新增成功");
|
this.open = false;
|
this.getList();
|
});
|
}
|
}
|
});
|
},
|
/** 删除按钮操作 */
|
handleDelete(row) {
|
const ids = row.id || this.ids;
|
this.$modal
|
.confirm('是否确认删除文件编号为"' + ids + '"的数据项?')
|
.then(function () {
|
return delDocumentfiles(ids);
|
})
|
.then(() => {
|
this.getList();
|
this.$modal.msgSuccess("删除成功");
|
})
|
.catch(() => {});
|
},
|
/** 导出按钮操作 */
|
handleExport() {
|
const queryParams = this.queryParams;
|
this.$modal
|
.confirm("是否确认导出所有文件数据项?")
|
.then(() => {
|
this.exportLoading = true;
|
return exportDocumentfiles(queryParams);
|
})
|
.then((response) => {
|
this.$download.name(response.msg);
|
this.exportLoading = false;
|
})
|
.catch(() => {});
|
},
|
download() {
|
let list = this.fileList;
|
if (list.length > 0) {
|
this.saveFile(list[0].url, this.getFileName(list[0].name, list[0].url));
|
} else {
|
this.$modal.msgWarning("未获取到文件地址,请确认");
|
}
|
},
|
handleDownload(row) {
|
if (row.fileurl != "" && row.fileurl != null) {
|
this.saveFile(
|
row.fileurl,
|
this.getFileName(row.filename, row.fileurl, row.filename)
|
);
|
} else {
|
this.$modal.msgWarning("未获取到文件地址,请确认");
|
}
|
},
|
|
/**
|
* 下载文件(必须带鉴权)。
|
*
|
* 背景:/profile/** 静态资源未在 SecurityConfig 中放行(anyRequest().authenticated()),
|
* 而后端 TokenService 只从请求头 Authorization 取 token。
|
* 因此用 <a href> 直接跳转下载不会携带 token,服务端返回 401,表现为“点下载没反应/下不到文件”。
|
* 这里改为 fetch 带 Authorization 头取回文件流,再用 blob 本地另存。
|
*
|
* @param {string} fileUrl 文件地址(库中存的是 /profile/upload/... 相对路径)
|
* @param {string} fileName 另存为的文件名
|
*/
|
saveFile(fileUrl, fileName) {
|
if (!fileUrl) {
|
this.$modal.msgWarning("未获取到文件地址,请确认");
|
return;
|
}
|
// 兼容历史数据中已是绝对地址的情况,避免重复拼接
|
const isAbsolute = /^https?:\/\//i.test(fileUrl);
|
const url = isAbsolute ? fileUrl : this.baseUrl + fileUrl;
|
|
this.$modal.loading("正在下载文件,请耐心等待!");
|
fetch(url, {
|
method: "get",
|
headers: { Authorization: "Bearer " + getToken() },
|
})
|
.then((response) => {
|
if (!response.ok) {
|
// 401/403/404 必须显式提示,否则会下到一个内容为错误页的文件
|
throw new Error("HTTP " + response.status);
|
}
|
return response.blob();
|
})
|
.then((blob) => {
|
const blobUrl = window.URL.createObjectURL(blob);
|
const link = document.createElement("a");
|
link.href = blobUrl;
|
link.setAttribute("download", fileName || "下载文件");
|
document.body.appendChild(link);
|
link.click();
|
document.body.removeChild(link);
|
window.URL.revokeObjectURL(blobUrl);
|
})
|
.catch((err) => {
|
console.error("文件下载失败:" + url, err);
|
this.$modal.msgError("文件下载失败,请确认文件是否存在或登录是否过期");
|
})
|
.finally(() => {
|
this.$modal.closeLoading();
|
});
|
},
|
|
/**
|
* 获取另存为的文件名。
|
*
|
* 优先级:带扩展名的原始文件名 > 文件地址末段 > 文档标题。
|
* 之所以不直接用 form.filename:该字段在表单中可手工编辑(如“人体器官移植条例”),
|
* 不带扩展名,直接用作另存名会导致系统无法识别打开方式。
|
*
|
* @param {string} storedName 原始文件名(如 form.filename 中存的 xxx.docx)
|
* @param {string} fileUrl 文件地址
|
* @param {string} title 备用名称(文档标题)
|
*/
|
getFileName(storedName, fileUrl, title) {
|
const hasExt = (name) => !!name && name.lastIndexOf(".") > -1;
|
|
if (hasExt(storedName)) {
|
return storedName;
|
}
|
|
const source = fileUrl || "";
|
if (source.lastIndexOf("/") > -1) {
|
const fromUrl = source.slice(source.lastIndexOf("/") + 1);
|
if (fromUrl) {
|
return fromUrl;
|
}
|
}
|
|
return title || storedName || "下载文件";
|
},
|
|
//文件上传成功回调
|
uploadSccess(response, file, fileList) {
|
//获取附件信息位置
|
if (response.code == 200) {
|
this.form.filename = file.raw.name;
|
//console.log(file);
|
this.$modal.msgSuccess(response.msg);
|
this.fileList.push({ name: response.fileName, url: response.fileName });
|
} else {
|
// 2026-10-09:上传失败必须提示。原来只 console.log,用户看不到失败原因(表现为"点了没反应")
|
this.$modal.msgError(response.msg || "上传失败,请重试");
|
}
|
//console.log("上传文件后:" + JSON.stringify(this.fileList));
|
},
|
// 删除文件
|
removeFile(file, fileList) {
|
this.fileList = [];
|
for (let i = 0; i < fileList.length; i++) {
|
this.fileList({ name: fileList[i].name, url: fileList[i].url });
|
}
|
console.log("移除文件后:" + JSON.stringify(this.fileList));
|
//this.fileList.splice(index, 1);
|
//this.$emit("input", this.listToString(this.fileList));
|
},
|
// 文件个数超出
|
handleExceed() {
|
this.$message.error(`上传文件数量已超过!`);
|
},
|
// 上传失败(HTTP 层错误,如登录过期、网络异常)
|
handleUploadError(err) {
|
const msg = (err && (err.msg || err.message)) || "";
|
this.$modal.msgError("上传失败,请重试" + (msg ? ":" + msg : ""));
|
},
|
},
|
};
|
</script>
|