index.vue 11.5 KB
Newer Older
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
<!-- 机组诊断的侧边导航 -->
<template>
  <div class="sidebar" v-loading="loading" :element-loading-background="loadingColor">
    <el-scrollbar class="scrollbar">
      <div class="menu-block">
        <!-- 搜索 -->
        <div class="menu-search global">
          <el-input class="input-style" v-model="searchValue" placeholder="快速搜索" @keyup.enter.native="search"></el-input>
          <el-button class="btn-style" @click="search">搜索</el-button>
          <el-button class="btn-style" @click="cleanUp">清空</el-button>
        </div>
        <!-- 菜单 -->
        <el-menu ref="menu" text-color="#fff" unique-opened1 @open="openMenu" @close="closeMenu">
          <el-submenu v-for="(factory, index) of menu" :key="index" :index="index+''">
            <template slot="title">
              <span>{{ factory.plantName }}</span>
            </template>
            <div class="sub-menu" v-for="(crew, index2) of factory.plantDevices" :key="index2">
              <div v-if="index2 == factory.plantDevices.length - 1" class="line-y-item"></div>
              <div class="line-x-item"></div>
              <el-submenu :index="index + '_' + index2">
                <template slot="title">
                  <span>{{ crew.deviceName }}</span>
                </template>
                <div class="sub-menu" v-for="(character, index3) of crew.characters" :key="index3">
                  <div v-if="index3 == crew.characters.length - 1" class="line-y-item"></div>
                  <div class="line-x-item"></div>
                  <el-checkbox-group class="check-list" v-model="checkList" :max="pointListMax">
                    <el-checkbox class="check-style" :label="index + '_' + index2 + '_' + index3" @change="changeMenu">
                      {{ character.cpName }} </el-checkbox>
                  </el-checkbox-group>
                </div>
              </el-submenu>
            </div>
          </el-submenu>
        </el-menu>
      </div>
    </el-scrollbar>
  </div>
</template>

<script>
  import API from '@/api/factory.js';
  import {
    ChartStyle
  } from '@/common/const.js';

  export default {
    data() {
      return {
        loading: false,
        loadingColor: ChartStyle.loadingColor,
        searchValue: '', // 搜索值
        menuAll: null, // 所有菜单列表
        menu: null, // 当前菜单列表
56
        pointListMax: 12, // 报警最多选择数量
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
        checkList: [], // 选择列表
        lastMenuKey: '', // 存储菜单最后一次的key,用于打开其他菜单时,主动调用关闭前一个菜单(清空测点,优化性能)
      };
    },
    computed: {
      // 根据当前菜单和选择列表,返回选择列表中每个项的测点信息
      checkNodeList() {
          if (!this.checkList.length) return [];
          let list = this.checkList.map(i => {
              let arr = i.split('_');
              let obj = {
                  factory: this.menu[arr[0]],
                  crew: this.menu[arr[0]].plantDevices[arr[1]],
                  character: this.menu[arr[0]].plantDevices[arr[1]].characters[arr[2]],
                  index: i
              };
              return obj;
          });
          return list;
      },
    },
    created() {
      this.initMenu();
    },
    methods: {
      // 初始化菜单
      initMenu() {
        this.menu = this.menuAll = this.$x_factoryList;
        this.initDefaultActive();
      },
      // 展开菜单,如果没有选择机组,则展开第一个机组的第一个部件的第一个测点,否则展开选择机组的第一个部件的第一个测点,如果有默认按钮,则找到默认按钮对应的测点展开
      async initDefaultActive() {
        this.$nextTick(async () => {
          let pointList = this.$route.query.pointList;
          try{
            pointList = JSON.parse(pointList);
          }catch(e){
            pointList = null;
          }
          if (pointList) {
            // 选择了测点
            let indexFactory = this.menu.findIndex(i => i.plantId == this.$x_factory.plantId); // 电厂索引,当前电厂
            let itemFactory = this.menu[indexFactory];
            let checkList = [];
            // 构造机组测点树结构
            let tmpTree = {};
            pointList.forEach(i => {
              let indexCrew = itemFactory.plantDevices.findIndex(j => j.deviceId == i.deviceId); // 机组索引
              if (!tmpTree[indexCrew]) tmpTree[indexCrew] = [i.kksCode];
              else tmpTree[indexCrew].push(i.kksCode);
            })
            // 遍历获取测点
            let tmpCount = 0; // 记录遍历次数
            let tmpLen = Object.keys(tmpTree).length;
            for (let indexCrew in tmpTree) {
              try{
                await this.openMenu(indexFactory + '_' + indexCrew); // 获取测点
                let itemCrew = itemFactory.plantDevices[indexCrew];
                tmpTree[indexCrew].forEach(i => {
                  let indexCharacter = itemCrew.characters.findIndex(j => j.kksCode == i); // 测点索引
                  checkList.push(indexFactory + '_' + indexCrew + '_' + indexCharacter); // 放入选择列表
                })
                // 如果都放进去了,模拟点击菜单
                if(++tmpCount == tmpLen) {
                  this.checkList = checkList;
                  this.changeMenu();
                  this.$refs.menu.open(indexFactory + '_' + indexCrew); // 展开机组菜单
                }
              }catch(e){
                console.log(e);
              }
            }
          } else {
            // 没有选择默认测点
            let indexFactory = 0; // 电厂索引,默认第一个
            let indexCrew = 0; // 机组索引,默认第一个
            let indexCharacter = 0; // 测点索引,默认第一个
            try{
              await this.openMenu(indexFactory + '_' + indexCrew); // 获取测点
              this.checkList = [indexFactory + '_' + indexCrew + '_' + indexCharacter]; // 模拟点击测点
              this.changeMenu();
              this.$refs.menu.open(indexFactory + '_' + indexCrew); // 展开机组菜单
            }catch(e){
              console.log(e);
              this.$refs.menu.open(indexFactory); // 展开电厂菜单
            }
          }
        });
      },
      // 展开菜单,获取机组测点
      async openMenu(key) {
        let arr = key.split('_');
        if (arr.length != 2) return; // 只有等于2(即机组菜单)时才需要后续的获取测点
        // 由于设置了只同一时间只存在一个菜单的展开,所以清空上一次菜单的测点
        this.closeMenu(this.lastMenuKey);
        this.lastMenuKey = key;
        // 查询测点
        let crew = this.menu[arr[0]].plantDevices[arr[1]];
        if (!crew.characters?.length) {
          this.loading = true;
          try {
            let res = await API.getCharacterList(crew.deviceId); // 获取测点信息
            crew.characters = res;
          } catch (e) {
            console.log(e);
          }
          this.loading = false;
        }
        return crew.characters;
      },
      // 关闭展开的菜单时,如果选择列表里有当前菜单的测点,则不清空测点,没有则清空
      closeMenu(key) {
        // let arr = key.split('_');
        // if (arr.length != 2) return;
        // if (this.checkList.find(i => i.indexOf(arr[0] + '_' + arr[1]) == 0)) return; // 这里只判断机组部件的索引是否包含,不去判断二级菜单
        // this.menu[arr[0]].plantDevices[arr[1]].characters = []; // 清空测点
      },
      // 切换菜单
      changeMenu() {
        this.$emit('changeMenu', this.checkNodeList);
      },
      // 搜索测点名
      search() {
        this.checkList = [];
        this.lastMenuKey = '';
        let copyMenu = JSON.parse(JSON.stringify(this.menuAll));
        this.menu = copyMenu.filter(i => {
          let newDev = i.plantDevices.filter(j => {
            let newCha = j.characters ? j.characters.filter(k => k.cpName.indexOf(this.searchValue) != -1) : [];
            j.characters = newCha;
            return newCha.length;
          })
          i.plantDevices = newDev;
          return newDev.length;
        });
      },
      // 清空搜索
      cleanUp() {
        this.checkList = [];
        this.lastMenuKey = '';
        this.searchValue = '';
        this.menu = this.menuAll;
      }
    }
  };
</script>

<style lang="scss" scoped>
  .sidebar {

    // el滚动条
    .scrollbar {
      height: 100%;
    }

    /deep/.el-scrollbar__wrap {
      overflow-x: hidden;
    }

    .menu-block {
      margin: 1.25rem;
    }

    // 搜索样式
    .menu-search {
      display: flex;
      margin-bottom: 0.625rem;
      height: 2.5rem;

      .input-style {
        margin-right: 0.625rem;
      }

      /deep/.el-input__inner {
        border-radius: 50px;
        height: 100%;
      }

      .btn-style {
        @extend %btn-default;
        font-size: 0.875rem;
        flex-shrink: 0;
      }
    }

    $item-height: 2.5rem;
    $line-color: rgba($color: #fff, $alpha: 0.3);

    // 菜单样式
    /deep/ .el-menu {
      border: none;
      position: relative;
      background-color: transparent;

      // 横向线条
      .line-x-item {
        width: calc(6% + 1px);
        height: 2px;
        background-color: $line-color;
        position: absolute;
        top: 2.125rem;
        left: 0;
      }

      // 纵向线条
      .line-y-item {
        width: 2px;
        height: 2.1875rem;
        background-color: $line-color;
        position: absolute;
        top: 0%;
        left: 0%;
      }

      .sub-menu {
        position: relative;
        width: 92%;
        padding-left: 6%;
        box-sizing: border-box;
        border-left: 2px solid $line-color;
      }

      .sub-menu:last-child {
        width: 92%;
        padding-left: 6%;
        box-sizing: border-box;
        border-left: none;
      }

      .check-list {
        width: 100%;
        display: flex;
        flex-direction: column;
        align-items: flex-end;

        .check-style {
          width: 100%;
          height: $item-height;
          margin-top: 1rem;
          padding: 0 1.25rem;
          box-sizing: border-box;
          background-color: rgba($color: $color-cyan, $alpha: 0.1);
          border-radius: 50px;
          display: flex;
          align-items: center;

          /deep/ .el-checkbox__label {
            font-size: 1rem !important;
            color: #fff;
          }
        }
      }

      // 组菜单标题和单项标题
      /deep/.el-submenu__title,
      /deep/.el-menu-item {
        height: 2.5rem;
        background-color: rgba($color: $color-cyan, $alpha: 0.1);
        display: flex;
        align-items: center;
        border-radius: 50px;
        font-size: 1rem;
        padding: 0 1.25rem !important;
        overflow: hidden;
      }

      // 组菜单标题和单项标题滑过
      /deep/.el-submenu__title:hover,
      /deep/.el-menu-item:hover {
        background-color: $color-deep-blue;
      }

      // 组菜单标题
      /deep/.el-submenu__title {
        margin-top: 1rem;
      }

      // 去掉图标
      /deep/.el-icon-arrow-down:before {
        content: '';
      }

      $disable-color: #888888;

      /deep/.el-checkbox__input.is-disabled+span.el-checkbox__label {
        color: $disable-color;
      }

      /deep/.el-checkbox__input.is-disabled .el-checkbox__inner {
        background-color: $disable-color;
        border: none;
      }

      /deep/ul {
        display: flex;
        flex-direction: column;
        align-items: flex-end;
      }
    }
  }
</style>