back-end done
This commit is contained in:
@@ -0,0 +1,90 @@
|
||||
<template>
|
||||
<div class="container-fluid">
|
||||
<div class="row">
|
||||
<admin-title-bar :title="title"></admin-title-bar>
|
||||
<div class="col-6">
|
||||
<admin-panel>
|
||||
<h2>افزودن یا بروزرسانی کاتالوگ:</h2>
|
||||
<el-divider></el-divider>
|
||||
<el-form>
|
||||
<input type="file" ref="file">
|
||||
<el-button @click="upload" type="success">افزودن</el-button>
|
||||
<p style="color: red;" v-if="validation.pdf">{{validation.pdf.msg}}</p>
|
||||
</el-form>
|
||||
<el-divider></el-divider>
|
||||
<a v-if="catalog && catalog.file" :href="catalog.file" target="_blank">
|
||||
<el-button>دانلود و مشاهده کاتالوگ فعلی</el-button>
|
||||
</a>
|
||||
</admin-panel>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
|
||||
<script>
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
catalog: null,
|
||||
validation: {},
|
||||
uploading: false,
|
||||
uploadProgress: null
|
||||
}
|
||||
},
|
||||
head() {
|
||||
return {
|
||||
title: this.title,
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
title() {
|
||||
if (!this.uploading) {
|
||||
return 'آپلود کاتالوگ اصلی سایت'
|
||||
} else {
|
||||
return this.uploadProgress
|
||||
}
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
upload() {
|
||||
this.validation = {}
|
||||
const data = new FormData()
|
||||
data.append('pdf', this.$refs.file.files[0])
|
||||
|
||||
const axiosConfig = {
|
||||
onUploadProgress: progressEvent => {
|
||||
this.uploading = true
|
||||
this.uploadProgress = 'درحال آپلود ' + Math.floor(((progressEvent.loaded / progressEvent.total) * 100)) + '%'
|
||||
|
||||
if ((progressEvent.loaded / progressEvent.total) * 100 === 100) {
|
||||
this.uploading = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.$axios.post(`/api/private/catalog`, data, axiosConfig)
|
||||
.then(res => {
|
||||
this.$message({
|
||||
type: 'success',
|
||||
message: 'کاتالوگ با موفقیت آپلود شد'
|
||||
})
|
||||
this.$refs.file.value = null
|
||||
this.catalog = res.data
|
||||
})
|
||||
.catch(err => {
|
||||
if (err.response.status === 422) this.validation = err.response.data.validation
|
||||
else console.log(err.response.data)
|
||||
})
|
||||
}
|
||||
},
|
||||
layout: 'admin',
|
||||
async asyncData({$axios}) {
|
||||
let catalog = await $axios.get('/api/public/catalog')
|
||||
return {
|
||||
catalog: catalog.data
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user