zhouwx
4 天以前 ff1169ac5114c68e96c5686a0caa5d69d8a60b8a
src/views/work/selfProblems/internalAudit/problemMng/noConformanceMng/index.vue
@@ -8,9 +8,10 @@
              plain
              icon="Plus"
              @click="openDialog('add',{})"
              v-hasPermi="['noConformanceMng:list:add']"
          >新增</el-button>
        </el-form-item>
        <el-form-item v-if="isAdmin" label="企业:" >
        <el-form-item v-if="isAdmin" label="单位:" >
          <el-select v-model="data.queryParams.companyId" placeholder="请选择" clearable>
            <el-option
                v-for="item in companyList"
@@ -29,18 +30,18 @@
    <!-- 表格数据 -->
    <el-table v-loading="loading" :data="dataList" :border="true">
      <el-table-column label="序号" type="index" align="center" width="80"/>
      <el-table-column label="文件名称" prop="inconsistentName" align="center"/>
      <el-table-column label="不符合项内容" prop="inconsistentName" align="center"/>
      <el-table-column label="年份" prop="year" align="center"/>
      <el-table-column label="文件" align="center">
        <template #default="scope">
          <el-link type="primary" @click="openFile(scope.row.filePath)">{{scope.row.inconsistentName + scope.row.format}}</el-link>
          <el-link v-for="(path,index) in scope.row.filePath?.split(',')" :key="index" type="primary" @click="openFile(path)">{{scope.row.inconsistentName + '文件'+(index + 1) + '.' + path.split('.')[1]}}<span v-if="index < scope.row.filePath?.split(',').length - 1">、</span></el-link>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" >
        <template #default="scope">
          <el-button link type="primary" @click="downloadFile(scope.row.filePath)">下载</el-button>
          <el-button link type="primary" @click="openDialog('edit',scope.row)">编辑</el-button>
          <el-button link type="danger" @click="handleDelete(scope.row)">删除</el-button>
<!--          <el-button link type="primary" @click="downloadFile(scope.row.filePath)" v-hasPermi="['noConformanceMng:list:edit']">下载</el-button>-->
          <el-button link type="primary" @click="openDialog('edit',scope.row)" v-hasPermi="['noConformanceMng:list:edit']">编辑</el-button>
          <el-button link type="danger" @click="handleDelete(scope.row)" v-hasPermi="['noConformanceMng:list:del']">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
@@ -140,20 +141,21 @@
const openFile = async(path)=>{
  const ext = path.split('.').pop().toLowerCase();
  if (ext === 'doc') {
    ElMessageBox.confirm('暂不支持线上预览.doc文件,是否下载查看?', '提示', { confirmButtonText: '确认', cancelButtonText: '取消', type: 'warning' }).then(() => {
    ElMessageBox.confirm('暂不支持线上预览.doc、.xls、.xlsx文件,是否下载查看?', '提示', { confirmButtonText: '确认', cancelButtonText: '取消', type: 'warning' }).then(() => {
      window.open(`${import.meta.env.VITE_APP_BASE_API}/${path}`, '_blank');
    }).catch(() => {
      console.log('取消预览')
    });
    return
  }
  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(`
  }else if(ext == 'pdf' || ext == 'jpg' ){
    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>
@@ -168,13 +170,15 @@
        </body>
      </html>
    `);
    // 3. 渲染 DOCX
    await renderAsync(arrayBuffer, win.document.getElementById('container'));
      // 3. 渲染 DOCX
      await renderAsync(arrayBuffer, win.document.getElementById('container'));
  } catch (error) {
    console.error('预览失败:', error);
    alert(`预览失败: ${error.message}`);
    } catch (error) {
      console.error('预览失败:', error);
      alert(`预览失败: ${error.message}`);
    }
  }
}
const openDialog = (type, value) => {