Fixiory
This commit is contained in:
parent
598c02e071
commit
a625dd0495
@ -6,7 +6,6 @@
|
||||
</label>
|
||||
<div
|
||||
class="image-container"
|
||||
@click="changeFile"
|
||||
@dragover="(event) => {
|
||||
event.preventDefault();
|
||||
}"
|
||||
@ -59,7 +58,7 @@ export default {
|
||||
default: 'input-file'
|
||||
},
|
||||
edit: {
|
||||
type: Object,
|
||||
type: File,
|
||||
default: null
|
||||
}
|
||||
},
|
||||
@ -74,7 +73,15 @@ export default {
|
||||
},
|
||||
watch: {
|
||||
edit () {
|
||||
this.getFileInfo(this.edit)
|
||||
if (this.edit) {
|
||||
this.getFileInfo(this.edit)
|
||||
} else {
|
||||
this.url = null
|
||||
this.file = null
|
||||
this.size = null
|
||||
this.name = null
|
||||
this.showError = false
|
||||
}
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
@ -96,9 +103,9 @@ export default {
|
||||
onFileChange (event) {
|
||||
this.getFileInfo(event.target.files[0])
|
||||
},
|
||||
changeFile () {
|
||||
document.getElementById(this.id).click()
|
||||
},
|
||||
// changeFile () {
|
||||
// document.getElementById(this.id).click()
|
||||
// },
|
||||
getFileInfo (file) {
|
||||
const acceptedExtensions = ['jpg', 'jpeg', 'png']
|
||||
const name = file.name
|
||||
|
17
package-lock.json
generated
17
package-lock.json
generated
@ -13,6 +13,7 @@
|
||||
"@fortawesome/free-solid-svg-icons": "^5.15.4",
|
||||
"@nuxtjs/axios": "^5.13.6",
|
||||
"@nuxtjs/fontawesome": "^1.1.2",
|
||||
"axios": "^0.24.0",
|
||||
"core-js": "^3.15.1",
|
||||
"nuxt": "^2.13.3"
|
||||
},
|
||||
@ -2724,6 +2725,14 @@
|
||||
"defu": "^5.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@nuxtjs/axios/node_modules/axios": {
|
||||
"version": "0.21.4",
|
||||
"resolved": "https://registry.npmjs.org/axios/-/axios-0.21.4.tgz",
|
||||
"integrity": "sha512-ut5vewkiu8jjGBdqpM44XxjuCjq9LAKeHVmoVfHVzy8eHgxxq8SbAVQNovDA8mVi05kP0Ea/n/UzcSHcTJQfNg==",
|
||||
"dependencies": {
|
||||
"follow-redirects": "^1.14.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@nuxtjs/eslint-config": {
|
||||
"version": "6.0.1",
|
||||
"resolved": "https://registry.npmjs.org/@nuxtjs/eslint-config/-/eslint-config-6.0.1.tgz",
|
||||
@ -3765,11 +3774,11 @@
|
||||
"integrity": "sha512-cMlDqaLEqfSaW8Z7N5Jw+lyIW869EzT73/F5lhtY9cLGoVxSXznfgfXMO0Z5K0o0Q2TkTXq+0KFsdnSe3jDViA=="
|
||||
},
|
||||
"node_modules/axios": {
|
||||
"version": "0.21.4",
|
||||
"resolved": "https://registry.npmjs.org/axios/-/axios-0.21.4.tgz",
|
||||
"integrity": "sha512-ut5vewkiu8jjGBdqpM44XxjuCjq9LAKeHVmoVfHVzy8eHgxxq8SbAVQNovDA8mVi05kP0Ea/n/UzcSHcTJQfNg==",
|
||||
"version": "0.24.0",
|
||||
"resolved": "https://registry.npmjs.org/axios/-/axios-0.24.0.tgz",
|
||||
"integrity": "sha512-Q6cWsys88HoPgAaFAVUb0WpPk0O8iTeisR9IMqy9G8AbO4NlpVknrnQS03zzF9PGAWgO3cgletO3VjV/P7VztA==",
|
||||
"dependencies": {
|
||||
"follow-redirects": "^1.14.0"
|
||||
"follow-redirects": "^1.14.4"
|
||||
}
|
||||
},
|
||||
"node_modules/axios-retry": {
|
||||
|
94
store/axios.js
Normal file
94
store/axios.js
Normal file
@ -0,0 +1,94 @@
|
||||
import axios from 'axios'
|
||||
|
||||
export const state = () => {
|
||||
return {
|
||||
url: 'https://161.35.216.122'
|
||||
}
|
||||
}
|
||||
|
||||
export const actions = {
|
||||
post: ({ commit, rootState, state, dispatch }, params) => {
|
||||
// eslint-disable-next-line
|
||||
return new Promise(async (resolve, reject) => {
|
||||
const headers = {
|
||||
headers: params[2] && params[2].guest ? { url: `${params[0]}` } : { Authorization: `Bearer ${rootState.auth.token}`, url: `${params[0]}` }
|
||||
}
|
||||
|
||||
const request = await axios.post(`${state.url}/api/store${params[0]}`, params[1], headers).catch((error) => {
|
||||
if (!params[2]) { dispatch('error', error.response) };
|
||||
resolve(error.response)
|
||||
})
|
||||
|
||||
if (request) {
|
||||
resolve(request)
|
||||
}
|
||||
})
|
||||
},
|
||||
get: ({ commit, rootState, state, dispatch }, params) => {
|
||||
// eslint-disable-next-line
|
||||
return new Promise(async (resolve, reject) => {
|
||||
const request = await axios.get(`${state.url}/api/store${params[0]}`).catch((error) => {
|
||||
dispatch('error', error.response)
|
||||
})
|
||||
|
||||
resolve(request)
|
||||
})
|
||||
},
|
||||
file: ({ commit, rootState, state, dispatch }, params) => {
|
||||
// eslint-disable-next-line
|
||||
return new Promise(async (resolve, reject) => {
|
||||
const headers = {
|
||||
headers: params[2] && params[2].guest ? { url: `${params[0]}` } : { Authorization: `Bearer ${rootState.auth.token}`, url: `${params[0]}` }
|
||||
}
|
||||
|
||||
const request = await axios.post(`${state.url}/api/store${params[0]}`, params[1], headers).catch((error) => {
|
||||
dispatch('error', error.response)
|
||||
})
|
||||
|
||||
resolve(request)
|
||||
})
|
||||
},
|
||||
error: ({ commit, rootState, state, dispatch }, data) => {
|
||||
if (data.status === 401) {
|
||||
localStorage.clear()
|
||||
sessionStorage.clear()
|
||||
sessionStorage.setItem('error_401', '1')
|
||||
window.location.href = '/'
|
||||
} else if (data.status === 500) {
|
||||
dispatch('alert/fire', {
|
||||
title: 'Spróbuj ponownie później',
|
||||
content: 'Wystąpił nieoczekiwany błąd po stronie serwera',
|
||||
icon: 'fa-exclamation-triangle',
|
||||
type: 'error'
|
||||
}, { root: true })
|
||||
} else if (data.status === 422) {
|
||||
dispatch('alert/fire', {
|
||||
title: 'Błędne dane',
|
||||
content: 'Proszę uzupełnić brakujące dane',
|
||||
icon: 'fa-exclamation-triangle',
|
||||
type: 'warning'
|
||||
}, { root: true })
|
||||
} else if (data.status === 403) {
|
||||
dispatch('alert/fire', {
|
||||
title: 'Brak uprawnień',
|
||||
content: 'Nie posiadasz wymaganych uprawnień',
|
||||
icon: 'fa-exclamation-triangle',
|
||||
type: 'error'
|
||||
}, { root: true })
|
||||
} else if (data.data && data.data.status === 'error' && data.data.message) {
|
||||
dispatch('alert/fire', {
|
||||
title: 'Wystąpił błąd',
|
||||
content: data.data.message,
|
||||
icon: 'fa-exclamation-triangle',
|
||||
type: 'error'
|
||||
}, { root: true })
|
||||
} else {
|
||||
dispatch('alert/fire', {
|
||||
title: 'Niezidentyfikowany błąd',
|
||||
content: `Doszło do błędu. Kod błędu: ${data.status}`,
|
||||
icon: 'fa-exclamation-triangle',
|
||||
type: 'error'
|
||||
}, { root: true })
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user