祖安之光
2025-12-03 9674af17d8e7ad8f85c9df3b89d99a71d7e39268
src/views/build/conpanyFunctionConsult/digitalFileDep/manageType/qualityManual/index.vue
@@ -10,7 +10,7 @@
<!--              @click="openDialog('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"
@@ -23,7 +23,7 @@
        <el-form-item >
          <el-button v-if="isAdmin" type="primary" @click="getList">查询</el-button>
          <el-button v-if="isAdmin" type="primary" plain @click="reset">重置</el-button>
          <el-button type="primary" @click="addFile">生成质量手册</el-button>
          <el-button type="primary" @click="addFile" v-hasPermi="['qualityManage2:list:add']">生成质量手册</el-button>
        </el-form-item>
      </el-form>
    </div>
@@ -37,9 +37,9 @@
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template #default="scope">
          <el-button link type="primary" @click="initFile(scope.row)">下载</el-button>
          <el-button link type="primary" @click="openDialog('add',scope.row)">上传</el-button>
          <el-button link type="danger" @click="handleDelete(scope.row)">删除</el-button>
          <el-button link type="primary" @click="initFile(scope.row)" v-hasPermi="['qualityManage2:list:edit']">下载</el-button>
          <el-button link type="primary" @click="openDialog('add',scope.row)" v-hasPermi="['qualityManage2:list:add']">上传</el-button>
          <el-button link type="danger" @click="handleDelete(scope.row)" v-hasPermi="['qualityManage2:list:del']">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
@@ -80,7 +80,7 @@
  getStandardDetail,
  getStandardQuality
} from "@/api/standardSys/standardSys";
import {getDepart, getDistribution, getSysClause} from "@/api/orgStructure/depart";
import {getDepart, getDistribution, getFunctionalRemarkList, getSysClause} from "@/api/orgStructure/depart";
const userStore = useUserStore()
const { proxy } = getCurrentInstance();
@@ -183,7 +183,7 @@
const getDeptList = async (val) => {
  const res = await getDepart({responsType: 1, companyId: val.companyId})
  if(res.code == 200){
    data.originDeptList = res.data
    data.originDeptList = JSON.parse(JSON.stringify(res.data))
    data.deptList.deptName = val.companyName
    data.deptList.children = proxy.handleTree(res.data, "deptId")
  }else{
@@ -229,12 +229,13 @@
  if(res.code === 200){
    if(!res.data || (res.data.companyIndustryTemplates.length == 0 && res.data.companyQualityPolicies.length == 0 && res.data.companySummaries.length == 0 && res.data.sysFunctionalDistributions
        .length == 0 && res.data.treeSelects.length == 0)){
      return Promise.reject(new Error('该企业暂无质量数据'));
      loading.value = false
      return Promise.reject(new Error('该企业暂无质量数据'))
    }
    data.companyInfo.summaries = res.data.companySummaries ? res.data.companySummaries[0]?.companySummary : []
    data.companyInfo.policies = res.data.companyQualityPolicies ? res.data.companyQualityPolicies[0]?.policy : []
    const duties = transToTableData(res.data.sysFunctionalDistributions,data.originDeptList)
    data.companyInfo.allDeptNames = duties.allDeptNames
    data.companyInfo.allDepts = duties.allDepts
    data.companyInfo.clauses = duties.clauses
    data.companyInfo.temps = res.data.companyIndustryTemplates?.map((item,index)=>{
      return {
@@ -242,6 +243,25 @@
        templateName: item.templateName
      }
    }) || []
    data.companyInfo.productServiceImages = res.data.productServiceDatas ? await processImagesToBase64(res.data.productServiceDatas): []
  }else{
    ElMessage.warning(res.message)
  }
}
const getRemarksList = async (companyId)=> {
  const res = await getFunctionalRemarkList({companyId: companyId})
  if(res.code == 200){
    const originRemark = res.data
    for(let item of originRemark){
      const foundObj = data.caluseList.find(i=>i.clauseNum == item.clauseNum)
      if(foundObj){
        foundObj.remark = item.remark
      }
    }
    data.companyInfo.remarks = originRemark.map(i=>{
      return `${i.clauseNum}:${i.remark}`
    }).join(';')
  }else{
    ElMessage.warning(res.message)
  }
@@ -250,22 +270,26 @@
const transToTableData=(duties,deptList)=>{
  // 步骤1:获取所有唯一的部门和条款编号
  // const allDeptNames = [...new Set(duties.map(item => item.deptName))];
  const allDeptNames = deptList ? deptList.map(item => item.deptName) : [...new Set(duties.map(item => item.deptName))]
  const allDepts = deptList
  const allClauseNums = [...new Set([
    ...data.caluseList.map(c => c.clauseNum),
    ...duties.map(d => d.clauseNum)
  ])];
// 步骤2:为每个条款生成完整的部门数据(缺失数据默认 chooseLab: 0)
  const mergeValues = ['4','5','6','7','7.1','8','8.2','8.3','8.4','8.5','9','9.1','10']
  const mergeValues = ['7.1','8.2','8.3','8.4','8.5','9.1']
  const processedClauses = allClauseNums.map(clauseNum => {
    const clauseContent = data.caluseList.find(c => c.clauseNum === clauseNum)?.content || "";
    // 为当前条款生成所有部门的数据(确保每个部门都有值)
    const deptValues = allDeptNames.map(deptName => {
    const deptValues = allDepts.map(dept => {
      const matchedDept = duties.find(
          item => item.clauseNum === clauseNum && item.deptName === deptName
      );
      return matchedDept ? (matchedDept.chooseLab==1?'●':'○' ): '○'
          item => item.clauseNum === clauseNum && item.deptId === dept.deptId
      )
      if(dept.deptType == '0'){
        return matchedDept ? (matchedDept.chooseLab==1?'●':'○' ): '○'
      }else{
        return matchedDept ? (matchedDept.chooseLab==1?'▲':'○' ): '○'
      }
    });
    return {
      clauseNum,
@@ -276,8 +300,59 @@
// 最终数据结构
  return {
    clauses: processedClauses,
    allDeptNames // 用于生成表头
    allDepts // 用于生成表头
  };
}
// 新增:将图片URL转换为Base64
async function urlToBase64(imageUrl) {
  return new Promise((resolve, reject) => {
    // 如果是相对路径,添加基础URL
    let fullUrl = imageUrl;
    if (!imageUrl.startsWith('http')) {
      fullUrl = import.meta.env.VITE_APP_BASE_API + '/' + imageUrl;
    }
    const xhr = new XMLHttpRequest();
    xhr.open('GET', fullUrl, true);
    xhr.responseType = 'blob';
    xhr.onload = function() {
      if (this.status === 200) {
        const blob = this.response;
        const reader = new FileReader();
        reader.onloadend = function() {
          resolve(reader.result); // 返回base64字符串
        };
        reader.onerror = reject;
        reader.readAsDataURL(blob);
      } else {
        reject(new Error(`图片加载失败: ${this.status}`));
      }
    };
    xhr.onerror = reject;
    xhr.send();
  });
}
// 新增:处理图片数组
async function processImagesToBase64(imageUrls) {
  try {
    const base64Images = [];
    for (const url of imageUrls) {
      try {
        const base64 = await urlToBase64(url);
        base64Images.push(base64);
      } catch (error) {
        console.warn(`无法加载图片 ${url}:`, error);
        // 可以添加一个占位图片或跳过
        base64Images.push('');
      }
    }
    return base64Images;
  } catch (error) {
    console.error('处理图片失败:', error);
    return [];
  }
}
const initFile = async (val) => {
@@ -289,6 +364,7 @@
    try {
      await getDeptList(val)
      await getInfo(val)
      await getRemarksList(val.companyId)
      // 2. 等待DOM更新完成
      await nextTick();
@@ -367,4 +443,4 @@
    pointer-events: none; /* 禁止交互 */
    z-index: -1;
  }
</style>
</style>