Browse Source

资料库调整

huangguoce 6 months ago
parent
commit
9e62c7d9db

+ 349 - 286
src/api/sys/OSSService.js

@@ -1,342 +1,405 @@
-import OSS from 'ali-oss'
-import { ElMessage } from 'element-plus'
-import request from '@/utils/httpRequest'
+import OSS from "ali-oss";
+import { ElMessage } from "element-plus";
+import request from "@/utils/httpRequest";
 import { PUBLIC_MODULES_PATH as prefix } from "../AppPath";
 
 export default class OSSSerive {
-	queryById (id) {
+	queryById(id) {
 		return request({
-			url: prefix + '/oss/file/queryById',
-			method: 'get',
+			url: prefix + "/oss/file/queryById",
+			method: "get",
 			params: { id: id },
-		})
+		});
+	}
+	saveMsg(param) {
+		return request({
+			url: prefix + "/oss/file/saveMsg",
+			method: "post",
+			data: param,
+		});
+	}
+	findFileList(attachmentId) {
+		return request({
+			url: prefix + "/oss/file/findFileList",
+			method: "get",
+			params: { attachmentId: attachmentId },
+		});
+	}
+	getTemporaryUrl(url) {
+		return request({
+			url: prefix + "/oss/file/getTemporaryUrl",
+			method: "get",
+			params: { url: url },
+		});
+	}
+	getFileSizeByUrl(url) {
+		return request({
+			url: prefix + "/oss/file/getFileSizeByUrl",
+			method: "get",
+			params: { url: url },
+		});
+	}
+	deleteMsgById(id) {
+		return request({
+			url: prefix + "/oss/file/deleteMsgById",
+			method: "get",
+			params: { id: id },
+		});
+	}
+	downLoadAttach(url) {
+		return request({
+			url: prefix + "/oss/file/downLoadAttach",
+			method: "get",
+			responseType: "blob",
+			params: { file: url },
+		});
 	}
-  saveMsg (param) {
-    return request({
-      url: prefix + '/oss/file/saveMsg',
-      method: 'post',
-      data: param
-    })
-  }
-  findFileList (attachmentId) {
-    return request({
-		  url: prefix + '/oss/file/findFileList',
-      method: 'get',
-      params: {attachmentId: attachmentId}
-    })
-  }
-  getTemporaryUrl (url) {
-    return request({
-      url: prefix + '/oss/file/getTemporaryUrl',
-      method: 'get',
-      params: {url: url}
-    })
-  }
-  getFileSizeByUrl (url) {
-    return request({
-      url: prefix + '/oss/file/getFileSizeByUrl',
-      method: 'get',
-      params: {url: url}
-    })
-  }
-  deleteMsgById (id) {
-    return request({
-      url: prefix + '/oss/file/deleteMsgById',
-      method: 'get',
-      params: {id: id}
-    })
-  }
-  downLoadAttach (url) {
-    return request({
-      url: prefix + '/oss/file/downLoadAttach',
-      method: 'get',
-      responseType: 'blob',
-      params: {file: url}
-    })
-  }
 
-	disposeXmlFile (data) {
-    return request({
-      url: prefix + '/oss/file/disposeXmlFile',
-      method: 'post',
-	  data: data
-    })
-  }
-	downLoadFileDisposeXmlFile (url) {
-    return request({
-      url: prefix + '/oss/file/downLoadFileDisposeXmlFile',
-      method: 'post',
-		params: {file: url}
-    })
-  }
-	isUsedByInvoiceNumber (invoiceNumber) {
+	disposeXmlFile(data) {
 		return request({
-			url: prefix + '/oss/file/isUsedByInvoiceNumber',
-			method: 'get',
-			params: {invoiceNumber: invoiceNumber}
-		})
+			url: prefix + "/oss/file/disposeXmlFile",
+			method: "post",
+			data: data,
+		});
+	}
+	downLoadFileDisposeXmlFile(url) {
+		return request({
+			url: prefix + "/oss/file/downLoadFileDisposeXmlFile",
+			method: "post",
+			params: { file: url },
+		});
+	}
+	isUsedByInvoiceNumber(invoiceNumber) {
+		return request({
+			url: prefix + "/oss/file/isUsedByInvoiceNumber",
+			method: "get",
+			params: { invoiceNumber: invoiceNumber },
+		});
+	}
+
+	downloadAndUploadToMyCollect(data) {
+		return request({
+			url: prefix + "/oss/file/downloadAndUploadToMyCollect",
+			method: "post",
+			data: data,
+		});
 	}
 }
 
 export const client = new OSS({
-  region: 'oss-cn-hangzhou', // oss地址
-  accessKeyId: 'LTAI5tKa6kzGr5EyPWJB4EcD', // 通过阿里云控制台创建的AccessKey ID。
-  accessKeySecret: 'arHxB7ZPhizrBYf4844TtyaRctPMgW', // 通过阿里云控制台创建的AccessKey Secret。
-	bucket: 'xgxm-test', // 仓库名字
+	region: "oss-cn-hangzhou", // oss地址
+	accessKeyId: "LTAI5tKa6kzGr5EyPWJB4EcD", // 通过阿里云控制台创建的AccessKey ID。
+	accessKeySecret: "arHxB7ZPhizrBYf4844TtyaRctPMgW", // 通过阿里云控制台创建的AccessKey Secret。
+	bucket: "xgxm-test", // 仓库名字
 	// bucket: 'xg-pg', // 仓库名字
-  useFetch: true, // 支持上传大于100KB的文件
-  secure: false // 返回的url为https
-})
+	useFetch: true, // 支持上传大于100KB的文件
+	secure: false, // 返回的url为https
+});
 
 export const headers = {
-  // 指定该Object被下载时网页的缓存行为。
-  'Cache-Control': 'no-cache',
-  // 指定该Object被下载时的名称。
-  'Content-Disposition': 'inline',
-  // 指定该Object被下载时的内容编码格式。
-  'Content-Encoding': 'UTF-8',
-  // 指定过期时间。
-  Expires: 'Wed, 08 Jul 2023 16:57:01 GMT',
-  // 指定Object的存储类型。
-  'x-oss-storage-class': 'Standard',
-  // 指定Object的访问权限。
-  // 'x-oss-object-acl': 'private',
-  // 设置Object的标签,可同时设置多个标签。
-  'x-oss-tagging': 'Tag1=1&Tag2=2',
-  // 指定CopyObject操作时是否覆盖同名目标Object。此处设置为true,表示禁止覆盖同名Object。
-  'x-oss-forbid-overwrite': 'true'
-  // 'secure': 'true'
-}
+	// 指定该Object被下载时网页的缓存行为。
+	"Cache-Control": "no-cache",
+	// 指定该Object被下载时的名称。
+	"Content-Disposition": "inline",
+	// 指定该Object被下载时的内容编码格式。
+	"Content-Encoding": "UTF-8",
+	// 指定过期时间。
+	Expires: "Wed, 08 Jul 2023 16:57:01 GMT",
+	// 指定Object的存储类型。
+	"x-oss-storage-class": "Standard",
+	// 指定Object的访问权限。
+	// 'x-oss-object-acl': 'private',
+	// 设置Object的标签,可同时设置多个标签。
+	"x-oss-tagging": "Tag1=1&Tag2=2",
+	// 指定CopyObject操作时是否覆盖同名目标Object。此处设置为true,表示禁止覆盖同名Object。
+	"x-oss-forbid-overwrite": "true",
+	// 'secure': 'true'
+};
 
-export function onChange (file, files) {
-  // console.log(file, 'file', files, 'Filest')
-  return files
+export function onChange(file, files) {
+	// console.log(file, 'file', files, 'Filest')
+	return files;
 }
 
 // eslint-disable-next-line no-unused-vars
-export function handleUploadSuccess (response, file, fileS) {
-  // console.log(response, file, fileS, 'response, file, fileList')
+export function handleUploadSuccess(response, file, fileS) {
+	// console.log(response, file, fileS, 'response, file, fileList')
 }
 
-export function handleRemove (e, files) {
-  return files
+export function handleRemove(e, files) {
+	return files;
 }
 
-export function fileName (file) {
-  // console.log('文件名称处理')
-  const tmpcnt = file.file.name.lastIndexOf('.')
-  let fileName = file.file.name.substring(0, tmpcnt)
-  // 将单引号‘’都转换成',将双引号“”都转换成"
-  fileName = fileName.replace(/’|‘/g, '\'').replace(/“|”/g, '')
-  // 将中括号【】转换成[],将大括号{}转换成{}
-  fileName = fileName.replace(/【/g, '(').replace(/】/g, ')').replace(/{/g, '(').replace(/}/g, ')')
-  fileName = fileName.replace(/\[/g, '(').replace(/]/g, ')').replace(/{/g, '(').replace(/}/g, ')')
-  // 将逗号,转换成,,将:转换成:
-  fileName = fileName.replace(/,/g, ',').replace(/:/g, ':')
-  // 将中文——转换为英文-
-  fileName = fileName.replace(/—/g, '-')
-  fileName = fileName.replace(/……/g, '')
-  fileName = fileName.replace(/±/g, '')
-  fileName = fileName.replace(/#/g, '')
-  fileName = fileName.replace(/%/g, '')
-  fileName = fileName.replace(/Π/g, '')
-  fileName = fileName.replace(/π/g, '')
-  fileName = fileName.replace(/·/g, '.')
-  // console.log('文件名处理结果', fileName)
-  return fileName
+export function fileName(file) {
+	// console.log('文件名称处理')
+	const tmpcnt = file.file.name.lastIndexOf(".");
+	let fileName = file.file.name.substring(0, tmpcnt);
+	// 将单引号‘’都转换成',将双引号“”都转换成"
+	fileName = fileName.replace(/’|‘/g, "'").replace(/“|”/g, "");
+	// 将中括号【】转换成[],将大括号{}转换成{}
+	fileName = fileName
+		.replace(/【/g, "(")
+		.replace(/】/g, ")")
+		.replace(/{/g, "(")
+		.replace(/}/g, ")");
+	fileName = fileName
+		.replace(/\[/g, "(")
+		.replace(/]/g, ")")
+		.replace(/{/g, "(")
+		.replace(/}/g, ")");
+	// 将逗号,转换成,,将:转换成:
+	fileName = fileName.replace(/,/g, ",").replace(/:/g, ":");
+	// 将中文——转换为英文-
+	fileName = fileName.replace(/—/g, "-");
+	fileName = fileName.replace(/……/g, "");
+	fileName = fileName.replace(/±/g, "");
+	fileName = fileName.replace(/#/g, "");
+	fileName = fileName.replace(/%/g, "");
+	fileName = fileName.replace(/Π/g, "");
+	fileName = fileName.replace(/π/g, "");
+	fileName = fileName.replace(/·/g, ".");
+	// console.log('文件名处理结果', fileName)
+	return fileName;
 }
 
-
-export function fileNameInvoice (file) {
+export function fileNameInvoice(file) {
 	// console.log('文件名称处理')
-	if(!file.name){
-		file = file.file
+	if (!file.name) {
+		file = file.file;
 	}
-	const tmpcnt = file.name.lastIndexOf('.')
-	let fileName = file.name.substring(0, tmpcnt)
+	const tmpcnt = file.name.lastIndexOf(".");
+	let fileName = file.name.substring(0, tmpcnt);
 	// 将单引号‘’都转换成',将双引号“”都转换成"
-	fileName = fileName.replace(/’|‘/g, '\'').replace(/“|”/g, '')
+	fileName = fileName.replace(/’|‘/g, "'").replace(/“|”/g, "");
 	// 将中括号【】转换成[],将大括号{}转换成{}
-	fileName = fileName.replace(/【/g, '(').replace(/】/g, ')').replace(/{/g, '(').replace(/}/g, ')')
-	fileName = fileName.replace(/\[/g, '(').replace(/]/g, ')').replace(/{/g, '(').replace(/}/g, ')')
+	fileName = fileName
+		.replace(/【/g, "(")
+		.replace(/】/g, ")")
+		.replace(/{/g, "(")
+		.replace(/}/g, ")");
+	fileName = fileName
+		.replace(/\[/g, "(")
+		.replace(/]/g, ")")
+		.replace(/{/g, "(")
+		.replace(/}/g, ")");
 	// 将逗号,转换成,,将:转换成:
-	fileName = fileName.replace(/,/g, ',').replace(/:/g, ':')
+	fileName = fileName.replace(/,/g, ",").replace(/:/g, ":");
 	// 将中文——转换为英文-
-	fileName = fileName.replace(/—/g, '-')
-	fileName = fileName.replace(/……/g, '')
-	fileName = fileName.replace(/±/g, '')
-	fileName = fileName.replace(/#/g, '')
-	fileName = fileName.replace(/%/g, '')
-	fileName = fileName.replace(/Π/g, '')
-	fileName = fileName.replace(/π/g, '')
-	fileName = fileName.replace(/·/g, '.')
+	fileName = fileName.replace(/—/g, "-");
+	fileName = fileName.replace(/……/g, "");
+	fileName = fileName.replace(/±/g, "");
+	fileName = fileName.replace(/#/g, "");
+	fileName = fileName.replace(/%/g, "");
+	fileName = fileName.replace(/Π/g, "");
+	fileName = fileName.replace(/π/g, "");
+	fileName = fileName.replace(/·/g, ".");
 	// console.log('文件名处理结果', fileName)
-	return fileName
+	return fileName;
 }
 
-export function beforeAvatarUpload (file, fileList, maxValue) {
-	if(file){
+export function beforeAvatarUpload(file, fileList, maxValue) {
+	if (file) {
 		// 文件大小校验
-		const isLt2M = file.size / 1024 / 1024 < maxValue
+		const isLt2M = file.size / 1024 / 1024 < maxValue;
 		if (!isLt2M) {
-			fileList.splice(fileList.length - 1, 1)
+			fileList.splice(fileList.length - 1, 1);
 			// console.log('文件大小不能超过 ' + maxValue + ' MB!')
 		}
-		return isLt2M
+		return isLt2M;
 	}
-	return 0
+	return 0;
 }
 
-export function exnameFix (file, isShow, names) {
-  const tmpcnt = file.name.lastIndexOf('.')
-  const exname = file.name.substring(tmpcnt + 1) // 获取后缀名
-  if (names.indexOf(exname) < 0) {
-    if (isShow === '1') {
-		ElMessage({
-			message: '不支持的格式。文件仅支持 ' + names + '格式!',
-			type: 'error',
-		})
-    }
-    return false
-  }
-  return true
+export function exnameFix(file, isShow, names) {
+	const tmpcnt = file.name.lastIndexOf(".");
+	const exname = file.name.substring(tmpcnt + 1); // 获取后缀名
+	if (names.indexOf(exname) < 0) {
+		if (isShow === "1") {
+			ElMessage({
+				message: "不支持的格式。文件仅支持 " + names + "格式!",
+				type: "error",
+			});
+		}
+		return false;
+	}
+	return true;
 }
 
-export async function httpRequest (file, name, type, maxValue) { // 阿里云OSS上传
-  if (!beforeAvatarUpload(file.file, [], maxValue)) {
-    return
-  }
-  // console.log('开始上传')
-  // 判断扩展名
-  const tmpcnt = file.file.name.lastIndexOf('.') // 获取.的下标
-  const exname = file.file.name.substring(tmpcnt + 1) // 获取后缀名
-  // console.log(exname, '后缀名')
-  const now = new Date()
-  const year = now.getFullYear()
-  const month = now.getMonth() + 1
-  const day = now.getDate() > 10 ? now.getDate() : '0' + now.getDate()
-  const filePath = '/attachment-file/assess/' + type + '/' + year + '/' + month + '/' + day + '/' + now.getTime()
-  // console.log(filePath, '文件存储路径')
-  const fileName = filePath + name + '.' + exname
-  // console.log(fileName, '文件名')
+export async function httpRequest(file, name, type, maxValue) {
+	// 阿里云OSS上传
+	if (!beforeAvatarUpload(file.file, [], maxValue)) {
+		return;
+	}
+	// console.log('开始上传')
+	// 判断扩展名
+	const tmpcnt = file.file.name.lastIndexOf("."); // 获取.的下标
+	const exname = file.file.name.substring(tmpcnt + 1); // 获取后缀名
+	// console.log(exname, '后缀名')
+	const now = new Date();
+	const year = now.getFullYear();
+	const month = now.getMonth() + 1;
+	const day = now.getDate() > 10 ? now.getDate() : "0" + now.getDate();
+	const filePath =
+		"/attachment-file/assess/" +
+		type +
+		"/" +
+		year +
+		"/" +
+		month +
+		"/" +
+		day +
+		"/" +
+		now.getTime();
+	// console.log(filePath, '文件存储路径')
+	const fileName = filePath + name + "." + exname;
+	// console.log(fileName, '文件名')
 
-  await client.multipartUpload(fileName, file.file, {
-	  // eslint-disable-next-line no-unused-vars
-    progress: await function (p, checkpoint) {
-      file.onProgress({percent: Math.floor(p * 100)}) // 触发el-upload组件的onProgress方法
-    }
-    // mime: type,
-  }).then(await function (result) {
-    // console.log(result)
-    if (result.res.status === 200) {
-      // file.onSuccess(result) // 触发el-upload组件的onSuccess方法
-      file.file.url = fileName
-    }
-	  // eslint-disable-next-line handle-callback-err,no-unused-vars
-  }).catch(function (err) {
-    console.log('上传失败',err)
-    file.onError('上传失败') // 触发el-upload组件的onError方法,此方法会移除文件列表
-  })
+	await client
+		.multipartUpload(fileName, file.file, {
+			// eslint-disable-next-line no-unused-vars
+			progress: await function (p, checkpoint) {
+				file.onProgress({ percent: Math.floor(p * 100) }); // 触发el-upload组件的onProgress方法
+			},
+			// mime: type,
+		})
+		.then(
+			await function (result) {
+				// console.log(result)
+				if (result.res.status === 200) {
+					// file.onSuccess(result) // 触发el-upload组件的onSuccess方法
+					file.file.url = fileName;
+				}
+				// eslint-disable-next-line handle-callback-err,no-unused-vars
+			}
+		)
+		.catch(function (err) {
+			console.log("上传失败", err);
+			file.onError("上传失败"); // 触发el-upload组件的onError方法,此方法会移除文件列表
+		});
 }
 
 // eslint-disable-next-line no-unused-vars
-function getTemporaryByUrl (url) {
-  return request({
-    url: prefix + '/oss/file/getTemporaryUrl',
-    method: 'get',
-    params: {url: url}
-  })
+function getTemporaryByUrl(url) {
+	return request({
+		url: prefix + "/oss/file/getTemporaryUrl",
+		method: "get",
+		params: { url: url },
+	});
 }
 
-export async function openWindowOnUrl (row) {
-  if (row.url === undefined || row.url === null || row.url === '') {
-    // Message.error('没有获取到文件的url')
-    return
-  }
-  let rowUrl = ''
-  let suffix = row.name.substring(row.name.lastIndexOf('.') + 1)
-  if (suffix === 'jpg' || suffix === 'png' || suffix === 'gif' || suffix === 'bmp' || suffix === 'jpeg') {
-    await getTemporaryByUrl(row.url).then((data) => {
-      // eslint-disable-next-line no-undef
-      onPreview(data)
-    })
-    return
-  }
-  await getTemporaryByUrl(row.url).then((data) => {
-    rowUrl = data
-  })
+export async function openWindowOnUrl(row) {
+	if (row.url === undefined || row.url === null || row.url === "") {
+		// Message.error('没有获取到文件的url')
+		return;
+	}
+	let rowUrl = "";
+	let suffix = row.name.substring(row.name.lastIndexOf(".") + 1);
+	if (
+		suffix === "jpg" ||
+		suffix === "png" ||
+		suffix === "gif" ||
+		suffix === "bmp" ||
+		suffix === "jpeg"
+	) {
+		await getTemporaryByUrl(row.url).then((data) => {
+			// eslint-disable-next-line no-undef
+			onPreview(data);
+		});
+		return;
+	}
+	await getTemporaryByUrl(row.url).then((data) => {
+		rowUrl = data;
+	});
 	suffix = suffix.toLowerCase();
-  if (suffix === 'pdf' || suffix === 'xml' || suffix === 'rar' || suffix === 'zip' || suffix === 'jar' || suffix === '7z') {
-	  var url = 'https://view.xdocin.com/xdoc?_xdoc='+encodeURIComponent(rowUrl);
-	  //预览参数
-	  var ops = {
-		  // "pdf": true, //word文档尝试以pdf方式显示,默认false
-		  // "img": true, //尝试以图片方式显示,默认false
-		  // "watermark": "XDOC文档预览", //水印文本,显示水印
-		  // "saveable": true, //是否允许保存源文件,默认false
-		  // "printable": false, //是否允许打印,默认true
-		  // "copyable": false, //是否允许选择复制内容,默认true
-		  // "toolbar": false, //是否显示工具条,默认true
-		  // "title": "文档预览", //自定义标题
-		  "expire": 1, //预览链接有效期,单位分钟,默认永久有效
-		  // "limit": "1,3", //限制页数,如:“5”表示只显示前5页,“2,5”表示从第2页开始的5页,对pdf/doc/docx/ppt/pptx有效
-		  // "mtime": 1633093801, //文件修改时间戳(精确到秒)或修改时间(如:2021-10-01 21:10:01),值改变刷新缓存,实时预览
-		  // "referer": "", //读取http源文件时传入的referer值
-		  // "header": "", //读取http源文件时传入的header值,格式为JSON字符串
-		  // "ip": "", //限制ip预览,多个用","分割,支持*,如:192.168.*
-		  // "password": "", //口令,用户需要输入正确的口令,才能预览
-	  };
-	  //传入预览参数
-	  for (var a in ops) {
-		  url += "&" + a + "=" + encodeURIComponent(ops[a]);
-	  }
+	if (
+		suffix === "pdf" ||
+		suffix === "xml" ||
+		suffix === "rar" ||
+		suffix === "zip" ||
+		suffix === "jar" ||
+		suffix === "7z"
+	) {
+		var url =
+			"https://view.xdocin.com/xdoc?_xdoc=" + encodeURIComponent(rowUrl);
+		//预览参数
+		var ops = {
+			// "pdf": true, //word文档尝试以pdf方式显示,默认false
+			// "img": true, //尝试以图片方式显示,默认false
+			// "watermark": "XDOC文档预览", //水印文本,显示水印
+			// "saveable": true, //是否允许保存源文件,默认false
+			// "printable": false, //是否允许打印,默认true
+			// "copyable": false, //是否允许选择复制内容,默认true
+			// "toolbar": false, //是否显示工具条,默认true
+			// "title": "文档预览", //自定义标题
+			expire: 1, //预览链接有效期,单位分钟,默认永久有效
+			// "limit": "1,3", //限制页数,如:“5”表示只显示前5页,“2,5”表示从第2页开始的5页,对pdf/doc/docx/ppt/pptx有效
+			// "mtime": 1633093801, //文件修改时间戳(精确到秒)或修改时间(如:2021-10-01 21:10:01),值改变刷新缓存,实时预览
+			// "referer": "", //读取http源文件时传入的referer值
+			// "header": "", //读取http源文件时传入的header值,格式为JSON字符串
+			// "ip": "", //限制ip预览,多个用","分割,支持*,如:192.168.*
+			// "password": "", //口令,用户需要输入正确的口令,才能预览
+		};
+		//传入预览参数
+		for (var a in ops) {
+			url += "&" + a + "=" + encodeURIComponent(ops[a]);
+		}
 
-    window.open(url, '_blank')
-  } else {
-    window.open('https://view.officeapps.live.com/op/view.aspx?src=' + encodeURIComponent(rowUrl), '_blank')
-  }
+		window.open(url, "_blank");
+	} else {
+		window.open(
+			"https://view.officeapps.live.com/op/view.aspx?src=" +
+				encodeURIComponent(rowUrl),
+			"_blank"
+		);
+	}
 }
 
-export async function toHref (row) {
-  if (row.url === null || row.url === undefined || row.url === '') {
-    // Message.error('没有获取到文件的url')
-    return
-  }
-  const link = document.createElement('a')
-  await getTemporaryByUrl(row.url).then((data) => {
-    const url = data // 完整的url则直接使用
-    // 这里是将url转成blob地址,
-    fetch(url).then(res => res.blob()).then(blob => { // 将链接地址字符内容转变成blob地址
-      link.href = URL.createObjectURL(blob)
-      link.download = row.name || '' // 下载文件的名字
-      // a.download = url.split('/')[url.split('/').length -1] //  // 下载文件的名字
-      document.body.appendChild(link)
-      link.click()
-      // 在资源下载完成后 清除 占用的缓存资源
-      window.URL.revokeObjectURL(link.href)
-      document.body.removeChild(link)
-    })
-  })
+export async function toHref(row) {
+	if (row.url === null || row.url === undefined || row.url === "") {
+		// Message.error('没有获取到文件的url')
+		return;
+	}
+	const link = document.createElement("a");
+	await getTemporaryByUrl(row.url).then((data) => {
+		const url = data; // 完整的url则直接使用
+		// 这里是将url转成blob地址,
+		fetch(url)
+			.then((res) => res.blob())
+			.then((blob) => {
+				// 将链接地址字符内容转变成blob地址
+				link.href = URL.createObjectURL(blob);
+				link.download = row.name || ""; // 下载文件的名字
+				// a.download = url.split('/')[url.split('/').length -1] //  // 下载文件的名字
+				document.body.appendChild(link);
+				link.click();
+				// 在资源下载完成后 清除 占用的缓存资源
+				window.URL.revokeObjectURL(link.href);
+				document.body.removeChild(link);
+			});
+	});
 }
 
-export async function toHrefByUrlAndName (url,name) {
-  if (url === null || url === undefined || url === '') {
-    // Message.error('没有获取到文件的url')
-    return
-  }
-  const link = document.createElement('a')
-  await getTemporaryByUrl(url).then((data) => {
-    const url = data // 完整的url则直接使用
-    // 这里是将url转成blob地址,
-    fetch(url).then(res => res.blob()).then(blob => { // 将链接地址字符内容转变成blob地址
-      link.href = URL.createObjectURL(blob)
-      link.download = name || '' // 下载文件的名字
-      // a.download = url.split('/')[url.split('/').length -1] //  // 下载文件的名字
-      document.body.appendChild(link)
-      link.click()
-      // 在资源下载完成后 清除 占用的缓存资源
-      window.URL.revokeObjectURL(link.href)
-      document.body.removeChild(link)
-    })
-  })
+export async function toHrefByUrlAndName(url, name) {
+	if (url === null || url === undefined || url === "") {
+		// Message.error('没有获取到文件的url')
+		return;
+	}
+	const link = document.createElement("a");
+	await getTemporaryByUrl(url).then((data) => {
+		const url = data; // 完整的url则直接使用
+		// 这里是将url转成blob地址,
+		fetch(url)
+			.then((res) => res.blob())
+			.then((blob) => {
+				// 将链接地址字符内容转变成blob地址
+				link.href = URL.createObjectURL(blob);
+				link.download = name || ""; // 下载文件的名字
+				// a.download = url.split('/')[url.split('/').length -1] //  // 下载文件的名字
+				document.body.appendChild(link);
+				link.click();
+				// 在资源下载完成后 清除 占用的缓存资源
+				window.URL.revokeObjectURL(link.href);
+				document.body.removeChild(link);
+			});
+	});
 }

+ 0 - 1
src/views/attachment/Form.vue

@@ -139,7 +139,6 @@ export default {
 							console.log(this.inputForm.workAttachments);
 
 							this.$refs.uploadComponent.newUpload(method, this.inputForm.workAttachments, 'workCollect')
-
 						})
 					})
 				}

+ 55 - 1
src/views/attachment/List.vue

@@ -39,6 +39,13 @@
                     :sort-config="{ remote: true }" :data="dataList" :checkbox-config="{}">
                     <vxe-column type="seq" width="40"></vxe-column>
                     <vxe-column field="fileName" sortable title="附件名称">
+                        <template #default="scope">
+                            <div>
+                                <el-link type="primary" :underline="false" @click="showFile(scope.row)">{{
+                                    scope.row.fileName
+                                }}</el-link>
+                            </div>
+                        </template>
                     </vxe-column>
                     <vxe-column field="classification" sortable title="收藏分类">
                     </vxe-column>
@@ -101,7 +108,9 @@
             </el-table>
             <el-alert type="success" title="接口传递参数说明:/接口url?参数名=参数值, 如果不传递参数,则使用默认值"
                 style="margin-top: 20px"></el-alert>
+
         </v-dialog>
+        <el-image-viewer hide-on-click-modal v-if="showViewer" @close="closeViewer" :url-list="[url]" zIndex="9999" />
         <workCollectAccessoryForm @refreshList="refreshList" ref="workCollectAccessoryRef"></workCollectAccessoryForm>
     </div>
 </template>
@@ -110,12 +119,17 @@
 import workCollectAccessoryService from "@/api/workCollectAccessory/index"
 import workCollectAccessoryForm from './Form.vue'
 import dictService from "@/api/sys/dictService"
+import OSSSerivce, {
+    openWindowOnUrl
+} from '@/api/sys/OSSService'
 export default {
     components: {
         workCollectAccessoryForm
     },
     data() {
         return {
+            url: "",
+            showViewer: false,
             activeName: 0,
             searchVisible: true,
             searchForm: {
@@ -135,11 +149,13 @@ export default {
             dialogInterfaceVisible: false,
             interfaceTable: [],
             loading: false,
-            userInfo: {}
+            userInfo: {},
+            ossService: null
         };
     },
     activated() {
         this.userInfo = this.$TOOL.data.get("USER_INFO");
+        this.ossService = new OSSSerivce()
         this.searchForm.createById = this.userInfo.id
         this.$nextTick(() => {
             // 将表格和工具栏进行关联
@@ -150,6 +166,44 @@ export default {
         this.refreshList();
     },
     methods: {
+        ifName(row) {
+            if (this.commonJS.isEmpty(row.fileName)) {
+                row.fileName = '---'
+                return false
+            }
+            let suffix = row.fileName.substring(row.fileName.lastIndexOf('.') + 1)
+            if (suffix === 'jpg' || suffix === 'png' || suffix === 'gif' || suffix === 'bmp' || suffix === 'jpeg') {
+                return true
+            } else {
+                return false
+            }
+        },
+        // 关闭查看器
+        closeViewer() {
+            this.url = ''
+            this.showViewer = false
+        },
+        onPreview(url) {
+            this.url = url
+            this.showViewer = true
+        },
+        // 预览文件
+        showFile(row) {
+            if (this.ifName(row)) {
+                this.ossService.getTemporaryUrl(row.url).then((data) => {
+                    console.log(data);
+                    this.onPreview(data)
+                })
+            } else {
+                console.log(2);
+                let obj = {
+                    name: row.fileName,
+                    url: row.url
+                }
+                openWindowOnUrl(obj)
+            }
+
+        },
         //获取字典值
         handleGetDict() {
             dictService.getDictListMapByDict("classification").then((data) => {

+ 38 - 5
src/views/common/AttachmentLib.vue

@@ -72,6 +72,8 @@
         </span>
       </template>
     </el-dialog>
+    <el-image-viewer hide-on-click-modal v-if="showViewer" @close="closeViewer" :url-list="[url]" zIndex="9999" />
+
   </div>
 </template>
 
@@ -93,6 +95,8 @@ export default {
   },
   data() {
     return {
+      url: "",
+      showViewer: false,
       ossService: null,
       visible: false,
       inputForm: {
@@ -125,12 +129,42 @@ export default {
   mounted() {
   },
   methods: {
+    ifName(row) {
+      if (this.commonJS.isEmpty(row.fileName)) {
+        row.fileName = '---'
+        return false
+      }
+      let suffix = row.fileName.substring(row.fileName.lastIndexOf('.') + 1)
+      if (suffix === 'jpg' || suffix === 'png' || suffix === 'gif' || suffix === 'bmp' || suffix === 'jpeg') {
+        return true
+      } else {
+        return false
+      }
+    },
+    // 关闭查看器
+    closeViewer() {
+      this.url = ''
+      this.showViewer = false
+    },
+    onPreview(url) {
+      this.url = url
+      this.showViewer = true
+    },
+    // 预览文件
     showFile(row) {
-      let obj = {
-        name: row.fileName,
-        url: row.url
+      if (this.ifName(row)) {
+        this.ossService.getTemporaryUrl(row.url).then((data) => {
+          this.onPreview(data)
+        })
+      } else {
+        console.log(2);
+        let obj = {
+          name: row.fileName,
+          url: row.url
+        }
+        openWindowOnUrl(obj)
       }
-      openWindowOnUrl(obj)
+
     },
     hasDuplicateName(arr) {
       const names = new Set();
@@ -148,7 +182,6 @@ export default {
         this.$message.error(`请勿选择相同名称文件进行上传`);
         return
       }
-      console.log(this.selectList);
       if (this.selectList.length == 0) {
         this.$message.error(`请选择文件后上传`);
         return

+ 29 - 1
src/views/common/UpLoadComponent.vue

@@ -13,7 +13,8 @@
       <template v-else #trigger>
         <el-button :loading="loading" type="primary" size="default"> 点击上传 </el-button>
       </template>
-      <AttachmentLib :directory="directory" @onDownToOss="handleOnDownToOss"></AttachmentLib>
+      <AttachmentLib v-if="auth !== 'view'" :directory="directory" @onDownToOss="handleOnDownToOss">
+      </AttachmentLib>
 
     </el-upload>
 
@@ -44,9 +45,11 @@
           <template #default="scope">
             <el-button text type="primary" key="01" icon="el-icon-download" size="small"
               @click="toHref(scope.row)">下载</el-button>
+
             <el-button text type="primary" key="02" icon="el-icon-delete" size="small"
               @click="deleteById(scope.row, scope.$index, fileList)"
               :disabled="auth === 'view' && delFlag === false && createBy !== scope.row.createBy.name">删除</el-button>
+
             <!--            <el-button v-if="createBy===scope.row.createBy.name" type="text"  icon="el-icon-delete" size="small"  @click="deleteById(scope.row, scope.$index)" :disabled="auth==='view'&&delFlag === false">删除2</el-button>-->
           </template>
         </el-table-column>
@@ -224,6 +227,31 @@ export default {
         }
       }
     },
+    addMyAttachment(row) {
+      this.$confirm(`确定收藏到个人资料库?`, "提示", {
+        confirmButtonText: "确定",
+        cancelButtonText: "取消",
+        type: "warning",
+      }).then(() => {
+        let inputForm = {
+          classification: "",
+          fileDescription: "",
+          workAttachments: []
+        }
+        inputForm.workAttachments.push(row)
+        this.ossService.downloadAndUploadToMyCollect({
+          url: row.lsUrl,
+          fileName: row.name,
+          dir: this.directory,
+          workCollectAccessoryDTO: {
+            ...inputForm
+          }
+        }).then(res => {
+          this.$message.success(`操作成功`);
+        })
+      });
+
+    },
     async httpRequest(file) {
       await httpRequest(file, fileName(file), this.directory, this.maxValue)
     },

+ 28 - 1
src/views/common/UpLoadComponentCcpm.vue

@@ -13,7 +13,8 @@
       <template v-else #trigger>
         <el-button :loading="loading" type="primary" size="default"> 点击上传 </el-button>
       </template>
-      <AttachmentLib :directory="directory" @onDownToOss="handleOnDownToOss"></AttachmentLib>
+      <AttachmentLib v-if="auth !== 'view'" :directory="directory" @onDownToOss="handleOnDownToOss">
+      </AttachmentLib>
 
     </el-upload>
     <div style="height: calc(100% - 80px);margin-top: 10px">
@@ -46,6 +47,7 @@
             <el-button text type="primary" icon="el-icon-delete" size="small"
               @click="deleteById(scope.row, scope.$index, fileList)"
               :disabled="auth === 'view' && delFlag === false && createBy !== scope.row.createBy.name">删除</el-button>
+
             <!--            <el-button v-if="createBy===scope.row.createBy.name" type="text"  icon="el-icon-delete" size="small"  @click="deleteById(scope.row, scope.$index)" :disabled="auth==='view'&&delFlag === false">删除2</el-button>-->
           </template>
         </el-table-column>
@@ -254,6 +256,31 @@ export default {
         this.fileList.push(file)
       })
     },
+    addMyAttachment(row) {
+      this.$confirm(`确定收藏到个人资料库?`, "提示", {
+        confirmButtonText: "确定",
+        cancelButtonText: "取消",
+        type: "warning",
+      }).then(() => {
+        let inputForm = {
+          classification: "",
+          fileDescription: "",
+          workAttachments: []
+        }
+        inputForm.workAttachments.push(row)
+        this.ossService.downloadAndUploadToMyCollect({
+          url: row.lsUrl,
+          fileName: row.name,
+          dir: this.directory,
+          workCollectAccessoryDTO: {
+            ...inputForm
+          }
+        }).then(res => {
+          this.$message.success(`操作成功`);
+        })
+      });
+
+    },
     getSize(value) {
       if (this.commonJS.isEmpty(value)) {
         return '0 B'

+ 28 - 1
src/views/common/UpLoadComponentV2.1.vue

@@ -13,7 +13,8 @@
       <template v-else #trigger>
         <el-button :loading="loading" type="primary" size="default"> 点击上传 </el-button>
       </template>
-      <AttachmentLib :directory="directory" @onDownToOss="handleOnDownToOss"></AttachmentLib>
+      <AttachmentLib v-if="auth !== 'view'" :directory="directory" @onDownToOss="handleOnDownToOss">
+      </AttachmentLib>
 
     </el-upload>
     <el-button v-if="showSign" :loading="loading" type="info" style="float: right;" @click="clickSign">签章</el-button>
@@ -87,6 +88,7 @@
               :disabled="false">下载</el-button>
             <el-button text type="primary" icon="el-icon-delete" @click="deleteById(scope.row, scope.$index, fileList)"
               :disabled="auth === 'view' && delFlag === false && createBy !== scope.row.createBy.name">删除</el-button>
+
             <!--<el-button text type="primary" icon="el-icon-edit"
                      @click="handleUpdate(scope.row, scope.$index)"
             >{{ scope.row.btn || "修改" }}</el-button>-->
@@ -436,6 +438,31 @@ export default {
         }
       }
     },
+    addMyAttachment(row) {
+      this.$confirm(`确定收藏到个人资料库?`, "提示", {
+        confirmButtonText: "确定",
+        cancelButtonText: "取消",
+        type: "warning",
+      }).then(() => {
+        let inputForm = {
+          classification: "",
+          fileDescription: "",
+          workAttachments: []
+        }
+        inputForm.workAttachments.push(row)
+        this.ossService.downloadAndUploadToMyCollect({
+          url: row.lsUrl,
+          fileName: row.name,
+          dir: this.directory,
+          workCollectAccessoryDTO: {
+            ...inputForm
+          }
+        }).then(res => {
+          this.$message.success(`操作成功`);
+        })
+      });
+
+    },
     async httpRequest(file) {
       await httpRequest(file, fileName(file), this.directory, this.maxValue)
     },

+ 28 - 1
src/views/common/UpLoadComponentV2.vue

@@ -13,7 +13,8 @@
       <template v-else #trigger>
         <el-button :loading="loading" type="primary" size="default"> 点击上传 </el-button>
       </template>
-      <AttachmentLib :directory="directory" @onDownToOss="handleOnDownToOss"></AttachmentLib>
+      <AttachmentLib v-if="auth !== 'view'" :directory="directory" @onDownToOss="handleOnDownToOss">
+      </AttachmentLib>
 
     </el-upload>
     <div style="height: calc(100% - 80px);margin-top: 10px">
@@ -67,6 +68,7 @@
             <el-button text type="primary" icon="el-icon-delete" size="small"
               @click="deleteById(scope.row, scope.$index, fileList)"
               :disabled="auth === 'view' && delFlag === false && createBy !== scope.row.createBy.name">删除</el-button>
+
             <!--<el-button size="small" type="text" icon="el-icon-edit"
                      @click="handleUpdate(scope.row, scope.$index)"
             >{{ scope.row.btn || "修改" }}</el-button>-->
@@ -397,6 +399,31 @@ export default {
         }
       }
     },
+    addMyAttachment(row) {
+      this.$confirm(`确定收藏到个人资料库?`, "提示", {
+        confirmButtonText: "确定",
+        cancelButtonText: "取消",
+        type: "warning",
+      }).then(() => {
+        let inputForm = {
+          classification: "",
+          fileDescription: "",
+          workAttachments: []
+        }
+        inputForm.workAttachments.push(row)
+        this.ossService.downloadAndUploadToMyCollect({
+          url: row.lsUrl,
+          fileName: row.name,
+          dir: this.directory,
+          workCollectAccessoryDTO: {
+            ...inputForm
+          }
+        }).then(res => {
+          this.$message.success(`操作成功`);
+        })
+      });
+
+    },
     async httpRequest(file) {
       await httpRequest(file, fileName(file), this.directory, this.maxValue)
     },

+ 28 - 1
src/views/common/UpLoadComponentV3.1.vue

@@ -13,7 +13,8 @@
       <template v-else #trigger>
         <el-button :loading="loading" type="primary" size="default"> 点击上传 </el-button>
       </template>
-      <AttachmentLib :directory="directory" @onDownToOss="handleOnDownToOss"></AttachmentLib>
+      <AttachmentLib v-if="auth !== 'view'" :directory="directory" @onDownToOss="handleOnDownToOss">
+      </AttachmentLib>
 
     </el-upload>
     <div style="height: calc(100% - 80px);margin-top: 10px">
@@ -69,6 +70,7 @@
               :disabled="false">下载</el-button>
             <el-button text type="primary" icon="el-icon-delete" @click="deleteById(scope.row, scope.$index, fileList)"
               :disabled="auth === 'view' && delFlag === false && createBy !== scope.row.createBy.name">删除</el-button>
+
             <!--<el-button type="text" icon="el-icon-edit"
                      @click="handleUpdate(scope.row, scope.$index)"
             >{{ scope.row.btn || "修改" }}</el-button>-->
@@ -626,6 +628,31 @@ export default {
         }
       })
     },
+    addMyAttachment(row) {
+      this.$confirm(`确定收藏到个人资料库?`, "提示", {
+        confirmButtonText: "确定",
+        cancelButtonText: "取消",
+        type: "warning",
+      }).then(() => {
+        let inputForm = {
+          classification: "",
+          fileDescription: "",
+          workAttachments: []
+        }
+        inputForm.workAttachments.push(row)
+        this.ossService.downloadAndUploadToMyCollect({
+          url: row.lsUrl,
+          fileName: row.name,
+          dir: this.directory,
+          workCollectAccessoryDTO: {
+            ...inputForm
+          }
+        }).then(res => {
+          this.$message.success(`操作成功`);
+        })
+      });
+
+    },
     // 开启/关闭页面的加载中状态
     changeLoading(loading) {
       if (this.commonJS.isNotEmpty(loading)) {

+ 28 - 1
src/views/common/UpLoadComponentV3.vue

@@ -13,7 +13,8 @@
       <template v-else #trigger>
         <el-button :loading="loading" type="primary" size="default"> 点击上传 </el-button>
       </template>
-      <AttachmentLib :directory="directory" @onDownToOss="handleOnDownToOss"></AttachmentLib>
+      <AttachmentLib v-if="auth !== 'view'" :directory="directory" @onDownToOss="handleOnDownToOss">
+      </AttachmentLib>
 
     </el-upload>
     <div style="height: calc(100% - 80px);margin-top: 10px">
@@ -60,6 +61,7 @@
             <el-button type="text" icon="el-icon-delete" size="small"
               @click="deleteById(scope.row, scope.$index, fileList)"
               :disabled="auth === 'view' && delFlag === false && createBy !== scope.row.createBy.name">删除</el-button>
+
             <!--<el-button size="small" type="text" icon="el-icon-edit"
                      @click="handleUpdate(scope.row, scope.$index)"
             >{{ scope.row.btn || "修改" }}</el-button>-->
@@ -568,6 +570,31 @@ export default {
     tableRowClassName({ row, rowIndex }) {
       row.index = rowIndex
     },
+    addMyAttachment(row) {
+      this.$confirm(`确定收藏到个人资料库?`, "提示", {
+        confirmButtonText: "确定",
+        cancelButtonText: "取消",
+        type: "warning",
+      }).then(() => {
+        let inputForm = {
+          classification: "",
+          fileDescription: "",
+          workAttachments: []
+        }
+        inputForm.workAttachments.push(row)
+        this.ossService.downloadAndUploadToMyCollect({
+          url: row.lsUrl,
+          fileName: row.name,
+          dir: this.directory,
+          workCollectAccessoryDTO: {
+            ...inputForm
+          }
+        }).then(res => {
+          this.$message.success(`操作成功`);
+        })
+      });
+
+    },
     // 行点击事件
     tableRowClick(row, column) {
       if (this.auth !== 'view') {