<template>
|
<div class="home-container">
|
<div style="height: 100%">
|
<div class="homeCard">
|
<div class="main-card">
|
<el-row class="cardTop">
|
<el-col :span="12" class="mainCardBtn">
|
<el-button type="primary" icon="Plus" size="default" @click="openDialog('add',{})">新增</el-button>
|
</el-col>
|
</el-row>
|
<el-table :data="reportData" style="width: 100%" height="calc(100% - 48px)"
|
:header-cell-style="{ background: '#fafafa' }">
|
<el-table-column prop="id" label="id" show-overflow-tooltip></el-table-column>
|
<el-table-column prop="fileName" label="文件名称" show-overflow-tooltip></el-table-column>
|
<el-table-column prop="fileType" label="文件类型" show-overflow-tooltip>
|
<template #default="scope">
|
{{ typeList.find(i => i.value == scope.row.fileType)?.label }}
|
</template>
|
</el-table-column>
|
<el-table-column prop="updateUser" label="修改人" show-overflow-tooltip></el-table-column>
|
<el-table-column prop="uploadDate" label="上传时间" show-overflow-tooltip></el-table-column>
|
<el-table-column label="操作" width="140">
|
<template #default="scope">
|
<el-button size="small" text type="primary" @click="openDialog('update',scope.row)">重新上报</el-button>
|
<el-button size="small" v-if="scope.row.filePath !== ''" text type="primary" @click="openFile(scope.row.filePath)">查看</el-button>
|
<el-button style="color: red" size="small" text type="primary" @click="onRowDel(scope.row)">删除</el-button>
|
</template>
|
</el-table-column>
|
</el-table>
|
<div class="pageBtn">
|
<el-pagination @size-change="onHandleSizeChange" small="false" @current-change="onHandleCurrentChange"
|
class="page-position" :pager-count="5" :page-sizes="[10, 20, 30]"
|
v-model:current-page="listQuery.pageIndex" background v-model:page-size="listQuery.pageSize"
|
layout="total, sizes, prev, pager, next, jumper" :total="total"></el-pagination>
|
</div>
|
</div>
|
</div>
|
</div>
|
<add-report ref="reportRef" @refresh="getData"></add-report>
|
</div>
|
</template>
|
|
<script lang="ts">
|
import {toRefs, reactive, onMounted, ref, defineComponent} from 'vue'
|
import {ElMessageBox, ElMessage} from 'element-plus'
|
import {Plus} from '@element-plus/icons-vue'
|
import addReport from "./components/addReport.vue"
|
import {judgeReportApi} from "/@/api/dataUpload/saftyBaseInfo/judgeReport";
|
import axios from "axios";
|
import Cookies from "js-cookie";
|
|
// 定义接口来定义对象的类型
|
interface TableDataRow {
|
id: number | null
|
fileType: number | null
|
fileName: string
|
updateUser: string
|
uploadDate: string
|
filePath: string
|
}
|
|
interface TableDataState {
|
reportData: [],
|
listQuery: {
|
searchParams: {}
|
pageIndex: number
|
pageSize: number
|
}
|
total: null | number
|
typeList: Array<object>
|
}
|
|
export default defineComponent({
|
name: 'saftyFile',
|
components: {addReport},
|
setup() {
|
const reportRef = ref();
|
const state = reactive<TableDataState>({
|
reportData: [],
|
listQuery: {
|
searchParams: {},
|
pageIndex: 1,
|
pageSize: 10
|
},
|
total: null,
|
typeList: [
|
{
|
value: 1,
|
label: '安全管理制度'
|
},
|
{
|
value: 2,
|
label: '安全操作规程',
|
},
|
{
|
value: 3,
|
label: '全员安全生产责任制'
|
}
|
]
|
});
|
|
// 页面加载时
|
onMounted(() => {
|
getData()
|
});
|
|
const getData = async () => {
|
const res = await judgeReportApi().getSafeFileList(state.listQuery)
|
if (res.data.code == 200) {
|
state.reportData = res.data.data
|
state.total = res.data.total
|
} else {
|
ElMessage({
|
type: 'warning',
|
message: res.data.msg
|
})
|
}
|
}
|
|
const openDialog = (type: string, data: object) => {
|
reportRef.value.open(type, data, state.typeList)
|
}
|
|
const openFile = (file: string) => {
|
// axios.get(file,{headers:{'Content-Type': 'application/json','Authorization': `${Cookies.get('token')}`,'uid':`${Cookies.get('uid')}`},responseType: 'blob'}).then(res=>{
|
// if (res) {
|
// const link = document.createElement('a')
|
// let blob = new Blob([res.data],{type: 'application/pdf'})
|
// link.style.display = "none";
|
// link.href = URL.createObjectURL(blob); // 创建URL
|
// window.open(link.href)
|
// } else {
|
// ElMessage({
|
// type: 'warning',
|
// message: '文件读取失败'
|
// });
|
// }
|
// })
|
window.open(file)
|
}
|
|
// 删除用户
|
const onRowDel = (row: TableDataRow) => {
|
ElMessageBox.confirm(`此操作将永久删除文件名称:“${row.fileName}”,是否继续?`, '提示', {
|
confirmButtonText: '确认',
|
cancelButtonText: '取消',
|
type: 'warning'
|
})
|
.then(async () => {
|
const res = await judgeReportApi().delSafeFile({ids: [row.id]})
|
if (res.data.code == '200') {
|
ElMessage({
|
type: 'success',
|
message: '删除成功'
|
})
|
await getData()
|
} else {
|
ElMessage({
|
type: 'warning',
|
message: res.data.msg
|
})
|
}
|
})
|
.catch(() => {
|
});
|
};
|
// 分页改变
|
const onHandleSizeChange = (val: number) => {
|
state.listQuery.pageSize = val;
|
getData()
|
};
|
// 分页改变
|
const onHandleCurrentChange = (val: number) => {
|
state.listQuery.pageIndex = val;
|
getData()
|
};
|
|
return {
|
reportRef,
|
openFile,
|
openDialog,
|
getData,
|
onRowDel,
|
onHandleSizeChange,
|
onHandleCurrentChange,
|
...toRefs(state)
|
};
|
}
|
});
|
</script>
|
<style lang="scss" scoped>
|
.home-container {
|
height: calc(100vh - 144px);
|
box-sizing: border-box;
|
overflow: hidden;
|
|
.demo-tabs {
|
width: 100%;
|
height: 100%;
|
|
&::v-deep(.el-tabs__content) {
|
height: calc(100% - 60px);
|
}
|
|
.el-tab-pane {
|
height: 100%;
|
}
|
}
|
|
.homeCard {
|
width: 100%;
|
padding: 20px;
|
box-sizing: border-box;
|
background: #fff;
|
border-radius: 4px;
|
|
.main-card {
|
width: 100%;
|
height: 100%;
|
|
.cardTop {
|
display: flex;
|
align-items: center;
|
justify-content: space-between;
|
margin-bottom: 20px;
|
|
.mainCardBtn {
|
margin: 0;
|
}
|
}
|
|
.pageBtn {
|
height: 60px;
|
display: flex;
|
align-items: center;
|
justify-content: right;
|
|
.demo-pagination-block + .demo-pagination-block {
|
margin-top: 10px;
|
}
|
|
.demo-pagination-block .demonstration {
|
margin-bottom: 16px;
|
}
|
}
|
}
|
|
&:last-of-type {
|
height: calc(100% - 100px);
|
}
|
}
|
|
.el-row {
|
display: flex;
|
align-items: center;
|
margin-bottom: 20px;
|
|
&:last-child {
|
margin-bottom: 0;
|
}
|
|
.grid-content {
|
align-items: center;
|
min-height: 36px;
|
}
|
|
.topInfo {
|
display: flex;
|
align-items: center;
|
font-size: 16px;
|
font-weight: bold;
|
|
& > div {
|
white-space: nowrap;
|
margin-right: 20px;
|
}
|
}
|
}
|
|
.el-card {
|
border: 0;
|
}
|
}
|
</style>
|