Blame view

src/layout/components/Navbar.vue 5.24 KB
yuanshuhui authored
1
2
<template>
  <div class="navbar">
3
4
5
6
7
8
    <hamburger
      id="hamburger-container"
      :is-active="sidebar.opened"
      class="hamburger-container"
      @toggleClick="toggleSideBar"
    />
yuanshuhui authored
9
10
11
12

    <breadcrumb id="breadcrumb-container" class="breadcrumb-container" />

    <div class="right-menu">
13
      <template v-if="device !== 'mobile'">
yuanshuhui authored
14
        <search id="header-search" class="right-menu-item" />
yuanshuhui authored
15
        <el-tooltip :content="$t('navbar.document')" effect="dark" placement="bottom">
yuanshuhui authored
16
17
18
19
20
          <hua-heng-doc id="huaheng-doc" class="right-menu-item hover-effect" />
        </el-tooltip>

        <screenfull id="screenfull" class="right-menu-item hover-effect" />
yuanshuhui authored
21
        <el-tooltip :content="$t('navbar.size')" effect="dark" placement="bottom">
yuanshuhui authored
22
23
          <size-select id="size-select" class="right-menu-item hover-effect" />
        </el-tooltip>
yuanshuhui authored
24
        <lang-select class="right-menu-item hover-effect" />
yuanshuhui authored
25
26
27
28
        <el-select
          v-model="warehouseCode"
          placeholder="仓库"
          size="mini"
yuanshuhui authored
29
          style="width: 120px; vertical-align: text-bottom"
yuanshuhui authored
30
          @change="handleSelect"
yuanshuhui authored
31
32
33
34
35
36
        >
          <el-option
            v-for="item in warehouseOptions"
            :key="item.code"
            :label="item.name"
            :value="item.code"
yuanshuhui authored
37
          >
yuanshuhui authored
38
39
          </el-option>
        </el-select>
yuanshuhui authored
40
      </template>
yuanshuhui authored
41
42
43
44
45
      <el-dropdown
        class="avatar-container right-menu-item hover-effect"
        trigger="click"
      >
yuanshuhui authored
46
        <div class="avatar-wrapper">
47
          <img :src="avatar" class="user-avatar" />
yuanshuhui authored
48
49
50
51
          <i class="el-icon-caret-bottom" />
        </div>
        <el-dropdown-menu slot="dropdown">
          <router-link to="/user/profile">
yuanshuhui authored
52
            <el-dropdown-item>{{ $t('navbar.profile') }}</el-dropdown-item>
yuanshuhui authored
53
54
          </router-link>
          <el-dropdown-item @click.native="setting = true">
yuanshuhui authored
55
            <span>{{ $t('navbar.layout') }}</span>
yuanshuhui authored
56
57
          </el-dropdown-item>
          <el-dropdown-item divided @click.native="logout">
yuanshuhui authored
58
            <span>{{ $t('navbar.logOut') }}</span>
yuanshuhui authored
59
60
61
62
63
64
65
66
          </el-dropdown-item>
        </el-dropdown-menu>
      </el-dropdown>
    </div>
  </div>
</template>

<script>
67
68
69
70
71
import { mapGetters } from "vuex";
import Breadcrumb from "@/components/Breadcrumb";
import Hamburger from "@/components/Hamburger";
import Screenfull from "@/components/Screenfull";
import SizeSelect from "@/components/SizeSelect";
yuanshuhui authored
72
import LangSelect from "@/components/LangSelect";
73
74
import Search from "@/components/HeaderSearch";
import HuaHengDoc from "@/components/HuaHeng/Doc";
yuanshuhui authored
75
import { getWarehouseByUserCode } from "@/api/system/warehouse";
yuanshuhui authored
76
77
78
79
80
81
82

export default {
  components: {
    Breadcrumb,
    Hamburger,
    Screenfull,
    SizeSelect,
yuanshuhui authored
83
    LangSelect,
yuanshuhui authored
84
    Search,
85
    HuaHengDoc,
yuanshuhui authored
86
  },
yuanshuhui authored
87
  data() {
yuanshuhui authored
88
89
90
91
92
    return {
      warehouseCode: this.$store.getters.warehouseCode,
      warehouseOptions: [],
    };
  },
yuanshuhui authored
93
  computed: {
94
    ...mapGetters(["sidebar", "avatar", "device"]),
yuanshuhui authored
95
96
    setting: {
      get() {
97
        return this.$store.state.settings.showSettings;
yuanshuhui authored
98
99
      },
      set(val) {
100
101
102
103
104
105
        this.$store.dispatch("settings/changeSetting", {
          key: "showSettings",
          value: val,
        });
      },
    },
yuanshuhui authored
106
  },
yuanshuhui authored
107
  created() {
yuanshuhui authored
108
109
110
111
    getWarehouseByUserCode(this.$store.getters.name).then((response) => {
      this.warehouseOptions = response.data;
    });
  },
yuanshuhui authored
112
113
  methods: {
    toggleSideBar() {
114
      this.$store.dispatch("app/toggleSideBar");
yuanshuhui authored
115
116
    },
    async logout() {
117
118
119
120
      this.$confirm("确定注销并退出系统吗?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
yuanshuhui authored
121
      }).then(() => {
yuanshuhui authored
122
        this.$store.dispatch("user/LogOut").then(() => {
123
124
125
126
          location.href = "/index";
        });
      });
    },
yuanshuhui authored
127
    handleSelect(value) {
yuanshuhui authored
128
      this.$store.dispatch("user/SwitchWarehouse", value)
yuanshuhui authored
129
    },
130
131
  },
};
yuanshuhui authored
132
133
134
135
136
137
138
139
</script>

<style lang="scss" scoped>
.navbar {
  height: 50px;
  overflow: hidden;
  position: relative;
  background: #fff;
140
  box-shadow: 0 1px 4px rgba(0, 21, 41, 0.08);
yuanshuhui authored
141
142
143
144
145
146

  .hamburger-container {
    line-height: 46px;
    height: 100%;
    float: left;
    cursor: pointer;
147
148
    transition: background 0.3s;
    -webkit-tap-highlight-color: transparent;
yuanshuhui authored
149
150

    &:hover {
151
      background: rgba(0, 0, 0, 0.025);
yuanshuhui authored
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
    }
  }

  .breadcrumb-container {
    float: left;
  }

  .errLog-container {
    display: inline-block;
    vertical-align: top;
  }

  .right-menu {
    float: right;
    height: 100%;
    line-height: 50px;

    &:focus {
      outline: none;
    }

    .right-menu-item {
      display: inline-block;
      padding: 0 8px;
      height: 100%;
      font-size: 18px;
      color: #5a5e66;
      vertical-align: text-bottom;

      &.hover-effect {
        cursor: pointer;
183
        transition: background 0.3s;
yuanshuhui authored
184
185

        &:hover {
186
          background: rgba(0, 0, 0, 0.025);
yuanshuhui authored
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
        }
      }
    }

    .avatar-container {
      margin-right: 30px;

      .avatar-wrapper {
        margin-top: 5px;
        position: relative;

        .user-avatar {
          cursor: pointer;
          width: 40px;
          height: 40px;
          border-radius: 10px;
        }

        .el-icon-caret-bottom {
          cursor: pointer;
          position: absolute;
          right: -20px;
          top: 25px;
          font-size: 12px;
        }
      }
    }
  }
}
</style>