Administrator
2021-07-14 4873e63b91c6a059b525c394236c72ac4bf32b3b
新增通知公告,附件上传下载
3 files modified
1 files added
598 ■■■■ changed files
src/api/desk/notice.js 13 ●●●●● patch | view | raw | blame | history
src/router/views/index.js 28 ●●●●● patch | view | raw | blame | history
src/views/desk/notice.vue 212 ●●●● patch | view | raw | blame | history
src/views/resource/uploadNotice.vue 345 ●●●●● patch | view | raw | blame | history
src/api/desk/notice.js
@@ -12,6 +12,18 @@
  })
}
export const getListPage = (current, size, params) => {
    return request({
        url: '/api/blade-desk/notice/page',
        method: 'get',
        params: {
            ...params,
            current,
            size,
        }
    })
}
export const remove = (ids) => {
  return request({
    url: '/api/blade-desk/notice/remove',
@@ -47,4 +59,3 @@
    }
  })
}
src/router/views/index.js
@@ -161,6 +161,34 @@
      component: () =>
        import( /* webpackChunkName: "views" */ '@/views/management/register')
    }]
    },
    {
        path: '/desk',
        redirect: '/desk/notice',
        component: Layout,
        children: [{
            path: 'notice',
            name: '通知公告',
            meta: {
                i18n: 'index',
            },
            component: () =>
                import ( /* webpackChunkName: "views" */ '@/views/desk/notice')
        }]
    },
    {
        path: '/resource',
        redirect: '/resource/uploadNotice',
        component: Layout,
        children: [{
            path: 'uploadNotice',
            name: '附件上传',
            meta: {
                i18n: 'index',
            },
            component: () =>
                import ( /* webpackChunkName: "views" */ '@/views/resource/uploadNotice')
        }]
  }, {
    path: '/management',
    redirect: '/management/index',
src/views/desk/notice.vue
@@ -1,6 +1,7 @@
<template>
  <basic-container>
    <avue-crud :option="option"
    <avue-crud
      :option="option"
               :table-loading="loading"
               :data="data"
               :page.sync="page"
@@ -11,32 +12,48 @@
               @row-update="rowUpdate"
               @row-save="rowSave"
               :before-open="beforeOpen"
      @filter="filterChange"
               @search-change="searchChange"
               @search-reset="searchReset"
               @selection-change="selectionChange"
               @current-change="currentChange"
               @size-change="sizeChange"
               @refresh-change="refreshChange"
               @on-load="onLoad">
      @on-load="onLoad"
    >
      <template slot="menuLeft">
        <el-button type="danger"
        <el-button
          type="danger"
                   size="small"
                   icon="el-icon-delete"
                   plain
                   v-if="permission.notice_delete"
                   @click="handleDelete">删 除
          v-if="deptCategory"
          @click="handleDelete"
          >删 除
        </el-button>
        <!-- v-if="permission.notice_delete" -->
      </template>
      <template slot-scope="{row}"
                slot="category">
      <template slot-scope="{ row }" slot="category">
        <el-tag>{{row.categoryName}}</el-tag>
      </template>
      <template slot-scope="{ type, size, row }" slot="menu">
        <el-button :size="size" :type="type" @click="handleUploadPage(row)"
          >附件上传
        </el-button>
        <!-- <el-button
          v-if="!deptCategory"
          :size="size"
          :type="type"
          @click="handleUploadPage(row)"
          >附件查看
        </el-button> -->
      </template>
    </avue-crud>
  </basic-container>
</template>
<script>
  import {getList, remove, update, add, getNotice} from "@/api/desk/notice";
import { getListPage, remove, update, add, getNotice } from "@/api/desk/notice";
  import {mapGetters} from "vuex";
  export default {
@@ -45,24 +62,33 @@
        form: {},
        query: {},
        loading: true,
      deptCategory: "",
      deptId: "",
      userId: "",
      permissionAdd: "",
      permissionDelete: "",
      permissionView: "",
      permissionEdit: "",
        page: {
          pageSize: 10,
          currentPage: 1,
          total: 0
        total: 0,
        },
        selectionList: [],
        option: {
          height: 'auto',
        height: "auto",
          calcHeight: 30,
          dialogWidth: 950,
          tip: false,
          searchShow: true,
          searchMenuSpan: 6,
          border: true,
        border: false,
          index: true,
        stripe: true,
          viewBtn: true,
          selection: true,
          excelBtn: true,
        excelBtn: false,
        menuWidth: 320,
          dialogClickModal: false,
          column: [
            {
@@ -71,29 +97,55 @@
              span: 24,
              row: true,
              search: true,
              rules: [{
            rules: [
              {
                required: true,
                message: "请输入通知标题",
                trigger: "blur"
              }]
                trigger: "blur",
            },
            ],
          },
          // {
          //   label: "通知类型",
          //   type: "select",
          //   dicUrl: "/api/blade-system/dict/dictionary?code=notice",
          //   props: {
          //     label: "dictValue",
          //     value: "dictKey",
          //   },
          //   dataType: "number",
          //   slot: true,
          //   addDisplay: false,
          //   editDisplay: false,
          //   defaultValue: "1",
          //   prop: "category",
          //   search: true,
          //   rules: [
          //     {
          //       required: true,
          //       message: "请输入通知类型",
          //       trigger: "blur",
          //     },
          //   ],
          // },
            {
              label: "通知类型",
              type: "select",
              dicUrl: "/api/blade-system/dict/dictionary?code=notice",
            label: "发布单位",
            prop: "deptId",
            type: "tree",
            dicUrl: "/api/blade-system/dept/lazy-tree",
              props: {
                label: "dictValue",
                value: "dictKey"
              label: "title",
              value: "id",
              },
              dataType: "number",
              slot: true,
              prop: "category",
              search: true,
              rules: [{
            addDisplay: false,
            editDisplay: false,
            rules: [
              {
                required: true,
                message: "请输入通知类型",
                trigger: "blur"
              }]
                message: "所属组织机构",
                trigger: "click",
              },
            ],
            },
            {
              label: "通知时间",
@@ -107,11 +159,13 @@
              editDisplay: false,
              viewDisplay: false,
              search: true,
              rules: [{
            rules: [
              {
                required: true,
                message: "请输入通知时间",
                trigger: "blur"
              }]
                trigger: "blur",
              },
            ],
            },
            {
              label: "通知日期",
@@ -119,30 +173,32 @@
              type: "date",
              format: "yyyy-MM-dd hh:mm:ss",
              valueFormat: "yyyy-MM-dd hh:mm:ss",
              rules: [{
            rules: [
              {
                required: true,
                message: "请输入通知日期",
                trigger: "click"
              }]
                trigger: "click",
              },
            ],
            },
            {
              label: "通知内容",
              prop: "content",
              component: 'AvueUeditor',
            component: "AvueUeditor",
              options: {
                action: '/api/blade-resource/oss/endpoint/put-file',
              action: "/api/blade-resource/oss/endpoint/put-file",
                props: {
                  res: "data",
                  url: "link",
                }
              },
              },
              hide: true,
              minRows: 6,
              span: 24,
            }
          ]
        },
        data: []
        ],
      },
      data: [],
      };
    },
    computed: {
@@ -152,49 +208,69 @@
          addBtn: this.vaildData(this.permission.notice_add, false),
          viewBtn: this.vaildData(this.permission.notice_view, false),
          delBtn: this.vaildData(this.permission.notice_delete, false),
          editBtn: this.vaildData(this.permission.notice_edit, false)
        editBtn: this.vaildData(this.permission.notice_edit, false),
        };
      },
      ids() {
        let ids = [];
        this.selectionList.forEach(ele => {
      this.selectionList.forEach((ele) => {
          ids.push(ele.id);
        });
        return ids.join(",");
      }
    },
  },
  mounted() {},
    methods: {
    //跳转到附近列表页面
    handleUploadPage(row) {
      this.$router.push({
        path: `/resource/uploadNotice`,
        query: {
          deptId: row.deptId,
        },
      });
    },
      rowSave(row, done, loading) {
        add(row).then(() => {
      row.category = 2;
      row.deptId = this.deptId;
      add(row).then(
        () => {
          this.onLoad(this.page);
          this.$message({
            type: "success",
            message: "操作成功!"
            message: "操作成功!",
          });
          done();
        }, error => {
        },
        (error) => {
          window.console.log(error);
          loading();
        });
        }
      );
      },
      rowUpdate(row, index, done, loading) {
        update(row).then(() => {
      row.category = 2;
      row.deptId = this.deptId;
      update(row).then(
        () => {
          this.onLoad(this.page);
          this.$message({
            type: "success",
            message: "操作成功!"
            message: "操作成功!",
          });
          done();
        }, error => {
        },
        (error) => {
          window.console.log(error);
          loading();
        });
        }
      );
      },
      rowDel(row) {
        this.$confirm("确定将选择数据删除?", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        type: "warning",
        })
          .then(() => {
            return remove(row.id);
@@ -203,7 +279,7 @@
            this.onLoad(this.page);
            this.$message({
              type: "success",
              message: "操作成功!"
            message: "操作成功!",
            });
          });
      },
@@ -232,7 +308,7 @@
        this.$confirm("确定将选择数据删除?", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        type: "warning",
        })
          .then(() => {
            return remove(this.ids);
@@ -241,14 +317,14 @@
            this.onLoad(this.page);
            this.$message({
              type: "success",
              message: "操作成功!"
            message: "操作成功!",
            });
            this.$refs.crud.toggleSelection();
          });
      },
      beforeOpen(done, type) {
        if (["edit", "view"].includes(type)) {
          getNotice(this.form.id).then(res => {
        getNotice(this.form.id).then((res) => {
            this.form = res.data.data;
          });
        }
@@ -264,29 +340,41 @@
        this.onLoad(this.page, this.query);
      },
      onLoad(page, params = {}) {
      this.deptId = JSON.parse(
        window.localStorage.getItem("saber-userInfo")
      ).content.dept_id;
      this.userId = JSON.parse(
        window.localStorage.getItem("saber-userInfo")
      ).content.user_id;
      if (this.deptId != 1123598813738675201) {
        params["deptId"] = this.deptId;
      }
        const {releaseTimeRange} = this.query;
        let values = {
          ...params,
        };
        if (releaseTimeRange) {
          values = {
            ...params,
            releaseTime_datege: releaseTimeRange[0],
            releaseTime_datelt: releaseTimeRange[1],
            ...this.query
          startTime: releaseTimeRange[0],
          endTime: releaseTimeRange[1],
          ...this.query,
          };
          values.releaseTimeRange = null;
        }
        this.loading = true;
        getList(page.currentPage, page.pageSize, values).then(res => {
      getListPage(page.currentPage, page.pageSize, values).then((res) => {
          const data = res.data.data;
          this.page.total = data.total;
          this.data = data.records;
          this.loading = false;
          this.selectionClear();
        });
      }
    }
    },
  },
  };
</script>
src/views/resource/uploadNotice.vue
New file
@@ -0,0 +1,345 @@
<template>
  <basic-container>
    <avue-crud
      :option="option"
      :table-loading="loading"
      :data="data"
      :page.sync="page"
      :permission="permissionList"
      :before-open="beforeOpen"
      v-model="form"
      ref="crud"
      @row-del="rowDel"
      @search-change="searchChange"
      @search-reset="searchReset"
      @selection-change="selectionChange"
      @current-change="currentChange"
      @size-change="sizeChange"
      @refresh-change="refreshChange"
      @on-load="onLoad"
    >
      <template slot="menuLeft">
        <el-button
          type="primary"
          size="small"
          plain
          v-if="permission.attach_upload"
          icon="el-icon-upload2"
          @click="handleUpload"
          >上 传
        </el-button>
        <el-button
          type="danger"
          size="small"
          icon="el-icon-delete"
          plain
          v-if="permission.attach_delete"
          @click="handleDelete"
          >删 除
        </el-button>
      </template>
      <template slot-scope="scope" slot="menu">
        <el-button
          type="text"
          icon="el-icon-download"
          size="small"
          v-if="permission.attach_download"
          @click="handleDownload(scope.row)"
          >下载
        </el-button>
      </template>
      <template slot-scope="{ row }" slot="attachSize">
        <el-tag>{{ `${row.attachSize} KB` }}</el-tag>
      </template>
    </avue-crud>
    <el-dialog
      title="附件管理"
      append-to-body
      :visible.sync="attachBox"
      width="555px"
    >
      <avue-form
        ref="form"
        :option="attachOption"
        v-model="attachForm"
        :upload-after="uploadAfter"
      >
      </avue-form>
    </el-dialog>
  </basic-container>
</template>
<script>
import { getList, getDetail, remove } from "@/api/resource/attach";
import { mapGetters } from "vuex";
export default {
  data() {
    var type = 4;
    var deptid = this.$route.query.deptId;
    return {
      form: {},
      query: {},
      putParam: "",
      loading: true,
      page: {
        pageSize: 10,
        currentPage: 1,
        total: 0,
      },
      attachBox: false,
      selectionList: [],
      option: {
        height: "auto",
        calcHeight: 30,
        tip: false,
        searchShow: true,
        searchMenuSpan: 6,
        border: false,
        index: true,
        stripe: true,
        viewBtn: true,
        selection: true,
        dialogClickModal: false,
        column: [
          {
            label: "附件地址",
            prop: "link",
            rules: [
              {
                required: true,
                message: "请输入附件地址",
                trigger: "blur",
              },
            ],
          },
          {
            label: "附件域名",
            prop: "domain",
            search: true,
            rules: [
              {
                required: true,
                message: "请输入附件域名",
                trigger: "blur",
              },
            ],
          },
          {
            label: "附件名称",
            prop: "name",
            search: true,
            rules: [
              {
                required: true,
                message: "请输入附件名称",
                trigger: "blur",
              },
            ],
          },
          {
            label: "附件原名",
            prop: "originalName",
            search: true,
            rules: [
              {
                required: true,
                message: "请输入附件原名",
                trigger: "blur",
              },
            ],
          },
          {
            label: "附件拓展名",
            prop: "extension",
            rules: [
              {
                required: true,
                message: "请输入附件拓展名",
                trigger: "blur",
              },
            ],
          },
          {
            label: "附件大小",
            prop: "attachSize",
            slot: true,
            rules: [
              {
                required: true,
                message: "请输入附件大小",
                trigger: "blur",
              },
            ],
          },
        ],
      },
      data: [],
      attachForm: {},
      attachOption: {
        submitBtn: false,
        emptyBtn: false,
        column: [
          {
            label: "附件上传",
            prop: "attachFile",
            type: "upload",
            drag: true,
            loadText: "模板上传中,请稍等",
            span: 24,
            propsHttp: {
              res: "data",
            },
            action:
              "/api/blade-resource/oss/endpoint/put-file-attach?type=" +
              type +
              "&deptid=" +
              deptid,
          },
        ],
      },
    };
  },
  computed: {
    ...mapGetters(["permission"]),
    permissionList() {
      return {
        addBtn: false,
        editBtn: false,
        viewBtn: false,
        delBtn: this.vaildData(this.permission.attach_delete, false),
      };
    },
    ids() {
      let ids = [];
      this.selectionList.forEach((ele) => {
        ids.push(ele.id);
      });
      return ids.join(",");
    },
  },
  mounted() {
    var flag = false,
      i = 0,
      ind = null;
    this.$store.state.tags.tagList.forEach((item, index) => {
      if (item.label == "附件上传") {
        if (flag == false) {
          ind = index;
          flag = true;
        }
        i++;
      }
    });
    if (i > 1) {
      this.$store.state.tags.tagList.splice(ind, 1);
    }
  },
  methods: {
    handleUpload() {
      this.attachBox = true;
    },
    uploadAfter(res, done, loading, column) {
      window.console.log(column);
      this.attachBox = false;
      this.refreshChange();
      done();
    },
    handleDownload(row) {
      window.open(`${row.link}`);
    },
    rowDel(row) {
      this.$confirm("确定将选择数据删除?", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          return remove(row.id);
        })
        .then(() => {
          this.onLoad(this.page);
          this.$message({
            type: "success",
            message: "操作成功!",
          });
        });
    },
    handleDelete() {
      if (this.selectionList.length === 0) {
        this.$message.warning("请选择至少一条数据");
        return;
      }
      this.$confirm("确定将选择数据删除?", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          return remove(this.ids);
        })
        .then(() => {
          this.onLoad(this.page);
          this.$message({
            type: "success",
            message: "操作成功!",
          });
          this.$refs.crud.toggleSelection();
        });
    },
    beforeOpen(done, type) {
      if (["edit", "view"].includes(type)) {
        getDetail(this.form.id).then((res) => {
          this.form = res.data.data;
        });
      }
      done();
    },
    searchReset() {
      this.query = {};
      this.onLoad(this.page);
    },
    searchChange(params, done) {
      this.query = params;
      this.page.currentPage = 1;
      this.onLoad(this.page, params);
      done();
    },
    selectionChange(list) {
      this.selectionList = list;
    },
    selectionClear() {
      this.selectionList = [];
      this.$refs.crud.toggleSelection();
    },
    currentChange(currentPage) {
      this.page.currentPage = currentPage;
    },
    sizeChange(pageSize) {
      this.page.pageSize = pageSize;
    },
    refreshChange() {
      this.onLoad(this.page, this.query);
    },
    onLoad(page, params = {}) {
      params.type = 4;
      params.deptid = this.$route.query.deptId;
      this.loading = true;
      getList(
        page.currentPage,
        page.pageSize,
        Object.assign(params, this.query)
      ).then((res) => {
        const data = res.data.data;
        this.page.total = data.total;
        this.data = data.records;
        this.loading = false;
        this.selectionClear();
      });
    },
  },
};
</script>
<style>
</style>