Commit 1b9bb8e2 authored by xhx's avatar xhx

资讯

parent 4531bd54
...@@ -45,6 +45,7 @@ ...@@ -45,6 +45,7 @@
import Vue, { PropType } from 'vue' import Vue, { PropType } from 'vue'
import vue2Dropzone from 'vue2-dropzone' import vue2Dropzone from 'vue2-dropzone'
import 'vue2-dropzone/dist/vue2Dropzone.min.css' import 'vue2-dropzone/dist/vue2Dropzone.min.css'
import FileService from '@/service/FileService/index'
import { Editor } from '@tiptap/vue-2' import { Editor } from '@tiptap/vue-2'
export default Vue.extend({ export default Vue.extend({
...@@ -60,10 +61,11 @@ export default Vue.extend({ ...@@ -60,10 +61,11 @@ export default Vue.extend({
confirmLoading: false, confirmLoading: false,
imageSrc: '', imageSrc: '',
dropzoneOptions: { dropzoneOptions: {
url: '/api/upload', url: '/proxyApi/api/v1/image/upload',
thumbnailWidth: 200, thumbnailWidth: 200,
maxFilesize: 200, maxFilesize: 200,
dictDefaultMessage: '拖动/选择文件上传图片(200M以内)', dictDefaultMessage: '拖动/选择文件上传图片(200M以内)',
paramName: 'uploadFile'
}, },
tab: 1, tab: 1,
} }
...@@ -79,7 +81,8 @@ export default Vue.extend({ ...@@ -79,7 +81,8 @@ export default Vue.extend({
showModal() { showModal() {
this.visible = true this.visible = true
}, },
vfileUploaded(file: File | Blob) { vfileUploaded(file: File | Blob, res: { data: string }) {
this.imageSrc = new FileService().getImageSrc(res.data)
/** Here is where you get your URL/Base64 string or what ever.*/ /** Here is where you get your URL/Base64 string or what ever.*/
}, },
cursorToEnd(){ cursorToEnd(){
......
...@@ -2,15 +2,15 @@ ...@@ -2,15 +2,15 @@
<!-- 上传概要图片 --> <!-- 上传概要图片 -->
<div class="border-dotted border-2 p-4 mb-5"> <div class="border-dotted border-2 p-4 mb-5">
<a-upload <a-upload
name="file" name="uploadFile"
list-type="picture-card" list-type="picture-card"
class="avatar-uploader" class="avatar-uploader"
:show-upload-list="false" :show-upload-list="false"
action="/api/upload" action="/proxyApi/api/v1/image/upload"
:before-upload="beforeUpload" :before-upload="beforeUpload"
@change="handleChange" @change="handleChange"
> >
<img v-if="imageUrl" :src="imageUrl" alt="avatar" /> <img v-if="imgUrl" :src="imgUrl" alt="avatar" />
<div v-else> <div v-else>
<a-icon :type="loading ? 'loading' : 'plus'" /> <a-icon :type="loading ? 'loading' : 'plus'" />
<div class="ant-upload-text"> <div class="ant-upload-text">
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
<script lang="ts"> <script lang="ts">
import Vue from 'vue' import Vue from 'vue'
import { message } from 'ant-design-vue' import { message } from 'ant-design-vue'
import FileService from '@/service/FileService/index'
function getBase64(img: Blob, callback: (any: any) => void) { function getBase64(img: Blob, callback: (any: any) => void) {
const reader = new FileReader(); const reader = new FileReader();
...@@ -34,10 +35,15 @@ function getBase64(img: Blob, callback: (any: any) => void) { ...@@ -34,10 +35,15 @@ function getBase64(img: Blob, callback: (any: any) => void) {
export default Vue.extend({ export default Vue.extend({
data(){ data(){
return{ return{
imageUrl: "", // imageUrl: "",
loading: false loading: false
} }
}, },
props: {
imgUrl: {
type: String
}
},
methods:{ methods:{
handleChange(info:any) { handleChange(info:any) {
if (info.file.status === 'uploading') { if (info.file.status === 'uploading') {
...@@ -45,11 +51,9 @@ export default Vue.extend({ ...@@ -45,11 +51,9 @@ export default Vue.extend({
return; return;
} }
if (info.file.status === 'done') { if (info.file.status === 'done') {
// Get this url from response in real world. const res = info.file.response?.data
getBase64(info.file.originFileObj, imageUrl => { const imageUrl = new FileService().getImageSrc(res)
this.imageUrl = imageUrl; this.$emit('update:imgUrl', imageUrl)
this.loading = false;
});
} }
}, },
beforeUpload(file:File) { beforeUpload(file:File) {
......
...@@ -30,25 +30,31 @@ export default Vue.extend({ ...@@ -30,25 +30,31 @@ export default Vue.extend({
visible:{ visible:{
type:Boolean, type:Boolean,
default:true default:true
},
editorContent: {
type: String
} }
}, },
data(){ data(){
let editor:any = undefined let editor:any = undefined
return { return {
editor, editor,
content:'' // content:''
} }
}, },
mounted(){ mounted(){
this.editor = new Editor({ this.editor = new Editor({
onUpdate: () => { onUpdate: () => {
this.content = this.editor.getHTML() // this.content = this.editor.getHTML()
this.$emit('getContent',this.content) // this.$emit('getContent',this.content)
const content = this.editor.getHTML()
this.$emit('update:editorContent', content)
}, },
extensions: [ extensions: [
StarterKit, StarterKit,
Timage, Timage,
], ],
content: this.editorContent,
autofocus: 'start', autofocus: 'start',
}) })
}, },
......
...@@ -39,7 +39,7 @@ export default Vue.extend({ ...@@ -39,7 +39,7 @@ export default Vue.extend({
startTime = firstM._d.getTime() startTime = firstM._d.getTime()
endTime = secondM._d.getTime() endTime = secondM._d.getTime()
} }
console.log(startTime)
this.$emit('getNewTime',startTime,endTime) this.$emit('getNewTime',startTime,endTime)
}, },
} }
......
...@@ -3,7 +3,8 @@ const columns:Array<column>=[ ...@@ -3,7 +3,8 @@ const columns:Array<column>=[
{ {
title: '发布时间', title: '发布时间',
align:'center', align:'center',
dataIndex: 'time', dataIndex: 'created_at',
scopedSlots: { customRender: 'created_at' },
}, },
{ {
title: '资讯标题', title: '资讯标题',
...@@ -13,12 +14,13 @@ const columns:Array<column>=[ ...@@ -13,12 +14,13 @@ const columns:Array<column>=[
{ {
title: '咨询分类', title: '咨询分类',
align:'center', align:'center',
dataIndex: 'type', dataIndex: 'article_type',
scopedSlots: { customRender: 'type' },
}, },
{ {
title: '作者名称', title: '作者名称',
align:'center', align:'center',
dataIndex: 'author', dataIndex: 'writer',
}, },
{ {
title: '新闻内容', title: '新闻内容',
...@@ -29,7 +31,8 @@ const columns:Array<column>=[ ...@@ -29,7 +31,8 @@ const columns:Array<column>=[
{ {
title: '状态', title: '状态',
align:'center', align:'center',
dataIndex: 'state', dataIndex: 'article_status',
scopedSlots: { customRender: 'status' },
}, },
{ {
title: '操作', title: '操作',
......
import baseAxios from '../index'
export default class NewsService {
static instance: NewsService
static getInstance() {
if (!NewsService.instance) {
NewsService.instance = new NewsService()
}
return NewsService.instance
}
/**
* 新增资讯
* @param data
* @returns
*/
addArticle(data: {
article_type: number,
content: string,
desc: string,
file_name: string,
title: string,
writer: string
}) {
return baseAxios({
url: '/article/admin/add',
method: 'post',
data,
})
}
/**
* 删除新闻文章
* @param data
* @returns
*/
delArticle(params: { uuid: string }) {
return baseAxios({
url: '/article/admin/delete/news',
method: 'delete',
params,
})
}
/**
* 删除政策文章
* @param data
* @returns
*/
delPolicyArticle(params: { uuid: string }) {
return baseAxios({
url: '/article/admin/delete/policy',
method: 'delete',
params,
})
}
/**
* 查询列表
* @param data
* @returns
*/
articleList(data: {
article_status: number|string,
article_type: number|undefined,
end_time: number|undefined,
limit: number,
offset: number,
start_time: number|undefined
}) {
return baseAxios({
url: '/article/admin/list',
method: 'post',
data,
})
}
/**
* 修改资讯
* @param data
* @returns
*/
editArticle(data: {
article_type: number,
content: string,
desc: string,
file_name: string,
title: string,
writer: string,
uuid: string
}) {
return baseAxios({
url: '/article/admin/modify',
method: 'post',
data,
})
}
/**
* 修改资讯状态
* @param data
* @returns
*/
modifyStatus(data: {
uuid: string,
article_status: number,
article_type: number|undefined
}) {
return baseAxios({
url: '/article/admin/modify/status',
method: 'post',
data,
})
}
/**
* 模糊查询新闻标题
* @param data
* @returns
*/
searchByTitle(data: {
title: string
}) {
return baseAxios({
url: '/article/query/fuzzy/news',
method: 'get',
params: data,
})
}
/**
* 模糊查询政策文章
* @param data
* @returns
*/
searchByPolicy(data: {
title: string
}) {
return baseAxios({
url: '/article/query/fuzzy/policy',
method: 'get',
params: data,
})
}
/**
* 查询新闻
* @param data
* @returns
*/
searchNews(uuid: string) {
return baseAxios({
url: '/article/query/news',
method: 'get',
params: {
uuid
},
})
}
/**
* 查询新闻列表
* @param data
* @returns
*/
searchList(data: {
limit: number,
offset: number
}) {
return baseAxios({
url: '/article/query/news/list',
method: 'post',
data,
})
}
/**
* 查询政策文章
* @param data
* @returns
*/
searchPolicy(uuid: string) {
return baseAxios({
url: '/article/query/policy',
method: 'get',
params: {
uuid
},
})
}
/**
* 查询政策列表
* @param data
* @returns
*/
searchPolicyList(data: {
limit: number,
offset: number
}) {
return baseAxios({
url: '/article/query/policy/list',
method: 'post',
data,
})
}
}
function getDate(day: Date,isSmaller:Boolean) { export function getDate(day: Date,isSmaller:Boolean) {
let mm:Number,dd:Number let mm:Number,dd:Number
if(isSmaller){ if(isSmaller){
mm = day.getMonth() + 1 < 10 ? + (day.getMonth()+1): day.getMonth()+1 ; mm = day.getMonth() + 1 < 10 ? + (day.getMonth()+1): day.getMonth()+1 ;
......
...@@ -2,21 +2,43 @@ ...@@ -2,21 +2,43 @@
<div> <div>
<p class=" text-2xl font-bold mb-5 ">{{title}}</p> <p class=" text-2xl font-bold mb-5 ">{{title}}</p>
<p class=" text-gray-400">发布时间:{{time}} <span class=" ml-2">作者:{{name}}</span></p> <p class=" text-gray-400">发布时间:{{time}} <span class=" ml-2">作者:{{name}}</span></p>
<p class="text-left p-5">{{content}}</p> <div class="text-left p-5" v-html="content"></div>
<!-- <p class="text-left p-5">{{content}}</p> -->
</div> </div>
</template> </template>
<script lang="ts"> <script lang="ts">
import Vue from 'vue' import Vue from 'vue'
import News from '@/service/News/index'
const news = new News()
export default Vue.extend({ export default Vue.extend({
data(){ data(){
return{ return{
title:'银保监会、人民银行联合出台现金管理类理财产品监管规则', title:'',
time:'2021-07-01', time:'',
name:'丁洁', name:'',
content:'“中国冰雪大篷车”是国家体育总局深入推进冰雪运动“南展西扩东进”战略,落实“带动三亿人参与冰雪运动”目标的重要群众性活动之一。“中国冰雪大篷车”将在为期半年的时间里,深入全国30余个城市,举办100场线下活动,同时结合持续的线上互动,以创新的体验模式、丰富的活动内容和众多的展示渠道,普及冰雪运动常识,推广冰雪运动理念,让普通大众在家门口就能感受冰雪运动的乐趣。' content:''
}
},
methods: {
getDetails() {
const type = this.$route.query.type
const uuid = this.$route.query.key as string
const request = +type === 1 ? 'searchPolicy' : 'searchNews'
news[request](uuid).then(res => {
console.log(res)
const { data } = res
this.time = data.created_at
this.name = data.writer
this.content = data.content
this.title = data.title
})
} }
},
created() {
this.getDetails()
} }
}) })
......
...@@ -5,37 +5,61 @@ ...@@ -5,37 +5,61 @@
<a-input placeholder="标题模糊搜索" v-model="searchPageReqParams.title" style="width: 150px; margin-right:10px;"/> <a-input placeholder="标题模糊搜索" v-model="searchPageReqParams.title" style="width: 150px; margin-right:10px;"/>
<!-- timepicker --> <!-- timepicker -->
<span class=" font-semibold">注册时间:</span> <span class=" font-semibold">注册时间:</span>
<timerange class=" mr-3" <timerange class=" mr-3" :startTime="searchPageReqParams.start_time" :endTime="searchPageReqParams.end_time"
@getNewTime="getNewTime"/> @getNewTime="getNewTime"/>
<!-- 咨询分类 --> <!-- 咨询分类 -->
<span class=" mr-3">资讯分类</span> <span class=" mr-3">资讯分类</span>
<a-select :default-value="newsType[0]" style="width: 120px; margin-right:10px;" v-model="searchPageReqParams.type"> <a-select :default-value="newsType[0]" style="width: 120px; margin-right:10px;" v-model="searchPageReqParams.article_type">
<a-select-option v-for="(type,i) in newsType" :key="i"> <a-select-option v-for="type in newsType" :key="type.value">
{{type}} {{type.label}}
</a-select-option> </a-select-option>
</a-select> </a-select>
<!-- 操作 --> <!-- 操作 -->
<a-button type="primary" style=" margin-right:10px;" @click="query">查询</a-button> <a-button type="primary" style=" margin-right:10px;" @click="query">查询</a-button>
<a-button type="primary" style=" margin-right:10px;" @click="reset">重置</a-button> <a-button type="primary" style=" margin-right:10px;" @click="reset">重置</a-button>
<a-button type="primary" @click="release">发布</a-button> <a-button type="primary" @click="release(null, null)">发布</a-button>
<!-- 资讯列表 --> <!-- 资讯列表 -->
<a-table :columns="columns" :data-source="list" style=" text-align: center; margin-top:40px;" bordered > <a-table
:columns="columns"
:data-source="list"
rowKey="columns"
style=" text-align: center; margin-top:40px;"
bordered
:pagination="pagination"
@change="tableChange">
<!-- 发布时间 -->
<span slot="created_at" slot-scope="text,record">
{{ record.created_at }}
</span>
<!-- 新闻内容 --> <!-- 新闻内容 -->
<span slot="content" slot-scope="text,record"> <span slot="content" slot-scope="text,record">
<a @click="toDetail(record.key)">查看</a> <a @click="toDetail(record.uuid, searchPageReqParams.article_type)">查看</a>
</span>
<!-- 新闻状态 -->
<span slot="status" slot-scope="text,record">
{{ record.article_status === 2 ? '已发布' : '未发布' }}
</span>
<!-- 新闻分类 -->
<span slot="type">
{{ searchPageReqParams.article_type === 2 ? '新闻' : '政策' }}
</span> </span>
<!-- 操作 --> <!-- 操作 -->
<span slot="action" slot-scope="text,record"> <span slot="action" slot-scope="text,record">
<a v-if="record.state=='已下架'" <a v-if="record.article_status==1"
@click="add(record.key)"> @click="add(record)">
上架 上架
</a> </a>
<a v-else <a v-else-if="record.article_status === 2"
@click="remove(record.key)"> @click="remove(record)">
下架 下架
</a> </a>
<a-divider type="vertical" /> <a-divider type="vertical" />
<a @click="onDelete(record.key)"> <a v-show="record.article_status==1"
@click="release(record.uuid, searchPageReqParams.article_type)">
编辑
</a>
<a-divider v-show="record.article_status==1" type="vertical" />
<a @click="onDelete(record)">
删除 删除
</a> </a>
</span> </span>
...@@ -56,10 +80,14 @@ ...@@ -56,10 +80,14 @@
<script lang="ts"> <script lang="ts">
import Vue from 'vue' import Vue from 'vue'
import { newsList } from '@/mock/index'
import { columns } from '@/const/columns/newsColunms' import { columns } from '@/const/columns/newsColunms'
import { modal } from './const' import { modal } from './const'
import { getDate } from '@/utils/days/index'
import timerange from '@/components//TimePicker/index.vue' import timerange from '@/components//TimePicker/index.vue'
import News from '@/service/News/index'
import { message } from 'ant-design-vue'
const news = new News()
export default Vue.extend({ export default Vue.extend({
components:{ timerange }, components:{ timerange },
...@@ -67,15 +95,21 @@ export default Vue.extend({ ...@@ -67,15 +95,21 @@ export default Vue.extend({
columns(){ columns(){
return columns return columns
}, },
list(){ getTime() {
return newsList
} }
}, },
props:{ props:{
newsType:{ newsType:{
type:Array, type:Array,
default(){ default(){
return ['全部','政策','新闻'] return [{
label: '新闻',
value: 2
}, {
label: '政策',
value: 1
}]
} }
} }
}, },
...@@ -83,32 +117,76 @@ export default Vue.extend({ ...@@ -83,32 +117,76 @@ export default Vue.extend({
return{ return{
show:false, show:false,
title:'', title:'',
list: [],
type:modal.on, type:modal.on,
text:'', text:'',
searchPageReqParams: { searchPageReqParams: {
title: '', title: '',
type: '', article_status: 0,
startTime: undefined as undefined | number, article_type: 1 as undefined | number,
endTime: undefined as undefined | number, start_time: undefined as undefined | number,
end_time: undefined as undefined | number,
},
pagination: {
current: 1,
defaultPageSize: 10,
total: 0
}, },
uuid: ''
} }
}, },
created() {
this.getList()
},
methods:{ methods:{
tableChange(e: any) {
console.log(e)
this.pagination.current = e.current
this.getList()
},
getList() {
const params = {
...this.searchPageReqParams,
limit: this.pagination.defaultPageSize,
// offset: 10
offset: (this.pagination.current - 1) * this.pagination.defaultPageSize
}
news.articleList(params).then(res => {
console.log(res)
this.list = res.data.items
this.pagination.total = res.data.total
if (this.searchPageReqParams.title) {
this.findTitle()
}
})
},
findTitle() {
const searchParams = this.searchPageReqParams.article_type === 1 ? "searchByPolicy" : "searchByTitle"
news[searchParams]({title: this.searchPageReqParams.title}).then(res => {
console.log(res)
})
},
query(){ query(){
console.log(this.searchPageReqParams); console.log(this.searchPageReqParams);
this.getList()
}, },
getNewTime(startTime:number,endTime:number){ getNewTime(startTime:number,endTime:number){
this.searchPageReqParams.startTime = startTime this.searchPageReqParams.start_time = startTime
this.searchPageReqParams.endTime = endTime this.searchPageReqParams.end_time = endTime
}, },
reset(){ reset(){
this.searchPageReqParams.title ='' this.searchPageReqParams.title = ''
this.searchPageReqParams.type = '' this.searchPageReqParams.article_status = 0
this.searchPageReqParams.startTime = undefined this.searchPageReqParams.article_type = 1
this.searchPageReqParams.endTime = undefined this.searchPageReqParams.start_time = undefined
this.searchPageReqParams.end_time = undefined
}, },
release(){ release(key?:string, type?:string){
this.$router.push({name:'publishNews'}) if (key && type) {
this.$router.push({name:'publishNews', query: {key, type}})
} else {
this.$router.push({name:'publishNews'})
}
}, },
edit(key:string){ edit(key:string){
this.$router.push({name:'publishNews',query:{key:key}}) this.$router.push({name:'publishNews',query:{key:key}})
...@@ -116,34 +194,58 @@ export default Vue.extend({ ...@@ -116,34 +194,58 @@ export default Vue.extend({
add(record:any){ add(record:any){
this.type = modal.on this.type = modal.on
this.show = true this.show = true
this.uuid = record.uuid
this.title = '上架资讯' this.title = '上架资讯'
this.text = '确定上架该资讯吗?' this.text = '确定上架该资讯吗?'
}, },
remove(record:any){ remove(record:any){
this.type = modal.off this.type = modal.off
this.show = true this.show = true
this.uuid = record.uuid
this.title = '下架资讯' this.title = '下架资讯'
this.text = '确定下架该资讯吗?' this.text = '确定下架该资讯吗?'
}, },
onDelete(record:any){ onDelete(record:any){
this.type = modal.delete this.type = modal.delete
this.show = true this.show = true
this.uuid = record.uuid
this.title = '删除资讯' this.title = '删除资讯'
this.text = '确定删除该资讯吗?' this.text = '确定删除该资讯吗?'
}, },
setStatus(status: number, msg: string) {
news.modifyStatus({
article_status: status,
article_type: this.searchPageReqParams.article_type,
uuid: this.uuid
}).then(res => {
if (res.code === 200) {
message.success(msg)
this.getList()
}
})
},
removeArticle() {
const props = this.searchPageReqParams.article_type === 1 ? 'delPolicyArticle' : 'delArticle'
news[props]({uuid: this.uuid}).then(res => {
if (res.code === 200) {
message.success('删除成功')
this.getList()
}
})
},
handleOk(record:any){ handleOk(record:any){
if( this.type == modal.on){ if( this.type == modal.on){
this.setStatus(2, '上架成功')
} else if( this.type == modal.off){ } else if( this.type == modal.off){
this.setStatus(1, '下架成功')
} else if( this.type == modal.delete){ } else if( this.type == modal.delete){
this.removeArticle()
this.pagination.current = 1
} }
this.show = false this.show = false
}, },
toDetail(key:string){ toDetail(key:string, type:number|undefined){
this.$router.push({name:'newsDetail',query:{key:key}}) this.$router.push({name:'newsDetail',query:{key:key,type:type}})
} }
} }
}) })
......
...@@ -7,16 +7,16 @@ ...@@ -7,16 +7,16 @@
<!-- 作者 --> <!-- 作者 -->
<a-input v-model="author" placeholder="请输入作者名称" style="width: 35%" /> <a-input v-model="author" placeholder="请输入作者名称" style="width: 35%" />
<!-- 文章分类 --> <!-- 文章分类 -->
<a-select style="width: 20%" v-model="type"> <a-select style="width: 20%" v-model="type" placeholder="请选择资讯分类">
<a-select-option v-for="type in articalType" :key="type">{{type}}</a-select-option> <a-select-option v-for="item in articalType" :key="item.value">{{item.label}}</a-select-option>
</a-select> </a-select>
</div> </div>
<!-- 上传概要图片 --> <!-- 上传概要图片 -->
<editor-upload class=" mt-5"/> <editor-upload class=" mt-5" :imgUrl.sync="imgUrl" />
<!-- 文章概要 --> <!-- 文章概要 -->
<a-textarea v-model="summary" :maxLength="50" placeholder="请输入文章概要,字数限制50字以内" auto-size /> <a-textarea v-model="summary" :maxLength="50" placeholder="请输入文章概要,字数限制50字以内" auto-size />
<!-- 编辑器 --> <!-- 编辑器 -->
<editor class="edit-news text-left mt-5" <editor class="edit-news text-left mt-5" :editorContent.sync="content"
@getContent="getContent"/> @getContent="getContent"/>
<!-- 发布操作 --> <!-- 发布操作 -->
<a-button type="primary" @click="onSubmit" class=" mt-5">确定发布</a-button> <a-button type="primary" @click="onSubmit" class=" mt-5">确定发布</a-button>
...@@ -27,6 +27,10 @@ ...@@ -27,6 +27,10 @@
import Vue from 'vue'; import Vue from 'vue';
import Editor from '@/components/Editor/index.vue' import Editor from '@/components/Editor/index.vue'
import EditorUpload from '@/components/Editor/editorUpload.vue' import EditorUpload from '@/components/Editor/editorUpload.vue'
import News from '@/service/News/index'
import { message } from 'ant-design-vue';
const news = new News()
export default Vue.extend({ export default Vue.extend({
components:{ Editor,EditorUpload }, components:{ Editor,EditorUpload },
...@@ -34,7 +38,13 @@ export default Vue.extend({ ...@@ -34,7 +38,13 @@ export default Vue.extend({
articalType:{ articalType:{
type:Array, type:Array,
default(){ default(){
return ['新闻','政策'] return [{
label: '新闻',
value: 2
}, {
label: '政策',
value: 1
}]
} }
} }
}, },
...@@ -42,16 +52,90 @@ export default Vue.extend({ ...@@ -42,16 +52,90 @@ export default Vue.extend({
return{ return{
title:'', title:'',
author:'', author:'',
type:'新闻', type: undefined as number|any,
imgUrl: '',
summary:'', summary:'',
content:'' content:''
} }
}, },
created() {
this.getDetails()
},
methods:{ methods:{
getDetails() {
console.log(Object.keys(this.$route.query))
if (Object.keys(this.$route.query).length === 0) {
this.type = undefined
return
}
const type = this.$route.query.type
const id = this.$route.query.key as string
this.type = +type
if (+type === 1) {
news.searchPolicy(id).then(res => {
console.log(res)
this.initData(res.data)
})
} else {
news.searchNews(id).then(res => {
this.initData(res.data)
})
}
},
initData(res: any) {
this.title = res.title
this.author = res.writer
this.imgUrl = res.file_name
this.summary = res.desc
this.content = res.content
},
getContent(value:string){ getContent(value:string){
this.content = value this.content = value
console.log(value)
},
getImage(val: string) {
this.imgUrl = val
},
addForm() {
const params = {
article_type: this.type,
content: this.content,
desc: this.summary,
file_name: this.imgUrl,
title: this.title,
writer: this.author
}
news.addArticle(params).then(res => {
if (res.code === 200) {
message.success('新增成功')
this.$router.push({ name: 'newsManage' })
}
})
},
editForm() {
const params = {
article_type: this.type,
content: this.content,
desc: this.summary,
file_name: this.imgUrl,
title: this.title,
writer: this.author,
uuid: this.$route.query.key as string
}
news.editArticle(params).then(res => {
if (res.code === 200) {
message.success('编辑成功')
this.$router.push({ name: 'newsManage' })
}
})
}, },
onSubmit() { onSubmit() {
console.log(this.imgUrl)
if (this.$route.query.key) {
this.editForm()
} else {
this.addForm()
}
// console.log(this.content); // console.log(this.content);
}, },
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment