Browse Source

消息功能

zhangjie 2 years ago
parent
commit
265e38f66b

+ 14 - 5
src/api.js

@@ -513,12 +513,21 @@ export const logTypeList = () => {
 };
 
 // notice -------------------------->
-export const userNoticeList = datas => {
-  return $get(`/api/notice/list`, datas);
+export const userSendNoticeList = datas => {
+  // subject=&stage=&sendUserId=
+  return $get(`/api/message/page_send`, datas);
 };
-export const fetchReleaseNotice = datas => {
-  return $get(`/api/notice/release`, datas);
+export const userReceiveNoticeList = datas => {
+  // subject=&stage=&receiveUserId=&lastId=
+  return $get(`/api/message/page_receive`, datas);
+};
+export const fetchReleaseUnreadNotice = datas => {
+  // subject=&stage=&receiveUserId=
+  return $get(`/api/message/list_receive_unread`, datas);
 };
 export const readNotice = ids => {
-  return $get(`/api/notice/rend`, { ids });
+  return $post(`/api/message/read`, { ids }, "json");
+};
+export const sendNotice = datas => {
+  return $post(`/api/message/send`, datas, "json");
 };

+ 11 - 0
src/assets/styles/marker.less

@@ -1002,6 +1002,17 @@
     padding: 15px;
     overflow: auto;
   }
+  .notice-more {
+    text-align: center;
+    width: 150px;
+    color: tint(@color-act1, 20%);
+    margin: 0 auto;
+    cursor: pointer;
+
+    &:hover {
+      color: @color-act1;
+    }
+  }
   .notice-item {
     margin-bottom: 30px;
   }

+ 155 - 27
src/modules/grading/components/NoticeDialog.vue

@@ -21,7 +21,7 @@
           </div>
         </div>
         <div
-          v-for="user in users"
+          v-for="user in markers"
           :key="user.id"
           class="user-item"
           @click="selectUser(user)"
@@ -36,22 +36,27 @@
       </div>
       <div class="notice-body">
         <div ref="NoticeContent" class="notice-content">
+          <div v-if="hasMore" class="notice-item notice-more" @click="nextPage">
+            获取更多
+          </div>
           <div v-for="notice in notices" :key="notice.id" class="notice-item">
             <div class="notice-item-head">
               <span class="notice-head-users">
-                {{ notice.sendUsers.map(item => item.name).join(",") }}
+                {{ notice.relateUsers }}
               </span>
               <span class="notice-head-time">
-                {{ notice.createTime | timestampFilter }}
+                {{ notice.createTime }}
               </span>
             </div>
             <div class="notice-item-content" v-html="notice.content"></div>
           </div>
         </div>
         <div v-if="IS_MARK_LEADER" class="notice-send">
-          <textarea placeholder="请输入"></textarea>
+          <textarea placeholder="请输入" v-model="content"></textarea>
           <div class="notice-send-footer">
-            <Button type="primary">发送</Button>
+            <Button type="primary" :loading="loading" @click="toSend"
+              >发送</Button
+            >
           </div>
         </div>
       </div>
@@ -61,11 +66,12 @@
 
 <script>
 import { mapState, mapMutations } from "vuex";
-import { noticeList, userList } from "./data";
 import {
-  userNoticeList,
-  fetchReleaseNotice,
+  userSendNoticeList,
+  userReceiveNoticeList,
+  fetchReleaseUnreadNotice,
   readNotice,
+  sendNotice,
   leaderMarkUserList
 } from "@/api";
 import timeMixin from "@/plugins/timeMixin";
@@ -75,11 +81,19 @@ export default {
   mixins: [timeMixin],
   data() {
     return {
+      workId: "",
+      subject: "",
       modalIsShow: false,
       curUserRoleType: this.$ls.get("user", { role: "" }).role,
       userSelectAll: false,
-      users: userList,
-      notices: noticeList
+      markers: [],
+      notices: [],
+      current: 0,
+      size: 10,
+      content: "",
+      hasMore: false,
+      fetching: false,
+      loading: false
     };
   },
   computed: {
@@ -92,7 +106,11 @@ export default {
     }
   },
   mounted() {
-    // this.initData();
+    const [workId, subject] = this.$route.params.subjectId.split("-");
+    this.workId = workId;
+    this.subject = subject;
+
+    this.initData();
   },
   beforeDestroy() {
     this.clearSetTs();
@@ -100,13 +118,14 @@ export default {
   methods: {
     ...mapMutations("marker", ["setShortcut", "recoverShortcut"]),
     async initData() {
-      this.getNoticeList();
-
       if (this.IS_MARK_LEADER) {
         this.getLeaderMarkerList();
+        this.getLeaderMarkerNoticeList();
+        return;
       }
 
       if (this.IS_MARKER) {
+        this.getMarkerNoticeList();
         this.addSetTime(() => {
           this.getNewNotice();
         }, 10 * 1000);
@@ -114,7 +133,9 @@ export default {
     },
     visibleChange(visible) {
       if (visible) {
-        this.setNoticeRead();
+        if (this.IS_MARKER) {
+          this.setNoticeRead();
+        }
         this.goToBottom();
         this.setShortcut([]);
       } else {
@@ -128,33 +149,98 @@ export default {
     },
     async getLeaderMarkerList() {
       const markerId = this.$ls.get("user", { id: "" }).id;
-      const [workId, subject] = this.$route.params.subjectId.split("-");
       const data = await leaderMarkUserList({
-        workId,
-        subject,
+        workId: this.workId,
+        subject: this.subject,
         stage: this.curSubject.stage,
         markerId
       });
-      const users = data || [];
-      this.users = users.map(item => {
+      const markers = data || [];
+      this.markers = markers.map(item => {
         item.selected = false;
         return item;
       });
     },
-    async getNoticeList() {
-      const data = await userNoticeList();
-      this.notices = data || [];
+    async nextPage() {
+      if (this.fetching) return;
+      this.fetching = true;
+
+      this.current++;
+      if (this.IS_MARKER) {
+        await this.getMarkerNoticeList().catch(() => {});
+      } else {
+        await this.getLeaderMarkerNoticeList().catch(() => {});
+      }
+      this.fetching = false;
+    },
+    async getLeaderMarkerNoticeList() {
+      const sendUserId = this.$ls.get("user", { id: "" }).id;
+      const lastId = this.notices.length ? this.notices.slice(-1)[0].id : null;
+      const data = await userSendNoticeList({
+        subject: this.subject,
+        stage: this.curSubject.stage,
+        sendUserId,
+        lastId,
+        page: this.current,
+        size: this.size
+      });
+      const notices = data.content.map(item => {
+        item.receiveUser = JSON.parse(item.receiveUser);
+        item.relateUsers = item.receiveUser.map(user => user.name).join(",");
+        return item;
+      });
+      notices.reverse();
+      this.hasMore = this.current + 1 < data.totalPages;
+      this.notices = [...notices, ...this.notices];
+    },
+    parseMarkerNotice(info) {
+      return {
+        ...info.message,
+        id: info.id,
+        read: info.read,
+        relateUsers: info.message.sendUserName
+      };
+    },
+    async getMarkerNoticeList() {
+      const receiveUserId = this.$ls.get("user", { id: "" }).id;
+      const lastId = this.notices.length ? this.notices.slice(-1)[0].id : null;
+      const data = await userReceiveNoticeList({
+        subject: this.subject,
+        stage: this.curSubject.stage,
+        receiveUserId,
+        lastId,
+        page: this.current,
+        size: this.size
+      });
+      const notices = data.content.map(item => {
+        return this.parseMarkerNotice(item);
+      });
+      notices.reverse();
+      this.hasMore = this.current + 1 < data.totalPages;
+      this.notices = [...notices, ...this.notices];
     },
     async getNewNotice() {
       this.clearSetTs();
 
-      const resData = await fetchReleaseNotice().catch(() => {});
+      const receiveUserId = this.$ls.get("user", { id: "" }).id;
+      const resData = await fetchReleaseUnreadNotice({
+        subject: this.subject,
+        stage: this.curSubject.stage,
+        receiveUserId
+      }).catch(() => {});
       const data = resData || [];
       const noticeIds = this.notices.map(item => item.id);
-      const validNotices = data.filter(item => noticeIds.includes(item.id));
+      const validNotices = data
+        .filter(item => !noticeIds.includes(item.id))
+        .map(item => this.parseMarkerNotice(item));
       if (validNotices.length) {
         this.notices.push(...validNotices);
+        this.open();
         this.goToBottom();
+
+        this.$nextTick(() => {
+          this.setNoticeRead();
+        });
       }
 
       this.addSetTime(() => {
@@ -163,7 +249,7 @@ export default {
     },
     setNoticeRead() {
       const noticeIds = this.notices
-        .filter(item => !item.readed)
+        .filter(item => !item.read)
         .map(item => item.id);
       if (!noticeIds.length) return;
       readNotice(noticeIds);
@@ -175,7 +261,7 @@ export default {
       this.modalIsShow = true;
     },
     selectChange() {
-      this.userSelectAll = !this.users.some(item => !item.selected);
+      this.userSelectAll = !this.markers.some(item => !item.selected);
     },
     selectUser(user) {
       user.selected = !user.selected;
@@ -183,9 +269,51 @@ export default {
     },
     selectAll() {
       this.userSelectAll = !this.userSelectAll;
-      this.users.forEach(user => {
+      this.markers.forEach(user => {
         user.selected = this.userSelectAll;
       });
+    },
+    async toSend() {
+      if (!this.content) {
+        this.$Message.error("请输入内容");
+        return;
+      }
+
+      const user = this.$ls.get("user", { id: "", name: "" });
+      const markers = this.markers
+        .filter(item => item.selected)
+        .map(item => {
+          return {
+            id: item.id,
+            name: item.name
+          };
+        });
+
+      if (!markers.length) {
+        this.$Message.error("请选择评卷员");
+        return;
+      }
+
+      if (this.loading) return;
+      this.loading = true;
+
+      const data = {
+        subject: this.subject,
+        stage: this.curSubject.stage,
+        sendUserId: user.id,
+        sendUserName: user.name,
+        content: this.content,
+        markers
+      };
+      const res = await sendNotice(data).catch(() => {});
+      this.loading = false;
+      if (!res) return;
+
+      this.content = "";
+      res.receiveUser = JSON.parse(res.receiveUser);
+      res.relateUsers = res.receiveUser.map(item => item.name).join(",");
+      this.notices.push({ ...res });
+      this.goToBottom();
     }
   }
 };

+ 1 - 1
src/modules/grading/leader/LeaderGrading.vue

@@ -34,7 +34,7 @@
         ref="GradeAction"
         v-if="curPaper.id"
       ></grade-action>
-      <grade-ribbon ref="GradeRibbon"></grade-ribbon>
+      <grade-ribbon v-if="curSubject.id" ref="GradeRibbon"></grade-ribbon>
     </div>
 
     <div class="marker-body">

+ 1 - 1
src/modules/grading/marker/MarkerGrading.vue

@@ -30,7 +30,7 @@
         ref="GradeAction"
         v-if="curPaper.id"
       ></grade-action>
-      <grade-ribbon ref="GradeRibbon"></grade-ribbon>
+      <grade-ribbon v-if="curSubject.id" ref="GradeRibbon"></grade-ribbon>
     </div>
 
     <div class="marker-body">

+ 1 - 1
src/modules/mark/leader/LeaderMarking.vue

@@ -28,7 +28,7 @@
         v-if="curPaper.id"
         ref="GradeAction"
       ></mark-action>
-      <grade-ribbon ref="GradeRibbon"></grade-ribbon>
+      <grade-ribbon v-if="curSubject.id" ref="GradeRibbon"></grade-ribbon>
     </div>
 
     <div class="marker-body">

+ 16 - 3
src/modules/mark/marker/MarkerMarking.vue

@@ -28,7 +28,7 @@
         ref="GradeAction"
         v-if="curPaper.id"
       ></mark-action>
-      <grade-ribbon ref="GradeRibbon"></grade-ribbon>
+      <grade-ribbon v-if="curSubject.id" ref="GradeRibbon"></grade-ribbon>
     </div>
 
     <div class="marker-body">
@@ -120,6 +120,7 @@ import GradeRibbon from "../../grading/components/GradeRibbon";
 import {
   getParamsSet,
   markerTaskList,
+  subjectDetail,
   markerChangeLevelPaperList,
   markerScoreTotalStatData,
   workLevelList,
@@ -168,7 +169,6 @@ export default {
       subjectId: this.$route.params.subjectId,
       subject: "",
       workSubject: {},
-      curSubject: {},
       changeStage: 0, // 是否显示改档及改档打分
       curStandardGradeId: "",
       levels: [],
@@ -187,7 +187,14 @@ export default {
     };
   },
   computed: {
-    ...mapState("marker", ["paramsSet", "page", "steps", "curStep", "curArea"]),
+    ...mapState("marker", [
+      "paramsSet",
+      "page",
+      "steps",
+      "curStep",
+      "curArea",
+      "curSubject"
+    ]),
     markerImageListClasses() {
       return ["marker-image-list", `marker-image-list-${this.page.size}`];
     }
@@ -209,6 +216,7 @@ export default {
       "setSteps",
       "setCurArea",
       "setCurStep",
+      "setCurSubject",
       "setCurUserRoleType",
       "setShortcut",
       "clearState"
@@ -216,6 +224,7 @@ export default {
     initData() {
       this.getParamsSetInfo();
       this.getWorkLevels();
+      this.getSubjectDetail();
     },
     async getParamsSetInfo() {
       const data = await getParamsSet(this.workId);
@@ -223,6 +232,10 @@ export default {
       this.changeStage = this.paramsSet.scoreConfig.changeStage;
       this.paramsSetReady = true;
     },
+    async getSubjectDetail() {
+      const curSubject = await subjectDetail(this.subjectId);
+      this.setCurSubject(curSubject || {});
+    },
     async getList() {
       const datas = {
         ...this.filter,