quick.vue 4.93 KB
Newer Older
1
<template>
潘际乾 committed
2
  <el-scrollbar style="height: 100%">
潘际乾 committed
3 4 5 6 7
    <div style="padding: 15px;">
      <router-link
        v-for="(item, index) in quickVisitItem"
        :key="index"
        :to="item.path"
潘际乾 committed
8
      >
潘际乾 committed
9 10
        <div
          class="content-wrapper"
11
          :style="{ height: Math.floor((cellContentHeight - 20) * 0.33) + 'px' }"
潘际乾 committed
12 13 14 15 16 17
        >
          <div class="visit-item-wrapper">
            <div class="visit-item">
              <img :src="item.icon" alt="" />
              <span>{{ item.name }}</span>
            </div>
18
          </div>
潘际乾 committed
19
        </div>
潘际乾 committed
20 21
      </router-link>
    </div>
潘际乾 committed
22 23 24
    <el-dialog
      :visible="visible"
      title="设置"
Wuyuqiu committed
25
      width="50%"
潘际乾 committed
26 27
      :before-close="handleClose"
    >
Wuyuqiu committed
28
      <div style="text-align: center" >
潘际乾 committed
29
        <el-transfer
Wuyuqiu committed
30
          style="text-align: left; display: inline-block;float:left;"
潘际乾 committed
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
          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>
49 50 51 52 53 54 55
</template>

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

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

<style scoped>
.content-wrapper {
  display: inline-block;
Wuyuqiu committed
159
  width: 24.33%;
160 161
  /* height: 30%; */
}
潘际乾 committed
162
.visit-item-wrapper {
163 164 165 166 167
  display: flex;
  height: 100%;
  justify-content: center;
  align-items: center;
}
潘际乾 committed
168
.visit-item {
169 170 171 172 173 174
  /* padding-bottom: 16px; */
  display: flex;
  flex-direction: column;
  align-items: center;
  cursor: pointer;
}
潘际乾 committed
175
.visit-item i {
176 177 178
  color: #0088ff;
  font-size: 36px;
}
潘际乾 committed
179
.visit-item span {
180
  color: #303133;
潘际乾 committed
181
  font-size: 12px;
182 183
  margin-top: 10px;
}
潘际乾 committed
184
.visit-item:hover span {
185 186 187
  color: var(--themecolor);
}
.el-scrollbar >>> .el-transfer-panel {
Wuyuqiu committed
188
  width: 216px;
潘际乾 committed
189
  height: 400px;
190 191 192 193
}
.el-scrollbar >>> .el-checkbox-group.el-transfer-panel__list {
  height: 500px;
}
Wuyuqiu committed
194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214

.el-scrollbar >>> .el-dialog .el-dialog__footer{
  text-align: center;
}

.el-scrollbar >>> .el-checkbox {
  float: left;
  text-align: left;
}

.el-scrollbar >>> .el-transfer-panel__header .el-checkbox {
  float: left;
  text-align: left;
  position:absolute;
}

.el-scrollbar >>> .el-transfer-panel__header .el-checkbox .el-checkbox__label span{
    position: relative;
    left: 100px;
    float: right;
}
215
</style>