提交 caeec372 authored 作者: 王鹏飞's avatar 王鹏飞

chore: 修改图片上传到ali-oss

上级 14c0ca3a
......@@ -15,6 +15,7 @@
"@ezijing/web-message-sdk": "^0.2.1",
"@tinymce/tinymce-vue": "^3.2.8",
"axios": "^0.21.1",
"blueimp-md5": "^2.19.0",
"core-js": "^3.9.0",
"cross-env": "^7.0.3",
"echarts": "^5.0.2",
......@@ -2379,9 +2380,9 @@
"integrity": "sha512-XpNj6GDQzdfW+r2Wnn7xiSAd7TM3jzkxGXBGTtWKuSXv1xUV+azxAm8jdWZN06QTQk+2N2XB9jRDkvbmQmcRtg=="
},
"node_modules/blueimp-md5": {
"version": "2.18.0",
"resolved": "https://registry.npmjs.org/blueimp-md5/-/blueimp-md5-2.18.0.tgz",
"integrity": "sha512-vE52okJvzsVWhcgUHOv+69OG3Mdg151xyn41aVQN/5W5S+S43qZhxECtYLAEHMSFWX6Mv5IZrzj3T5+JqXfj5Q=="
"version": "2.19.0",
"resolved": "https://registry.npmmirror.com/blueimp-md5/-/blueimp-md5-2.19.0.tgz",
"integrity": "sha512-DRQrD6gJyy8FbiE4s+bDoXS9hiW3Vbx5uCdwvcCf3zLHL+Iv7LtGHLpr+GZV8rHG8tK766FGYBwRbu8pELTt+w=="
},
"node_modules/bn.js": {
"version": "5.1.3",
......@@ -15637,9 +15638,9 @@
"integrity": "sha512-XpNj6GDQzdfW+r2Wnn7xiSAd7TM3jzkxGXBGTtWKuSXv1xUV+azxAm8jdWZN06QTQk+2N2XB9jRDkvbmQmcRtg=="
},
"blueimp-md5": {
"version": "2.18.0",
"resolved": "https://registry.npmjs.org/blueimp-md5/-/blueimp-md5-2.18.0.tgz",
"integrity": "sha512-vE52okJvzsVWhcgUHOv+69OG3Mdg151xyn41aVQN/5W5S+S43qZhxECtYLAEHMSFWX6Mv5IZrzj3T5+JqXfj5Q=="
"version": "2.19.0",
"resolved": "https://registry.npmmirror.com/blueimp-md5/-/blueimp-md5-2.19.0.tgz",
"integrity": "sha512-DRQrD6gJyy8FbiE4s+bDoXS9hiW3Vbx5uCdwvcCf3zLHL+Iv7LtGHLpr+GZV8rHG8tK766FGYBwRbu8pELTt+w=="
},
"bn.js": {
"version": "5.1.3",
......
......@@ -80,6 +80,7 @@
"@ezijing/web-message-sdk": "^0.2.1",
"@tinymce/tinymce-vue": "^3.2.8",
"axios": "^0.21.1",
"blueimp-md5": "^2.19.0",
"core-js": "^3.9.0",
"cross-env": "^7.0.3",
"echarts": "^5.0.2",
......
......@@ -87,6 +87,7 @@ export default class API {
*/
_reqSuccess(res) {
const { data } = res
if (!data) return data
// token 失效
if (data.code === 1001) {
window.location.href = `${webConf.others.loginUrl}?rd=${encodeURIComponent(window.location.href)}`
......
import BaseAPI from '@/api/base_api'
import md5 from 'blueimp-md5'
const httpRequest = new BaseAPI(webConf)
/**
* 上传文件
*/
export function uploadFile(data) {
return httpRequest.post('/api/lms/util/upload-file', data, {
// export function uploadFile(data) {
// return httpRequest.post('/api/lms/util/upload-file', data, {
// headers: { 'Content-Type': 'multipart/form-data' }
// })
// }
// 获取oss signature
export function getSignature() {
return httpRequest.get('/api/usercenter/aliyun/get-signature')
}
// 图片上传
export function uploadAliOSS(data) {
return httpRequest.post('https://webapp-pub.oss-cn-beijing.aliyuncs.com', data, {
withCredentials: false,
headers: { 'Content-Type': 'multipart/form-data' }
})
}
export async function uploadFile({ file }) {
const prefix = 'upload/lms/'
const key = prefix + md5(file.name + Date.now()) + file.name.substr(file.name.lastIndexOf('.'))
const response = await getSignature()
const params = {
key,
OSSAccessKeyId: response.accessid,
policy: response.policy,
signature: response.signature,
success_action_status: '200',
file,
url: `${response.host}/${key}`
}
await uploadAliOSS(params)
return { error: '', success: true, url: params.url }
}
......@@ -15,8 +15,7 @@
</template>
<script>
import cAction from '@action'
import { uploadFile } from '@/api/common'
export default {
name: 'VUpload',
props: {
......@@ -34,15 +33,11 @@ export default {
},
methods: {
httpRequest(xhr) {
cAction.Player.uploadFile({ file: xhr.file })
.then(response => {
if (response.success) {
this.$emit('input', response.url)
}
})
.catch(error => {
console.log(error)
})
uploadFile({ file: xhr.file }).then(response => {
if (response.success) {
this.$emit('input', response.url)
}
})
}
}
}
......
......@@ -51,6 +51,8 @@
</template>
<script>
import { uploadFile } from '@/api/common'
import * as api from '../../api'
export default {
data() {
......@@ -73,8 +75,7 @@ export default {
this.file.file = file.raw
},
uploadFile() {
api
.uploadFile(this.file)
uploadFile(this.file)
.then(data => {
this.successFileUrl = data.url
this.filesArr.pop()
......
......@@ -33,7 +33,7 @@
</template>
<script>
import * as api from '../../api'
import { uploadFile } from '@/api/common'
export default {
name: 'VUpload',
......@@ -69,8 +69,7 @@ export default {
methods: {
httpRequest(xhr) {
this.isUploading = true
api
.uploadFile({ file: xhr.file })
uploadFile({ file: xhr.file })
.then(response => {
if (response.success) {
if (Array.isArray(this.value)) {
......
......@@ -55,6 +55,7 @@
</template>
<script>
import cAction from '@action'
import { uploadFile } from '@/api/common'
export default {
props: {
......@@ -139,7 +140,7 @@ export default {
},
uploadFile () {
const loading = this.$loading({ lock: true, text: '', spinner: '', background: 'rgba(255, 255, 255, 0.9)' })
cAction.Affairs.uploadFile(this.file).then(data => {
uploadFile(this.file).then(data => {
this.successFileUrl = data.url
// this.filesArr.pop()
}).catch(e => { this.filesArr.pop(); this.$message.error(e.message) }).finally(() => { loading.close() })
......
......@@ -67,6 +67,7 @@
<script>
import cAction from '@action'
import { uploadFile } from '@/api/common'
export default {
props: {
......@@ -163,7 +164,7 @@ export default {
},
uploadFile () {
const loading = this.$loading({ lock: true, text: '', spinner: '', background: 'rgba(255, 255, 255, 0.9)' })
cAction.chapterAction.uploadFile(this.file).then(data => {
uploadFile(this.file).then(data => {
this.successFileUrl = data.url
this.filesArr.pop()
}).catch(e => { this.filesArr.pop(); this.$message.error(e.message) }).finally(() => { loading.close() })
......
......@@ -63,6 +63,7 @@
<script>
import cAction from '@action'
import { uploadFile } from '@/api/common'
export default {
props: {
......@@ -156,7 +157,7 @@ export default {
},
uploadFile () {
const loading = this.$loading({ lock: true, text: '', spinner: '', background: 'rgba(255, 255, 255, 0.9)' })
cAction.chapterAction.uploadFile(this.file).then(data => {
uploadFile(this.file).then(data => {
this.successFileUrl = data.url
this.filesArr.pop()
}).catch(e => { this.filesArr.pop(); this.$message.error(e.message) }).finally(() => { loading.close() })
......
......@@ -65,6 +65,7 @@
<script>
import cAction from '@action'
import { uploadFile } from '@/api/common'
export default {
props: {
......@@ -132,7 +133,7 @@ export default {
},
uploadFile() {
const loading = this.$loading({ lock: true, text: '', spinner: '', background: 'rgba(255, 255, 255, 0.9)' })
cAction.Affairs.uploadFile(this.file)
uploadFile(this.file)
.then(data => {
this.successFileUrl = data.url
this.filesArr.pop()
......
......@@ -51,6 +51,7 @@
<script>
import cAction from '@action'
import { uploadFile } from '@/api/common'
import VEditor from '@/components/tinymce'
......@@ -94,7 +95,7 @@ export default {
},
uploadFile() {
const loading = this.$loading({ lock: true, text: '', spinner: '', background: 'rgba(255, 255, 255, 0.9)' })
cAction.Other.uploadFile(this.file)
uploadFile(this.file)
.then(data => {
this.successFileUrl = data.url
this.filesArr.pop()
......
......@@ -98,6 +98,7 @@
<script>
import cAction from '@action'
import { uploadFile } from '@/api/common'
export default {
components: { },
......@@ -135,7 +136,7 @@ export default {
},
uploadFile1 () {
const loading = this.$loading({ lock: true, text: '', spinner: '', background: 'rgba(255, 255, 255, 0.9)' })
cAction.Other.uploadFile(this.file1).then(data => {
uploadFile(this.file1).then(data => {
this.successFileUrl1 = data.url
this.filesArr1.pop()
}).catch(e => { this.filesArr1.pop(); this.$message.error(e.message) }).finally(() => { loading.close() })
......@@ -149,7 +150,7 @@ export default {
},
uploadFile2 () {
const loading = this.$loading({ lock: true, text: '', spinner: '', background: 'rgba(255, 255, 255, 0.9)' })
cAction.Other.uploadFile(this.file2).then(data => {
uploadFile(this.file2).then(data => {
this.successFileUrl2 = data.url
this.filesArr2.pop()
}).catch(e => { this.filesArr2.pop(); this.$message.error(e.message) }).finally(() => { loading.close() })
......
......@@ -54,6 +54,7 @@
<script>
import cAction from '@action'
import { uploadFile } from '@/api/common'
export default {
props: {
......@@ -133,7 +134,7 @@ export default {
},
uploadFile () {
const loading = this.$loading({ lock: true, text: '', spinner: '', background: 'rgba(255, 255, 255, 0.9)' })
cAction.chapterAction.uploadFile(this.file).then(data => {
uploadFile(this.file).then(data => {
this.successFileUrl = data.url
this.filesArr.pop()
}).catch(e => { this.filesArr.pop(); this.$message.error(e.message) }).finally(() => { loading.close() })
......
......@@ -45,6 +45,7 @@
<script>
import cAction from '@action'
import { uploadFile } from '@/api/common'
export default {
props: {
......@@ -107,7 +108,7 @@ export default {
},
uploadFile () {
const loading = this.$loading({ lock: true, text: '', spinner: '', background: 'rgba(255, 255, 255, 0.9)' })
cAction.Other.uploadFile(this.file).then(data => {
uploadFile(this.file).then(data => {
this.successFileUrl = data.url
this.filesArr.pop()
}).catch(e => { this.filesArr.pop(); this.$message.error(e.message) }).finally(() => { loading.close() })
......
......@@ -38,6 +38,7 @@
<script>
import action from '@action'
import { uploadFile } from '@/api/common'
export default {
components: {},
......@@ -82,7 +83,7 @@ export default {
spinner: '',
background: 'rgba(255, 255, 255, 0.9)'
})
action.Other.uploadFile(this.file)
uploadFile(this.file)
.then(data => {
this.imgUrl = data.url
this.updateUser()
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论