明梦爽
2022-04-17 5529b7077126be368abd444d45ec085d8c7779e3
src/components/Administrator/AdMain.vue
@@ -3,14 +3,7 @@
    <!-- 级联选择器 -->
    <el-row class="block">
      <el-col :span="4">
        <el-cascader
          v-model="value"
          :options="options"
          clearable
          filterable
          :getCheckedNodes="true"
          @change="handleChange">
        </el-cascader>
        <el-cascader v-model="value" :options="options" clearable filterable :getCheckedNodes="true" @change="handleChange"> </el-cascader>
      </el-col>
      <el-col :span="5">
        <el-button type="primary" icon="el-icon-edit" @click="goAdEdit()">点击对普通管理员进行管理</el-button>
@@ -25,8 +18,7 @@
          </el-col>
          <el-col :span="10">
            <!-- 新闻搜索 -->
            <el-input clearable placeholder="请输入所要查询的新闻标题" v-model="search" class="input-with-select">
            </el-input>
            <el-input clearable placeholder="请输入所要查询的新闻标题" v-model="search" class="input-with-select"> </el-input>
          </el-col>
        </el-row>
        <!-- 新闻表格区域 -->
@@ -42,12 +34,9 @@
              <span>{{ (currentPage-1)*pageSize+scope.$index+1 }}</span>
            </template>
          </el-table-column>
          <el-table-column prop="releaseTime" label="日期" width="" >
          </el-table-column>
          <el-table-column prop="title" label="新闻标题" width="">
          </el-table-column>
          <el-table-column prop="id" label="id" width="">
          </el-table-column>
          <el-table-column prop="releaseTime" label="日期" width=""> </el-table-column>
          <el-table-column prop="title" label="新闻标题" width=""> </el-table-column>
          <el-table-column prop="id" label="id" width=""> </el-table-column>
          <el-table-column label="操作" width="">
            <template slot-scope="scope">
              <!-- {{ scope.row.id }} -->
@@ -57,7 +46,6 @@
                <el-button type="info" @click="deleteNews(scope.row.id)">删除</el-button>
              </div>
            </template>
          </el-table-column>
        </el-table>
        <!-- 分页 -->
@@ -68,20 +56,17 @@
              @size-change="handleSizeChange"
              @current-change="handleCurrentChange"
              :current-page="currentPage"
              :page-sizes="[6,12, 18,]"
              :page-sizes="[6, 12, 18]"
              :page-size="100"
              layout="total, sizes, prev, pager, next, jumper"
              :total="total">
              :total="total"
            >
            </el-pagination>
          </div>
        </div>
      </el-card>
      <!-- 修改新闻的对话框 -->
      <el-dialog
        title="修改新闻"
        :visible.sync="editDialogVisible"
        width="50%"
        :before-close="handleClose">
      <el-dialog title="修改新闻" :visible.sync="editDialogVisible" width="50%" :before-close="handleClose">
        <!-- rules表单验证规则,ref当前表单的验证对象 -->
        <el-form ref="editFormRef" :model="editForm"  label-width="80px" status-icon>
          <el-form-item label="id:">
@@ -91,13 +76,7 @@
            <el-input v-model="editForm.title"></el-input>
          </el-form-item>
          <el-form-item label="发布日期:">
            <el-date-picker
              v-model="editForm.releaseTime"
              type="date"
              placeholder="请选择发布日期"
              format="yyyy 年 MM 月 dd 日"
              value-format="yyyy-MM-dd"
            ></el-date-picker>
            <el-date-picker v-model="editForm.releaseTime" type="date" placeholder="请选择发布日期" format="yyyy 年 MM 月 dd 日" value-format="yyyy-MM-dd"></el-date-picker>
          </el-form-item>
        </el-form>
        <span slot="footer" class="dialog-footer">
@@ -132,103 +111,114 @@
      fuzzytable:false, //模糊查询表格的显示
      fuzzyForm:{ fuzzytitle:'',fuzzytotal:0,fuzzycurrent:1,fuzzysize:6 },  //模糊查询列表对象
      value: [],
      options: [{
      options: [
        {
        value: 1,
        label: '首页',
        children: [{
          children: [
            {
          value:42,
          label: '通知公告',
              label: '通知公告'
        }, 
        {
          value:43,
          label: '工作动态',
              label: '工作动态'
        },
        {
          value:44,
          label: '学院动态',
              label: '学院动态'
        },
        {
          value:45,
          label: '轮播图',
        }],
      },{
              label: '轮播图'
            }
          ]
        },
        {
          value: 22,
          label: '科协概况',
          children: [{
          children: [
            {
            value:27,
            label: '简介',
              label: '简介'
          }, 
          {
            value:28,
            label: '章程',
              label: '章程'
          },
          {
            value:29,
            label: '组织结构',
              label: '组织结构'
          },
          {
            value:30,
            label: '工作职责',
              label: '工作职责'
          },
          {
            value:31,
            label: '专职人员',
          }],
              label: '专职人员'
            }
          ]
        },
        {
          value: 23,
          label: '政策法规',
          children: [{
          children: [
            {
            value:35,
            label: '中国科协政策文件',
              label: '中国科协政策文件'
          }, 
          {
            value:36,
            label: '地方科协政策文件',
              label: '地方科协政策文件'
          },
          {
            value:37,
            label: '社团管理文件',
          }],
              label: '社团管理文件'
            }
          ]
        },
        {
          value: 25,
          label: '学术交流',
          children: [{
          children: [
            {
            value:38,
            label: '学术信息',
              label: '学术信息'
          }, 
          {
            value:39,
            label: '科技竞赛',
          }],
              label: '科技竞赛'
            }
          ]
        },
        {
          value: 27,
          label: '科普风采',
          children: [{
          children: [
            {
            value:40,
            label: '平顶山学院科普活动',
              label: '平顶山学院科普活动'
          }, 
          {
            value:41,
            label: '平顶山市政协科普活动',
          }],
      }]
              label: '平顶山市政协科普活动'
            }
          ]
        }
      ]
    }
  },
  created(){
  },
  mounted(){
  },
  created() {},
  mounted() {},
  methods: {
    //修改对话框关闭的方法
    handleClose(done) {
      this.$confirm('确认关闭?')
        .then(_ => {
          done();
          done()
        })
        .catch(_ => {});
        .catch(_ => {})
    },
    //跳转普通管理列表
    goAdEdit(){
@@ -238,17 +228,18 @@
    handleChange(value) {
      // console.log(value);
      // console.log(value[1]);
      this.currentPage = 1;
      this.newsCategoryId = value[1]; //将得到的小标题id存放起来
      this.query(this.newsCategoryId);
      this.currentPage = 1
      this.newsCategoryId = value[1] //将得到的小标题id存放起来
      this.query(this.newsCategoryId)
    },
    query(newsCategoryId){
      const data = {
        current:this.currentPage,
        newsCategoryId:newsCategoryId,
        size:this.pageSize
      };
      getNewsList(data).then(res=>{
      }
      getNewsList(data)
        .then(res => {
        // console.log(res);
        if (res.code !== 200) {
          return this.$message.error('获取新闻列表失败')
@@ -256,8 +247,9 @@
          this.tableData = res.data.records
          this.total = res.data.total
        }
      }).catch(err => {
        console.log(err);
        })
        .catch(err => {
          console.log(err)
      })
    },
    //展示修改对话框
@@ -268,7 +260,7 @@
          this.editForm = res.data
        }     
      })
      this.editDialogVisible = true;
      this.editDialogVisible = true
    },
    //确定修改表单提交,验证发起请求
    editNew(){
@@ -278,11 +270,11 @@
        title:this.editForm.title
      }
      update(data).then(res=>{
        console.log('dsadasas',res);
        console.log('dsadasas', res)
        if (res.code == 200) {
          this.editDialogVisible =false;
          this.editDialogVisible = false
          this.$message.success('修改新闻成功!')
          this.query(this.newsCategoryId);
          this.query(this.newsCategoryId)
        }
      })
    },
@@ -301,7 +293,8 @@
        size: this.fuzzyForm.fuzzysize,
        title:title
      }
      fuzzy(data).then(res => {
      fuzzy(data)
        .then(res => {
        // console.log(res);
        if (res.code !== 200) {
          return this.$message.error('查询新闻列表失败')
@@ -309,8 +302,9 @@
          this.fuzzytableData = res.data.records
          this.fuzzyForm.fuzzytotal = res.data.total
        }
      }).catch(err => {
        console.log(err);
        })
        .catch(err => {
          console.log(err)
      })
    },
    //清空查询列表内容
@@ -335,20 +329,20 @@
      })
      //如果用户点击确定则返回confirm
      //如果用户点击取消则返回cancel
      console.log(res);
      console.log(res)
      if(res !== 'confirm'){
        return this.$message.info('已取消删除~')
      }else{
        console.log(id);
        console.log(id)
        const data = {
          id:id
        }
        //参数data 要以对象的形式传入
        deleteNew(data).then(res => {
          console.log('>>>'+res);
          console.log('>>>' + res)
          if(res.code == 200){
            this.$message.success('删除新闻成功!')
            this.query(this.newsCategoryId);
            this.query(this.newsCategoryId)
          }else{
            return this.$message.error('删除新闻失败!')
          }
@@ -365,12 +359,12 @@
    },
    handleCurrentChange(val) {
      // console.log(`当前页: ${val}`);
      this.currentPage = val;
      this.currentPage = val
      this.query(this.newsCategoryId)
    },
    handleSizeChange(val) {
      // console.log(`每页 ${val} 条`);
      this.pageSize = val;
      this.pageSize = val
      this.query(this.newsCategoryId)
    },
    handleCurrentChangefuzzy(val){
@@ -383,39 +377,55 @@
    },
    //去往添加编辑页面
    goEdit(id){
      let title = '';
      console.log(this.value);
      if (this.value.length = 2) {
        let t = this.value[0];
        let i = this.value[1];
      let title = ''
      console.log(this.value)
      if ((this.value.length = 2)) {
        let t = this.value[0]
        let i = this.value[1]
        this.options.forEach( item => {
          if(item.value == t){
            title += item.label+'/'
            item.children.forEach( e => {
              if(e.value == i) title += e.label;
              if (e.value == i) title += e.label
            })
          }
        })
      }
      if (this.newsCategoryId==27&&this.total==1||this.newsCategoryId==28&&this.total==1||this.newsCategoryId==29&&this.total==1||
      this.newsCategoryId==30&&this.total==1||this.newsCategoryId==31&&this.total==1) {
      if (
        (this.newsCategoryId == 27 && this.total == 1) ||
        (this.newsCategoryId == 28 && this.total == 1) ||
        (this.newsCategoryId == 29 && this.total == 1) ||
        (this.newsCategoryId == 30 && this.total == 1) ||
        (this.newsCategoryId == 31 && this.total == 1)
      ) {
        this.$message.error('该新闻标题下只能存在一篇新闻')
      }else if(this.newsCategoryId==27||this.newsCategoryId==28||this.newsCategoryId==29||this.newsCategoryId==30||
      this.newsCategoryId==31||this.newsCategoryId == 35||this.newsCategoryId==36||this.newsCategoryId==37||
      this.newsCategoryId==38||this.newsCategoryId==39||this.newsCategoryId==40||
      this.newsCategoryId==41||this.newsCategoryId==42||this.newsCategoryId==43||
      this.newsCategoryId==44){
      } else if (
        this.newsCategoryId == 27 ||
        this.newsCategoryId == 28 ||
        this.newsCategoryId == 29 ||
        this.newsCategoryId == 30 ||
        this.newsCategoryId == 31 ||
        this.newsCategoryId == 35 ||
        this.newsCategoryId == 36 ||
        this.newsCategoryId == 37 ||
        this.newsCategoryId == 38 ||
        this.newsCategoryId == 39 ||
        this.newsCategoryId == 40 ||
        this.newsCategoryId == 41 ||
        this.newsCategoryId == 42 ||
        this.newsCategoryId == 43 ||
        this.newsCategoryId == 44
      ) {
        this.$router.push({path:'/administrator/edit',query:{id:id,title:title}})
        console.log(this.newsCategoryId);
        console.log(this.newsCategoryId)
      }else if(this.newsCategoryId==45){
        this.$router.push({path:'/administrator/editlunbo',query:{id:id,title:title}})
        // console.log(this.newsCategoryId);
      }else{
        this.$message.error('请先选择新闻标题')
      }
    }
  },
  }
}
</script>