index.vue 18.1 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728
<script lang="ts" setup name="Layout">
import hotkeys from 'hotkeys-js'
import LinkView from './components/views/link.vue'
import Header from './components/Header/index.vue'
import MainSidebar from './components/MainSidebar/index.vue'
import SubSidebar from './components/SubSidebar/index.vue'
import Tabbar from './components/Tabbar/index.vue'
import useSettingsStore from '@/store/modules/settings'
import useKeepAliveStore from '@/store/modules/keepAlive'
import useKeepAliveCompCache from '@/store/modules/keepAliveCompCache'
import useMenuStore from '@/store/modules/menu'
import { markRaw } from "vue";
import { commonPageConfig } from "@/utils/enum";
import {
  Close
} from "@element-plus/icons-vue";
import { getAllMessageList, getMessageCount, updateMessageState, updateAllFinish } from '@/api/modules/queryService';
import useUserStore from "@/store/modules/user";
import useDataFinanceStore from "@/store/modules/dataFinance";
import Moment from 'moment';

const router = useRouter()
const userStore = useUserStore();
const userData = JSON.parse(userStore.userData)
const financeStore = useDataFinanceStore();
const { proxy } = getCurrentInstance() as any;

const routeInfo = useRoute()

const settingsStore = useSettingsStore()
const keepAliveStore = useKeepAliveStore()
const menuStore = useMenuStore()
const keepAliveCompCache = useKeepAliveCompCache();

const isLink = computed(() => !!routeInfo.meta.link)
const isRouterAlive = ref(true);
// 局部组件刷新
const reload = () => {
  isRouterAlive.value = false;
  nextTick(() => {
    isRouterAlive.value = true;
  });
}
provide("reload", reload);

watch(() => settingsStore.settings.menu.subMenuCollapse, (val) => {
  if (settingsStore.mode === 'mobile') {
    if (!val) {
      document.body.classList.add('overflow-hidden')
    }
    else {
      document.body.classList.remove('overflow-hidden')
    }
  }
})

watch(() => routeInfo.path, () => {
  if (settingsStore.mode === 'mobile') {
    settingsStore.$patch((state) => {
      state.settings.menu.subMenuCollapse = true
    })
  }
})

onMounted(() => {
  hotkeys('f5', (e) => {
    if (settingsStore.settings.toolbar.enablePageReload) {
      e.preventDefault()
      useMainPage().reload()
    }
  })
  hotkeys('alt+`', (e) => {
    if (settingsStore.settings.menu.enableHotkeys) {
      e.preventDefault()
      useMenu().switchTo(menuStore.actived + 1 < menuStore.allMenus.length ? menuStore.actived + 1 : 0)
    }
  })
})
onUnmounted(() => {
  hotkeys.unbind('f5')
  hotkeys.unbind('alt+`')
})

/**
 * 在组件外面包一层,使用fullPath进行缓存,否则会出现,不同的编辑页面同时存在,关闭其中一个再次打开,缓存未被清除。
*/
const wrap = (route, component) => {
  if (!route.meta.reuse) {
    return component;
  }
  let name = route.fullPath;
  let wrapper: any = null;
  let wrapperMap = keepAliveCompCache.keepAliveCompCache;
  if (wrapperMap.has(name)) {
    wrapper = wrapperMap.get(name)
  } else {
    wrapper = {
      name: name,
      render() {
        return markRaw(component)
      },
    }
    keepAliveCompCache.add(name, wrapper);
  }
  return markRaw(wrapper);
}

/** 消息列表分页 */
const pageInfo = ref({
  ...commonPageConfig,
  limit: 50,
  rows: 0,
  type: "normal",
  pageSizeShow: false,
});

/** 待办列表分页 */
const dealPageInfo = ref({
  ...commonPageConfig,
  limit: 50,
  rows: 0,
  type: "normal",
  pageSizeShow: false,
});

/** 待办消息列表数据 */
const dealMessageList: any = ref([]);
/** 所有的消息列表数据 */
const messageAllList: any = ref([]);

const msgCntPromise = ref();

const drawerVisible = ref(false);

const tabList = ref([{ tabName: '待办' }, { tabName: '消息' }])

const noFinishCnt = ref(0);
/** 待办消息总数 */
const dealTotalRows = ref(0)
/** 消息总数 */
const messageTotalRows = ref(0)
const messageType = ref(1); // 1为待办,2为消息
// 代办消息切换
const tabClick = (index) => {
  messageType.value = index == 0 ? 1 : 2;
}

const pageChange = (info) => {
  if (messageType.value == 2) {
    pageInfo.value.curr = Number(info.curr);
    pageInfo.value.limit = Number(info.limit);
    getMessageList(messageType.value);
  } else {
    dealPageInfo.value.curr = Number(info.curr);
    dealPageInfo.value.limit = Number(info.limit);
    getMessageList(messageType.value);
  }
};

const messageJump = (item) => {
  if (!item.jumpUrl || item.jumpUrl == '/') {
    return;//不跳转    
  }
  if (item.jumpUrl.startsWith('/data-finance/financial-Match?')) {
    let index = item.jumpUrl.indexOf("?");
    if (index == -1) {
      proxy.$ElMessage.error('url地址不对');
      return;
    }
    let params = item.jumpUrl.substring(index + 1);
    let searchParams = new URLSearchParams(params);
    financeStore.setCircuGUid(searchParams.get("guid") || '');
    financeStore.setGoodsName(searchParams.get("goodsName") || "");
    let goPath = item.jumpUrl.substring(0, index);
    router.push({
      path: goPath
    });
    drawerVisible.value = false;
  } else {
    router.push(item.jumpUrl);
    drawerVisible.value = false;
  }
}

//消息已读
const messageRemark = (item) => {
  updateMessageState([item.guid]).then((res: any) => {
    if (res.code == proxy.$passCode) {
      messageJump(item);
      getMessageList(2);
      getMsgCnt();
    } else {
      proxy.$ElMessage.error(res.msg);
    }
  })
}

const messageJumpHover = (item) => {
  if (messageType.value == 1) {
    messageJump(item);
  } else {
    messageRemark(item);
  }
}

const handleClickMsg = () => {
  drawerVisible.value = true;
  getMessageList(1)
  getMessageList(2);
}

const getMessageList = (type = 1) => {
  let param: any = {
    messageType: type,
    pageIndex: type == 1 ? dealPageInfo.value.curr : pageInfo.value.curr,
    pageSize: 50,
    tenantGuid: userData.tenantGuid,
    staffGuid: userData.staffGuid
  };
  if (type == 1) {
    param.isFinish = 'N';
  }
  getAllMessageList(param).then((res: any) => {
    if (res.code === proxy.$passCode) {
      if (type == 1) {
        dealPageInfo.value.rows = res.data.totalRows || 0;
        //dealTotalRows.value = dealPageInfo.value.rows;
        dealMessageList.value =  res.data.records || [];
      } else {
        pageInfo.value.rows = res.data.totalRows || 0;
        //messageTotalRows.value = pageInfo.value.rows;
        messageAllList.value = res.data.records || [];
      }
    } else {
      proxy.$ElMessage.error(res.msg);
    }
  })
}

const messageAllRead = () => {
  proxy.$openMessageBox('确定全部标记为已读吗?', () => {
    updateAllFinish(userData.staffGuid).then((res: any) => {
      if (res.code == proxy.$passCode) {
        proxy.$ElMessage.success('操作成功');
        getMessageList(2);
        getMsgCnt();
      } else {
        proxy.$ElMessage.error(res.msg);
      }
    });
  }, () => {
    proxy.$ElMessage.info("已取消删除");
  });
}

const createServerConnect = () => {
  const websocketUrl = 'websocket-prod.zgsjzc.com'; //正式环境的
  const ws = new WebSocket(`wss://${websocketUrl}/websocket/${userData.staffGuid}`);
  ws.onopen = function () {
    console.log('Connected to server.');
  };
  ws.onmessage = function (res) {
    if (res.data == '\"连接成功\"') return;
      getMsgCnt();
      getMessageList(1);
      getMessageList(2);
  };
  ws.onclose = function(e) {
    console.log('websocket 断开: ' + e.code + ' ' + e.reason + ' ' + e.wasClean);
  };
}

const getMsgCnt = () => {
  msgCntPromise.value = getMessageCount({
    tenantGuid: userData.tenantGuid,
    staffGuid: userData.staffGuid
  }).then((res: any) => {
    msgCntPromise.value = null;
    if (res.code === proxy.$passCode) {
      let data = res.data || {};
      noFinishCnt.value = (data['1'] || 0) + (data['2'] || 0);
      dealTotalRows.value = data['1'] || 0;
      messageTotalRows.value = data['2'] || 0;
    } else {
      proxy.$ElMessage.error(res.msg);
    }
  })
}

onMounted(() => {
  getMsgCnt();
  createServerConnect();
});

</script>

<template>
  <div class="layout">
    <div id="app-main">
      <Header :noFinishCnt="noFinishCnt" @clickMsgSetting="handleClickMsg" />
      <div class="wrapper">
        <div class="sidebar-container"
          :class="{ show: settingsStore.mode === 'mobile' && !settingsStore.settings.menu.subMenuCollapse, 'is-collapse': settingsStore.mode === 'pc' && settingsStore.settings.menu.subMenuCollapse }">
          <MainSidebar />
          <SubSidebar />
        </div>
        <div class="sidebar-mask"
          :class="{ show: settingsStore.mode === 'mobile' && !settingsStore.settings.menu.subMenuCollapse }"
          @click="settingsStore.toggleSidebarCollapse()" v-preReClick />
        <div class="main-container"
          :class="{ 'is-full': settingsStore.mode === 'pc' && settingsStore.settings.menu.subMenuCollapse }"
          :style="{ 'padding-bottom': $route.meta.paddingBottom } as any">
          <Tabbar />
          <div class="main">
            <router-view v-slot="{ Component, route }" v-if="isRouterAlive">
              <transition name="main" mode="out-in" appear>
                <keep-alive :include="keepAliveStore.list">
                  <component :is="wrap(route, Component)" v-show="!isLink" :key="route.fullPath" />
                </keep-alive>
              </transition>
            </router-view>
            <LinkView v-if="isLink" />
          </div>
          <Copyright />
        </div>
      </div>
      <el-backtop :right="20" :bottom="20" title="回到顶部" />
    </div>
     <!-- 消息管理抽屉 -->
     <el-drawer title="通知中心" v-model="drawerVisible" direction="rtl" :with-header="false" :modal="true"
        class="popper-class-home" width="450px">
        <div class="hover-title">
          <span>通知中心</span>
          <el-icon :size="24">
            <Close @click="drawerVisible = false" />
          </el-icon>
        </div>
        <div class="common-tab-box">
          <div class="common-tab-left">
            <div :class="messageType == (index + 1) ? 'common-tab-list common-tab-active' : 'common-tab-list'"
              v-for="(item, index) in tabList" :key="index" @click="tabClick(index)">
              {{ item.tabName }}{{ index == 0 ? dealTotalRows > 99 ? '(99+)' : `${dealTotalRows === 0 ? '' : ('(' + dealTotalRows + ')')}` :
                messageTotalRows > 99 ? '99+' : `${messageTotalRows === 0 ? '' : ('(' + messageTotalRows + ')')}` }}
            </div>
          </div>
          <div class="common-tab-right">
            <span v-show="messageType == 2 && messageAllList.length > 0" @click="messageAllRead"><img src="@/assets/images/all-read.png" alt="" />全部已读</span>
          </div>
        </div>
        <div class="notice-hover-box">
          <div class="notice-list" v-show="messageType == 2" @click="messageJumpHover(item)" v-for="(item, index) in messageAllList" :key="item.guid">
            <div class="notice-list-left">
              <span :style="item.isFinish !== 'Y' ? 'background:#fb2323;' : '#fff'"></span><span>{{ item.title || '-'
                }}</span>
            </div>
            <div class="notice-list-center">{{ item.content || '-' }}</div>
            <div class="notice-list-right">{{ !item.createTime ? '--' : Moment(item.createTime).format('YYYY-MM-DD HH:mm:ss') }}</div>
          </div>
          <div class="notice-list" v-show="messageType == 1" @click="messageJumpHover(item)" v-for="(item, index) in dealMessageList" :key="item.guid">
            <div class="notice-list-left">
              <span :style="item.isFinish !== 'Y' ? 'background:#fb2323;' : '#fff'"></span><span>{{ item.title || '-' }}</span>
            </div>
            <div class="notice-list-center">{{ item.content || '-' }}</div>
            <div class="notice-list-right">{{ !item.createTime ? '--' : Moment(item.createTime).format('YYYY-MM-DD HH:mm:ss') }}</div>
          </div>
        </div>
        <div v-show="messageType == 2 && !messageAllList.length" class="card-noData">
          <img src="@/assets/images/no-data.png" :style="{ width: '96px', height: '96px' }" />
          <span>暂无消息</span>
        </div>
        <div v-show="messageType == 1 && !dealMessageList.length" class="card-noData">
          <img src="@/assets/images/no-data.png" :style="{ width: '96px', height: '96px' }" />
          <span>暂无待办</span>
        </div>
        <PageNav v-show="messageType == 2 && messageAllList.length" :class="[pageInfo.type]" :pageInfo="pageInfo" @pageChange="pageChange" />
        <PageNav v-show="messageType == 1 && dealMessageList.length" :class="[dealPageInfo.type]" :pageInfo="dealPageInfo" @pageChange="pageChange" />
      </el-drawer>
  </div>
</template>

<style lang="scss" scoped>
[data-mode="mobile"] {
  .sidebar-container {
    transform: translateX(calc((var(--g-main-sidebar-width) + var(--g-sub-sidebar-width)) * -1));

    &.show {
      transform: translateX(0);
    }
  }

  .main-container {
    margin-left: 0 !important;
  }

  &[data-menu-mode="single"] {
    .sidebar-container {
      transform: translateX(calc(var(--g-sub-sidebar-width) * -1));

      &.show {
        transform: translateX(0);
      }
    }
  }
}

.layout {
  height: 100%;
}

#app-main {
  width: 100%;
  height: 100%;
  margin: 0 auto;
  transition: all 0.3s;
}

.wrapper {
  position: relative;
  width: 100%;
  height: 100%;
  box-shadow: -1px 0 0 0 var(--g-box-shadow-color);
  transition: padding-top 0.3s;

  .sidebar-container {
    position: fixed;
    z-index: 1010;
    top: 0;
    bottom: 0;
    display: flex;
    width: calc(var(--g-main-sidebar-actual-width) + var(--g-sub-sidebar-actual-width));
    transition: width 0.3s, transform 0.3s, top 0.3s;

    &.is-collapse {
      width: 0;
    }
  }

  .sidebar-mask {
    position: fixed;
    z-index: 1000;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image: radial-gradient(transparent 1px, rgb(0 0 0 / 30%) 1px);
    background-size: 4px 4px;
    backdrop-filter: saturate(50%) blur(4px);
    transition: all 0.2s;
    opacity: 0;
    visibility: hidden;

    &.show {
      opacity: 1;
      visibility: visible;
    }
  }

  .main-sidebar-container:not(.main-sidebar-leave-active)+.sub-sidebar-container {
    left: var(--g-main-sidebar-width);
  }

  .main-container {
    display: flex;
    flex-direction: column;
    height: 100%;
    margin-left: calc(var(--g-main-sidebar-actual-width) + var(--g-sub-sidebar-actual-width));
    background-color: var(--g-main-bg);
    transition: margin-left 0.3s, background-color 0.3s;

    &.is-full {
      margin-left: 0;
    }

    .topbar-container {
      top: 0;
      z-index: 998;
    }

    .main {
      height: 100%;
      flex: auto;
      position: relative;
      overflow: hidden;
      transition: 0.3s;
    }

    .tabbar-container+.main {
      margin: var(--g-tapbar-height) 0 0;
    }
  }
}

header:not(.header-leave-active)+.wrapper {
  padding-top: var(--g-header-height);

  .sidebar-container {
    top: var(--g-header-height);

    :deep(.sidebar-logo) {
      display: none;
    }

    :deep(.el-menu) {
      padding-top: 0;
    }
  }

  .main-container {
    .topbar-container {
      top: var(--g-header-height);

      :deep(.tools) {
        display: none;
      }
    }
  }
}

.app-setting {
  position: fixed;
  z-index: 10;
  right: 0;
  top: calc(50% + 250px);
  width: 50px;
  height: 50px;
  border-top-left-radius: 5px;
  border-bottom-left-radius: 5px;
  font-size: 24px;
  color: #fff;
  background-color: var(--el-color-primary);
  cursor: pointer;

  svg {
    animation: rotate 5s linear infinite;
  }

  @keyframes rotate {
    from {
      transform: rotate(0deg);
    }

    to {
      transform: rotate(360deg);
    }
  }
}

// 主内容区动画
.main-enter-active {
  transition: 0.2s;
}

.main-leave-active {
  transition: 0.15s;
}

.main-enter-from {
  opacity: 0;
  margin-left: -20px;
}

.main-leave-to {
  opacity: 0;
  margin-left: 20px;
}

.notice-hover-box {
  max-height: calc(100vh - 120px);
  overflow: auto;
}

.notice-hover-box .notice-list {
  display: flex;
  justify-content: space-between;
  padding: 4px 16px;
  line-height: 25px;
  box-sizing: border-box;
}

.notice-hover-box {

  .notice-list-left {
    display: flex;
    flex: 1;
    text-align: left;
    color: #666;
  }

  .notice-list-left span:last-child {
    display: -webkit-box !important;
    font-weight: 600;
  }

  .notice-list-left span:first-child {
    float: left;
    flex-shrink: 0;
    display: block !important;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    margin-right: 8px;
    margin-top: 10px;
  }

  .notice-list {
    display: block;
    text-align: left;
    border-bottom: 1px solid #d9d9d9;

    &:hover {
      background: #fafafa;
      cursor: pointer;
    }
  }

  .notice-list-center {
    font-size: 12px;
    line-height: 18px;
    color: #666;
    padding-left: 13px;
  }

  .notice-list-right {
    color: #999999;
    padding-left: 13px;
    font-size: 12px;
    flex-shrink: 0;
  }
}

.hover-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  margin: 10px 0;
  color: #666;
  font-weight: 600;
}

.hover-title span {
  display: block;
  font-size: 16px;
}

.hover-title i {
  cursor: pointer;

  &.el-icon svg {
    height: 18px;
    width: 18px;
  }
}

/* 页面tab */
.common-tab-box {
  display: flex;
  justify-content: space-between;
  height: 32px;
  line-height: 32px;
  color: #666;
  margin-top: 4px;
  border-bottom: 1px solid #d9d9d9;
  outline: none;
  background: #fff;
}

.common-tab-left {
  display: flex;
  padding-left: 12px;
}

.common-tab-list {
  padding: 0 20px;
  text-align: center;
  box-sizing: border-box;
  cursor: pointer;
}

.common-tab-active {
  color: #4fa1a4;
  border-bottom: 2px solid #4fa1a4;
}

.common-tab-right {
  font-size: 12px;
  color: #666666;
  cursor: pointer;
  margin-right: 16px;

}

.common-tab-right img {
  width: 1rem;
  height: 1rem;
  vertical-align: text-bottom
}

:deep(.popper-class-home) {
  position: absolute;
  width: 450px !important;
  height: 100vh;

  .el-drawer__body.el-drawer__body {
    padding: 0;
  }
}

.card-noData {
  height: calc(100% - 80px);
  width: 100%;
  background: #fafafa;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  color: #909399;
  font-size: 14px;
}

.page_nav_wrap {
  padding: 0px 16px;
}

:deep(.el-overlay.is-message-box) {
  z-index: 99999;
}
</style>