|
@@ -109,9 +109,9 @@ export function fileName (file) {
|
|
|
|
|
|
export function beforeAvatarUpload (file) {
|
|
|
// 文件大小校验
|
|
|
- const isLt2M = file.size / 1024 / 1024 < 1024
|
|
|
+ const isLt2M = file.size / 1024 / 1024 < 300
|
|
|
if (!isLt2M) {
|
|
|
- this.$message.error('文件大小不能超过 1G !')
|
|
|
+ this.$message.error('文件大小不能超过 300M !')
|
|
|
}
|
|
|
return isLt2M
|
|
|
}
|
|
@@ -160,3 +160,83 @@ export async function httpRequest (file, name, type) { // 阿里云OSS上传
|
|
|
file.onError('上传失败') // 触发el-upload组件的onError方法,此方法会移除文件列表
|
|
|
})
|
|
|
}
|
|
|
+
|
|
|
+// eslint-disable-next-line no-unused-vars
|
|
|
+function getTemporaryByUrl (url) {
|
|
|
+ return request({
|
|
|
+ url: '/oss/file/getTemporaryUrl',
|
|
|
+ method: 'get',
|
|
|
+ params: {url: url}
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
+export async function openWindowOnUrl (row) {
|
|
|
+ var rowurl = ''
|
|
|
+ let suffix = row.name.substring(row.name.lastIndexOf('.') + 1)
|
|
|
+ if (suffix === 'jpg' || suffix === 'png' || suffix === 'gif' || suffix === 'bmp' || suffix === 'jpeg') {
|
|
|
+ if (row.url !== null && row.url !== undefined && row.url !== '') {
|
|
|
+ // eslint-disable-next-line no-undef
|
|
|
+ onPreview(row.temporaryUrl)
|
|
|
+ return
|
|
|
+ } else {
|
|
|
+ await getTemporaryByUrl(row.raw.url).then((data) => {
|
|
|
+ // eslint-disable-next-line no-undef
|
|
|
+ onPreview(data.data)
|
|
|
+ })
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (row.url !== null && row.url !== undefined && row.url !== '') {
|
|
|
+ if (suffix === 'pdf') {
|
|
|
+ window.open('https://view.xdocin.com/xdoc?_xdoc=' + encodeURIComponent(row.temporaryUrl), '_blank')
|
|
|
+ } else if (suffix === 'rar' || suffix === 'zip' || suffix === 'jar' || suffix === '7z') {
|
|
|
+ window.open('http://ow365.cn/?i=30045&furl=' + encodeURIComponent(row.temporaryUrl), '_blank')
|
|
|
+ } else {
|
|
|
+ window.open('https://view.officeapps.live.com/op/view.aspx?src=' + encodeURIComponent(row.temporaryUrl), '_blank')
|
|
|
+ }
|
|
|
+ } else if (row.raw.url !== null && row.raw.url !== undefined && row.raw.url !== '') {
|
|
|
+ await getTemporaryByUrl(row.raw.url).then((data) => {
|
|
|
+ rowurl = data.data
|
|
|
+ })
|
|
|
+ if (suffix === 'pdf') {
|
|
|
+ window.open('https://view.xdocin.com/xdoc?_xdoc=' + encodeURIComponent(rowurl), '_blank')
|
|
|
+ } else if (suffix === 'rar' || suffix === 'zip' || suffix === 'jar' || suffix === '7z') {
|
|
|
+ window.open('http://ow365.cn/?i=30045&furl=' + encodeURIComponent(rowurl), '_blank')
|
|
|
+ } else {
|
|
|
+ window.open('https://view.officeapps.live.com/op/view.aspx?src=' + encodeURIComponent(rowurl), '_blank')
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+export async function toHref (row) {
|
|
|
+ const link = document.createElement('a')
|
|
|
+ if (row.id === null || row.id === undefined || row.id === '') {
|
|
|
+ await getTemporaryByUrl(row.raw.url).then((data) => {
|
|
|
+ const url = data.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)
|
|
|
+ })
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ const url = row.temporaryUrl // 完整的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)
|
|
|
+ })
|
|
|
+ }
|
|
|
+}
|