fix: upload image
This commit is contained in:
+242
-165
@@ -2,10 +2,24 @@
|
|||||||
<div>
|
<div>
|
||||||
<CustomSubHeader>
|
<CustomSubHeader>
|
||||||
<CBreadcrumb class="border-0 mb-0">{{ title }}</CBreadcrumb>
|
<CBreadcrumb class="border-0 mb-0">{{ title }}</CBreadcrumb>
|
||||||
<CButton size="sm" color="primary" class="mr-auto" :to="{ name: 'admin-news' }">برگشت به صفحه قبل</CButton>
|
<CButton
|
||||||
<CButton v-if="$route.params.details === 'new'" size="sm" color="success" class="mr-1" @click="post">افزودن
|
size="sm"
|
||||||
|
color="primary"
|
||||||
|
class="mr-auto"
|
||||||
|
:to="{ name: 'admin-news' }"
|
||||||
|
>برگشت به صفحه قبل</CButton
|
||||||
|
>
|
||||||
|
<CButton
|
||||||
|
v-if="$route.params.details === 'new'"
|
||||||
|
size="sm"
|
||||||
|
color="success"
|
||||||
|
class="mr-1"
|
||||||
|
@click="post"
|
||||||
|
>افزودن
|
||||||
</CButton>
|
</CButton>
|
||||||
<CButton v-else size="sm" color="success" class="mr-1" @click="update">بروزرسانی</CButton>
|
<CButton v-else size="sm" color="success" class="mr-1" @click="update"
|
||||||
|
>بروزرسانی</CButton
|
||||||
|
>
|
||||||
</CustomSubHeader>
|
</CustomSubHeader>
|
||||||
<CRow>
|
<CRow>
|
||||||
<CCol lg="6">
|
<CCol lg="6">
|
||||||
@@ -17,15 +31,19 @@
|
|||||||
<CCol>
|
<CCol>
|
||||||
<h6>
|
<h6>
|
||||||
قسمت انتخابی
|
قسمت انتخابی
|
||||||
<i v-c-tooltip="'شما باید تعیین کنید که این خبر برای کدام قسمت پرتال می باشد'"
|
<i
|
||||||
class="fas fa-question-circle"></i>
|
v-c-tooltip="
|
||||||
|
'شما باید تعیین کنید که این خبر برای کدام قسمت پرتال می باشد'
|
||||||
|
"
|
||||||
|
class="fas fa-question-circle"
|
||||||
|
></i>
|
||||||
</h6>
|
</h6>
|
||||||
<el-select
|
<el-select
|
||||||
:disabled="$auth.user.portals.length === 1"
|
:disabled="$auth.user.portals.length === 1"
|
||||||
v-model="news.modelType"
|
v-model="news.modelType"
|
||||||
placeholder="انتخاب کنید"
|
placeholder="انتخاب کنید"
|
||||||
style="width: 100%;"
|
style="width: 100%"
|
||||||
@change="[clearIDs('catId'),clearIDs('newsFile')]"
|
@change="[clearIDs('catId'), clearIDs('newsFile')]"
|
||||||
>
|
>
|
||||||
<el-option
|
<el-option
|
||||||
v-for="item in portals"
|
v-for="item in portals"
|
||||||
@@ -36,14 +54,14 @@
|
|||||||
</el-option>
|
</el-option>
|
||||||
</el-select>
|
</el-select>
|
||||||
<p
|
<p
|
||||||
style="margin-top : 5px !important ; color : red"
|
style="margin-top: 5px !important ; color: red"
|
||||||
class="form-err"
|
class="form-err"
|
||||||
v-if="validation.modelType"
|
v-if="validation.modelType"
|
||||||
>
|
>
|
||||||
{{ validation.modelType.msg }}
|
{{ validation.modelType.msg }}
|
||||||
</p>
|
</p>
|
||||||
<template v-if="filterParent">
|
<template v-if="filterParent">
|
||||||
<el-divider/>
|
<el-divider />
|
||||||
<CRow>
|
<CRow>
|
||||||
<CCol sm="12">
|
<CCol sm="12">
|
||||||
<h6>
|
<h6>
|
||||||
@@ -56,7 +74,7 @@
|
|||||||
<el-select
|
<el-select
|
||||||
filterable
|
filterable
|
||||||
clearable
|
clearable
|
||||||
style="width : 100%"
|
style="width: 100%"
|
||||||
v-model="catId"
|
v-model="catId"
|
||||||
placeholder="انتخاب دسته بندی"
|
placeholder="انتخاب دسته بندی"
|
||||||
@change="clearIDs('newsFile')"
|
@change="clearIDs('newsFile')"
|
||||||
@@ -71,7 +89,7 @@
|
|||||||
</el-option>
|
</el-option>
|
||||||
</el-select>
|
</el-select>
|
||||||
<p
|
<p
|
||||||
style="margin-top : 5px !important ; color : red"
|
style="margin-top: 5px !important ; color: red"
|
||||||
class="form-err"
|
class="form-err"
|
||||||
v-if="validation.catId"
|
v-if="validation.catId"
|
||||||
>
|
>
|
||||||
@@ -94,7 +112,9 @@
|
|||||||
<CTextarea
|
<CTextarea
|
||||||
:class="validation.summaryTitle ? 'err' : null"
|
:class="validation.summaryTitle ? 'err' : null"
|
||||||
label="رو تیتر"
|
label="رو تیتر"
|
||||||
:description="validation.summaryTitle? validation.summaryTitle.msg: null "
|
:description="
|
||||||
|
validation.summaryTitle ? validation.summaryTitle.msg : null
|
||||||
|
"
|
||||||
v-model="news.summaryTitle"
|
v-model="news.summaryTitle"
|
||||||
rows="3"
|
rows="3"
|
||||||
/>
|
/>
|
||||||
@@ -118,7 +138,9 @@
|
|||||||
<CTextarea
|
<CTextarea
|
||||||
:class="validation.leadTitle ? 'err' : null"
|
:class="validation.leadTitle ? 'err' : null"
|
||||||
label="لید"
|
label="لید"
|
||||||
:description="validation.leadTitle? validation.leadTitle.msg: null "
|
:description="
|
||||||
|
validation.leadTitle ? validation.leadTitle.msg : null
|
||||||
|
"
|
||||||
v-model="news.leadTitle"
|
v-model="news.leadTitle"
|
||||||
rows="3"
|
rows="3"
|
||||||
/>
|
/>
|
||||||
@@ -131,7 +153,9 @@
|
|||||||
:class="validation.metaTagDesc ? 'err' : null"
|
:class="validation.metaTagDesc ? 'err' : null"
|
||||||
label="توضیحات برای موتورهای جست و جو"
|
label="توضیحات برای موتورهای جست و جو"
|
||||||
placeholder="در صورتی که این کادر را خالی بگذارید از متن لید استفاده خواهد شد."
|
placeholder="در صورتی که این کادر را خالی بگذارید از متن لید استفاده خواهد شد."
|
||||||
:description="validation.metaTagDesc? validation.metaTagDesc.msg: null"
|
:description="
|
||||||
|
validation.metaTagDesc ? validation.metaTagDesc.msg : null
|
||||||
|
"
|
||||||
v-model="news.metaTagDesc"
|
v-model="news.metaTagDesc"
|
||||||
rows="3"
|
rows="3"
|
||||||
/>
|
/>
|
||||||
@@ -158,8 +182,7 @@
|
|||||||
size="small"
|
size="small"
|
||||||
@click="showInput"
|
@click="showInput"
|
||||||
>کلمه جدید
|
>کلمه جدید
|
||||||
</el-button
|
</el-button>
|
||||||
>
|
|
||||||
</div>
|
</div>
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<el-tag
|
<el-tag
|
||||||
@@ -204,10 +227,7 @@
|
|||||||
<CCard>
|
<CCard>
|
||||||
<CCardBody>
|
<CCardBody>
|
||||||
<CCol sm="12">
|
<CCol sm="12">
|
||||||
<el-checkbox
|
<el-checkbox v-model="news.publish" label="انتشار خبر" />
|
||||||
v-model="news.publish"
|
|
||||||
label="انتشار خبر"
|
|
||||||
/>
|
|
||||||
</CCol>
|
</CCol>
|
||||||
<CCol sm="12">
|
<CCol sm="12">
|
||||||
<el-checkbox
|
<el-checkbox
|
||||||
@@ -248,7 +268,6 @@
|
|||||||
label="قرار گرفتن در بخش اطلاعیه ها"
|
label="قرار گرفتن در بخش اطلاعیه ها"
|
||||||
/>
|
/>
|
||||||
</CCol>
|
</CCol>
|
||||||
|
|
||||||
</CCardBody>
|
</CCardBody>
|
||||||
</CCard>
|
</CCard>
|
||||||
<CCard>
|
<CCard>
|
||||||
@@ -266,7 +285,7 @@
|
|||||||
<el-select
|
<el-select
|
||||||
v-model="news.newsFileId"
|
v-model="news.newsFileId"
|
||||||
placeholder="انتخاب کنید"
|
placeholder="انتخاب کنید"
|
||||||
style="width: 100%;"
|
style="width: 100%"
|
||||||
filterable
|
filterable
|
||||||
clearable
|
clearable
|
||||||
>
|
>
|
||||||
@@ -279,7 +298,7 @@
|
|||||||
</el-option>
|
</el-option>
|
||||||
</el-select>
|
</el-select>
|
||||||
<p
|
<p
|
||||||
style="margin-top : 5px !important ; color : red"
|
style="margin-top: 5px !important ; color: red"
|
||||||
class="form-err"
|
class="form-err"
|
||||||
v-if="validation.newsFileId"
|
v-if="validation.newsFileId"
|
||||||
>
|
>
|
||||||
@@ -288,16 +307,20 @@
|
|||||||
</CCol>
|
</CCol>
|
||||||
</CCardBody>
|
</CCardBody>
|
||||||
</CCard>
|
</CCard>
|
||||||
<CCard v-if="$route.params.details !=='new'">
|
<CCard v-if="$route.params.details !== 'new'">
|
||||||
<CCardBody>
|
<CCardBody>
|
||||||
<CCol sm="12">
|
<CCol sm="12">
|
||||||
<h6>
|
<h6>تغییر زمان ثبت خبر</h6>
|
||||||
تغییر زمان ثبت خبر
|
<date-picker
|
||||||
</h6>
|
clearable
|
||||||
<date-picker clearable input-format="YYYY-MM-DD HH:mm" format="YYYY-MM-DD HH:mm" display-format="jYYYY/jMM/jDD HH:mm"
|
input-format="YYYY-MM-DD HH:mm"
|
||||||
v-model="news.customDate" type="datetime"/>
|
format="YYYY-MM-DD HH:mm"
|
||||||
|
display-format="jYYYY/jMM/jDD HH:mm"
|
||||||
|
v-model="news.customDate"
|
||||||
|
type="datetime"
|
||||||
|
/>
|
||||||
<p
|
<p
|
||||||
style="margin-top : 5px !important ; color : red"
|
style="margin-top: 5px !important ; color: red"
|
||||||
class="form-err"
|
class="form-err"
|
||||||
v-if="validation.customDate"
|
v-if="validation.customDate"
|
||||||
>
|
>
|
||||||
@@ -308,29 +331,41 @@
|
|||||||
</CCard>
|
</CCard>
|
||||||
<CCard>
|
<CCard>
|
||||||
<CCardBody>
|
<CCardBody>
|
||||||
<p style="font-weight: bold; color: red;">*در صورتی که عکس خبر وارد نشده باشد خبر در حالت ناقص قرار می گیرد</p>
|
<p style="font-weight: bold; color: red">
|
||||||
|
*در صورتی که عکس خبر وارد نشده باشد خبر در حالت ناقص قرار می گیرد
|
||||||
|
</p>
|
||||||
<CCol sm="12">
|
<CCol sm="12">
|
||||||
<h4>عکس خبر هنگام نمایش در لیست اخبار</h4>
|
<h4>عکس خبر هنگام نمایش در لیست اخبار</h4>
|
||||||
<el-divider/>
|
<el-divider />
|
||||||
<CCol>
|
<CCol>
|
||||||
<img :src="news.thumbCover" style="width: 100%;" alt=""/>
|
<img :src="news.thumbCover" style="width: 100%" alt="" />
|
||||||
</CCol>
|
</CCol>
|
||||||
<input type="file" ref="thumbCover" @change="imagePreview2"/>
|
<input type="file" ref="thumbCover" @change="imagePreview2" />
|
||||||
<p style="margin-top: 5px !important;" class="form-err text-danger" v-if="validation.thumbCover">
|
<p
|
||||||
{{ validation.thumbCover.msg }}</p>
|
style="margin-top: 5px !important"
|
||||||
|
class="form-err text-danger"
|
||||||
|
v-if="validation.thumbCover"
|
||||||
|
>
|
||||||
|
{{ validation.thumbCover.msg }}
|
||||||
|
</p>
|
||||||
<p class="mt-3 text-muted">
|
<p class="mt-3 text-muted">
|
||||||
عکس 300*600 باشد. در غیر این صورت اتوماتیک بریده می شود.
|
عکس 300*600 باشد. در غیر این صورت اتوماتیک بریده می شود.
|
||||||
</p>
|
</p>
|
||||||
</CCol>
|
</CCol>
|
||||||
<CCol sm="12">
|
<CCol sm="12">
|
||||||
<h4>کاور اصلی خبر</h4>
|
<h4>کاور اصلی خبر</h4>
|
||||||
<el-divider/>
|
<el-divider />
|
||||||
<CCol>
|
<CCol>
|
||||||
<img :src="news.cover" style="width: 100%;" alt=""/>
|
<img :src="news.cover" style="width: 100%" alt="" />
|
||||||
</CCol>
|
</CCol>
|
||||||
<input type="file" ref="cover" @change="imagePreview"/>
|
<input type="file" ref="cover" @change="imagePreview" />
|
||||||
<p style="margin-top: 5px !important;" class="form-err text-danger" v-if="validation.cover">
|
<p
|
||||||
{{ validation.cover.msg }}</p>
|
style="margin-top: 5px !important"
|
||||||
|
class="form-err text-danger"
|
||||||
|
v-if="validation.cover"
|
||||||
|
>
|
||||||
|
{{ validation.cover.msg }}
|
||||||
|
</p>
|
||||||
<p class="mt-3 text-muted">
|
<p class="mt-3 text-muted">
|
||||||
عکس 1080*1920 باشد. در غیر این صورت اتوماتیک بریده می شود.
|
عکس 1080*1920 باشد. در غیر این صورت اتوماتیک بریده می شود.
|
||||||
</p>
|
</p>
|
||||||
@@ -346,49 +381,52 @@
|
|||||||
<h2>لیست فایل های ضمیمه</h2>
|
<h2>لیست فایل های ضمیمه</h2>
|
||||||
<el-divider></el-divider>
|
<el-divider></el-divider>
|
||||||
<el-table :data="news.attachments">
|
<el-table :data="news.attachments">
|
||||||
|
<el-table-column type="index" label="#"> </el-table-column>
|
||||||
|
|
||||||
<el-table-column
|
<el-table-column label="فایل" width="">
|
||||||
type="index"
|
|
||||||
label="#"
|
|
||||||
>
|
|
||||||
</el-table-column>
|
|
||||||
|
|
||||||
<el-table-column
|
|
||||||
label="فایل"
|
|
||||||
width=""
|
|
||||||
>
|
|
||||||
<template slot-scope="scope">
|
<template slot-scope="scope">
|
||||||
<a :href="scope.row.file" target="_blank">{{ scope.row.title }}</a>
|
<a :href="scope.row.file" target="_blank">{{
|
||||||
|
scope.row.title
|
||||||
|
}}</a>
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
|
|
||||||
|
<el-table-column label="ویرایش" width="75" align="center">
|
||||||
<el-table-column
|
|
||||||
label="ویرایش"
|
|
||||||
width="75"
|
|
||||||
align="center"
|
|
||||||
>
|
|
||||||
<template slot-scope="scope">
|
<template slot-scope="scope">
|
||||||
<CButton color="danger" variant="outline" @click="deleteFile(scope.row._id)">
|
<CButton
|
||||||
|
color="danger"
|
||||||
|
variant="outline"
|
||||||
|
@click="deleteFile(scope.row._id)"
|
||||||
|
>
|
||||||
<i class="far fa-trash-alt"></i>
|
<i class="far fa-trash-alt"></i>
|
||||||
</CButton>
|
</CButton>
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
|
|
||||||
</el-table>
|
</el-table>
|
||||||
</CCol>
|
</CCol>
|
||||||
<CCol sm="6">
|
<CCol sm="6">
|
||||||
<h2>افزودن فایل ضمیمه</h2>
|
<h2>افزودن فایل ضمیمه</h2>
|
||||||
<el-divider></el-divider>
|
<el-divider></el-divider>
|
||||||
<input type="file" ref="attFile"/>
|
<input type="file" ref="attFile" />
|
||||||
<p class="text-danger" v-if="validation.file">{{ validation.file.msg }}</p>
|
<p class="text-danger" v-if="validation.file">
|
||||||
<br>
|
{{ validation.file.msg }}
|
||||||
<br>
|
</p>
|
||||||
<input type="text" ref="attTitle" placeholder="عنوان فایل را بنویسید" style="width: 300px;"/>
|
<br />
|
||||||
<p class="text-danger" v-if="validation.attTitle">{{ validation.attTitle.msg }}</p>
|
<br />
|
||||||
<br>
|
<input
|
||||||
<br>
|
type="text"
|
||||||
<el-button size="small" type="success" @click="addFile">افزودن</el-button>
|
ref="attTitle"
|
||||||
|
placeholder="عنوان فایل را بنویسید"
|
||||||
|
style="width: 300px"
|
||||||
|
/>
|
||||||
|
<p class="text-danger" v-if="validation.attTitle">
|
||||||
|
{{ validation.attTitle.msg }}
|
||||||
|
</p>
|
||||||
|
<br />
|
||||||
|
<br />
|
||||||
|
<el-button size="small" type="success" @click="addFile"
|
||||||
|
>افزودن</el-button
|
||||||
|
>
|
||||||
</CCol>
|
</CCol>
|
||||||
</CRow>
|
</CRow>
|
||||||
</CCardBody>
|
</CCardBody>
|
||||||
@@ -399,7 +437,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import axiosUploadProcess from "@/mixins/axiosUploadProcess"
|
import axiosUploadProcess from "@/mixins/axiosUploadProcess";
|
||||||
import moment from "moment-jalaali";
|
import moment from "moment-jalaali";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
@@ -414,11 +452,11 @@ export default {
|
|||||||
editorConfig: {
|
editorConfig: {
|
||||||
language: "en",
|
language: "en",
|
||||||
extraPlugins: ["bidi", "justify"],
|
extraPlugins: ["bidi", "justify"],
|
||||||
versionCheck:false
|
versionCheck: false,
|
||||||
},
|
},
|
||||||
parents: null,
|
parents: null,
|
||||||
portals: null
|
portals: null,
|
||||||
}
|
};
|
||||||
},
|
},
|
||||||
mixins: [axiosUploadProcess],
|
mixins: [axiosUploadProcess],
|
||||||
computed: {
|
computed: {
|
||||||
@@ -429,20 +467,28 @@ export default {
|
|||||||
},
|
},
|
||||||
catId: {
|
catId: {
|
||||||
get() {
|
get() {
|
||||||
if (this.$route.params.details === 'new') return this.news.catId
|
if (this.$route.params.details === "new") return this.news.catId;
|
||||||
else return this.news.catId._id
|
else return this.news.catId._id;
|
||||||
},
|
},
|
||||||
set(value) {
|
set(value) {
|
||||||
if (this.$route.params.details === 'new') this.news.catId = value
|
if (this.$route.params.details === "new") this.news.catId = value;
|
||||||
else this.news.catId._id = value
|
else this.news.catId._id = value;
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
filterParent() {
|
filterParent() {
|
||||||
return this.parents.filter(item => item.modelType === this.news.modelType)
|
return this.parents.filter(
|
||||||
|
(item) => item.modelType === this.news.modelType
|
||||||
|
);
|
||||||
},
|
},
|
||||||
filteredSetNewsFile() {
|
filteredSetNewsFile() {
|
||||||
return this.newsFile.filter(item => item.modelType === this.news.modelType && (this.$route.params.details === 'new' ? item.catId === this.news.catId : item.catId === this.news.catId._id))
|
return this.newsFile.filter(
|
||||||
}
|
(item) =>
|
||||||
|
item.modelType === this.news.modelType &&
|
||||||
|
(this.$route.params.details === "new"
|
||||||
|
? item.catId === this.news.catId
|
||||||
|
: item.catId === this.news.catId._id)
|
||||||
|
);
|
||||||
|
},
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
jDate(date) {
|
jDate(date) {
|
||||||
@@ -466,8 +512,8 @@ export default {
|
|||||||
this.inputValue = "";
|
this.inputValue = "";
|
||||||
},
|
},
|
||||||
clearIDs(mode) {
|
clearIDs(mode) {
|
||||||
if (mode === 'catId') this.catId = ''
|
if (mode === "catId") this.catId = "";
|
||||||
if (mode === 'newsFile') this.news.newsFileId = ''
|
if (mode === "newsFile") this.news.newsFileId = "";
|
||||||
},
|
},
|
||||||
imagePreview(e) {
|
imagePreview(e) {
|
||||||
this.news.cover = URL.createObjectURL(e.target.files[0]);
|
this.news.cover = URL.createObjectURL(e.target.files[0]);
|
||||||
@@ -491,13 +537,18 @@ export default {
|
|||||||
data.append("special", this.news.special);
|
data.append("special", this.news.special);
|
||||||
data.append("notifications", this.news.notifications);
|
data.append("notifications", this.news.notifications);
|
||||||
data.append("keywords", JSON.stringify(this.news.keywords));
|
data.append("keywords", JSON.stringify(this.news.keywords));
|
||||||
data.append("metaTagDesc", this.news?.metaTagDesc || this.news?.leadTitle);
|
data.append(
|
||||||
|
"metaTagDesc",
|
||||||
|
this.news?.metaTagDesc || this.news?.leadTitle
|
||||||
|
);
|
||||||
data.append("modelType", this.news.modelType);
|
data.append("modelType", this.news.modelType);
|
||||||
if (this.news.newsFileId) {
|
if (this.news.newsFileId) {
|
||||||
data.append("newsFileId", this.news.newsFileId);
|
data.append("newsFileId", this.news.newsFileId);
|
||||||
}
|
}
|
||||||
if (this.$refs.cover.files[0]) data.append("cover", this.$refs.cover.files[0]);
|
if (this.$refs.cover.files[0])
|
||||||
if (this.$refs.thumbCover.files[0]) data.append("thumbCover", this.$refs.thumbCover.files[0]);
|
data.append("cover", this.$refs.cover.files[0]);
|
||||||
|
if (this.$refs.thumbCover.files[0])
|
||||||
|
data.append("thumbCover", this.$refs.thumbCover.files[0]);
|
||||||
|
|
||||||
this.$axios
|
this.$axios
|
||||||
.post(`/api/admin/news`, data, this.axiosConfig)
|
.post(`/api/admin/news`, data, this.axiosConfig)
|
||||||
@@ -532,9 +583,9 @@ export default {
|
|||||||
if (err.response.status === 422) {
|
if (err.response.status === 422) {
|
||||||
this.validation = err.response.data.validation;
|
this.validation = err.response.data.validation;
|
||||||
this.$message({
|
this.$message({
|
||||||
type: 'warning',
|
type: "warning",
|
||||||
message: 'پارامتر هارو بررسی کنید'
|
message: "پارامتر هارو بررسی کنید",
|
||||||
})
|
});
|
||||||
} else console.log(err.response.data);
|
} else console.log(err.response.data);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
@@ -562,8 +613,10 @@ export default {
|
|||||||
if (this.news.newsFileId) {
|
if (this.news.newsFileId) {
|
||||||
data.append("newsFileId", this.news.newsFileId);
|
data.append("newsFileId", this.news.newsFileId);
|
||||||
}
|
}
|
||||||
if (this.$refs.cover.files[0]) data.append("cover", this.$refs.cover.files[0]);
|
if (this.$refs.cover.files[0])
|
||||||
if (this.$refs.thumbCover.files[0]) data.append("thumbCover", this.$refs.thumbCover.files[0]);
|
data.append("cover", this.$refs.cover.files[0]);
|
||||||
|
if (this.$refs.thumbCover.files[0])
|
||||||
|
data.append("thumbCover", this.$refs.thumbCover.files[0]);
|
||||||
|
|
||||||
this.$axios
|
this.$axios
|
||||||
.put(`/api/admin/news/${this.news._id}`, data, this.axiosConfig)
|
.put(`/api/admin/news/${this.news._id}`, data, this.axiosConfig)
|
||||||
@@ -572,9 +625,24 @@ export default {
|
|||||||
type: "success",
|
type: "success",
|
||||||
message: "اطلاعات بروزرسانی شد.",
|
message: "اطلاعات بروزرسانی شد.",
|
||||||
});
|
});
|
||||||
this.$nuxt.refresh();
|
|
||||||
this.$refs.cover.value = null
|
// بروزرسانی تصاویر در صورت تغییر
|
||||||
this.$refs.thumbCover.value = null
|
if (response.data.cover && response.data.cover !== this.news.cover) {
|
||||||
|
this.news.cover = response.data.cover + "?t=" + Date.now();
|
||||||
|
}
|
||||||
|
if (
|
||||||
|
response.data.thumbCover &&
|
||||||
|
response.data.thumbCover !== this.news.thumbCover
|
||||||
|
) {
|
||||||
|
this.news.thumbCover =
|
||||||
|
response.data.thumbCover + "?t=" + Date.now();
|
||||||
|
}
|
||||||
|
|
||||||
|
// بروزرسانی سایر اطلاعات
|
||||||
|
this.news.newsStatus = response.data.newsStatus;
|
||||||
|
|
||||||
|
this.$refs.cover.value = null;
|
||||||
|
this.$refs.thumbCover.value = null;
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
if (err.response.status === 401) {
|
if (err.response.status === 401) {
|
||||||
@@ -597,101 +665,109 @@ export default {
|
|||||||
}
|
}
|
||||||
if (err.response.status === 422) {
|
if (err.response.status === 422) {
|
||||||
this.$message({
|
this.$message({
|
||||||
type: 'warning',
|
type: "warning",
|
||||||
message: 'پارامترها رو بررسی کنید'
|
message: "پارامترها رو بررسی کنید",
|
||||||
})
|
});
|
||||||
this.validation = err.response.data.validation;
|
this.validation = err.response.data.validation;
|
||||||
} else console.log(err.response.data);
|
} else console.log(err.response.data);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
addFile() {
|
addFile() {
|
||||||
this.validation = {}
|
this.validation = {};
|
||||||
const data = new FormData()
|
const data = new FormData();
|
||||||
data.append('file', this.$refs.attFile.files[0])
|
data.append("file", this.$refs.attFile.files[0]);
|
||||||
data.append('attTitle', this.$refs.attTitle.value)
|
data.append("attTitle", this.$refs.attTitle.value);
|
||||||
|
|
||||||
this.$axios.post(`/api/admin/news/attachments/${this.news._id}`, data, this.axiosConfig)
|
this.$axios
|
||||||
.then(res => {
|
.post(
|
||||||
|
`/api/admin/news/attachments/${this.news._id}`,
|
||||||
|
data,
|
||||||
|
this.axiosConfig
|
||||||
|
)
|
||||||
|
.then((res) => {
|
||||||
this.$message({
|
this.$message({
|
||||||
type: 'success',
|
type: "success",
|
||||||
message: 'فایل با موفقیت اضافه شد'
|
message: "فایل با موفقیت اضافه شد",
|
||||||
|
});
|
||||||
|
this.$refs.attFile.value = null;
|
||||||
|
this.$refs.attTitle.value = null;
|
||||||
|
this.$nuxt.refresh();
|
||||||
})
|
})
|
||||||
this.$refs.attFile.value = null
|
.catch((err) => {
|
||||||
this.$refs.attTitle.value = null
|
|
||||||
this.$nuxt.refresh()
|
|
||||||
})
|
|
||||||
.catch(err => {
|
|
||||||
if (err.response.status === 401) {
|
if (err.response.status === 401) {
|
||||||
return this.$message({
|
return this.$message({
|
||||||
type: 'error',
|
type: "error",
|
||||||
message: 'لطفا دوباره وارد سیستم شوید.'
|
message: "لطفا دوباره وارد سیستم شوید.",
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
if (err.response.status === 403) {
|
if (err.response.status === 403) {
|
||||||
return this.$message({
|
return this.$message({
|
||||||
type: 'error',
|
type: "error",
|
||||||
message: err.response.data.message
|
message: err.response.data.message,
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
if (err.response.status === 500) {
|
if (err.response.status === 500) {
|
||||||
return this.$message({
|
return this.$message({
|
||||||
type: 'error',
|
type: "error",
|
||||||
message: 'مشکلی در ارسال درخواست پیش آمده'
|
message: "مشکلی در ارسال درخواست پیش آمده",
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
if (err.response.status === 422) {
|
if (err.response.status === 422) {
|
||||||
this.$message({
|
this.$message({
|
||||||
type: 'warning',
|
type: "warning",
|
||||||
message: 'پارامترها را بررسی کنید'
|
message: "پارامترها را بررسی کنید",
|
||||||
})
|
});
|
||||||
this.validation = err.response.data.validation
|
this.validation = err.response.data.validation;
|
||||||
} else console.log(err.response.data);
|
} else console.log(err.response.data);
|
||||||
})
|
});
|
||||||
},
|
},
|
||||||
deleteFile(id) {
|
deleteFile(id) {
|
||||||
this.$confirm('فایل حذف شود؟', 'هشدار', {
|
this.$confirm("فایل حذف شود؟", "هشدار", {
|
||||||
confirmButtonText: 'بله',
|
confirmButtonText: "بله",
|
||||||
cancelButtonText: 'لغو',
|
cancelButtonText: "لغو",
|
||||||
type: 'warning'
|
type: "warning",
|
||||||
})
|
})
|
||||||
.then(async () => {
|
.then(async () => {
|
||||||
this.$axios.delete(`/api/admin/news/attachments/${id}`)
|
this.$axios
|
||||||
.then(res => {
|
.delete(`/api/admin/news/attachments/${id}`)
|
||||||
|
.then((res) => {
|
||||||
this.$message({
|
this.$message({
|
||||||
type: 'success',
|
type: "success",
|
||||||
message: 'فایل با موفقیت حذف شد'
|
message: "فایل با موفقیت حذف شد",
|
||||||
|
});
|
||||||
|
this.news.attachments = this.news.attachments.filter(
|
||||||
|
(item) => item._id !== id
|
||||||
|
);
|
||||||
})
|
})
|
||||||
this.news.attachments = this.news.attachments.filter(item => item._id !== id)
|
.catch((err) => {
|
||||||
})
|
|
||||||
.catch(err => {
|
|
||||||
if (err.response.status === 401) {
|
if (err.response.status === 401) {
|
||||||
return this.$message({
|
return this.$message({
|
||||||
type: 'error',
|
type: "error",
|
||||||
message: 'لطفا دوباره وارد سیستم شوید.'
|
message: "لطفا دوباره وارد سیستم شوید.",
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
if (err.response.status === 403) {
|
if (err.response.status === 403) {
|
||||||
return this.$message({
|
return this.$message({
|
||||||
type: 'error',
|
type: "error",
|
||||||
message: err.response.data.message
|
message: err.response.data.message,
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
if (err.response.status === 422) {
|
if (err.response.status === 422) {
|
||||||
return this.$message({
|
return this.$message({
|
||||||
type: 'error',
|
type: "error",
|
||||||
message: err.response.data.message
|
message: err.response.data.message,
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
console.log(err.response.data)
|
console.log(err.response.data);
|
||||||
})
|
});
|
||||||
})
|
})
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
this.$message({
|
this.$message({
|
||||||
type: 'warning',
|
type: "warning",
|
||||||
message: 'عملیات لغو شد'
|
message: "عملیات لغو شد",
|
||||||
})
|
});
|
||||||
})
|
});
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
head() {
|
head() {
|
||||||
return {
|
return {
|
||||||
@@ -699,24 +775,26 @@ export default {
|
|||||||
};
|
};
|
||||||
},
|
},
|
||||||
layout: "admin",
|
layout: "admin",
|
||||||
async asyncData({$axios, $auth, params, query, error}) {
|
async asyncData({ $axios, $auth, params, query, error }) {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
const requests = [
|
const requests = [
|
||||||
$axios.get("/api/admin/category/getParent", {
|
$axios.get("/api/admin/category/getParent", {
|
||||||
params: {
|
params: {
|
||||||
type: "news",
|
type: "news",
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
$axios.get("/api/admin/portals", {progress: false}),
|
$axios.get("/api/admin/portals", { progress: false }),
|
||||||
$axios.get(`/api/admin/newsFile`, {progress: false})
|
$axios.get(`/api/admin/newsFile`, { progress: false }),
|
||||||
];
|
];
|
||||||
|
|
||||||
const fetch = await Promise.all(requests);
|
const fetch = await Promise.all(requests);
|
||||||
|
|
||||||
let [parents, portals, newsFile] = fetch;
|
let [parents, portals, newsFile] = fetch;
|
||||||
|
|
||||||
const setModelType = $auth.user.portals.length !== 1 ? $auth.user.portals : $auth.user.portals[0];
|
const setModelType =
|
||||||
|
$auth.user.portals.length !== 1
|
||||||
|
? $auth.user.portals
|
||||||
|
: $auth.user.portals[0];
|
||||||
|
|
||||||
// const setFilterParent =
|
// const setFilterParent =
|
||||||
// $auth.user.portals.length !== 1
|
// $auth.user.portals.length !== 1
|
||||||
@@ -725,7 +803,6 @@ export default {
|
|||||||
// (item) => item.modelType === $auth.user.portals[0]
|
// (item) => item.modelType === $auth.user.portals[0]
|
||||||
// );
|
// );
|
||||||
|
|
||||||
|
|
||||||
if (params.details !== "new") {
|
if (params.details !== "new") {
|
||||||
const news = await $axios.get(`/api/admin/news/${params.details}`);
|
const news = await $axios.get(`/api/admin/news/${params.details}`);
|
||||||
|
|
||||||
@@ -734,7 +811,7 @@ export default {
|
|||||||
parents: parents.data,
|
parents: parents.data,
|
||||||
news: news.data,
|
news: news.data,
|
||||||
// filterParent: parents.data,
|
// filterParent: parents.data,
|
||||||
newsFile: newsFile.data
|
newsFile: newsFile.data,
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
return {
|
return {
|
||||||
@@ -743,9 +820,9 @@ export default {
|
|||||||
// filterParent: parents.data,
|
// filterParent: parents.data,
|
||||||
newsFile: newsFile.data,
|
newsFile: newsFile.data,
|
||||||
news: {
|
news: {
|
||||||
title: '',
|
title: "",
|
||||||
summaryTitle: '',
|
summaryTitle: "",
|
||||||
leadTitle: '',
|
leadTitle: "",
|
||||||
catId: $auth.user.specialPermissions,
|
catId: $auth.user.specialPermissions,
|
||||||
allowComment: false,
|
allowComment: false,
|
||||||
// slider: false,
|
// slider: false,
|
||||||
@@ -755,17 +832,17 @@ export default {
|
|||||||
special: false,
|
special: false,
|
||||||
publish: true,
|
publish: true,
|
||||||
notifications: false,
|
notifications: false,
|
||||||
pageContent: '',
|
pageContent: "",
|
||||||
keywords: [],
|
keywords: [],
|
||||||
metaTagDesc: '',
|
metaTagDesc: "",
|
||||||
newsStatus: false,
|
newsStatus: false,
|
||||||
modelType: setModelType,
|
modelType: setModelType,
|
||||||
newsFileId: ''
|
newsFileId: "",
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(e)
|
console.log(e);
|
||||||
if (e?.response?.status === 401) {
|
if (e?.response?.status === 401) {
|
||||||
error({
|
error({
|
||||||
status: 401,
|
status: 401,
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user