update:add ci cd files ==> do not edit those file
This commit is contained in:
@@ -0,0 +1,192 @@
|
||||
<template>
|
||||
<div>
|
||||
<CustomSubHeader>
|
||||
<CBreadcrumb class="border-0 mb-0">{{ title }}</CBreadcrumb>
|
||||
<CButton size="sm" color="primary" class="mr-auto" :to="{name: 'admin-galleryCategories'}">برگشت به صفحه قبل</CButton>
|
||||
<CButton v-if="$route.params.category === '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>
|
||||
<CRow>
|
||||
<CCol sm="12">
|
||||
<CInput
|
||||
:class="validation.fa_title ? 'err' : null"
|
||||
label="عنوان فارسی"
|
||||
:description="validation.fa_title ? validation.fa_title.msg : null"
|
||||
v-model="galleryCategory.locale.fa.title"
|
||||
/>
|
||||
<CInput
|
||||
:class="validation.fa_description ? 'err' : null"
|
||||
label="توضیح فارسی"
|
||||
:description="validation.fa_description ? validation.fa_description.msg : null"
|
||||
v-model="galleryCategory.locale.fa.description"
|
||||
/>
|
||||
<el-divider></el-divider>
|
||||
<CInput
|
||||
:class="validation.en_title ? 'err' : null"
|
||||
label="عنوان انگلیسی"
|
||||
:description="validation.en_title ? validation.en_title.msg : null"
|
||||
v-model="galleryCategory.locale.en.title"
|
||||
/>
|
||||
<CInput
|
||||
:class="validation.en_description ? 'err' : null"
|
||||
label="توضیح انگلیسی"
|
||||
:description="validation.en_description ? validation.en_description.msg : null"
|
||||
v-model="galleryCategory.locale.en.description"
|
||||
/>
|
||||
<span style="font-weight: 600">ترتیب نمایش</span>
|
||||
<el-select v-model="galleryCategory.index" filterable style="width: 100%;margin-top: 5px;">
|
||||
<el-option
|
||||
v-for="item in galleryCategories.length + 20"
|
||||
v-if="galleryCategories.filter(item2=>Number(item2.index) !== item+1)"
|
||||
:key="item + 202"
|
||||
:value="item+1"
|
||||
:label="item+1"/>
|
||||
</el-select>
|
||||
<p v-if="validation.index" class="text-danger" style="margin-top: 5px;">{{ validation.index.msg }}</p>
|
||||
</CCol>
|
||||
</CRow>
|
||||
</CForm>
|
||||
</CCardBody>
|
||||
</CCard>
|
||||
</CCol>
|
||||
<CCol lg="6">
|
||||
<CCard>
|
||||
<CCardBody>
|
||||
<p>کاور</p>
|
||||
<img :src="galleryCategory.cover" alt="" style="width: 100%;max-width: 600px;">
|
||||
<input type="file" ref="cover" @change="preview">
|
||||
<p class="text-danger" v-if="validation.cover">{{ validation.cover.msg }}</p>
|
||||
</CCardBody>
|
||||
</CCard>
|
||||
</CCol>
|
||||
</CRow>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
galleryCategory: null,
|
||||
galleryCategories: null,
|
||||
validation: {}
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
title() {
|
||||
return this.$route.params.category === 'new' ? 'افزودن دسته بندی' : 'مشاهده دسته بندی'
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
preview() {
|
||||
this.galleryCategory.cover = URL.createObjectURL(event.target.files[0])
|
||||
},
|
||||
post() {
|
||||
this.validation = {}
|
||||
const data = new FormData()
|
||||
data.append('fa_title', this.galleryCategory.locale.fa.title)
|
||||
data.append('en_title', this.galleryCategory.locale.en.title)
|
||||
|
||||
data.append('fa_description', this.galleryCategory.locale.fa.description)
|
||||
data.append('en_description', this.galleryCategory.locale.en.description)
|
||||
data.append('index', this.galleryCategory.index)
|
||||
|
||||
if (this.$refs.cover.files[0]) data.append('cover', this.$refs.cover.files[0])
|
||||
|
||||
this.$axios.post(`/api/admin/galleryCategory`, data)
|
||||
.then(response => {
|
||||
this.$message({
|
||||
type: 'success',
|
||||
message: 'دسته بندی با موفقیت ایجاد شد.'
|
||||
})
|
||||
this.$router.push({name: 'admin-galleryCategories'})
|
||||
})
|
||||
.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)
|
||||
})
|
||||
},
|
||||
update() {
|
||||
this.validation = {}
|
||||
const data = new FormData()
|
||||
data.append('fa_title', this.galleryCategory.locale.fa.title)
|
||||
data.append('en_title', this.galleryCategory.locale.en.title)
|
||||
|
||||
data.append('fa_description', this.galleryCategory.locale.fa.description)
|
||||
data.append('en_description', this.galleryCategory.locale.en.description)
|
||||
data.append('index', this.galleryCategory.index)
|
||||
|
||||
if (this.$refs.cover.files[0]) data.append('cover', this.$refs.cover.files[0])
|
||||
|
||||
this.$axios.put(`/api/admin/galleryCategory/${this.galleryCategory._id}`, data)
|
||||
.then(response => {
|
||||
this.$message({
|
||||
type: 'success',
|
||||
message: 'اطلاعات بروزرسانی شد.'
|
||||
})
|
||||
})
|
||||
.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 {
|
||||
const galleryCategories = await $axios.$get(`/api/public/galleryCategories`)
|
||||
|
||||
if (params.category !== 'new') {
|
||||
const galleryCategory = await $axios.$get(`/api/admin/galleryCategory/${params.category}`)
|
||||
|
||||
return {
|
||||
galleryCategory,
|
||||
galleryCategories,
|
||||
}
|
||||
} else {
|
||||
return {
|
||||
galleryCategories,
|
||||
galleryCategory: {
|
||||
locale: {
|
||||
fa: {
|
||||
title: '',
|
||||
description: ''
|
||||
},
|
||||
en: {
|
||||
title: '',
|
||||
description: ''
|
||||
}
|
||||
},
|
||||
index : 0
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
error({status: 404, message: 'page not found'})
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -0,0 +1,128 @@
|
||||
<template>
|
||||
<div>
|
||||
<CustomSubHeader>
|
||||
<CBreadcrumb class="border-0 mb-0">{{ title }}</CBreadcrumb>
|
||||
<CButton size="sm" color="success" :to="{name: 'admin-galleryCategories-category',params:{category: '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="galleryCategories"
|
||||
style="width: 100%">
|
||||
<el-table-column
|
||||
type="index"
|
||||
label="#">
|
||||
</el-table-column>
|
||||
|
||||
<el-table-column
|
||||
label="کاور"
|
||||
width="200">
|
||||
<template slot-scope="scope">
|
||||
<img :src="!scope.row.thumb.includes('undefined') ? scope.row.thumb : '/img/default-img.png'" alt="" style="width: 50%">
|
||||
</template>
|
||||
</el-table-column>
|
||||
|
||||
<el-table-column
|
||||
prop="locale.fa.title"
|
||||
label="عنوان فارسی"
|
||||
width="">
|
||||
</el-table-column>
|
||||
|
||||
<el-table-column
|
||||
prop="locale.en.title"
|
||||
label="عنوان انگلیسی"
|
||||
width="">
|
||||
</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-galleryCategories-category',params: {category: 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: 'لیست',
|
||||
galleryCategories: null
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
remove(id) {
|
||||
this.$confirm('این مورد حذف شود؟', 'هشدار', {
|
||||
confirmButtonText: 'بله',
|
||||
cancelButtonText: 'لغو',
|
||||
type: 'warning'
|
||||
}).then(async () => {
|
||||
this.$axios.delete(`/api/admin/galleryCategory/${id}`)
|
||||
.then(res => {
|
||||
this.$message({
|
||||
type: 'success',
|
||||
message: 'دسته بندی با موفقیت حذف شد'
|
||||
})
|
||||
this.galleryCategories = this.galleryCategories.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 galleryCategories = await $axios.get(`/api/public/galleryCategories`)
|
||||
|
||||
return {
|
||||
galleryCategories: galleryCategories.data
|
||||
}
|
||||
} catch (e) {
|
||||
error({status: 500, message: 'there is a problem here'})
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
Reference in New Issue
Block a user