fix
This commit is contained in:
@@ -3,13 +3,59 @@
|
|||||||
<CustomSubHeader>
|
<CustomSubHeader>
|
||||||
<CBreadcrumb class="border-0 mb-0">برند ها</CBreadcrumb>
|
<CBreadcrumb class="border-0 mb-0">برند ها</CBreadcrumb>
|
||||||
<CButton size="sm" color="primary" class="mr-auto" :to="{ name: 'admin-brands' }">برگشت به صفحه قبل</CButton>
|
<CButton size="sm" color="primary" class="mr-auto" :to="{ name: 'admin-brands' }">برگشت به صفحه قبل</CButton>
|
||||||
<CButton v-if="$route.params.item === 'new'" size="sm" color="success" style="margin-right: 10px" @click="add"
|
<CButton v-if="$route.params.item === 'new'" size="sm" color="success" style="margin-right: 10px" @click="post"
|
||||||
>افزودن</CButton
|
>افزودن</CButton
|
||||||
>
|
>
|
||||||
<CButton v-else size="sm" color="success" style="margin-right: 10px" @click="update">بروزرسانی</CButton>
|
<CButton v-else size="sm" color="success" style="margin-right: 10px" @click="update">بروزرسانی</CButton>
|
||||||
</CustomSubHeader>
|
</CustomSubHeader>
|
||||||
<CRow>
|
<CRow>
|
||||||
|
<CCol xl="6" lg="6" sm="12">
|
||||||
|
<CInput
|
||||||
|
v-model="brand.title"
|
||||||
|
label="نام"
|
||||||
|
horizontal
|
||||||
|
:description="validation.title ? validation.title.msg : null"
|
||||||
|
:class="validation.title ? 'err' : null"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<CInput
|
||||||
|
v-model="brand.link"
|
||||||
|
label="لینک"
|
||||||
|
horizontal
|
||||||
|
:description="validation.link ? validation.link.msg : null"
|
||||||
|
:class="validation.link ? 'err' : null"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<CTextarea
|
||||||
|
v-model="brand.description"
|
||||||
|
label="توضیح"
|
||||||
|
horizontal
|
||||||
|
rows="4"
|
||||||
|
:description="validation.description ? validation.description.msg : null"
|
||||||
|
:class="validation.description ? 'err' : null"
|
||||||
|
/>
|
||||||
|
</CCol>
|
||||||
|
<CCol xl="6" lg="6" sm="12">
|
||||||
|
|
||||||
|
<CRow>
|
||||||
|
<CCol col="12" class="mb-3">
|
||||||
|
<img :src="brand.logo" alt="" style="width: 100%; max-width: 500px" />
|
||||||
|
</CCol>
|
||||||
|
<CCol col="1">
|
||||||
|
<span>کاور</span>
|
||||||
|
</CCol>
|
||||||
|
<CCol col="11">
|
||||||
|
<label for="file" class="btn-upload">آپلود تصویر</label>
|
||||||
|
<input id="file" ref="myFiles" style="display: none;" type="file" @change="imagePreview" />
|
||||||
|
</CCol>
|
||||||
|
<CCol col="11" class="mr-auto mt-3">
|
||||||
|
<small v-if="validation.logo" class="form-text alert-danger w-100">
|
||||||
|
{{ validation.logo.msg }}
|
||||||
|
</small>
|
||||||
|
</CCol>
|
||||||
|
</CRow>
|
||||||
|
|
||||||
|
</CCol>
|
||||||
</CRow>
|
</CRow>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
@@ -33,7 +79,10 @@
|
|||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
brand: {
|
brand: {
|
||||||
|
title:'',
|
||||||
|
link:'',
|
||||||
|
description:'',
|
||||||
|
logo:''
|
||||||
},
|
},
|
||||||
validation: {},
|
validation: {},
|
||||||
|
|
||||||
@@ -45,8 +94,40 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
imagePreview(event) {
|
||||||
|
this.brand.logo = URL.createObjectURL(event.target.files[0])
|
||||||
|
},
|
||||||
|
post(){
|
||||||
|
this.validation = {}
|
||||||
|
const data = new FormData()
|
||||||
|
data.append('title', this.brand.title)
|
||||||
|
data.append('link', this.brand.link)
|
||||||
|
data.append('description', this.brand.description)
|
||||||
|
data.append('logo', this.$refs.myFiles.files[0])
|
||||||
|
this.$axios
|
||||||
|
.post('/api/admin/brand', data, this.axiosConfig)
|
||||||
|
.then(res => {
|
||||||
|
this.$message({
|
||||||
|
type: 'success',
|
||||||
|
message: 'پیام با موفقیت برای کاربران ارسال شد'
|
||||||
|
})
|
||||||
|
this.$router.push({ name: 'admin-announcements', query: { ...this.$route.query } })
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
if (err.response.status === 422) {
|
||||||
|
this.$message({
|
||||||
|
type: 'warning',
|
||||||
|
message: 'پارامتر ها رو بررسی کنید'
|
||||||
|
})
|
||||||
|
this.validation = err.response.data.validation
|
||||||
|
}
|
||||||
|
if (err.response.status === 401)
|
||||||
|
this.$message({
|
||||||
|
type: 'error',
|
||||||
|
message: 'دوباره وارد سیستم شوید'
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@@ -21,18 +21,20 @@ const createbrand = [
|
|||||||
title, link, description,
|
title, link, description,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (req.files?.image) {
|
if (req.files?.logo) {
|
||||||
const image = req.files.image
|
const image = req.files.logo
|
||||||
const fileName = 'brands' + Date.now() + '.' + image.name
|
const fileName = 'brands' + Date.now() + '.' + image.name
|
||||||
const acceptableFormats = ['png', 'jpg', 'jpeg', 'webp']
|
const acceptableFormats = ['png', 'jpg', 'jpeg', 'webp']
|
||||||
if (!acceptableFormats.includes(image.mimetype.split('/')[1]))
|
if (!acceptableFormats.includes(image.mimetype.split('/')[1]))
|
||||||
return res.status(422).json({ validation: { image: { msg: _faSr.format.image } } })
|
return res.status(422).json({ validation: { logo: { msg: _faSr.format.image } } })
|
||||||
if (image.size / 1024 > maxAttachmentSize)
|
if (image.size / 1024 > maxAttachmentSize)
|
||||||
return res
|
return res
|
||||||
.status(422)
|
.status(422)
|
||||||
.json({ validation: { image: { msg: `حجم تصویر نباید بیشتر از ${maxAttachmentSize} KB باشد.` } } })
|
.json({ validation: { logo: { msg: `حجم تصویر نباید بیشتر از ${maxAttachmentSize} KB باشد.` } } })
|
||||||
data.image = fileName
|
data.logo = fileName
|
||||||
await image.mv(`./static/uploads/images/brands/${fileName}`)
|
await image.mv(`./static/uploads/images/brands/${fileName}`)
|
||||||
|
}else{
|
||||||
|
res.status(422).json({ validation: { logo: { msg: `تصویر را ارسال کنید` } } })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user