Files
2024-10-10 21:57:37 +03:30

127 lines
3.7 KiB
Vue

<template>
<div>
<CustomSubHeader>
<CBreadcrumb class="border-0 mb-0">{{ title }}</CBreadcrumb>
<CButton size="sm" color="success" :to="{name: 'admin-slider-slide',params:{slide: 'new'}}" class="mr-auto">افزودن</CButton>
</CustomSubHeader>
<CCard>
<CCardHeader>
<slot name="header">
<i class="fal fa-bars"></i>
<span>{{ list_title }}</span>
</slot>
</CCardHeader>
<CCardBody>
<el-table
:data="slides"
style="width: 100%">
<el-table-column
type="index"
label="#">
</el-table-column>
<el-table-column
label="مدیا"
width="250">
<template slot-scope="scope">
<img v-if="scope.row.isImage" :src="scope.row.image" alt="" style="width: 100%;">
<video v-else :src="scope.row.video" style="width: 100%;" controls muted></video>
</template>
</el-table-column>
<el-table-column
label="نوع"
width="">
<template slot-scope="scope">
<span v-if="scope.row.isImage">عکس</span>
<span v-else>ویدیو</span>
</template>
</el-table-column>
<el-table-column
label="ویرایش"
width="110"
align="center">
<template slot-scope="scope">
<CButton color="danger" variant="outline" :key="scope.row._id + Math.random()" @click="remove(scope.row._id)">
<i class="far fa-trash-alt"></i>
</CButton>
<!-- <CButton color="success" variant="outline" :key="scope.row._id" :to="{name: 'admin-slider-slide',params: {slide: scope.row._id}}">-->
<!-- <i class="far fa-eye"></i>-->
<!-- </CButton>-->
</template>
</el-table-column>
</el-table>
</CCardBody>
</CCard>
</div>
</template>
<script>
export default {
data() {
return {
title: 'لیست اسلاید های صفحه اصلی',
list_title: 'لیست',
slides: null
}
},
methods: {
remove(id) {
this.$confirm('این مورد حذف شود؟', 'هشدار', {
confirmButtonText: 'بله',
cancelButtonText: 'لغو',
type: 'warning'
}).then(async () => {
this.$axios.delete(`/api/admin/slide/${id}`)
.then(res => {
this.$message({
type: 'success',
message: 'مورد با موفقیت حذف شد'
})
this.slides = this.slides.filter(item => item._id !== id)
})
.catch(err => {
if (err.response.status === 401) {
return this.$message({
type: 'error',
message: 'لطفا دوباره وارد سیستم شوید.'
})
}
if (err.response.status === 403) {
return this.$message({
type: 'error',
message: err.response.data.message
})
} else console.log(err.response.data)
})
}).catch(() => {
this.$message({
type: 'warning',
message: 'عملیات لغو شد'
})
})
}
},
head() {
return {
title: this.title
}
},
layout: 'admin',
async asyncData({$axios, error}) {
try {
const slides = await $axios.get(`/api/public/slides`)
return {
slides: slides.data
}
} catch (e) {
error({status: 500, message: 'there is a problem here'})
}
}
}
</script>