Commit 680c86fe authored by hanfeng's avatar hanfeng

添加新闻模块

parent 6fe82b9b
import fetch from 'utils/fetch';
/**
* 获取列表
* @param query
*/
export function page(query) {
return fetch({
url: '/api/uccn/article/all',
method: 'post',
data:query
});
}
/**
* 添加
* @param query
*/
export function add(query) {
return fetch({
url: '/api/uccn/article/add',
method: 'post',
data:query
});
}
/**
* 删除
* @param query
*/
export function update(query) {
return fetch({
url: '/api/uccn/article/update',
method: 'put',
data:query
});
}
/**
* 上架
* @param id
*/
export function putaway(id) {
return fetch({
url: '/api/uccn/article/putaway/'+id,
method: 'put'
});
}
/**
* 下架
* @param query
*/
export function soldOut(id) {
return fetch({
url: '/api/uccn/article/soldOut/'+id,
method: 'put',
});
}
/**
* 删除
* @param id
*/
export function remove(id) {
return fetch({
url: '/api/uccn/article/remove/'+id,
method: 'put'
});
}
/**
* 查询一条
* @param query
*/
export function getOne(query) {
return fetch({
url: '/api/uccn/article/app/unauth/one',
method: 'get',
params:query
});
}
<template>
<!-- 车型:创建、编辑 -->
<div>
<h4>{{popupTitle}}</h4>
<el-form :model="form" :rules="rules" ref="form" label-width="90px">
<el-row>
<el-col :span="8">
<el-form-item label="文章标题" prop="title">
<el-input v-model="form.title" type="text" placeholder="请输入文章标题"></el-input>
</el-form-item>
</el-col>
</el-row>
<el-row>
<el-col :span="8">
<el-form-item label="文章摘要" prop="epitome">
<el-input v-model="form.epitome" type="text" placeholder="请输入文章摘要"></el-input>
</el-form-item>
</el-col>
</el-row>
<el-row>
<el-col :span="8">
<el-form-item label="作者" prop="author">
<el-input v-model="form.author" type="text" placeholder="请输入文章作者"></el-input>
</el-form-item>
</el-col>
</el-row>
<el-row>
<el-col :span="8">
<el-form-item label="发布人" prop="publisher">
<el-input v-model="form.publisher" type="text"placeholder="请输入发布人"></el-input>
</el-form-item>
</el-col>
</el-row>
<el-form-item label="是否上架">
<el-radio class="radio" v-model="form.status" label="1"></el-radio>
<el-radio class="radio" v-model="form.status" label="0"></el-radio>
</el-form-item>
<el-row>
<el-col :span="8">
<el-form-item label="发布网站">
<el-radio class="radio" v-model="form.type" label="0">所有网站</el-radio>
<el-radio class="radio" v-model="form.type" label="1">新欣房车官网</el-radio>
<el-radio class="radio" v-model="form.type" label="2">滴房车官网</el-radio>
</el-form-item>
</el-col>
</el-row>
<el-form-item label="封面图">
<el-upload
class="upload-demo"
:headers="getHeaderWithToken"
:action="BASE_API+'/api/universal/file/app/unauth/admin/upload'"
:show-file-list="false"
:on-success="handleAvatarSuccess"
:on-progress="uploadProcess"
list-type="picture">
<el-progress v-show="imgFlag == true" type="circle" :percentage="percent"
style="margin-top: 20px"></el-progress>
<img v-if="$utils.isString(form.coverImage) && !$utils.isEmpty(form.coverImage) && !imgFlag" :src="form.coverImage"
style="width:300px;max-height:300px;">
<i v-else-if="!imgFlag" class="el-icon-plus avatar-uploader-icon"
style="lineHeight:100px;width:300px;height: 100px;border: 1px dashed #ccc;"></i>
</el-upload>
</el-form-item>
<el-row>
<el-tabs v-model="activeName" type="card">
<el-tab-pane label="文章内容" name="first">
<div class="editor-container" v-if="activeName=='first'">
<UE :editorId="activeName" :defaultMsg="form.text" :config=config ref="ue"
@ready="editorReadyEvent"></UE>
</div>
</el-tab-pane>
</el-tabs>
</el-row>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button @click="cancel">取 消</el-button>
<el-button type="primary" v-if="popupTitle=='创建'" @click="create('form')">确 定</el-button>
<el-button type="primary" v-if="popupTitle=='编辑'" @click="update('form')">确 定</el-button>
</div>
</div>
</template>
<style>
textarea {
display: none;
}
.el-upload-list {
display: flex;
width: 100px;
}
.el-upload-list li {
margin-left: 10px;
}
</style>
<script>
import UE from '../../modal/Ueditor';//百度ue富文本
import {
add,
update,
getOne
} from 'src/api/officialWebsite/news';
import {
getToken
} from '../../../utils/auth';
import {mapGetters} from 'vuex';
import ElRow from "element-ui/packages/row/src/row";
import ElCol from "element-ui/packages/col/src/col";
import ElFormItem from "../../../../node_modules/element-ui/packages/form/src/form-item.vue";
import ElRadio from "../../../../node_modules/element-ui/packages/radio/src/radio.vue";
export default {
props: ["oneRow","popupTitle"],//
name: 'popup',
components: {
ElRadio,
ElFormItem,
ElCol,
ElRow,
UE
},
data() {
return {
imgPosterFlag: false,
percent_poster: 0,
BASE_API: process.env.BASE_API,
percent: 0,//上传进度
imgFlag: false,
config: {
initialFrameWidth: null,
initialFrameHeight: 350
},
fileList2: [],
activeName: '',
form: {
title: undefined,
status: '0',
type: '0',
epitome: undefined,
text:"",
author:undefined,
publisher:undefined
},
rules: {
title: {
type: 'string',
required: true,
message: '请输入标题',
trigger: 'blur'
},
epitome: {
type: 'string',
required: true,
message: '请输入文章摘要',
trigger: 'blur'
},
},
}
},
created() {
},
mounted() {
this.getAllTag();
// this.cleanForm();
},
computed: {
...mapGetters([
'elements',
'vehicleWarningMsgType'
]),
getHeaderWithToken() {
return {Authorization: getToken()};
}
},
methods: {
getAllTag() {
this.activeName = 'first';
if(this.popupTitle == "编辑"){
let row = this.oneRow;
this.getOne(row.id);
}
},
/**
* 封面图上传进度
* */
uploadProcess(event, file, fileList) {
this.imgFlag = true;
console.log(event.percent);
this.percent = Math.floor(event.percent);
},
/**
* 封面图上传
* **/
handleAvatarSuccess(res, file) {
console.log(res)
this.percent = 0;
this.imgFlag = false;
this.form.coverImage = res.data;
},
/**
* 创建
* */
create(formName) {
const set = this.$refs;
set[formName].validate(valid => {
if (valid) {
add(this.form).then(response => {
if (response.status === 200) {
this.$notify({
title: '成功',
message: '创建成功',
type: 'success',
duration: 2000
});
this.$emit("oneDialogEvent", true);
} else {
this.$notify({
title: '创建失败',
message: '操作失败!',
type: 'error',
duration: 2000
});
}
});
} else {
return;
}
});
},
/**
* 编辑
* */
update(formName) {
const set = this.$refs;
set[formName].validate(valid => {
if (valid) {
update(this.form).then(response => {
if (response.status === 200) {
this.$notify({
title: '成功',
message: '编辑成功',
type: 'success',
duration: 2000
});
this.$emit("oneDialogEvent", true);
} else {
this.$notify({
title: '编辑失败',
message: '操作失败!',
type: 'error',
duration: 2000
});
}
});
} else {
return;
}
});
},
/**
* 获取一条车型数据
* */
getOne(id) {
let query = {id:id,urlType:2}
getOne(query).then(response => {
if(this.$utils.isInteger(response.data.status)) {
response.data.status=response.data.status.toString()
response.data.type=response.data.type.toString()
}
response.data.text=response.data.text?response.data.text:''
this.form = response.data
})
},
/**
* 深拷贝
*/
objDeepCopy(source) {
var sourceCopy = source instanceof Array ? [] : {};
for (var item in source) {
sourceCopy[item] = typeof source[item] === 'object' ? objDeepCopy(source[item]) : source[item];
}
return sourceCopy;
},
/**
* 富文本内容
* @param step
*/
editorReadyEvent(instance) {
let t = this;
instance.addListener('contentChange', () => {
t.form.text = instance.getContent();
});
},
/**
* 关闭编辑
*/
cancel(){
this.cleanForm();
this.$emit("oneDialogEvent", false);
},
/**
* 弹框数据
*/
cleanForm() {
this.activeName = '';
this.form = {
title: undefined,
status: '0',
type: '0',
epitome: undefined,
text:"",
author:undefined,
publisher:undefined
}
}
}
}
</script>
<style>
.flex-aic {
display: flex;
align-items: center;
}
.left-item {
width: 300px;
border-left: 1px solid #999;
border-right: 1px solid #999;
border-bottom: 1px solid #999;
padding: 3px;
}
.right-item {
width: 400px;
border-right: 1px solid #999;
border-bottom: 1px solid #999;
padding: 3px;
}
</style>
<template>
<div class="app-container calendar-list-container" v-loading.body="showLoadingBody">
<div v-if="!popupDialogVisible">
<div class="filter-container" ref="filter-container">
<el-form :inline="inline" ref="queryForm" :model="listQuery" label-width="100px">
<el-row>
<!-- <el-col :span="8"></el-col>-->
<!-- <el-form-item label="新闻内容">-->
<!-- <el-input v-model.number="listQuery.newsContent" placeholder="请输入新闻内容"></el-input>-->
<!-- </el-form-item>-->
</el-row>
</el-form>
<!-- <el-button class="filter-item" type="primary" v-waves icon="search" @click="handleFilter">搜索</el-button>-->
<el-button class="filter-item" style="margin-left: 10px;" @click="handleCreate"
type="primary" icon="edit">添加
</el-button>
</div>
<el-table :key='tableKey' :data="list" border fit highlight-current-row
style="width: 100%">
<el-table-column
type="index"
align="center" label="序号" width="65">
</el-table-column>
<el-table-column align="center" label="封面图/标题">
<template scope="scope">
<img :src="scope.row.coverImage" style="width: 30px;"/>
<span>{{scope.row.title}}</span>
</template>
</el-table-column>
<el-table-column width="200" align="center" label="文章摘要">
<template scope="scope">
<span>{{scope.row.epitome}}</span>
</template>
</el-table-column>
<el-table-column align="center" label="作者">
<template scope="scope">
<span>{{scope.row.author}}</span>
</template>
</el-table-column>
<el-table-column width="200" align="center" label="发布人">
<template scope="scope">
<span>{{scope.row.publisher}}</span>
</template>
</el-table-column>
<el-table-column width="100" align="center" label="状态">
<template scope="scope">
<span>{{scope.row.statusString}}</span>
</template>
</el-table-column>
<el-table-column width="150" align="center" label="文章发布网站">
<template scope="scope">
<span>{{scope.row.typeString}}</span>
</template>
</el-table-column>
<el-table-column width="100" align="center" label="排序">
<template scope="scope">
<el-button size="mini" type="text" @click="clickRank(scope.row)">{{scope.row.weight?scope.row.weight:0}}
</el-button>
</template>
</el-table-column>
<el-table-column align="center" width="200" label="操作" fixed="right">
<template scope="scope">
<el-button size="small" class="el-button el-button--text el-button--small" @click="handleUpdate(scope.row)">
{{'编辑'}}
</el-button>
<el-button size="small" class="el-button el-button--text el-button--small" style="color: #6ce26c;"
v-if="scope.row.status==2|| scope.row.status==0" @click="upStatus(scope.row,1)">上架
</el-button>
<el-button size="small" class="el-button el-button--text el-button--small" style="color: #1d90e6"
v-if="scope.row.status==1" @click="upStatus(scope.row,2)">下架
</el-button>
<el-button class="el-button el-button--text el-button--small" style="color:red;" size="small"
@click="deleteHandler(scope.row)">删除
</el-button>
</template>
</el-table-column>
</el-table>
<div v-show="!listLoading" class="pagination-container">
<el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
:current-page.sync="listQuery.page" :page-sizes="[10,20,30, 50]" :page-size="listQuery.limit"
layout="total, sizes, prev, pager, next, jumper" :total="total"></el-pagination>
</div>
</div>
<!-- 车型编辑 -->
<popup v-if="popupDialogVisible" :oneRow="oneRow"
:popupTitle="modalTitle" v-on:oneDialogEvent="oneDialogEvent"
></popup>
<!-- 排序 modal弹窗 -->
<el-dialog :title="modalTitle" :visible.sync="rankDialogVisible">
<el-form :model="labelForm" ref="labelForm" label-width="90px">
<el-row>
<el-col :span="8">
<el-form-item label="排序" prop="rank">
<el-input v-model="labelForm.weight" placeholder="请输入排序值"></el-input>
</el-form-item>
</el-col>
</el-row>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button @click="cancelHandel">取 消</el-button>
<el-button type="primary" @click="updateParentLabelRank('labelForm')">确 定</el-button>
</div>
</el-dialog>
</div>
</template>
<script>
import popup from './modal/popup'// 车型
import 'static/css/uploadImg.css';// 引入图片上传组件对话框
import {mapGetters} from 'vuex';
import {
page,
add,
update,
putaway,
soldOut,
remove
} from 'src/api/officialWebsite/news';
import Element1 from "../admin/menu/components/element";
import ElRow from "element-ui/packages/row/src/row";
import ElCol from "element-ui/packages/col/src/col";
export default {
name: 'tourManage',
components: {
ElCol,
ElRow,
Element1,
popup
},
data() {
return {
// 0-所有,1-新欣房车官网,2-滴房车官网
// brandlist: [{id:1,name:'所有网站'},{id:2,name:'欣新房车官网'},{id:3,name:'滴房车官网'}],
modalTitle: "创建",
BASE_API: process.env.BASE_API,
popupDialogVisible: false,//添加、编辑弹框
showLoadingBody: false,
form: {
tagNames: "",//标签
name: undefined,//旅游名称
saleCount: undefined,//销量
stock: undefined,//总数量
},
list: null,
total: null,
publishWebSite: {
0: '所有',
1: '欣新房车官网',
2: '滴房车官网'
},
status: {
0: '下架',
1: '上架'
},
listLoading: true,
listQuery: {
page: 1,
limit: 20,
newsContent: undefined,//新闻包含内容
type: undefined
},
inline: true,
textMap: {
update: '编辑',
create: '创建'
},
labelForm: {},
tableKey: 0,
departureDialogVisible: false,
arrivalDialogVisible: false,
rankDialogVisible: false//排序
}
},
created() {
this.getList();
},
computed: {
...mapGetters([
'elements',
'belong2Type'
])
},
methods: {
/**
* 添加
* */
handleCreate() {
this.modalTitle = '创建';
this.oneRow = {};
this.popupDialogVisible = true;
},
upStatus(row, type) {
if (this.$utils.isInteger(type)) {
if (type == 1) {
putaway(row.id).then(response => {
if (response.status === 200) {
this.$notify({
title: '成功',
message: '成功',
type: 'success',
duration: 2000
});
this.getList();
} else {
this.$notify({
title: '失败',
message: '操作失败!',
type: 'error',
duration: 2000
});
}
});
}
if (type == 2) {
soldOut(row.id).then(response => {
if (response.status === 200) {
this.$notify({
title: '成功',
message: '成功',
type: 'success',
duration: 2000
});
this.getList();
} else {
this.$notify({
title: '失败',
message: '操作失败!',
type: 'error',
duration: 2000
});
}
});
}
}
},
/**
* 删除
* */
deleteHandler(row) {
this.$confirm('确定删除吗?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
remove(row.id).then(response => {
if (response.status === 200) {
this.$notify({
title: '成功',
message: '删除成功',
type: 'success',
duration: 2000
});
// this.bannerDialogVisible = false;
this.getList();
} else {
this.$notify({
title: '删除失败',
message: '操作失败!',
type: 'error',
duration: 2000
});
}
});
})
},
/**
* 编辑
* */
handleUpdate(row) {
this.modalTitle = '编辑';
this.oneRow = row;
this.popupDialogVisible = true;
},
/**
* 排序点击事件
* */
clickRank(row) {
this.modalTitle = "编辑";
this.labelForm = {weight: row.weight, id: row.id};
this.rankDialogVisible = true;
},
/**
* 弹框-取消
* */
cancelHandel() {
this.rankDialogVisible = false;
},
/**
* 编辑排序
* */
updateParentLabelRank(formName) {
const set = this.$refs;
let params = {id: this.labelForm.id,weight: this.labelForm.weight};
update(params).then(response => {
if (response.status === 200) {
this.$notify({
title: '成功',
message: '编辑成功',
type: 'success',
duration: 2000
});
this.rankDialogVisible = false;
this.getList();
} else {
this.$notify({
title: '编辑失败',
message: '操作失败!',
type: 'error',
duration: 2000
});
}
});
},
/**
* modal传递回来的数据
* */
oneDialogEvent(e) {
this.popupDialogVisible = false;
if (e) {
//编辑成功-重新加载列表
this.getList();
}
},
handleAvatarSuccess(res, file) {
this.form.drivingLicensePath = res.data;
this.showLoadingBody = false;
},
/**
* 获取新闻列表
* */
getList() {
this.listLoading = true;
page(this.listQuery).then(response => {
let totalCountRs = undefined;
let listRs = undefined;
let publishWebSite = this.publishWebSite;
let status = this.status
if (!this.$utils.isEmpty(response.data.list) && this.$utils.isInteger(response.data.total)) {
response.data.list.map(function (item) {
item.coverImage = item.coverImage ? item.coverImage : '';
item.typeString = publishWebSite[item.type] ;
item.statusString = status[item.status] ;
});
console.log(response.data.list)
listRs = response.data.list;
totalCountRs = response.data.total;
}
this.listLoading = false;
this.list = listRs;
this.total = totalCountRs;
})
},
handleFilter() {
this.listQuery.page = 1;
this.$refs.queryForm.validate(valid => {
if (valid) {
this.getList();
} else {
return false;
}
});
},
handleSizeChange(val) {
this.listQuery.limit = val;
this.getList();
},
handleCurrentChange(val) {
this.listQuery.page = val;
this.getList();
}
}
}
</script>
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