zhangzengfei
2022-06-08 182aed85616f7ac60d0ffb02e4feac5661b80e0c
src/pages/library/components/baseList.vue
@@ -1,17 +1,9 @@
<template>
  <div
    :style="listWidth ? `width:${listWidth};` : ''"
    class="out-div el-menu-vertical-demo"
  >
  <div :style="listWidth ? `width:${listWidth};` : ''" class="out-div el-menu-vertical-demo">
    <el-collapse v-model="activeNames">
      <el-collapse-item name="1" class="el-collapse-item__wrap">
        <template slot="title">
          <img
            v-if="title === '同步库'"
            src="/images/library/同步库2.png"
            alt=""
            srcset=""
          />
          <img v-if="title === '同步库'" src="/images/library/同步库2.png" alt="" srcset="" />
          <img v-else src="/images/library/本地库2.png" alt="" srcset="" />
          <span class="m5">{{ title }}</span>
          <el-tooltip content="添加同步库" placement="top">
@@ -37,26 +29,11 @@
            @click.native="clickCategory(index, 'sync', item)"
            :class="{ activeRow: categoryIndex == 'sync' + index }"
          >
            <el-col
              :span="12"
              :class="item.bwType === '1' ? 'c-red' : 'c-green'"
            >
              <p
                style="text-align: left; margin-left: 5px"
                class="name-ellipsis"
                :title="item.tableName"
              >
                <span
                  class="iconfont iconrenyuanku-09"
                  v-if="item.tableType == 'person'"
                ></span>
                <span
                  class="iconfont iconcheliangku-09"
                  v-if="item.tableType == 'car'"
                ></span>
                <span style="font-size: 14px; font-weight: bold">
                  {{ item.tableName }}</span
                >
            <el-col :span="12" :class="item.bwType === '1' ? 'c-red' : 'c-green'">
              <p style="text-align: left; margin-left: 5px" class="name-ellipsis" :title="item.tableName">
                <span class="iconfont iconrenyuanku-09" v-if="item.tableType == 'person'"></span>
                <span class="iconfont iconcheliangku-09" v-if="item.tableType == 'car'"></span>
                <span style="font-size: 14px; font-weight: bold"> {{ item.tableName }}</span>
              </p>
            </el-col>
            <el-col :span="10" :offset="1">
@@ -110,23 +87,10 @@
            @click.native="clickCategory(index, 'local', item)"
            :class="{ activeRow: categoryIndex == 'local' + index }"
          >
            <el-col
              :span="12"
              :class="item.bwType === '1' ? 'c-red' : 'c-green'"
            >
              <p
                style="text-align: left; margin-left: 5px"
                class="name-ellipsis"
                :title="item.tableName"
              >
                <span
                  class="iconfont iconrenyuanku-09"
                  v-if="item.tableType == 'person'"
                ></span>
                <span
                  class="iconfont iconcheliangku-09"
                  v-if="item.tableType == 'car'"
                ></span>
            <el-col :span="12" :class="item.bwType === '1' ? 'c-red' : 'c-green'">
              <p style="text-align: left; margin-left: 5px" class="name-ellipsis" :title="item.tableName">
                <span class="iconfont iconrenyuanku-09" v-if="item.tableType == 'person'"></span>
                <span class="iconfont iconcheliangku-09" v-if="item.tableType == 'car'"></span>
                <span> {{ item.tableName }}</span>
              </p>
            </el-col>
@@ -159,7 +123,7 @@
  </div>
</template>
<script>
import { updateDbTableStatus } from "@/api/baseLibrary";
import { updateDbTableStatus } from "@/api/baseLibrary"
export default {
  name: "baseList",
  data() {
@@ -169,112 +133,113 @@
      categoryIndex: "",
      syncTableList: [],
      localTableList: [],
      clickBase: {}, // 当前点击的底库对象
    };
      clickBase: {} // 当前点击的底库对象
    }
  },
  computed: {
    isAdmin() {
      if (
        sessionStorage.getItem("userInfo") &&
        sessionStorage.getItem("userInfo") !== ""
      ) {
        let loginName = JSON.parse(sessionStorage.getItem("userInfo")).username;
        return loginName === "superadmin" || loginName === "basic";
      if (sessionStorage.getItem("userInfo") && sessionStorage.getItem("userInfo") !== "") {
        let loginName = JSON.parse(sessionStorage.getItem("userInfo")).username
        return loginName === "superadmin" || loginName === "basic"
      }
      return false;
    },
      return false
    }
  },
  mounted() {
    this.init();
    this.init()
  },
  methods: {
    isShow(authority) {
      return (
        this.isAdmin || this.buttonAuthority.indexOf("," + authority + ",") > -1
      );
      return this.isAdmin || this.buttonAuthority.indexOf("," + authority + ",") > -1
    },
    async init() {
      await this.BaseManageData.querySyncTables();
      this.syncTableList = this.BaseManageData.syncTables;
      this.defaultShow();
      await this.BaseManageData.queryLocalTables();
      this.localTableList = this.BaseManageData.localTables;
      this.defaultShow();
    async init(typ) {
      await this.BaseManageData.querySyncTables()
      this.syncTableList = this.BaseManageData.syncTables
      if (typ) {
        this.clickLast(typ)
      } else {
        this.defaultShow()
      }
      await this.BaseManageData.queryLocalTables()
      this.localTableList = this.BaseManageData.localTables
      if (typ) {
        this.clickLast(typ)
      } else {
        this.defaultShow()
      }
    },
    add(type) {
      this.$emit("changeShow", null, type);
      this.$emit("changeShow", null, type)
    },
    clickLast(type) {
      this.$nextTick(() => {
        this.clickCategory(
          this.syncTableList.length - 1,
          type,
          this.syncTableList[this.syncTableList.length - 1]
        );
      });
      // this.$nextTick(() => {
      // });
      this.clickCategory(this.syncTableList.length - 1, type, this.syncTableList[this.syncTableList.length - 1])
    },
    clickCategory(index, type, item) {
      this.categoryIndex = type + index;
      this.categoryIndex = type + index
      // 调用切换右侧面板的函数并且切换父组件中isSelected的值让另一个组件清除被选中状态
      this.clickBase = item;
      this.$emit("getList", item, type);
      this.clickBase = item
      this.$emit("getList", item, type)
      console.log("clickCategory", item, type)
    },
    // 默认显示第一个库的数据
    defaultShow() {
      if (this.syncTableList && this.syncTableList.length) {
        this.clickCategory(0, "sync", this.syncTableList[0]);
        this.clickCategory(0, "sync", this.syncTableList[0])
      } else {
        if (this.localTableList && this.localTableList.length) {
          this.clickCategory(0, "local", this.syncTableList[0]);
          this.clickCategory(0, "local", this.syncTableList[0])
        }
      }
    },
    // 添加时间比较函数
    dateParse(dateString) {
      var SEPARATOR_BAR = "-";
      var SEPARATOR_SLASH = "/";
      var SEPARATOR_DOT = ".";
      var dateArray;
      var SEPARATOR_BAR = "-"
      var SEPARATOR_SLASH = "/"
      var SEPARATOR_DOT = "."
      var dateArray
      if (dateString.indexOf(SEPARATOR_BAR) > -1) {
        dateArray = dateString.split(SEPARATOR_BAR);
        dateArray = dateString.split(SEPARATOR_BAR)
      } else if (dateString.indexOf(SEPARATOR_SLASH) > -1) {
        dateArray = dateString.split(SEPARATOR_SLASH);
        dateArray = dateString.split(SEPARATOR_SLASH)
      } else {
        dateArray = dateString.split(SEPARATOR_DOT);
        dateArray = dateString.split(SEPARATOR_DOT)
      }
      return new Date(dateArray[0], dateArray[1] - 1, dateArray[2]);
      return new Date(dateArray[0], dateArray[1] - 1, dateArray[2])
    },
    isEmpty(str) {
      if (!str || str === undefined || str === null) {
        return true;
        return true
      } else {
        return false;
        return false
      }
    },
    }
  },
  props: {
    listWidth: {
      default: "224px",
      type: String,
      type: String
    },
    title: {
      default: "同步库",
      type: String,
      type: String
    },
    titleB: {
      default: "本地库",
      type: String,
      type: String
    },
    isSelected: {
      default: false,
      type: Boolean,
      type: Boolean
    },
    type: {
      default: "",
      type: String,
    },
  },
};
      type: String
    }
  }
}
</script>
<style lang="scss">
.iconStyle1 {