214 lines
7.9 KiB
Vue
214 lines
7.9 KiB
Vue
<template>
|
|
<div>
|
|
<CustomSubHeader>
|
|
<CBreadcrumb class="border-0 mb-0">{{ title }}</CBreadcrumb>
|
|
<CButton size="sm" color="primary" class="mr-auto" :to="{name: 'admin-slider'}">برگشت به صفحه قبل</CButton>
|
|
<CButton v-if="$route.params.slide === 'new'" size="sm" color="success" class="mr-1" @click="post">افزودن</CButton>
|
|
<!-- <CButton v-else size="sm" color="success" class="mr-1" @click="update">بروزرسانی</CButton>-->
|
|
</CustomSubHeader>
|
|
<CRow>
|
|
<!-- <CCol lg="6">-->
|
|
<!-- <CCard>-->
|
|
<!-- <CCardBody>-->
|
|
<!-- <CForm>-->
|
|
<!-- <h4 class="mt-5">فارسی</h4>-->
|
|
<!-- <el-divider></el-divider>-->
|
|
<!-- <CInput-->
|
|
<!-- :class="validation.fa_name ? 'err' : null"-->
|
|
<!-- label="نام فارسی"-->
|
|
<!-- :description="validation.fa_name ? validation.fa_name.msg : null"-->
|
|
<!-- v-model="slide.locale.fa.name"-->
|
|
<!-- />-->
|
|
<!-- <CInput-->
|
|
<!-- :class="validation.fa_position ? 'err' : null"-->
|
|
<!-- label="سمت فارسی"-->
|
|
<!-- :description="validation.fa_position ? validation.fa_position.msg : null"-->
|
|
<!-- v-model="slide.locale.fa.position"-->
|
|
<!-- />-->
|
|
<!-- <CTextarea-->
|
|
<!-- :class="validation.fa_slide ? 'err' : null"-->
|
|
<!-- label="کامنت فارسی"-->
|
|
<!-- :description="validation.fa_slide ? validation.fa_slide.msg : null"-->
|
|
<!-- v-model="slide.locale.fa.slide"-->
|
|
<!-- />-->
|
|
|
|
|
|
<!-- <h4 class="mt-5">انگلیسی</h4>-->
|
|
<!-- <el-divider></el-divider>-->
|
|
<!-- <CInput-->
|
|
<!-- :class="validation.en_name ? 'err' : null"-->
|
|
<!-- label="نام انگلیسی"-->
|
|
<!-- :description="validation.en_name ? validation.en_name.msg : null"-->
|
|
<!-- v-model="slide.locale.en.name"-->
|
|
<!-- />-->
|
|
<!-- <CInput-->
|
|
<!-- :class="validation.en_position ? 'err' : null"-->
|
|
<!-- label="سمت انگلیسی"-->
|
|
<!-- :description="validation.en_position ? validation.en_position.msg : null"-->
|
|
<!-- v-model="slide.locale.en.position"-->
|
|
<!-- />-->
|
|
<!-- <CTextarea-->
|
|
<!-- :class="validation.en_slide ? 'err' : null"-->
|
|
<!-- label="کامنت انگلیسی"-->
|
|
<!-- :description="validation.en_slide ? validation.en_slide.msg : null"-->
|
|
<!-- v-model="slide.locale.en.slide"-->
|
|
<!-- />-->
|
|
|
|
<!-- </CForm>-->
|
|
<!-- </CCardBody>-->
|
|
<!-- </CCard>-->
|
|
<!-- </CCol>-->
|
|
<CCol sm="12">
|
|
<CCard>
|
|
<CCardBody>
|
|
<el-switch style="direction: ltr" v-model="slide.isImage" active-text="عکس" inactive-text="ویدیو" inactive-color="#ff4949"></el-switch>
|
|
</CCardBody>
|
|
</CCard>
|
|
</CCol>
|
|
<CCol v-if="slide.isImage" lg="6">
|
|
<CCard>
|
|
<CCardBody>
|
|
<h2>عکس</h2>
|
|
<el-divider></el-divider>
|
|
<img :src="slide.image" alt="" style="width: 100%;max-width: 600px;">
|
|
<input type="file" ref="image" @change="preview">
|
|
<p class="text-danger" v-if="validation.image">{{ validation.image.msg }}</p>
|
|
</CCardBody>
|
|
</CCard>
|
|
</CCol>
|
|
<CCol v-else lg="6">
|
|
<CCard>
|
|
<CCardBody>
|
|
<h2>ویدیو</h2>
|
|
<el-divider></el-divider>
|
|
<video :src="slide.video" style="width: 100%;max-width: 600px;" controls muted autoplay></video>
|
|
<input type="file" ref="video" @change="preview2">
|
|
<p class="text-danger" v-if="validation.video">{{ validation.video.msg }}</p>
|
|
</CCardBody>
|
|
</CCard>
|
|
</CCol>
|
|
</CRow>
|
|
</div>
|
|
</template>
|
|
|
|
<script>
|
|
import axiosUploadProcess from "~/mixins/axiosUploadProcess"
|
|
|
|
export default {
|
|
data() {
|
|
return {
|
|
slide: null,
|
|
validation: {}
|
|
}
|
|
},
|
|
mixins: [axiosUploadProcess],
|
|
computed: {
|
|
title() {
|
|
return this.$route.params.slide === 'new' ? 'افزودن اسلاید جدید' : 'مشاهده اطلاعات اسلاید'
|
|
}
|
|
},
|
|
methods: {
|
|
preview() {
|
|
this.slide.image = URL.createObjectURL(event.target.files[0])
|
|
},
|
|
preview2() {
|
|
this.slide.video = URL.createObjectURL(event.target.files[0])
|
|
},
|
|
post() {
|
|
this.validation = {}
|
|
|
|
const data = new FormData()
|
|
data.append('isImage', this.slide.isImage)
|
|
|
|
if (this.slide.isImage) data.append('image', this.$refs.image.files[0])
|
|
else data.append('video', this.$refs.video.files[0])
|
|
|
|
this.$axios.post(`/api/admin/slide`, data, this.axiosConfig)
|
|
.then(response => {
|
|
this.$message({
|
|
type: 'success',
|
|
message: 'اسلاید با موفقیت ایجاد شد.'
|
|
})
|
|
this.$router.push({name: 'admin-slider'})
|
|
})
|
|
.catch(err => {
|
|
if (err.response.status === 401) {
|
|
return this.$message({
|
|
type: 'error',
|
|
message: 'لطفا دوباره وارد سیستم شوید.'
|
|
})
|
|
}
|
|
if (err.response.status === 422) {
|
|
this.validation = err.response.data.validation
|
|
return this.$message({
|
|
type: 'warning',
|
|
message: 'پارامتر ها رو بررسی و دوباره تلاش کنید'
|
|
})
|
|
} else console.log(err.response.data)
|
|
})
|
|
},
|
|
// update() {
|
|
// this.validation = {}
|
|
// const data = new FormData()
|
|
// data.append('fa_name', this.slide.locale.fa.name)
|
|
// data.append('en_name', this.slide.locale.en.name)
|
|
//
|
|
// data.append('fa_position', this.slide.locale.fa.position)
|
|
// data.append('en_position', this.slide.locale.en.position)
|
|
//
|
|
// data.append('fa_slide', this.slide.locale.fa.slide)
|
|
// data.append('en_slide', this.slide.locale.en.slide)
|
|
//
|
|
// if (this.$refs.image.files[0]) data.append('image', this.$refs.image.files[0])
|
|
//
|
|
// this.$axios.put(`/api/admin/slide/${this.slide._id}`, data, this.axiosConfig)
|
|
// .then(response => {
|
|
// this.$message({
|
|
// type: 'success',
|
|
// message: 'اطلاعات بروزرسانی شد.'
|
|
// })
|
|
// this.$refs.image.value = null
|
|
// this.$nuxt.refresh()
|
|
// })
|
|
// .catch(err => {
|
|
// if (err.response.status === 401) {
|
|
// return this.$message({
|
|
// type: 'error',
|
|
// message: 'لطفا دوباره وارد سیستم شوید.'
|
|
// })
|
|
// }
|
|
// if (err.response.status === 422) this.validation = err.response.data.validation
|
|
// else console.log(err.response.data)
|
|
// })
|
|
// }
|
|
},
|
|
head() {
|
|
return {
|
|
title: this.title
|
|
}
|
|
},
|
|
layout: 'admin',
|
|
async asyncData({$axios, params, error}) {
|
|
try {
|
|
if (params.slide !== 'new') {
|
|
const slide = await $axios.get(`/api/public/slide/${params.slide}`)
|
|
return {
|
|
slide: slide.data
|
|
}
|
|
} else {
|
|
return {
|
|
slide: {
|
|
isImage: true,
|
|
image: '',
|
|
video: ''
|
|
}
|
|
}
|
|
}
|
|
} catch (e) {
|
|
error({status: 404, message: 'page not found'})
|
|
}
|
|
}
|
|
}
|
|
</script>
|
|
|