|
@@ -1,5 +1,14 @@
|
|
|
<template>
|
|
|
- <div class="box">
|
|
|
+ <div class="imgnewshome">
|
|
|
+ <el-card class="box-card-left">
|
|
|
+ <div slot="header">
|
|
|
+ <span>新闻类别</span>
|
|
|
+ <el-tooltip effect="dark" content="添加类型" placement="top-start">
|
|
|
+ <el-button style="float: right; padding: 3px 0" icon="el-icon-plus" type="text" @click="treeTypeAdd"></el-button>
|
|
|
+ </el-tooltip>
|
|
|
+ </div>
|
|
|
+ <deepTree :operation="true" @edit="treeEdit" @remove="treeRemove" @nodeClick="treeClick" class="deepTree" :data="typeList"></deepTree>
|
|
|
+ </el-card>
|
|
|
<el-card class="box-card">
|
|
|
<div slot="header" class="clearfix">
|
|
|
<span>图片新闻管理</span>
|
|
@@ -11,7 +20,41 @@
|
|
|
</el-card>
|
|
|
<dialogAndDrawer :width="'35%'" :title="title" :visibleSync="visibleSync" v-if="visibleSync" @close="visibleSync = false">
|
|
|
<template v-slot:windowMain>
|
|
|
- <formData :filed="formfiled" :data="formdata" :rules="formrules" @save="formSave"></formData>
|
|
|
+ <formData ref="formData" :filed="formfiled" :data="formdata" :rules="formrules" @save="formSave">
|
|
|
+ <template v-slot:formItem="{ item, formdata }">
|
|
|
+ <!-- 缩略图 -->
|
|
|
+ <el-upload
|
|
|
+ v-if="item.name == 'img'"
|
|
|
+ class="avatar-uploader"
|
|
|
+ action="/api/files/avatar/upload"
|
|
|
+ :show-file-list="false"
|
|
|
+ :on-success="handleAvatarSuccess"
|
|
|
+ :before-upload="beforeAvatarUpload">
|
|
|
+ <img v-if="formdata[item.name] && formdata[item.name] !== ''" :src="formdata[item.name]" class="avatar">
|
|
|
+ <i v-else class="el-icon-plus avatar-uploader-icon"></i>
|
|
|
+ </el-upload>
|
|
|
+ </template>
|
|
|
+ <template v-slot:ext="{ formdata }">
|
|
|
+ <!-- 地址 -->
|
|
|
+ <el-form-item v-if="formdata && formdata.type == '0'" label="地址">
|
|
|
+ <el-input v-model="formdata['url']" placeholder="请输入地址"></el-input>
|
|
|
+ </el-form-item>
|
|
|
+ <!-- 栏目 -->
|
|
|
+ <el-form-item v-if="formdata && formdata.type == '1'" label="栏目">
|
|
|
+ <el-select v-model="formdata['column']" placeholder="请选择栏目">
|
|
|
+ <el-option v-for="i in columnList" :key="i.code" :label="i.name" :value="i.code">
|
|
|
+ </el-option>
|
|
|
+ </el-select>
|
|
|
+ </el-form-item>
|
|
|
+ <!-- 单页 -->
|
|
|
+ <el-form-item v-if="formdata && formdata.type == '2'" label="单页">
|
|
|
+ <el-select v-model="formdata['pages']" placeholder="请选择单页">
|
|
|
+ <el-option v-for="i in pagesList" :key="i._id" :label="i.title" :value="i._id">
|
|
|
+ </el-option>
|
|
|
+ </el-select>
|
|
|
+ </el-form-item>
|
|
|
+ </template>
|
|
|
+ </formData>
|
|
|
</template>
|
|
|
</dialogAndDrawer>
|
|
|
</div>
|
|
@@ -20,48 +63,74 @@
|
|
|
import filterList from '@components/filterList/index.vue';
|
|
|
import dialogAndDrawer from '@components/dialogAndDrawer.vue';
|
|
|
import formData from '@components/formData/index.vue';
|
|
|
+import deepTree from '@components/deepTree.vue';
|
|
|
import { mapState, mapActions } from 'vuex';
|
|
|
export default {
|
|
|
components: {
|
|
|
filterList,
|
|
|
dialogAndDrawer,
|
|
|
- formData
|
|
|
+ formData,
|
|
|
+ deepTree
|
|
|
},
|
|
|
data() {
|
|
|
return {
|
|
|
title: '',
|
|
|
visibleSync: false,
|
|
|
filed: [
|
|
|
- { name: 'name', label: '名称', filter: true },
|
|
|
- { name: 'code', label: '编码', filter: true }
|
|
|
+ { name: 'title', label: '标题', filter: true },
|
|
|
+ { name: 'bind', label: '绑定类型编码' }
|
|
|
],
|
|
|
formdata: {},
|
|
|
- formfiled: [
|
|
|
- { name: 'name', label: '名称' },
|
|
|
- { name: 'code', label: '编码' }
|
|
|
- ],
|
|
|
- formrules: {}
|
|
|
+ formfiled: [],
|
|
|
+ formrules: {},
|
|
|
+ type: null
|
|
|
};
|
|
|
},
|
|
|
computed: {
|
|
|
- ...mapState(['imgNewsList', 'Total'])
|
|
|
+ ...mapState(['imgNewsList', 'Total', 'typeList', 'columnList', 'pagesList'])
|
|
|
},
|
|
|
async mounted() {
|
|
|
- await this.filterQuery();
|
|
|
+ await this.typeQuery();
|
|
|
+ await this.codeQuery();
|
|
|
+ await this.columnQuery();
|
|
|
+ await this.pagesQuery();
|
|
|
},
|
|
|
methods: {
|
|
|
- ...mapActions(['imgNewsQuery', 'imgNewsCreate', 'imgNewsUpdate', 'imgNewsDelete', 'imgNewsQuery', 'queryBind', 'batchUnBind', 'batchBind']),
|
|
|
+ ...mapActions(['typeQuery', 'typeCreate', 'typeUpdate', 'typeDelete', 'imgNewsQuery', 'imgNewsCreate', 'imgNewsUpdate', 'imgNewsDelete', 'imgNewsQuery', 'imgNewsFetch', 'codeQuery', 'columnQuery', 'pagesQuery']),
|
|
|
+ typeChage () {
|
|
|
+ if (this.type == null) {
|
|
|
+ // 类别
|
|
|
+ this.formfiled = [
|
|
|
+ { name: 'title', label: '名称', filter: true },
|
|
|
+ { name: 'type', label: '类型', filter: true }
|
|
|
+ ];
|
|
|
+ } else {
|
|
|
+ // 新闻
|
|
|
+ this.formfiled = [
|
|
|
+ { name: 'img', label: '缩略图', formater: 'slot' },
|
|
|
+ { name: 'title', label: '名称' },
|
|
|
+ { name: 'bind', label: '绑定类型', formater: 'dict:typeList' },
|
|
|
+ { name: 'type', label: '类型', formater: 'dict:imgNewsType' }
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ this.visibleSync = true;
|
|
|
+ },
|
|
|
// 添加
|
|
|
addimgNews () {
|
|
|
+ if (this.type == null) {
|
|
|
+ this.$message.error('请先选择类型');
|
|
|
+ return;
|
|
|
+ }
|
|
|
this.formdata = {};
|
|
|
this.title = '添加图片新闻';
|
|
|
- this.visibleSync = true;
|
|
|
+ this.typeChage();
|
|
|
},
|
|
|
// 修改
|
|
|
- filtereEdit (e) {
|
|
|
- this.formdata = e;
|
|
|
+ async filtereEdit (e) {
|
|
|
+ const res = await this.imgNewsFetch({ id: e._id });
|
|
|
+ this.formdata = res.data;
|
|
|
this.title = '修改图片新闻';
|
|
|
- this.visibleSync = true;
|
|
|
+ this.typeChage();
|
|
|
},
|
|
|
// 删除
|
|
|
async filterDelete (e) {
|
|
@@ -71,8 +140,39 @@ export default {
|
|
|
},
|
|
|
// 查询
|
|
|
async filterQuery ({ filter = {}, paging = { page: 0, size: 10 } } = {}) {
|
|
|
+ if (this.type == null) {
|
|
|
+ this.$message.error('请先选择类型');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ filter.bind = this.type;
|
|
|
await this.imgNewsQuery({ filter, paging });
|
|
|
},
|
|
|
+ // 添加
|
|
|
+ treeTypeAdd() {
|
|
|
+ this.type = null;
|
|
|
+ this.formdata = {};
|
|
|
+ this.title = '添加类别';
|
|
|
+ this.typeChage();
|
|
|
+ },
|
|
|
+ // 修改
|
|
|
+ treeEdit(e) {
|
|
|
+ this.type = null;
|
|
|
+ this.formdata = e;
|
|
|
+ this.title = '修改类别';
|
|
|
+ this.typeChage();
|
|
|
+ },
|
|
|
+ // 删除
|
|
|
+ async treeRemove(e) {
|
|
|
+ this.type = null;
|
|
|
+ const res = await this.typeDelete({ id: e?._id });
|
|
|
+ this.$resChange(res, '删除成功');
|
|
|
+ this.typeQuery();
|
|
|
+ },
|
|
|
+ // 选择
|
|
|
+ treeClick(e) {
|
|
|
+ this.type = e.data.code;
|
|
|
+ this.filterQuery();
|
|
|
+ },
|
|
|
// 表单保存
|
|
|
async formSave (e) {
|
|
|
if (e.isRevise && e?.isRevise == false) {
|
|
@@ -81,30 +181,99 @@ export default {
|
|
|
}
|
|
|
this.$delete(e, 'isRevise');
|
|
|
let res, msg;
|
|
|
- // 修改
|
|
|
- if (e._id) {
|
|
|
- res = await this.imgNewsUpdate(e);
|
|
|
- msg = '图片新闻修改成功';
|
|
|
+ // 图片新闻
|
|
|
+ if (this.type !== null) {
|
|
|
+ // 修改
|
|
|
+ if (e._id) {
|
|
|
+ res = await this.imgNewsUpdate(e);
|
|
|
+ msg = '图片新闻修改成功';
|
|
|
+ } else {
|
|
|
+ res = await this.imgNewsCreate(e);
|
|
|
+ msg = '图片新闻添加成功';
|
|
|
+ }
|
|
|
+ this.filterQuery();
|
|
|
} else {
|
|
|
- res = await this.imgNewsCreate(e);
|
|
|
- msg = '图片新闻修改成功';
|
|
|
+ // 新闻类别
|
|
|
+ if (e._id) {
|
|
|
+ // 类别修改
|
|
|
+ res = await this.typeUpdate(e);
|
|
|
+ msg = '类别修改成功';
|
|
|
+ } else {
|
|
|
+ // 类别添加
|
|
|
+ res = await this.typeCreate(e);
|
|
|
+ msg = '类别添加成功';
|
|
|
+ }
|
|
|
+ this.typeQuery();
|
|
|
}
|
|
|
this.$resChange(res, msg);
|
|
|
- this.filterQuery();
|
|
|
this.visibleSync = false;
|
|
|
+ },
|
|
|
+ // 缩略图上传
|
|
|
+ handleAvatarSuccess(res, file) {
|
|
|
+ // this.imageUrl = URL.createObjectURL(file.raw);
|
|
|
+ this.$refs.formData.setForm('img', res.data.filePath);
|
|
|
+ },
|
|
|
+ beforeAvatarUpload(file) {
|
|
|
+ const isJPG = file.type === 'image/jpeg';
|
|
|
+ const isLt2M = file.size / 1024 / 1024 < 2;
|
|
|
+
|
|
|
+ if (!isJPG) {
|
|
|
+ this.$message.error('上传头像图片只能是 JPG 格式!');
|
|
|
+ }
|
|
|
+ if (!isLt2M) {
|
|
|
+ this.$message.error('上传头像图片大小不能超过 2MB!');
|
|
|
+ }
|
|
|
+ return isJPG && isLt2M;
|
|
|
}
|
|
|
}
|
|
|
};
|
|
|
</script>
|
|
|
-<style lang="scss" scoped>
|
|
|
-.box {
|
|
|
+<style lang="scss">
|
|
|
+.imgnewshome {
|
|
|
width: 100%;
|
|
|
height: 100%;
|
|
|
+ display: flex;
|
|
|
.box-card {
|
|
|
+ width: 84%;
|
|
|
height: 100%;
|
|
|
.el-card__body {
|
|
|
height: 100%;
|
|
|
}
|
|
|
}
|
|
|
+ .box-card-left {
|
|
|
+ width: 15%;
|
|
|
+ height: 100%;
|
|
|
+ .el-card__body {
|
|
|
+ height: 88%;
|
|
|
+ .deepTree {
|
|
|
+ width: 100%;
|
|
|
+ height: 100%;
|
|
|
+ overflow-y: auto;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+.avatar-uploader-icon {
|
|
|
+ font-size: 28px;
|
|
|
+ color: #8c939d;
|
|
|
+ width: 120px;
|
|
|
+ height: 120px;
|
|
|
+ line-height: 120px !important;
|
|
|
+ text-align: center;
|
|
|
+}
|
|
|
+.avatar {
|
|
|
+ width: 120px;
|
|
|
+ height: 120px;
|
|
|
+ display: block;
|
|
|
+}
|
|
|
+.el-upload {
|
|
|
+ border: 1px dashed #d9d9d9;
|
|
|
+ border-radius: 6px;
|
|
|
+ cursor: pointer;
|
|
|
+ position: relative;
|
|
|
+ overflow: hidden;
|
|
|
+}
|
|
|
+.el-upload:hover {
|
|
|
+ border-color: #409EFF;
|
|
|
}
|
|
|
</style>
|