From 71094b0c93a02d87b3b5045016bdf51c5fa547d0 Mon Sep 17 00:00:00 2001
From: guoshilong <123456>
Date: Wed, 28 Feb 2024 16:38:40 +0800
Subject: [PATCH] 消息管理

---
 src/views/message/components/DeptUserTable.vue |  242 ++++++++++++++++++++++
 src/views/message/sysMessage.vue               |   27 -
 src/views/message/userMessage.vue              |  357 ++++++++++++++++++++++++++++++++
 3 files changed, 608 insertions(+), 18 deletions(-)

diff --git a/src/views/message/components/DeptUserTable.vue b/src/views/message/components/DeptUserTable.vue
new file mode 100644
index 0000000..8bd9c85
--- /dev/null
+++ b/src/views/message/components/DeptUserTable.vue
@@ -0,0 +1,242 @@
+<template>
+  <el-dialog class="dept-user-table-dialog" width="70%" title="选择接收人" modal-append-to-body="false"
+             append-to-body="true"
+             :close-on-click-model="true" :visible.sync="showDialog" @close="showDialog = false">
+    <div class="left">
+      <el-scrollbar>
+        <basic-container>
+          <avue-tree :option="treeOption" :data="treeData" @node-click="nodeClick"/>
+        </basic-container>
+      </el-scrollbar>
+    </div>
+    <div class="right">
+      <avue-crud :option="option" :search.sync="search" :table-loading="loading" :data="data" ref="crud"
+                 v-model="form"
+                 :page.sync="page" @search-change="searchChange"
+                 @search-reset="searchReset" @selection-change="selectionChange" @current-change="currentChange"
+                 @size-change="sizeChange" @refresh-change="refreshChange" @on-load="onLoad"></avue-crud>
+    </div>
+    <div slot="footer" class="dialog-footer">
+      <el-button @click="showDialog = false">取 消</el-button>
+      <el-button type="primary" @click="submit">确 定</el-button>
+    </div>
+  </el-dialog>
+
+
+</template>
+
+<script>
+import {getDeptLazyTree} from "@/api/system/dept";
+import {getList} from "@/api/system/user";
+import {mapGetters} from "vuex";
+
+export default {
+  name: "DeptUserTable",
+  data() {
+    return {
+      showDialog: false,
+      form: {},
+      search: {},
+      selectionList: [],
+      query: {},
+      loading: true,
+      platformLoading: false,
+      page: {
+        pageSize: 10,
+        currentPage: 1,
+        total: 0
+      },
+      treeDeptId: '',
+      treeData: [],
+      treeOption: {
+        nodeKey: 'id',
+        lazy: true,
+        treeLoad: function (node, resolve) {
+          const parentId = (node.level === 0) ? 0 : node.data.id
+          getDeptLazyTree(parentId).then(res => {
+            resolve(res.data.data.map(item => {
+              return {
+                ...item,
+                leaf: !item.hasChildren
+              }
+            }))
+          })
+        },
+        addBtn: false,
+        menu: false,
+        size: 'small',
+        props: {
+          labelText: '标题',
+          label: 'title',
+          value: 'value',
+          children: 'children'
+        }
+      },
+      option: {
+        height: 'auto',
+        calcHeight: 120,
+        tip: false,
+        searchShow: true,
+        searchMenuSpan: 6,
+        border: true,
+        index: true,
+        selection: true,
+        viewBtn: true,
+        dialogType: 'drawer',
+        dialogClickModal: false,
+        menu: false,
+        addBtn: false,
+        rowKey: "id",
+        reserveSelection: true,
+        column: [
+          {
+            label: "登录账号",
+            prop: "account",
+            search: true,
+            searchLabelWidth: 76,
+            display: false
+          },
+          {
+            label: "用户姓名",
+            prop: "realName",
+            search: true,
+            display: false
+          },
+          {
+            label: "所属角色",
+            prop: "roleName",
+            slot: true,
+            display: false
+          },
+          {
+            label: "电话",
+            prop: "phone",
+            slot: true,
+            display: false
+          },
+          {
+            label: "邮箱",
+            prop: "email",
+            slot: true,
+            display: false
+          },
+        ],
+      },
+      data: [],
+    }
+  },
+  computed: {
+    ...mapGetters(["userInfo", "permission"]),
+    ids() {
+      let ids = []
+      this.selectionList.forEach(ele => {
+        console.log(ele, "---------")
+        ids.push(ele.id)
+      })
+      return ids.join(",")
+    },
+    idsList() {
+      let ids = []
+      this.selectionList.forEach(ele => {
+        ids.push({
+          id: ele.id,
+          name: ele.name
+        })
+      })
+      return ids
+    }
+  },
+  methods: {
+    submit() {
+      this.$emit("selectPersonList", this.idsList)
+      this.showDialog = false
+    },
+
+    show() {
+      this.showDialog = true
+    },
+
+    nodeClick(data) {
+      this.treeDeptId = data.id
+      this.page.currentPage = 1
+      this.onLoad(this.page)
+    },
+    searchReset() {
+      this.query = {}
+      this.treeDeptId = ''
+      this.onLoad(this.page)
+    },
+    searchChange(params, done) {
+      this.query = params
+      this.page.currentPage = 1
+      this.onLoad(this.page, params)
+      done()
+    },
+    selectionChange(list) {
+      console.log(list, "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 = {}) {
+      this.loading = true
+      getList(page.currentPage, page.pageSize, Object.assign(params, this.query), this.treeDeptId).then(res => {
+        const data = res.data.data
+        this.page.total = data.total
+        this.data = data.records
+        this.loading = false
+        // this.selectionClear()
+      })
+    },
+  }
+}
+</script>
+
+<style lang="scss">
+
+
+.dept-user-table-dialog {
+  margin: 0 !important;
+
+  .el-dialog {
+    display: flex;
+    flex-direction: column;
+    margin: auto !important;
+    position: absolute;
+    top: 0 !important;
+    left: 0 !important;
+    right: 0 !important;
+    bottom: 0 !important;
+    //width: 1000px !important;
+    height: 800px !important;
+
+    .el-dialog__body {
+      height: 0 !important;
+      flex: 1;
+      display: flex;
+
+      .left {
+        width: 0;
+        flex: 2;
+      }
+
+      .right {
+        margin-left: 10px;
+        flex: 9;
+      }
+    }
+  }
+}
+
+</style>
diff --git a/src/views/message/sysMessage.vue b/src/views/message/sysMessage.vue
index a0d1c4f..92f1c1a 100644
--- a/src/views/message/sysMessage.vue
+++ b/src/views/message/sysMessage.vue
@@ -62,15 +62,16 @@
         editBtn: false,
         addBtnText: "消息发送",
         saveBtnText: "发送",
-        delBtn:false,
+        delBtn: false,
         column: [
           {
             label: "消息类型",
             prop: "type",
             type: "checkbox",
-            search:true,
+            dataType: "string",
+            search: true,
             searchSpan: 4,
-            searchLabelWidth:96,
+            searchLabelWidth: 96,
             row: true,
             dicUrl: "/api/blade-system/dict-biz/dictionary?code=messageType",
             props: {
@@ -91,6 +92,7 @@
             multiple: true,
             dicUrl: `/api/blade-system/dept/lazy-list`,
             dicData: [],
+            dataType: "string",
             props: {
               label: 'name',
               value: 'id'
@@ -129,7 +131,7 @@
             label: "发送时间",
             prop: "createTime",
             span: 24,
-            display:false
+            display: false
           },
           {
             label: "发送时间",
@@ -141,7 +143,7 @@
             hide: true,
             display: false,
             search: true,
-            searchLabelWidth:96,
+            searchLabelWidth: 96,
           },
         ]
       },
@@ -192,19 +194,8 @@
     },
 
     rowSave(row, done, loading) {
-      console.log(typeof row.type,"+++++++++++")
-      if (typeof  row.type == 'object'){
-        row.type = row.type.sort((a,b)=>a-b).join(",")
-      }else{
-        row.type = row.type.split(",").sort((a,b)=>a-b).join(",")
-      }
-
-      if (typeof  row.receiver == 'object'){
-        row.receiver = row.receiver.join(",")
-      }
-
-      // row.receiver = row.receiver.join(",")
-      // row.type = row.type.join(",")
+      console.log(row)
+      row.type = row.type.split(",").sort((a, b) => a - b).join(",")
       row['messageResource'] = 1
       customizeSave(row).then(() => {
         this.onLoad(this.page);
diff --git a/src/views/message/userMessage.vue b/src/views/message/userMessage.vue
new file mode 100644
index 0000000..70329a2
--- /dev/null
+++ b/src/views/message/userMessage.vue
@@ -0,0 +1,357 @@
+<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-update="rowUpdate"
+               @row-save="rowSave"
+               @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="danger"
+                   size="small"
+                   icon="el-icon-delete"
+                   plain
+                   v-if="permission.messageRecord_delete"
+                   @click="handleDelete">删 除
+        </el-button>
+      </template>
+
+      <template slot-scope="{disabled,size}" slot="receiverForm">
+        <div style="display: flex">
+            <el-input :disabled="disabled" :size="size" v-model="form.receiver" placeholder="请选择接收人"></el-input>
+
+          <div style="margin-left: 10px">
+            <el-button type="primary" size="small" @click="showDialog">选择</el-button>
+          </div>
+        </div>
+      </template>
+    </avue-crud>
+
+
+
+    <DeptUserTable ref="deptUserTable" @selectPersonList="selectPersonList"></DeptUserTable>
+
+
+
+  </basic-container>
+</template>
+
+<script>
+import {getList, getDetail, add, update, remove, customizeSave} from "@/api/messageRecord/messageRecord";
+import {mapGetters} from "vuex";
+import {getDeptLazyTree, getDeptUserTree, getLazyList} from "@/api/system/dept";
+import DeptUserTable from "@/views/message/components/DeptUserTable.vue";
+
+export default {
+  components: {DeptUserTable},
+  data() {
+    return {
+      form: {},
+      query: {},
+      loading: true,
+      page: {
+        pageSize: 10,
+        currentPage: 1,
+        total: 0
+      },
+      selectionList: [],
+      option: {
+        dialogDirection:'rtl',
+        dialogType:'drawer',
+        height: 'auto',
+        calcHeight: 30,
+        tip: false,
+        searchShow: true,
+        searchMenuSpan: 6,
+        border: true,
+        index: true,
+        viewBtn: true,
+        dialogClickModal: false,
+        editBtn: false,
+        addBtnText: "消息发送",
+        saveBtnText: "发送",
+        delBtn: false,
+        selection: true,
+        column: [
+          {
+            label: "消息类型",
+            prop: "type",
+            type: "checkbox",
+            dataType: "string",
+            search: true,
+            searchSpan: 4,
+            searchLabelWidth: 96,
+            row: true,
+            dicUrl: "/api/blade-system/dict-biz/dictionary?code=messageType",
+            props: {
+              label: "dictValue",
+              value: "dictKey",
+            },
+            rules: [{
+              required: true,
+              message: "请选择消息类型",
+              trigger: "blur"
+            }]
+          },
+          {
+            label: "接收人",
+            prop: "receiver",
+            type:"select",
+            formslot:true,
+            disabled:true,
+            hide:true,
+            span: 24,
+            viewDisplay:false,
+            rules: [{
+              required: true,
+              message: "请选择接收人",
+              trigger: "blur"
+            }]
+          },
+          {
+            label: "接收人",
+            prop: "userName",
+            addDisplay: false,
+          },
+          {
+            label: "标题",
+            prop: "title",
+            type: "input",
+            span: 24,
+            rules: [{
+              required: true,
+              message: "请输入标题",
+              trigger: "blur"
+            }]
+          },
+          {
+            label: "内容",
+            prop: "content",
+            type: "textarea",
+            minRow: 5,
+            span: 24,
+            rules: [{
+              required: true,
+              message: "请输入内容",
+              trigger: "blur"
+            }]
+          },
+          {
+            label: "发送时间",
+            prop: "createTime",
+            span: 24,
+            display: false
+          },
+          {
+            label: "发送时间",
+            prop: "dateTime",
+            type: "daterange",
+            format: "yyyy-MM-dd",
+            valueFormat: "yyyy-MM-dd",
+            searchRange: true,
+            hide: true,
+            display: false,
+            search: true,
+            searchLabelWidth: 96,
+          },
+        ]
+      },
+      data: [],
+
+      personList:[],
+    };
+  },
+  computed: {
+    ...mapGetters(["permission", "userInfo"]),
+    permissionList() {
+      return {
+        addBtn: this.vaildData(this.permission.messageRecord_add, false),
+        viewBtn: this.vaildData(this.permission.messageRecord_view, false),
+        delBtn: this.vaildData(this.permission.messageRecord_delete, false),
+        editBtn: this.vaildData(this.permission.messageRecord_edit, false)
+      };
+    },
+    ids() {
+      let ids = [];
+      this.selectionList.forEach(ele => {
+        ids.push(ele.id);
+      });
+      return ids.join(",");
+    }
+  },
+  created() {
+    // this.getTreeData()
+  },
+  methods: {
+    selectPersonList(personList){
+      console.log(personList,"++++++++++++")
+
+      this.personList = personList
+
+     let nameList = personList.map(e=>{
+       return e.name
+     })
+      this.form.receiver = nameList.join(",")
+    },
+
+    showDialog(){
+      this.$refs.deptUserTable.show()
+    },
+
+    getTreeData() {
+      getDeptUserTree({id: this.userInfo.dept_id}).then(res => {
+        console.log(res, "+++++++++++")
+        let data = res.data.data
+        let receiver = this.findObject(this.option.column, 'receiver')
+        receiver.dicData = data
+      })
+
+    },
+
+    rowSave(row, done, loading) {
+      console.log(row)
+      row.type = row.type.split(",").sort((a, b) => a - b).join(",")
+      row['messageResource'] = 2
+      row.receiver = this.personList.map(e=>e.id).join(",")
+      customizeSave(row).then(() => {
+        this.onLoad(this.page);
+        this.$message({
+          type: "success",
+          message: "操作成功!"
+        });
+        done();
+      }, error => {
+        loading();
+        window.console.log(error);
+      });
+    },
+    rowUpdate(row, index, done, loading) {
+      update(row).then(() => {
+        this.onLoad(this.page);
+        this.$message({
+          type: "success",
+          message: "操作成功!"
+        });
+        done();
+      }, error => {
+        loading();
+        console.log(error);
+      });
+    },
+    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) {
+      console.log('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 = {}) {
+      this.loading = true;
+      //系统消息
+      params.messageResource = '2'
+      params.createUser = this.userInfo.user_id
+      const {dateTime} = this.query
+      let values = {...params,}
+      if (dateTime) {
+        values = {
+          ...params,
+          startTime: dateTime[0],
+          endTime: dateTime[1],
+          ...this.query,
+        }
+        values.dateTime = null
+      }
+
+      getList(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>
+
+<style>
+</style>

--
Gitblit v1.9.3