quick.vue 4.43 KB
Newer Older
1
<template>
潘际乾 committed
2 3 4 5 6 7 8 9 10 11 12 13 14 15
  <el-scrollbar style="height: 100%">
    <router-link
      v-for="(item, index) in quickVisitItem"
      :key="index"
      :to="item.path"
    >
      <div
        class="content-wrapper"
        :style="{ height: Math.floor(cellContentHeight * 0.33) + 'px' }"
      >
        <div class="visit-item-wrapper">
          <div class="visit-item">
            <img :src="item.icon" alt="" />
            <span>{{ item.name }}</span>
16
          </div>
潘际乾 committed
17
        </div>
18
      </div>
潘际乾 committed
19
    </router-link>
20

潘际乾 committed
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
    <el-dialog
      :visible="visible"
      title="设置"
      width="60%"
      :before-close="handleClose"
    >
      <div style="text-align: center">
        <el-transfer
          style="text-align: left; display: inline-block"
          v-model="selectedVals"
          filterable
          :titles="['未添加', '已添加']"
          :button-texts="['移除', '添加']"
          :format="{
            noChecked: '${total}',
            hasChecked: '${checked}/${total}',
          }"
          :data="transferData"
        >
        </el-transfer>
      </div>
      <span slot="footer" class="dialog-footer">
        <c-button @click="cancel">取消</c-button>
        <c-button type="primary" @click="save">保存</c-button>
      </span>
    </el-dialog>
  </el-scrollbar>
48 49 50 51 52 53 54
</template>

<script>
import icons from "./icons.js";

export default {
  props: {
潘际乾 committed
55 56
    quickType: {
      type: String,
57 58
      required: true,
    },
潘际乾 committed
59 60
    cellContentHeight: {
      type: Number,
61
      required: true,
潘际乾 committed
62
    },
63
  },
潘际乾 committed
64
  data() {
65 66 67 68 69 70 71 72
    return {
      allAvailableItems: [],
      quickVisitItem: [],
      visible: false,
      selectedVals: [],
      transferData: [],
    };
  },
潘际乾 committed
73
  mounted() {
74 75 76
    this.$nextTick(() => {
      this.init();
      this.generateVisitItems(this.getCachedVisitItems());
潘际乾 committed
77
    });
78 79 80 81 82 83 84
  },
  methods: {
    init() {
      const arr = [];
      this.getAllAvailableItems(this.$store.state.UserContext.menu, arr);
      this.allAvailableItems = arr;
      this.transferData = arr.map((item) => {
潘际乾 committed
85
        const ps = item.path.split("/");
86 87
        return {
          key: item.path,
潘际乾 committed
88
          label: `${ps[ps.length - 1]} - ${item.name}`,
89 90 91 92 93
        };
      });
    },
    getCachedVisitItems() {
      const data = localStorage.getItem(
潘际乾 committed
94
        `quick-${this.quickType}-${this.getUserRole()}`
95 96 97 98 99
      );
      return JSON.parse(data);
    },
    setCachedVisitItems(data) {
      localStorage.setItem(
潘际乾 committed
100
        `quick-${this.quickType}-${this.getUserRole()}`,
101 102 103
        JSON.stringify(data)
      );
    },
潘际乾 committed
104 105 106 107
    getUserRole() {
      const userId = this.$store.state.UserContext.userId;
      return userId.toLowerCase() === "zl" ? "admin" : "normal";
    },
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
    generateVisitItems(keys) {
      const res = [];
      for (let i = 0; i < keys.length; i++) {
        const key = keys[i];
        const f = this.allAvailableItems.find((item) => item.path === key);
        if (f) {
          res.push({
            name: f.name,
            path: f.path,
            icon: icons[key]
              ? icons[key]
              : require("~/assets/icons/信用证.svg"),
          });
        }
      }
      this.quickVisitItem = res;
    },
    openSetting() {
      this.selectedVals = this.quickVisitItem.map((item) => item.path);
      this.visible = true;
    },
    cancel() {
      this.visible = false;
    },
    save() {
      this.setCachedVisitItems(this.selectedVals);
      this.generateVisitItems(this.selectedVals);
      this.visible = false;
    },
    handleClose(done) {
      this.visible = false;
      done();
    },
    getAllAvailableItems(source, arr) {
      for (let i = 0; i < source.length; i++) {
        const s = source[i];
        if (s.children.length > 0) {
          this.getAllAvailableItems(s.children, arr);
        } else {
          arr.push(s);
        }
      }
    },
  },
潘际乾 committed
152
};
153 154 155 156 157
</script>

<style scoped>
.content-wrapper {
  display: inline-block;
潘际乾 committed
158
  width: 33.33%;
159 160
  /* height: 30%; */
}
潘际乾 committed
161
.visit-item-wrapper {
162 163 164 165 166
  display: flex;
  height: 100%;
  justify-content: center;
  align-items: center;
}
潘际乾 committed
167
.visit-item {
168 169 170 171 172 173
  /* padding-bottom: 16px; */
  display: flex;
  flex-direction: column;
  align-items: center;
  cursor: pointer;
}
潘际乾 committed
174
.visit-item i {
175 176 177
  color: #0088ff;
  font-size: 36px;
}
潘际乾 committed
178
.visit-item span {
179 180 181 182
  color: #303133;
  font-size: 14px;
  margin-top: 10px;
}
潘际乾 committed
183
.visit-item:hover span {
184 185 186 187
  color: var(--themecolor);
}
.el-scrollbar >>> .el-transfer-panel {
  width: 300px;
潘际乾 committed
188
  height: 400px;
189 190 191 192 193
}
.el-scrollbar >>> .el-checkbox-group.el-transfer-panel__list {
  height: 500px;
}
</style>