| | |
| | | <!-- @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" |
| | |
| | | <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> |
| | |
| | | </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> |
| | |
| | | templateName: item.templateName |
| | | } |
| | | }) || [] |
| | | data.companyInfo.productServiceImages = res.data.productServiceDatas ? await processImagesToBase64(res.data.productServiceDatas): [] |
| | | }else{ |
| | | ElMessage.warning(res.message) |
| | | } |
| | |
| | | }; |
| | | } |
| | | |
| | | // 新增:将图片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) => { |
| | | data.companyInfo = {} |
| | | loading.value = true |