|
@@ -0,0 +1,272 @@
|
|
|
+<template>
|
|
|
+ <div class="mainBox">
|
|
|
+ <div class="layerBox">
|
|
|
+ <tableTitle :name="tableDivTitle"/>
|
|
|
+ <el-form :model="form" ref="form" :rules="formRules" label-position="left" label-width="120px">
|
|
|
+ <div class="formDiv">
|
|
|
+ <div>
|
|
|
+ <el-form-item label="列表标题:" prop="listTitle" class="custom-align-right" v-if="this.type==1">
|
|
|
+ <el-input v-model="form.listTitle" autocomplete="off" placeholder="请输入列表标题"></el-input>
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item label="内容标题:" prop="contentTitle" class="custom-align-right">
|
|
|
+ <el-input v-model="form.contentTitle" autocomplete="off" placeholder="请输入内容标题"></el-input>
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item label="内容标题:" prop="content" class="custom-align-right">
|
|
|
+ <myEditor ref="myEditor" v-model="form.content"></myEditor>
|
|
|
+ </el-form-item>
|
|
|
+ <div>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ </el-form>
|
|
|
+ </div>
|
|
|
+ <div class="bottomBtnBox">
|
|
|
+ <el-button type="info" @click="returnPage">返回</el-button>
|
|
|
+ <el-button type="primary" @click="editToServe" v-if="editStatus==true">修改</el-button>
|
|
|
+ <el-button type="primary" @click="addToServe" v-else>添加</el-button>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+</template>
|
|
|
+
|
|
|
+<script>
|
|
|
+//表格标题
|
|
|
+import tableTitle from './components/tableTitle';
|
|
|
+//引入公用样式
|
|
|
+import '@/styles/global.less';
|
|
|
+//引入富文本编辑器
|
|
|
+import myEditor from '../../components/edit/myEditor.vue';
|
|
|
+
|
|
|
+export default {
|
|
|
+ components: {
|
|
|
+ tableTitle,
|
|
|
+ myEditor
|
|
|
+ },
|
|
|
+ data() {
|
|
|
+ //0.全局操作 start ------------------------------------------------------------>
|
|
|
+ //表单验证
|
|
|
+ const validateEmpty = (rule,value,callback) => {
|
|
|
+ if (value == '') {
|
|
|
+ callback(new Error('该项不能为空!'))
|
|
|
+ } else {
|
|
|
+ callback()
|
|
|
+ }
|
|
|
+ }
|
|
|
+ const validateArray = (rule, value, callback) => {
|
|
|
+ if (value.length == 0) {
|
|
|
+ callback(new Error('该项不能为空!'))
|
|
|
+ } else {
|
|
|
+ callback()
|
|
|
+ }
|
|
|
+ }
|
|
|
+ let self = this;
|
|
|
+ //0.全局操作 end ------------------------------------------------------------>
|
|
|
+ return {
|
|
|
+ //1.表单项 start ------------------------------------------------------------>
|
|
|
+ editStatus:false,//是否为编辑状态
|
|
|
+ tableDivTitle:"添加单页内容",
|
|
|
+ fcat_id:"",//单页导航id
|
|
|
+ type:"",//单页内容分类
|
|
|
+ //提交表单
|
|
|
+ form: {
|
|
|
+ listTitle:"",//列表标题
|
|
|
+ contentTitle:"",//内容标题
|
|
|
+ content:"",//内容
|
|
|
+ },
|
|
|
+ //1.2 表单验证规则
|
|
|
+ formRules: {
|
|
|
+ listTitle:[{required:true,trigger:'blur',validator:validateEmpty}],
|
|
|
+ contentTitle:[{required:true,trigger:'blur',validator:validateEmpty}],
|
|
|
+ content:[{required:true,trigger:'blur',validator:validateEmpty}],
|
|
|
+ },
|
|
|
+ //1.3富文本编辑器配置
|
|
|
+
|
|
|
+ //表单项 end ------------------------------------------------------------>
|
|
|
+ };
|
|
|
+ },
|
|
|
+ methods: {
|
|
|
+ //1.提交表单 start ------------------------------------------------------------>
|
|
|
+ //1.1 直接上传图片
|
|
|
+ beforeAvatarUpload(file) {
|
|
|
+ const isJPG = file.type === 'image/jpeg';
|
|
|
+ const isPNG = file.type === 'image/png';
|
|
|
+ const isLt2M = file.size / 1024 / 1024 < 2;
|
|
|
+
|
|
|
+ if (!isJPG && !isPNG) {
|
|
|
+ this.$message.error('上传缩略图只能是 JPG 或 PNG 格式!');
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ if (!isLt2M) {
|
|
|
+ this.$message.error('上传缩略图大小不能超过 2MB!');
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ const formData = new FormData();
|
|
|
+ formData.append('file', file);
|
|
|
+
|
|
|
+ this.$store.dispatch('pool/uploadFile',formData).then(res=> {
|
|
|
+ this.imgUrl = res.data.imgUrl;//显示缩略图
|
|
|
+ this.form.imgurl = res.data.imgUrl;//提供表单地址
|
|
|
+ // console.log(res.data.imgUrl)
|
|
|
+ }).catch(() => {
|
|
|
+ this.$message({
|
|
|
+ type: 'info',
|
|
|
+ message: '网络错误,请重试!'
|
|
|
+ });
|
|
|
+ })
|
|
|
+ // 阻止默认的上传行为
|
|
|
+ return false;
|
|
|
+ },
|
|
|
+ //1.2 提交表单
|
|
|
+ addToServe(){
|
|
|
+ //先进行验证
|
|
|
+ this.$refs.form.validate(valid => {
|
|
|
+ if (valid) {
|
|
|
+ let data = {
|
|
|
+ fcat_id:this.fcat_id,
|
|
|
+ type:this.type,
|
|
|
+ list_title:this.form.listTitle,
|
|
|
+ con_title:this.form.contentTitle,
|
|
|
+ content:this.form.content,
|
|
|
+ }
|
|
|
+ this.$store.dispatch('tabbar/addFooterContent',data).then(res=> {
|
|
|
+ //汇报结果
|
|
|
+ this.$message({
|
|
|
+ type: 'success',
|
|
|
+ message: '已成功添加单页内容!'
|
|
|
+ });
|
|
|
+ this.cleatForm();
|
|
|
+ //返回列表页
|
|
|
+ this.returnPage()
|
|
|
+ }).catch(() => {
|
|
|
+ this.$message({
|
|
|
+ type: 'info',
|
|
|
+ message: '网络错误,请重试!'
|
|
|
+ });
|
|
|
+ })
|
|
|
+ }
|
|
|
+ })
|
|
|
+ },
|
|
|
+ //1.3 清理表单
|
|
|
+ cleatForm(){
|
|
|
+ // this.form.type = "";
|
|
|
+ // this.form.fcat_id = "";
|
|
|
+ this.form.listTitle = "";
|
|
|
+ this.form.content = "";
|
|
|
+ this.form.contentTitle = "";
|
|
|
+ },
|
|
|
+ //提交表单 end ------------------------------------------------------------>
|
|
|
+
|
|
|
+ //2.跳转操作 start ------------------------------------------------------------>
|
|
|
+
|
|
|
+ returnPage(){
|
|
|
+ // if(this.editStatus==true){
|
|
|
+ // this.fcat_id = this.$route.query.fcat_id;
|
|
|
+ // }
|
|
|
+ this.$router.push({
|
|
|
+ path: '/TabbarDetail',
|
|
|
+ query: {
|
|
|
+ id: this.fcat_id,
|
|
|
+ type:this.type,
|
|
|
+ }
|
|
|
+ });
|
|
|
+ },
|
|
|
+ //跳转操作 end ------------------------------------------------------------>
|
|
|
+
|
|
|
+ //3.回显操作 ------------------------------------------------------------>
|
|
|
+ //3.1回显数据
|
|
|
+ getMainData() {
|
|
|
+ let data = {
|
|
|
+ id: this.$route.query.id + ""
|
|
|
+ };
|
|
|
+ this.$store.dispatch('tabbar/getOneFooterContent', data).then(res => {
|
|
|
+ this.form.listTitle = res.data.list_title;
|
|
|
+ this.form.contentTitle = res.data.con_title;
|
|
|
+ this.fcat_id = res.data.fcat_id;
|
|
|
+ //回显编辑器内容
|
|
|
+ this.$nextTick(() => {
|
|
|
+ this.form.content = res.data.content;
|
|
|
+ });
|
|
|
+ }).catch(() => {
|
|
|
+ this.$message({
|
|
|
+ type: 'info',
|
|
|
+ message: '网络错误,请重试!'
|
|
|
+ });
|
|
|
+ });
|
|
|
+ },
|
|
|
+ //1.3提交修改
|
|
|
+ editToServe(){
|
|
|
+ //添加要修改的id
|
|
|
+ this.form.id = this.editId + "";
|
|
|
+ //先进行验证
|
|
|
+ this.$refs.form.validate(valid => {
|
|
|
+ if (valid) {
|
|
|
+ let data = {
|
|
|
+ id:this.$route.query.id,
|
|
|
+ list_title:this.form.listTitle,
|
|
|
+ con_title:this.form.contentTitle,
|
|
|
+ content:this.form.content,
|
|
|
+ type:this.type,
|
|
|
+ }
|
|
|
+
|
|
|
+ this.$store.dispatch('tabbar/upFooterContent',data).then(res=> {
|
|
|
+ //汇报结果
|
|
|
+ this.$message({
|
|
|
+ type: 'success',
|
|
|
+ message: '已成功修改单页内容!'
|
|
|
+ });
|
|
|
+ this.cleatForm();
|
|
|
+ //返回列表页
|
|
|
+ this.returnPage()
|
|
|
+ }).catch(() => {
|
|
|
+ this.$message({
|
|
|
+ type: 'info',
|
|
|
+ message: '网络错误,请重试!'
|
|
|
+ });
|
|
|
+ })
|
|
|
+ }
|
|
|
+ })
|
|
|
+ },
|
|
|
+ //跳转操作 end ------------------------------------------------------------>
|
|
|
+
|
|
|
+ //4.富文本编辑器 start ------------------------------------------------------------>
|
|
|
+ //4.1 编辑器点击上传图片
|
|
|
+
|
|
|
+ //富文本编辑器 end ------------------------------------------------------------>
|
|
|
+
|
|
|
+ },
|
|
|
+ mounted(){
|
|
|
+ //1.判断是新建还是回显
|
|
|
+ if(this.$route.query.dialogName!=undefined && this.$route.query.dialogName=="编辑"){
|
|
|
+ this.fcat_id = this.$route.query.fcat_id;
|
|
|
+ this.type = this.$route.query.tabbarType;
|
|
|
+ this.editStatus = true;
|
|
|
+ console.log("编辑内容!")
|
|
|
+ this.getMainData();
|
|
|
+ }else{
|
|
|
+ this.type = this.$route.query.tabbarType;
|
|
|
+ this.fcat_id = this.$route.query.fcat_id;
|
|
|
+ this.editStatus = false;
|
|
|
+ console.log("添加内容!")
|
|
|
+ }
|
|
|
+ },
|
|
|
+};
|
|
|
+</script>
|
|
|
+
|
|
|
+<style scoped lang="less">
|
|
|
+
|
|
|
+ //执行v-deep穿透scope选择器 start------------------------------------------------------------>*/
|
|
|
+ ::v-deep .custom-form-item > .el-form-item__label {
|
|
|
+ line-height: 140px !important;
|
|
|
+ }
|
|
|
+ ::v-deep .custom-textarea .el-textarea__inner {
|
|
|
+ resize: none; /* 禁止用户拖拽调整大小 */
|
|
|
+ }
|
|
|
+ ::v-deep .custom-align-right .el-form-item__label {
|
|
|
+ text-align: right; /* 设置标签文字右对齐 */
|
|
|
+ }
|
|
|
+ ::v-deep .el-select {
|
|
|
+ width: 100%; /* 禁止用户拖拽调整大小 */
|
|
|
+ }
|
|
|
+
|
|
|
+ //执行v-deep穿透scope选择器 end------------------------------------------------------------>*/
|
|
|
+</style>
|