odc.xiaohui
2023-03-07 034d8675792fee6af5af592df0b69acd3ad8a215
src/views/common/Publicity.vue
@@ -21,7 +21,7 @@
          <el-form-item>
            <el-upload name="multipartFile" class="upload-demo" action="/api/publicity/upload " :show-file-list="false"
              :before-upload="beforeAvatarUpload" :on-success="respond" :limit="1">
                       :before-upload="beforeAvatarUpload" :on-success="respond" :limit="1">
              <el-button type="primary">导入</el-button>
            </el-upload>
          </el-form-item>
@@ -52,7 +52,7 @@
            <template slot-scope="scope">
              <el-button type="text" size="medium" @click="details(scope.row.id)">详情</el-button>
              <el-button type="text" size="medium" @click="punlish(scope.row.id, scope.row.status)"
                :disabled="scope.row.status == 2">
                         :disabled="scope.row.status == 2">
                <span v-if="scope.row.status === 1" style="color:#ff0000">下架</span>
                <span v-else>发布</span>
              </el-button>
@@ -63,24 +63,38 @@
        </el-table>
      </template>
      <el-pagination @current-change="handleCurrentChange" :current-page="queryInfo.current" :page-size="queryInfo.size"
        layout="prev, pager, next" :total="total"></el-pagination>
                     layout="prev, pager, next" :total="total"></el-pagination>
    </el-card>
    <!--添加公共宣传弹窗-->
    <el-dialog title="公共宣传添加" :visible.sync="addPublicityVisibel" width="50%" :before-close="addPublicityClose"
      :append-to-body="true">
               :append-to-body="true">
      <el-row :gutter="15">
        <el-form ref="addPublicityForm" :model="addPublicityForm" :rules="rules" size="medium" label-width="100px">
          <el-col :span="12">
            <el-form-item label="标题 " prop="publicityTitle">
              <el-input v-model="addPublicityForm.publicityTitle" clearable placeholder="请输入标题"
                :style="{ width: '100%' }"></el-input>
                        :style="{ width: '100%' }"></el-input>
            </el-form-item>
          </el-col>
          <el-col>
            <el-form-item label="正文图片">
              <el-upload
                  action="/api/minio/upload"
                  list-type="picture-card"
                  :with-credentials="true"
                  :on-preview="handlePictureCardPreview"
                  :on-success="uploadSuccess3"
                  :on-remove="handleRemove"
                  :file-list="addPublicityForm.img">
                <i slot="default" class="el-icon-plus"></i>
              </el-upload>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="内容 " prop="content">
              <el-input v-model="addPublicityForm.text" type="textarea" placeholder="请输入公告内容" clearable
                :autosize="{ minRows: 4, maxRows: 4 }" :style="{ width: '100%' }"></el-input>
                        :autosize="{ minRows: 4, maxRows: 4 }" :style="{ width: '100%' }"></el-input>
            </el-form-item>
          </el-col>
        </el-form>
@@ -91,21 +105,42 @@
      </span>
    </el-dialog>
    <!-- 图片放大弹窗 -->
    <el-dialog :visible.sync="dialogVisible">
      <img width="100%" :src="dialogImageUrl" alt="">
    </el-dialog>
    <!--公共宣传详情弹窗-->
    <el-dialog title="公共宣传详情" :visible.sync="detailsVisible" width="50%" :append-to-body="true"
      :before-close="detailsVisibleclose">
               :before-close="detailsVisibleclose">
      <el-row :gutter="15">
        <el-form ref="addGroupForm" :model="addGroupForm" size="medium" label-width="100px">
            <el-col :span="12">
        <el-form ref="addGroupForm" :model="detailsRow" size="medium" label-width="100px">
          <el-col :span="12">
            <el-form-item label="标题" prop="effectiveEtime">
              <el-input v-model="detailsRow.publicityTitle" disabled></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="24">
          <el-form-item label="正文图片">
            <el-upload
                action="/api/minio/upload"
                list-type="picture-card"
                :with-credentials="true"
                :on-preview="handlePictureCardPreview"
                :on-success="uploadSuccess3"
                :on-remove="handleRemove"
                :file-list="detailsRow.img"
                disabled
                class="freePic">
              <i slot="default" class="el-icon-plus"></i>
            </el-upload>
          </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="内容 " prop="text">
              <el-input v-model="detailsRow.text" type="textarea" placeholder="请输入公告内容" disabled
                :autosize="{ minRows: 4, maxRows: 4 }" :style="{ width: '100%' }"></el-input>
                        :autosize="{ minRows: 4, maxRows: 4 }" :style="{ width: '100%' }"></el-input>
            </el-form-item>
          </el-col>
          <!-- <el-col :span="12">
@@ -125,7 +160,7 @@
          <el-col :span="12">
            <el-form-item label="发布时间" prop="effectiveEtime">
              <el-date-picker v-model="detailsRow.releaseTime" type="datetime" placeholder="选择日期时间" disabled
                :style="{ width: '100%' }" value-format="yyyy-MM-dd HH:mm:ss">
                              :style="{ width: '100%' }" value-format="yyyy-MM-dd HH:mm:ss">
              </el-date-picker>
            </el-form-item>
          </el-col>
@@ -188,8 +223,9 @@
  name: "Publicity",
  data() {
    return {
      fileList: [],
      dialogImageUrl: '',
      dialogVisible: false,
      //详细内容弹框
      detailsVisible: false,
      //详细内容
@@ -197,7 +233,8 @@
      //表单提交内容
      addPublicityForm: {
        publicityTitle: '',
        text: ''
        text: '',
        img: []
      },
      //添加弹框
      addPublicityVisibel: false,
@@ -254,130 +291,161 @@
  },
  methods:
  {
    //删除
    remove(val) {
      this.$http.delete('/api/publicity/' + val).then(res => {
        this.$message({
          message: '删除成功',
          type: 'success'
        })
      {
        uploadSuccess3(res, file) {
          if (res.code === 200) {
            this.addPublicityForm.img.push({
              name: res.data,
              url: '/minio/img/' + res.data,
              uid: this.addPublicityForm.img.length
            })
          } else {
            this.$message.error(res.msg)
          }
        },
        // 正文图片上传,删除操作
        handleRemove(file, fileList) {
          // file是点击删除的文件,fileList时删除后剩下的文件列表
          this.addPublicityForm.img = fileList
        },
        handlePictureCardPreview(file) {
          this.dialogImageUrl = file.url
          this.dialogVisible = true
        },
        //删除
        remove(val) {
          this.$http.delete('/api/publicity/' + val).then(res => {
            this.$message({
              message: '删除成功',
              type: 'success'
            })
        this.search();
      })
    },
    //发布/下架
    punlish(val, val2) {
      if (val2 == 0) {
        this.$http.get('/api/publicity/release/' + val).then(res => {
          this.$message({
            message: '发布成功',
            type: 'success'
            this.search();
          })
        },
        //发布/下架
        punlish(val, val2) {
          if (val2 == 0) {
            this.$http.get('/api/publicity/release/' + val).then(res => {
                  this.$message({
                    message: '发布成功',
                    type: 'success'
                  })
          this.search();
        }
        )
      }
      if (val2 == 1) {
        this.$http.get('/api/publicity/offline/' + val).then(res => {
          this.$message({
            message: '下架成功',
            type: 'success'
          })
          this.search();
        }
        );
      }
    },
                  this.search();
                }
            )
          }
          if (val2 == 1) {
            this.$http.get('/api/publicity/offline/' + val).then(res => {
                  this.$message({
                    message: '下架成功',
                    type: 'success'
                  })
                  this.search();
                }
            );
          }
        },
    //详情
    details(val) {
      this.detailsVisible = true;
      this.$http.get('/api/publicity/' + val).then(res => this.detailsRow = res.data.data);
    },
    //添加
    add() {
      this.$refs.addPublicityForm.validate(async (vaild) => {
        if (!vaild) return this.$message.error('输入有误')
        let param = null;
        param = this.addPublicityForm;
        addPublicityList(param).then(res => {
          this.$message({
            message: '操作成功',
            type: 'success'
        //详情
        details(val) {
          this.detailsVisible = true;
          this.$http.get('/api/publicity/' + val).then(res => {
            this.detailsRow = res.data.data
            this.detailsRow.img = this.detailsRow['photoStr'].split(',').map(item => {
              return {
                name: item,
                url: '/minio/img/' + item,
                uid: this.detailsRow['photoStr'].split(',').length
              }
            })
            this.fileList = this.detailsRow.img
          });
          this.addPublicityForm = {}
          this.init();
        }
        )
        this.addPublicityVisibel = false;
      })
    },
    //关闭之前
    addPublicityClose() {
      this.addPublicityVisibel = false;
    },
    detailsVisibleclose() {
      this.detailsVisible = false;
    },
    //分页方法
    handleCurrentChange(val) {
      this.queryInfo.current = val;
      this.search();
    },
    //导入
    beforeAvatarUpload(file) {
      let Xls = file.name.split('.');
      if (Xls[1] === 'xls' || Xls[1] === 'xlsx') {
        return file
      } else {
        this.$message.error('上传文件只能是 xls/xlsx 格式!')
        return false
      }
    },
    //导入成功
    respond(res) {
      if (res.code == 200) {
        this.$message({
          message: '上传成功',
          type: 'success'
        }
        )
      } else {
        this.$message({
          message: res.msg,
          type: 'error'
        })
      }
      location.reload();
    },
    //公共宣传加载
    init() {
      let param = {}
      param.current = this.queryInfo.current
      param.size = this.queryInfo.size
      param.status = this.queryInfo.status !== null ? this.queryInfo.status : ''
      getPublicityList(param).then(res => {
        this.publicityList = res.records;
        this.total = res.total
      })
    },
    //查询
    search() {
      let param = {}
      param.publicityTitle = this.queryInfo.publicityTitle;
      param.current = this.queryInfo.current
      param.size = this.queryInfo.size
      param.status = this.queryInfo.status !== null ? this.queryInfo.status : ''
      getPublicityList(param).then(res => {
        this.publicityList = res.records;
        this.total = res.total
        this.current = res.current
      })
    },
        },
        //添加
        add() {
          this.$refs.addPublicityForm.validate(async (vaild) => {
            if (!vaild) return this.$message.error('输入有误')
            let param = null;
            param = JSON.parse(JSON.stringify(this.addPublicityForm));
            param.photoStr = param.img.map(item => item.name).join(',');
            addPublicityList(param).then(res => {
                  this.$message({
                    message: '操作成功',
                    type: 'success'
                  });
                  this.addPublicityForm = {}
                  this.init();
                }
            )
            this.addPublicityVisibel = false;
          })
        },
        //关闭之前
        addPublicityClose() {
          this.addPublicityVisibel = false;
        },
        detailsVisibleclose() {
          this.detailsVisible = false;
        },
        //分页方法
        handleCurrentChange(val) {
          this.queryInfo.current = val;
          this.search();
        },
        //导入
        beforeAvatarUpload(file) {
          let Xls = file.name.split('.');
          if (Xls[1] === 'xls' || Xls[1] === 'xlsx') {
            return file
          } else {
            this.$message.error('上传文件只能是 xls/xlsx 格式!')
            return false
          }
        },
        //导入成功
        respond(res) {
          if (res.code == 200) {
            this.$message({
                  message: '上传成功',
                  type: 'success'
                }
            )
          } else {
            this.$message({
              message: res.msg,
              type: 'error'
            })
          }
          location.reload();
        },
        //公共宣传加载
        init() {
          let param = {}
          param.current = this.queryInfo.current
          param.size = this.queryInfo.size
          param.status = this.queryInfo.status !== null ? this.queryInfo.status : ''
          getPublicityList(param).then(res => {
            this.publicityList = res.records;
            this.total = res.total
          })
        },
        //查询
        search() {
          let param = {}
          param.publicityTitle = this.queryInfo.publicityTitle;
          param.current = this.queryInfo.current
          param.size = this.queryInfo.size
          param.status = this.queryInfo.status !== null ? this.queryInfo.status : ''
          getPublicityList(param).then(res => {
            this.publicityList = res.records;
            this.total = res.total
            this.current = res.current
          })
        },
  }
      }
}
</script>
@@ -385,4 +453,7 @@
::v-deep(.el-table thead) {
  color: #000000;
}
.freePic ::v-deep .el-upload--picture-card {
  display: none;
}
</style>