<template>
|
<div class="notice">
|
<el-dialog
|
v-model="dialogVisible"
|
title="证书列表"
|
width="600px"
|
:before-close="handleClose"
|
:close-on-press-escape="false"
|
:close-on-click-modal="false"
|
>
|
<el-button
|
style="margin-bottom: 15px;float: right"
|
type="primary"
|
@click="openAddDialog('add',{})"
|
>新增</el-button>
|
<el-table v-loading="loading" :data="dataList" :border="true" >
|
<el-table-column type="index" label="序号" width="80" align="center"></el-table-column>
|
<el-table-column label="证书名称" prop="certifityName" align="center" />
|
<el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="200" >
|
<template #default="scope" >
|
<el-button link type="primary" @click="openFile(scope.row.filePath)">查看</el-button>
|
<el-button link type="primary" @click="downloadFile(scope.row)">下载</el-button>
|
<el-button link type="primary" @click="openAddDialog('edit',scope.row)" >编辑</el-button>
|
<el-button link type="danger" @click="handleDelete(scope.row)" >删除</el-button>
|
</template>
|
</el-table-column>
|
</el-table>
|
|
<div class="pag-container">
|
<!-- <el-pagination-->
|
<!-- v-model:current-page="data.queryParams.pageNum"-->
|
<!-- v-model:page-size="data.queryParams.pageSize"-->
|
<!-- :page-sizes="[10,15,20,25]"-->
|
<!-- layout="total, sizes, prev, pager, next, jumper"-->
|
<!-- :total="total"-->
|
<!-- @size-change="handleSizeChange"-->
|
<!-- @current-change="handleCurrentChange"-->
|
<!-- />-->
|
</div>
|
</el-dialog>
|
<addCertDialog ref="certRef" @getList="getCertList"></addCertDialog>
|
</div>
|
</template>
|
<script setup>
|
import {reactive, ref, toRefs, defineEmits, nextTick, onMounted} from 'vue'
|
import {ElMessage, ElMessageBox} from "element-plus";
|
import addCertDialog from './addCert.vue'
|
import {addUser, editUser, getUserById, resetPwd} from "@/api/onlineEducation/user"
|
import {Base64} from "js-base64"
|
import {getCompany} from "@/api/onlineEducation/company";
|
import {addIndustryTemp, updateIndustryTemp, updateInfoPlatforms} from "@/api/staffManage/staff";
|
import {getToken} from "@/utils/auth";
|
import {delPic} from "@/api/onlineEducation/banner";
|
import {addFile, editFile} from "@/api/qualityManage/range";
|
import {addProductFile, editProductFile} from "@/api/selfProblems/productFile";
|
import {delSupplierById, delSupplierCert, getPerformance, getSupplierCert} from "@/api/supplier/supplierList";
|
import axios from "axios";
|
import {renderAsync} from "docx-preview";
|
|
const emit = defineEmits(["getList"]);
|
const dialogVisible = ref(false)
|
const superRef = ref()
|
const certRef = ref()
|
const state = reactive({
|
title: '',
|
supplierSureId: null
|
})
|
onMounted(() => {
|
|
});
|
const loading = ref(false);
|
const dataList = ref([]);
|
const total = ref(0);
|
const openDialog = async (type, value) => {
|
state.supplierSureId = value.id
|
await getCertList()
|
dialogVisible.value = true
|
}
|
const getCertList = async () => {
|
const param = {
|
supplierSureId: state.supplierSureId
|
}
|
const res = await getSupplierCert(param)
|
if(res.code == 200){
|
dataList.value = res.data
|
|
}else {
|
ElMessage.warning(res.message)
|
}
|
}
|
|
|
|
const handleClose = () => {
|
dialogVisible.value = false;
|
}
|
const openAddDialog = (type,value) => {
|
value.supplierSureId = state.supplierSureId
|
certRef.value.openDialog(type,value)
|
}
|
|
const handleDelete = (val) => {
|
ElMessageBox.confirm(
|
'确定删除此条数据?',
|
'提示',
|
{
|
confirmButtonText: '确定',
|
cancelButtonText: '取消',
|
type: 'warning',
|
})
|
.then( async() => {
|
const res = await delSupplierCert(val.id);
|
if(res.code === 200){
|
ElMessage({
|
type: 'success',
|
message: '删除成功'
|
});
|
getCertList();
|
}else{
|
ElMessage.warning(res.message)
|
}
|
})
|
}
|
const downloadFile = (e)=>{
|
axios.get(import.meta.env.VITE_APP_BASE_API + '/' +e.filePath,{headers:{'Content-Type': 'application/json','Authorization': `${getToken()}`},responseType: 'blob'}).then(res=>{
|
if (res) {
|
const link = document.createElement('a')
|
let blob = new Blob([res.data],{type: res.data.type})
|
link.style.display = "none";
|
link.href = URL.createObjectURL(blob); // 创建URL
|
link.setAttribute("download", e.certifityName);
|
document.body.appendChild(link);
|
link.click();
|
document.body.removeChild(link);
|
} else {
|
ElMessage({
|
type: 'warning',
|
message: '文件读取失败'
|
});
|
}
|
})
|
}
|
const openFile = async(path)=>{
|
|
const ext = path.split('.').pop().toLowerCase();
|
if (ext === 'doc') {
|
ElMessageBox.confirm('暂不支持线上预览.doc文件,是否下载查看?', '提示', { confirmButtonText: '确认', cancelButtonText: '取消', type: 'warning' }).then(() => {
|
window.open(`${import.meta.env.VITE_APP_BASE_API}/${path}`, '_blank');
|
}).catch(() => {
|
console.log('取消预览')
|
});
|
return
|
}else if(ext == 'pdf' || ext == 'jpg' || ext == 'jpeg' || ext == 'png' ){
|
window.open(`${import.meta.env.VITE_APP_BASE_API}/${path}`, '_blank');
|
}else{
|
try {
|
// 1. 获取文件
|
const response = await fetch(import.meta.env.VITE_APP_BASE_API + '/' + path);
|
const arrayBuffer = await response.arrayBuffer()
|
// 2. 创建新窗口
|
const win = window.open('', '_blank')
|
win.document.write(`
|
<!DOCTYPE html>
|
<html>
|
<head>
|
<title>预览</title>
|
<style>
|
body { margin: 20px; font-family: Arial; }
|
.docx-container { width: 100%; height: 100%; }
|
</style>
|
</head>
|
<body>
|
<div id="container" class="docx-container"></div>
|
</body>
|
</html>
|
`);
|
// 3. 渲染 DOCX
|
await renderAsync(arrayBuffer, win.document.getElementById('container'));
|
|
} catch (error) {
|
alert(`预览失败: ${error.message}`);
|
}
|
}
|
}
|
defineExpose({
|
openDialog
|
});
|
|
</script>
|
|
<style scoped lang="scss">
|
.notice{
|
:deep(.el-form .el-form-item__label) {
|
font-size: 15px;
|
}
|
.file {
|
display: flex;
|
flex-direction: column;
|
align-items: flex-start;
|
}
|
}
|
</style>
|