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

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

上级 e8a457dc
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
"@ckeditor/ckeditor5-vue2": "^1.0.5", "@ckeditor/ckeditor5-vue2": "^1.0.5",
"@ezijing/web-message-sdk": "^0.2.1", "@ezijing/web-message-sdk": "^0.2.1",
"axios": "^0.21.1", "axios": "^0.21.1",
"blueimp-md5": "^2.19.0",
"core-js": "^3.9.0", "core-js": "^3.9.0",
"cross-env": "^7.0.3", "cross-env": "^7.0.3",
"echarts": "^5.0.2", "echarts": "^5.0.2",
...@@ -2369,9 +2370,9 @@ ...@@ -2369,9 +2370,9 @@
"integrity": "sha512-XpNj6GDQzdfW+r2Wnn7xiSAd7TM3jzkxGXBGTtWKuSXv1xUV+azxAm8jdWZN06QTQk+2N2XB9jRDkvbmQmcRtg==" "integrity": "sha512-XpNj6GDQzdfW+r2Wnn7xiSAd7TM3jzkxGXBGTtWKuSXv1xUV+azxAm8jdWZN06QTQk+2N2XB9jRDkvbmQmcRtg=="
}, },
"node_modules/blueimp-md5": { "node_modules/blueimp-md5": {
"version": "2.18.0", "version": "2.19.0",
"resolved": "https://registry.npmjs.org/blueimp-md5/-/blueimp-md5-2.18.0.tgz", "resolved": "https://registry.npmmirror.com/blueimp-md5/-/blueimp-md5-2.19.0.tgz",
"integrity": "sha512-vE52okJvzsVWhcgUHOv+69OG3Mdg151xyn41aVQN/5W5S+S43qZhxECtYLAEHMSFWX6Mv5IZrzj3T5+JqXfj5Q==" "integrity": "sha512-DRQrD6gJyy8FbiE4s+bDoXS9hiW3Vbx5uCdwvcCf3zLHL+Iv7LtGHLpr+GZV8rHG8tK766FGYBwRbu8pELTt+w=="
}, },
"node_modules/bn.js": { "node_modules/bn.js": {
"version": "5.1.3", "version": "5.1.3",
...@@ -15616,9 +15617,9 @@ ...@@ -15616,9 +15617,9 @@
"integrity": "sha512-XpNj6GDQzdfW+r2Wnn7xiSAd7TM3jzkxGXBGTtWKuSXv1xUV+azxAm8jdWZN06QTQk+2N2XB9jRDkvbmQmcRtg==" "integrity": "sha512-XpNj6GDQzdfW+r2Wnn7xiSAd7TM3jzkxGXBGTtWKuSXv1xUV+azxAm8jdWZN06QTQk+2N2XB9jRDkvbmQmcRtg=="
}, },
"blueimp-md5": { "blueimp-md5": {
"version": "2.18.0", "version": "2.19.0",
"resolved": "https://registry.npmjs.org/blueimp-md5/-/blueimp-md5-2.18.0.tgz", "resolved": "https://registry.npmmirror.com/blueimp-md5/-/blueimp-md5-2.19.0.tgz",
"integrity": "sha512-vE52okJvzsVWhcgUHOv+69OG3Mdg151xyn41aVQN/5W5S+S43qZhxECtYLAEHMSFWX6Mv5IZrzj3T5+JqXfj5Q==" "integrity": "sha512-DRQrD6gJyy8FbiE4s+bDoXS9hiW3Vbx5uCdwvcCf3zLHL+Iv7LtGHLpr+GZV8rHG8tK766FGYBwRbu8pELTt+w=="
}, },
"bn.js": { "bn.js": {
"version": "5.1.3", "version": "5.1.3",
......
...@@ -79,6 +79,7 @@ ...@@ -79,6 +79,7 @@
"@ckeditor/ckeditor5-vue2": "^1.0.5", "@ckeditor/ckeditor5-vue2": "^1.0.5",
"@ezijing/web-message-sdk": "^0.2.1", "@ezijing/web-message-sdk": "^0.2.1",
"axios": "^0.21.1", "axios": "^0.21.1",
"blueimp-md5": "^2.19.0",
"core-js": "^3.9.0", "core-js": "^3.9.0",
"cross-env": "^7.0.3", "cross-env": "^7.0.3",
"echarts": "^5.0.2", "echarts": "^5.0.2",
......
...@@ -87,6 +87,12 @@ export default class API { ...@@ -87,6 +87,12 @@ export default class API {
*/ */
_reqSuccess(res) { _reqSuccess(res) {
const { data } = res const { data } = res
if (!data) return data
// token 失效
if (data.code === 1001) {
window.location.href = `${webConf.others.loginUrl}?rd=${encodeURIComponent(window.location.href)}`
return Promise.reject(data)
}
/* 带 code 参数,新接口模型 */ /* 带 code 参数,新接口模型 */
if (data.code !== undefined) { if (data.code !== undefined) {
if (data.code !== 0 && !/getinfo$/gi.test(res.config.url)) { if (data.code !== 0 && !/getinfo$/gi.test(res.config.url)) {
......
import BaseAPI from '@/api/base_api' import BaseAPI from '@/api/base_api'
import md5 from 'blueimp-md5'
const httpRequest = new BaseAPI(webConf) const httpRequest = new BaseAPI(webConf)
/** /**
* 上传文件 * 上传文件
*/ */
export function uploadFile(data) { // export function uploadFile(data) {
return httpRequest.post('/api/lms/util/upload-file', 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' } 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 @@ ...@@ -15,8 +15,7 @@
</template> </template>
<script> <script>
import cAction from '@action' import { uploadFile } from '@/api/common'
export default { export default {
name: 'VUpload', name: 'VUpload',
props: { props: {
...@@ -34,15 +33,11 @@ export default { ...@@ -34,15 +33,11 @@ export default {
}, },
methods: { methods: {
httpRequest(xhr) { httpRequest(xhr) {
cAction.Player.uploadFile({ file: xhr.file }) uploadFile({ file: xhr.file }).then(response => {
.then(response => { if (response.success) {
if (response.success) { this.$emit('input', response.url)
this.$emit('input', response.url) }
} })
})
.catch(error => {
console.log(error)
})
} }
} }
} }
......
...@@ -51,6 +51,8 @@ ...@@ -51,6 +51,8 @@
</template> </template>
<script> <script>
import { uploadFile } from '@/api/common'
import * as api from '../../api' import * as api from '../../api'
export default { export default {
data() { data() {
...@@ -73,8 +75,7 @@ export default { ...@@ -73,8 +75,7 @@ export default {
this.file.file = file.raw this.file.file = file.raw
}, },
uploadFile() { uploadFile() {
api uploadFile(this.file)
.uploadFile(this.file)
.then(data => { .then(data => {
this.successFileUrl = data.url this.successFileUrl = data.url
this.filesArr.pop() this.filesArr.pop()
......
...@@ -33,7 +33,7 @@ ...@@ -33,7 +33,7 @@
</template> </template>
<script> <script>
import * as api from '../../api' import { uploadFile } from '@/api/common'
export default { export default {
name: 'VUpload', name: 'VUpload',
...@@ -69,8 +69,7 @@ export default { ...@@ -69,8 +69,7 @@ export default {
methods: { methods: {
httpRequest(xhr) { httpRequest(xhr) {
this.loading = true this.loading = true
api uploadFile({ file: xhr.file })
.uploadFile({ file: xhr.file })
.then(response => { .then(response => {
if (response.success) { if (response.success) {
this.$message.success(this.$t('上传成功')) this.$message.success(this.$t('上传成功'))
......
...@@ -55,6 +55,7 @@ ...@@ -55,6 +55,7 @@
</template> </template>
<script> <script>
import cAction from '@action' import cAction from '@action'
import { uploadFile } from '@/api/common'
export default { export default {
props: { props: {
...@@ -139,7 +140,7 @@ export default { ...@@ -139,7 +140,7 @@ export default {
}, },
uploadFile () { uploadFile () {
const loading = this.$loading({ lock: true, text: '', spinner: '', background: 'rgba(255, 255, 255, 0.9)' }) 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.successFileUrl = data.url
// this.filesArr.pop() // this.filesArr.pop()
}).catch(e => { this.filesArr.pop(); this.$message.error(e.message) }).finally(() => { loading.close() }) }).catch(e => { this.filesArr.pop(); this.$message.error(e.message) }).finally(() => { loading.close() })
......
...@@ -67,6 +67,7 @@ ...@@ -67,6 +67,7 @@
<script> <script>
import cAction from '@action' import cAction from '@action'
import { uploadFile } from '@/api/common'
export default { export default {
props: { props: {
...@@ -163,7 +164,7 @@ export default { ...@@ -163,7 +164,7 @@ export default {
}, },
uploadFile () { uploadFile () {
const loading = this.$loading({ lock: true, text: '', spinner: '', background: 'rgba(255, 255, 255, 0.9)' }) 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.successFileUrl = data.url
this.filesArr.pop() this.filesArr.pop()
}).catch(e => { this.filesArr.pop(); this.$message.error(e.message) }).finally(() => { loading.close() }) }).catch(e => { this.filesArr.pop(); this.$message.error(e.message) }).finally(() => { loading.close() })
......
...@@ -63,6 +63,7 @@ ...@@ -63,6 +63,7 @@
<script> <script>
import cAction from '@action' import cAction from '@action'
import { uploadFile } from '@/api/common'
export default { export default {
props: { props: {
...@@ -156,7 +157,7 @@ export default { ...@@ -156,7 +157,7 @@ export default {
}, },
uploadFile () { uploadFile () {
const loading = this.$loading({ lock: true, text: '', spinner: '', background: 'rgba(255, 255, 255, 0.9)' }) 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.successFileUrl = data.url
this.filesArr.pop() this.filesArr.pop()
}).catch(e => { this.filesArr.pop(); this.$message.error(e.message) }).finally(() => { loading.close() }) }).catch(e => { this.filesArr.pop(); this.$message.error(e.message) }).finally(() => { loading.close() })
......
...@@ -65,6 +65,7 @@ ...@@ -65,6 +65,7 @@
<script> <script>
import cAction from '@action' import cAction from '@action'
import { uploadFile } from '@/api/common'
export default { export default {
props: { props: {
...@@ -132,7 +133,7 @@ export default { ...@@ -132,7 +133,7 @@ export default {
}, },
uploadFile() { uploadFile() {
const loading = this.$loading({ lock: true, text: '', spinner: '', background: 'rgba(255, 255, 255, 0.9)' }) 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 => { .then(data => {
this.successFileUrl = data.url this.successFileUrl = data.url
this.filesArr.pop() this.filesArr.pop()
......
...@@ -51,6 +51,7 @@ ...@@ -51,6 +51,7 @@
<script> <script>
import cAction from '@action' import cAction from '@action'
import { uploadFile } from '@/api/common'
import VEditor from '@/components/ckeditor' import VEditor from '@/components/ckeditor'
...@@ -94,7 +95,7 @@ export default { ...@@ -94,7 +95,7 @@ export default {
}, },
uploadFile() { uploadFile() {
const loading = this.$loading({ lock: true, text: '', spinner: '', background: 'rgba(255, 255, 255, 0.9)' }) 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 => { .then(data => {
this.successFileUrl = data.url this.successFileUrl = data.url
this.filesArr.pop() this.filesArr.pop()
......
...@@ -98,6 +98,7 @@ ...@@ -98,6 +98,7 @@
<script> <script>
import cAction from '@action' import cAction from '@action'
import { uploadFile } from '@/api/common'
export default { export default {
components: { }, components: { },
...@@ -135,7 +136,7 @@ export default { ...@@ -135,7 +136,7 @@ export default {
}, },
uploadFile1 () { uploadFile1 () {
const loading = this.$loading({ lock: true, text: '', spinner: '', background: 'rgba(255, 255, 255, 0.9)' }) 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.successFileUrl1 = data.url
this.filesArr1.pop() this.filesArr1.pop()
}).catch(e => { this.filesArr1.pop(); this.$message.error(e.message) }).finally(() => { loading.close() }) }).catch(e => { this.filesArr1.pop(); this.$message.error(e.message) }).finally(() => { loading.close() })
...@@ -149,7 +150,7 @@ export default { ...@@ -149,7 +150,7 @@ export default {
}, },
uploadFile2 () { uploadFile2 () {
const loading = this.$loading({ lock: true, text: '', spinner: '', background: 'rgba(255, 255, 255, 0.9)' }) 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.successFileUrl2 = data.url
this.filesArr2.pop() this.filesArr2.pop()
}).catch(e => { this.filesArr2.pop(); this.$message.error(e.message) }).finally(() => { loading.close() }) }).catch(e => { this.filesArr2.pop(); this.$message.error(e.message) }).finally(() => { loading.close() })
......
...@@ -54,6 +54,7 @@ ...@@ -54,6 +54,7 @@
<script> <script>
import cAction from '@action' import cAction from '@action'
import { uploadFile } from '@/api/common'
export default { export default {
props: { props: {
...@@ -133,7 +134,7 @@ export default { ...@@ -133,7 +134,7 @@ export default {
}, },
uploadFile () { uploadFile () {
const loading = this.$loading({ lock: true, text: '', spinner: '', background: 'rgba(255, 255, 255, 0.9)' }) 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.successFileUrl = data.url
this.filesArr.pop() this.filesArr.pop()
}).catch(e => { this.filesArr.pop(); this.$message.error(e.message) }).finally(() => { loading.close() }) }).catch(e => { this.filesArr.pop(); this.$message.error(e.message) }).finally(() => { loading.close() })
......
...@@ -45,6 +45,7 @@ ...@@ -45,6 +45,7 @@
<script> <script>
import cAction from '@action' import cAction from '@action'
import { uploadFile } from '@/api/common'
export default { export default {
props: { props: {
...@@ -107,7 +108,7 @@ export default { ...@@ -107,7 +108,7 @@ export default {
}, },
uploadFile () { uploadFile () {
const loading = this.$loading({ lock: true, text: '', spinner: '', background: 'rgba(255, 255, 255, 0.9)' }) 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.successFileUrl = data.url
this.filesArr.pop() this.filesArr.pop()
}).catch(e => { this.filesArr.pop(); this.$message.error(e.message) }).finally(() => { loading.close() }) }).catch(e => { this.filesArr.pop(); this.$message.error(e.message) }).finally(() => { loading.close() })
......
...@@ -38,6 +38,7 @@ ...@@ -38,6 +38,7 @@
<script> <script>
import action from '@action' import action from '@action'
import { uploadFile } from '@/api/common'
export default { export default {
components: {}, components: {},
...@@ -82,7 +83,7 @@ export default { ...@@ -82,7 +83,7 @@ export default {
spinner: '', spinner: '',
background: 'rgba(255, 255, 255, 0.9)' background: 'rgba(255, 255, 255, 0.9)'
}) })
action.Other.uploadFile(this.file) uploadFile(this.file)
.then(data => { .then(data => {
this.imgUrl = data.url this.imgUrl = data.url
this.updateUser() this.updateUser()
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论