Bladeren bron

图片管理

Wang-Xiao-Ran 1 jaar geleden
bovenliggende
commit
03393a5085
2 gewijzigde bestanden met toevoegingen van 372 en 0 verwijderingen
  1. 52 0
      src/api/my/jnbImg.js
  2. 320 0
      src/views/my/jnbImg.vue

+ 52 - 0
src/api/my/jnbImg.js

@@ -0,0 +1,52 @@
+import request from '@/utils/request'
+
+// 查询图片管理列表
+export function listImg(query) {
+  return request({
+    url: '/my/img/list',
+    method: 'get',
+    params: query
+  })
+}
+
+// 查询图片管理详细
+export function getImg(id) {
+  return request({
+    url: '/my/img/' + id,
+    method: 'get'
+  })
+}
+
+// 新增图片管理
+export function addImg(data) {
+  return request({
+    url: '/my/img',
+    method: 'post',
+    data: data
+  })
+}
+
+// 修改图片管理
+export function updateImg(data) {
+  return request({
+    url: '/my/img',
+    method: 'put',
+    data: data
+  })
+}
+
+// 删除图片管理
+export function delImg(id) {
+  return request({
+    url: '/my/img/' + id,
+    method: 'delete'
+  })
+}
+
+//确实是否存在状态为开启的封面图片
+export function isCover(){
+  return request({
+    url: '/my/img/isCover',
+    method: 'get'
+  })
+}

+ 320 - 0
src/views/my/jnbImg.vue

@@ -0,0 +1,320 @@
+<template>
+  <div class="app-container">
+    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
+      <el-form-item label="图片名称" prop="imgName">
+        <el-input
+          v-model="queryParams.imgName"
+          placeholder="请输入图片名称"
+          clearable
+          @keyup.enter.native="handleQuery"
+        />
+      </el-form-item>
+      <el-form-item>
+        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
+        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
+      </el-form-item>
+    </el-form>
+
+    <el-row :gutter="10" class="mb8">
+      <el-col :span="1.5">
+        <el-button
+          type="primary"
+          plain
+          icon="el-icon-plus"
+          size="mini"
+          @click="handleAdd"
+          v-hasPermi="['system:jnbImg:add']"
+        >新增
+        </el-button>
+      </el-col>
+      <el-col :span="1.5">
+        <el-button
+          type="success"
+          plain
+          icon="el-icon-edit"
+          size="mini"
+          :disabled="single"
+          @click="handleUpdate"
+          v-hasPermi="['system:jnbImg:edit']"
+        >修改
+        </el-button>
+      </el-col>
+      <el-col :span="1.5">
+        <el-button
+          type="danger"
+          plain
+          icon="el-icon-delete"
+          size="mini"
+          :disabled="multiple"
+          @click="handleDelete"
+          v-hasPermi="['system:jnbImg:del']"
+        >删除
+        </el-button>
+      </el-col>
+      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
+    </el-row>
+
+    <el-table v-loading="loading" :data="imgList" @selection-change="handleSelectionChange">
+      <el-table-column type="selection" width="55" align="center"/>
+      <el-table-column label="图片名称" align="center" prop="imgName"/>
+      <el-table-column label="图片" align="center" prop="imgUrl">
+        <template slot-scope="scope">
+          <image-preview :src="scope.row.imgUrl" :width="50" :height="50"/>
+        </template>
+      </el-table-column>
+      <el-table-column label="状态" align="center" prop="imgSwitch">
+        <template slot-scope="scope">
+          <dict-tag :options="dict.type.jnb_img_switch" :value="scope.row.imgSwitch"/>
+        </template>
+      </el-table-column>
+      <el-table-column label="图片类型" align="center" prop="imgType">
+        <template slot-scope="scope">
+          <dict-tag :options="dict.type.jnb_img_type" :value="scope.row.imgType"/>
+        </template>
+      </el-table-column>
+      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
+        <template slot-scope="scope">
+          <el-button
+            size="mini"
+            type="text"
+            icon="el-icon-edit"
+            @click="handleUpdate(scope.row)"
+            v-hasPermi="['system:jnbImg:edit']"
+          >修改
+          </el-button>
+          <el-button
+            size="mini"
+            type="text"
+            icon="el-icon-delete"
+            @click="handleDelete(scope.row)"
+            v-hasPermi="['system:jnbImg:del']"
+          >删除
+          </el-button>
+        </template>
+      </el-table-column>
+    </el-table>
+
+    <pagination
+      v-show="total>0"
+      :total="total"
+      :page.sync="queryParams.pageNum"
+      :limit.sync="queryParams.pageSize"
+      @pagination="getList"
+    />
+
+    <!-- 添加或修改图片管理对话框 -->
+    <el-dialog :title="title" :visible.sync="open" width="600px" append-to-body>
+      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
+        <el-row :gutter="24">
+          <el-col :span="12">
+            <el-form-item label="图片类型" prop="imgType">
+              <el-select v-model="form.imgType" placeholder="请选择图片类型">
+                <el-option
+                  v-for="dict in dict.type.jnb_img_type"
+                  :key="dict.value"
+                  :label="dict.label"
+                  :value="dict.value"
+                ></el-option>
+              </el-select>
+            </el-form-item>
+          </el-col>
+          <el-col :span="12">
+            <el-form-item label="图片名称" prop="imgName">
+              <el-input v-model="form.imgName" placeholder="请输入图片名称"/>
+            </el-form-item>
+          </el-col>
+        </el-row>
+        <el-form-item label="开关" prop="imgSwitch">
+          <el-radio-group v-model="form.imgSwitch">
+            <el-radio
+              v-for="dict in dict.type.jnb_img_switch"
+              :key="dict.value"
+              :label="dict.value"
+            >{{ dict.label }}
+            </el-radio>
+          </el-radio-group>
+        </el-form-item>
+        <el-form-item label="图片路径" prop="imgUrl">
+          <image-upload v-model="form.imgUrl" limit="1"/>
+        </el-form-item>
+      </el-form>
+      <div slot="footer" class="dialog-footer">
+        <el-button type="primary" @click="submitForm">确 定</el-button>
+        <el-button @click="cancel">取 消</el-button>
+      </div>
+    </el-dialog>
+  </div>
+</template>
+
+<script>
+import {listImg, getImg, delImg, addImg, updateImg, isCover} from "@/api/my/jnbImg";
+
+export default {
+  name: "Img",
+  dicts: ['jnb_img_type', 'jnb_img_switch'],
+  data() {
+    return {
+      // 遮罩层
+      loading: true,
+      // 选中数组
+      ids: [],
+      // 非单个禁用
+      single: true,
+      // 非多个禁用
+      multiple: true,
+      // 显示搜索条件
+      showSearch: true,
+      // 总条数
+      total: 0,
+      // 图片管理表格数据
+      imgList: [],
+      // 弹出层标题
+      title: "",
+      // 是否显示弹出层
+      open: false,
+      // 查询参数
+      queryParams: {
+        pageNum: 1,
+        pageSize: 10,
+        imgUrl: null,
+        imgName: null,
+        imgSwitch: null,
+        imgType: null
+      },
+      // 表单参数
+      form: {},
+      // 表单校验
+      rules: {
+        imgUrl: [
+          {required: true, message: "图片路径不能为空", trigger: "blur"}
+        ],
+        imgName: [
+          {required: true, message: "图片名称不能为空", trigger: "blur"}
+        ],
+        imgSwitch: [
+          {required: true, message: "请选择图片状态", trigger: "change"}
+        ],
+        imgType: [
+          {required: true, message: "图片类型不能为空", trigger: "change"}
+        ]
+      }
+    };
+  },
+  created() {
+    this.getList();
+  },
+  methods: {
+    /** 查询图片管理列表 */
+    getList() {
+      this.loading = true;
+      listImg(this.queryParams).then(response => {
+        this.imgList = response.rows;
+        this.total = response.total;
+        this.loading = false;
+      });
+    },
+    // 取消按钮
+    cancel() {
+      this.open = false;
+      this.reset();
+    },
+    // 表单重置
+    reset() {
+      this.form = {
+        id: null,
+        imgUrl: null,
+        imgName: null,
+        imgSwitch: null,
+        imgType: null
+      };
+      this.resetForm("form");
+    },
+    /** 搜索按钮操作 */
+    handleQuery() {
+      this.queryParams.pageNum = 1;
+      this.getList();
+    },
+    /** 重置按钮操作 */
+    resetQuery() {
+      this.resetForm("queryForm");
+      this.handleQuery();
+    },
+    // 多选框选中数据
+    handleSelectionChange(selection) {
+      this.ids = selection.map(item => item.id)
+      this.single = selection.length !== 1
+      this.multiple = !selection.length
+    },
+    /** 新增按钮操作 */
+    handleAdd() {
+      this.reset();
+      this.open = true;
+      this.title = "添加图片管理";
+    },
+    /** 修改按钮操作 */
+    handleUpdate(row) {
+      this.reset();
+      const id = row.id || this.ids
+      getImg(id).then(response => {
+        this.form = response.data;
+        this.open = true;
+        this.title = "修改图片管理";
+      });
+    },
+    /** 提交按钮 */
+    submitForm() {
+      let flag = true;
+      //如果图片类型为封面图片, 切图片状态为开, 则查询后台是否存在图片状态为开的数据, 不存在返回true, 存在返回false
+      if (this.form.imgType === "1" && this.form.imgSwitch === "switch_on") {
+        isCover().then(res => {
+          if (res.data) {
+            flag = false;
+            this.$modal.msgError("封面图片只能存在一张, 请先关闭其他封面图片");
+          }else{
+            this.isSubmit();
+          }
+        })
+      }else{
+        this.isSubmit();
+      }
+    },
+    isSubmit(){
+      //如果为true, 则继续执行后续代码, 否则停止执行.
+      this.$refs["form"].validate(valid => {
+        if (valid) {
+          if (this.form.id != null) {
+            updateImg(this.form).then(response => {
+              this.$modal.msgSuccess("修改成功");
+              this.open = false;
+              this.getList();
+            });
+          } else {
+            addImg(this.form).then(response => {
+              this.$modal.msgSuccess("新增成功");
+              this.open = false;
+              this.getList();
+            });
+          }
+        }
+      });
+    },
+    /** 删除按钮操作 */
+    handleDelete(row) {
+      const ids = row.id || this.ids;
+      this.$modal.confirm('是否确认删除图片管理编号为"' + ids + '"的数据项?').then(function () {
+        return delImg(ids);
+      }).then(() => {
+        this.getList();
+        this.$modal.msgSuccess("删除成功");
+      }).catch(() => {
+      });
+    },
+    /** 导出按钮操作 */
+    handleExport() {
+      this.download('my/img/export', {
+        ...this.queryParams
+      }, `img_${new Date().getTime()}.xlsx`)
+    }
+  }
+};
+</script>