Add brands
This commit is contained in:
@@ -8,6 +8,9 @@
|
|||||||
>
|
>
|
||||||
<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>
|
||||||
|
|
||||||
|
<CCard>
|
||||||
|
<CCardBody>
|
||||||
<CRow>
|
<CRow>
|
||||||
<CCol xl="6" lg="6" sm="12">
|
<CCol xl="6" lg="6" sm="12">
|
||||||
<CInput
|
<CInput
|
||||||
@@ -36,17 +39,16 @@
|
|||||||
/>
|
/>
|
||||||
</CCol>
|
</CCol>
|
||||||
<CCol xl="6" lg="6" sm="12">
|
<CCol xl="6" lg="6" sm="12">
|
||||||
|
|
||||||
<CRow>
|
<CRow>
|
||||||
<CCol col="12" class="mb-3">
|
<CCol col="12" class="mb-3">
|
||||||
<img :src="brand.logo" alt="" style="width: 100%; max-width: 500px" />
|
<img :src="brand.logo" alt="" style="width: 100%; max-width: 300px" />
|
||||||
</CCol>
|
</CCol>
|
||||||
<CCol col="1">
|
<CCol col="1">
|
||||||
<span>کاور</span>
|
<span>کاور</span>
|
||||||
</CCol>
|
</CCol>
|
||||||
<CCol col="11">
|
<CCol col="11">
|
||||||
<label for="file" class="btn-upload">آپلود تصویر</label>
|
<label for="file" class="btn-upload">آپلود تصویر</label>
|
||||||
<input id="file" ref="myFiles" style="display: none;" type="file" @change="imagePreview" />
|
<input id="file" ref="myFiles" style="display: none" type="file" @change="imagePreview" />
|
||||||
</CCol>
|
</CCol>
|
||||||
<CCol col="11" class="mr-auto mt-3">
|
<CCol col="11" class="mr-auto mt-3">
|
||||||
<small v-if="validation.logo" class="form-text alert-danger w-100">
|
<small v-if="validation.logo" class="form-text alert-danger w-100">
|
||||||
@@ -54,22 +56,24 @@
|
|||||||
</small>
|
</small>
|
||||||
</CCol>
|
</CCol>
|
||||||
</CRow>
|
</CRow>
|
||||||
|
|
||||||
</CCol>
|
</CCol>
|
||||||
</CRow>
|
</CRow>
|
||||||
|
</CCardBody>
|
||||||
|
</CCard>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
export default {
|
export default {
|
||||||
name: 'AddminBrandsItem',
|
name: 'AddminBrandsItem',
|
||||||
layout: 'admin',
|
layout: 'admin',
|
||||||
async asyncData({ $axios, params, error }) {
|
async asyncData({ $axios, params, error }) {
|
||||||
try {
|
try {
|
||||||
const data = {}
|
const data = {}
|
||||||
if (params.admin !== 'new') {
|
if (params.item !== 'new') {
|
||||||
const brand = await $axios.get(`/api/admin/brand/${params.item}`)
|
const brand = await $axios.get(`/api/admin/brand/${params.item}`)
|
||||||
data.brand = brand.data
|
data.brand = brand.data
|
||||||
|
data.brand.logo = '/uploads/images/brands/' + brand.data.logo
|
||||||
}
|
}
|
||||||
return data
|
return data
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@@ -79,25 +83,30 @@
|
|||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
brand: {
|
brand: {
|
||||||
title:'',
|
title: '',
|
||||||
link:'',
|
link: '',
|
||||||
description:'',
|
description: '',
|
||||||
logo:''
|
logo: ''
|
||||||
},
|
},
|
||||||
validation: {},
|
validation: {}
|
||||||
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
head() {
|
head() {
|
||||||
return {
|
return {
|
||||||
title: "برندها"
|
title: 'برندها'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
computed: {
|
||||||
|
config() {
|
||||||
|
return this.$config
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
imagePreview(event) {
|
imagePreview(event) {
|
||||||
this.brand.logo = URL.createObjectURL(event.target.files[0])
|
this.brand.logo = URL.createObjectURL(event.target.files[0])
|
||||||
},
|
},
|
||||||
post(){
|
|
||||||
|
post() {
|
||||||
this.validation = {}
|
this.validation = {}
|
||||||
const data = new FormData()
|
const data = new FormData()
|
||||||
data.append('title', this.brand.title)
|
data.append('title', this.brand.title)
|
||||||
@@ -109,9 +118,9 @@
|
|||||||
.then(res => {
|
.then(res => {
|
||||||
this.$message({
|
this.$message({
|
||||||
type: 'success',
|
type: 'success',
|
||||||
message: 'پیام با موفقیت برای کاربران ارسال شد'
|
message: 'برند با موفقیت ثبت شد'
|
||||||
})
|
})
|
||||||
this.$router.push({ name: 'admin-announcements', query: { ...this.$route.query } })
|
this.$router.push({ name: 'admin-brands' })
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
if (err.response.status === 422) {
|
if (err.response.status === 422) {
|
||||||
@@ -127,7 +136,53 @@
|
|||||||
message: 'دوباره وارد سیستم شوید'
|
message: 'دوباره وارد سیستم شوید'
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
},
|
||||||
|
update(){
|
||||||
|
|
||||||
|
this.validation = {}
|
||||||
|
const data = new FormData()
|
||||||
|
data.append('title', this.brand.title)
|
||||||
|
data.append('link', this.brand.link)
|
||||||
|
data.append('description', this.brand.description)
|
||||||
|
if(this.$refs.myFiles.files[0]){
|
||||||
|
data.append('logo', this.$refs.myFiles.files[0])
|
||||||
|
}
|
||||||
|
|
||||||
|
this.$axios
|
||||||
|
.put(`/api/admin/brand/${this.$route.params.item}`, data, this.axiosConfig)
|
||||||
|
.then(res => {
|
||||||
|
this.$message({
|
||||||
|
type: 'success',
|
||||||
|
message: 'برند با موفقیت ثبت شد'
|
||||||
|
})
|
||||||
|
this.$router.push({ name: 'admin-brands'})
|
||||||
|
})
|
||||||
|
.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>
|
||||||
|
<style lang="scss">
|
||||||
|
.btn-upload {
|
||||||
|
background-color: cornflowerblue;
|
||||||
|
padding: 0.5rem 1rem;
|
||||||
|
border-radius: 0.5rem;
|
||||||
|
cursor: pointer;
|
||||||
|
color: white;
|
||||||
|
float: left;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|||||||
@@ -20,7 +20,7 @@
|
|||||||
|
|
||||||
<el-table-column width="80">
|
<el-table-column width="80">
|
||||||
<template slot-scope="scope">
|
<template slot-scope="scope">
|
||||||
<img width="60" :src="config.apiAsanMarket + scope.row.logo">
|
<img width="60" :src="'/uploads/images/brands/'+scope.row.logo">
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
|
|
||||||
@@ -30,13 +30,13 @@
|
|||||||
|
|
||||||
<el-table-column label="توضیحات" width="">
|
<el-table-column label="توضیحات" width="">
|
||||||
<template slot-scope="scope">
|
<template slot-scope="scope">
|
||||||
<span class="singleLineTxt" :title="scope.row.national"> {{ scope.row.description }} </span>
|
<span class="singleLineTxt" :title="scope.row.description"> {{ scope.row.description }} </span>
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
|
|
||||||
<el-table-column label="لینک" width="">
|
<el-table-column label="لینک" width="">
|
||||||
<template slot-scope="scope">
|
<template slot-scope="scope">
|
||||||
<span class="singleLineTxt" :title="scope.row.national"> {{ scope.row.link }} </span>
|
<span class="singleLineTxt" :title="scope.row.link"> {{ scope.row.link }} </span>
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
|
|
||||||
@@ -91,7 +91,7 @@
|
|||||||
},
|
},
|
||||||
beforeMount(){
|
beforeMount(){
|
||||||
|
|
||||||
this.$axios.get('/api/public//brand').then(res=>{
|
this.$axios.get('/api/public/brand').then(res=>{
|
||||||
this.brands = res.data
|
this.brands = res.data
|
||||||
console.log(res.data)
|
console.log(res.data)
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ const Brand = require("../models/Brand");
|
|||||||
const { checkValidations } = require("../plugins/controllersHelperFunctions")
|
const { checkValidations } = require("../plugins/controllersHelperFunctions")
|
||||||
const { body, validationResult } = require('express-validator')
|
const { body, validationResult } = require('express-validator')
|
||||||
const { _sr } = require("../plugins/serverResponses")
|
const { _sr } = require("../plugins/serverResponses")
|
||||||
|
const maxAttachmentSize = 2048
|
||||||
|
|
||||||
|
|
||||||
//@desc Create a brand
|
//@desc Create a brand
|
||||||
@@ -93,8 +94,8 @@ const updatebrand = [
|
|||||||
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]))
|
||||||
@@ -103,7 +104,7 @@ const updatebrand = [
|
|||||||
return res
|
return res
|
||||||
.status(422)
|
.status(422)
|
||||||
.json({ validation: { image: { msg: `حجم تصویر نباید بیشتر از ${maxAttachmentSize} KB باشد.` } } })
|
.json({ validation: { image: { 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}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Binary file not shown.
|
After Width: | Height: | Size: 155 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 56 KiB |
Reference in New Issue
Block a user