ZZJ
2022-07-14 10c762851cf552a75c61ff5b1bcf4057028f0179
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
56
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
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
<template>
  <div class="IndexHeader">
    <div class="header" :class="{ showBox: isShow, disOpacity: !opacity }">
      <!-- 右侧 -->
      <div class="left">
        <router-link to="/">
          <img class="logo" src="/images/index/LOGO.png" alt="" />
        </router-link>
        <div class="title" @click="$router.push('/')">工业互联网平台</div>
        <div class="label" @click="$router.push('/')">首页</div>
        <div class="label">云服务</div>
        <div class="label" @click="$router.push('/manageCenter')">管理中心</div>
        <div class="label" @click="$router.push('/product')">应用商城</div>
      </div>
 
      <!-- 左侧 -->
      <div class="right">
        <el-input
          placeholder="请输入关键词"
          v-model="keyWord"
          @focus="showInputBox(true)"
          :class="{ Unlogin: !userInfo }"
        >
          <div class="iconList" slot="suffix">
            <i class="search iconfont" v-if="!isShow">&#xe607;</i>
            <i class="search iconfont" v-if="isShow">&#xe607;</i>
            <i class="del iconfont" v-if="isShow" @click="showInputBox(false)"
              >&#xe60f;</i
            >
          </div>
        </el-input>
 
        <!-- 未登录情况 -->
        <div
          class="headerLogin"
          v-if="!userInfo"
          @click="$router.push('/login')"
        >
          登录
        </div>
        <div
          class="register"
          v-if="!userInfo"
          @click="$router.push('/register')"
        >
          免费注册
        </div>
 
        <!-- 已登录情况 -->
        <img
          class="userImg"
          src="/images/index/8.jpg"
          alt=""
          v-if="userInfo"
          @mouseenter="showUserBox"
          @mouseleave="hiddenUserBox"
          style="border-radius: 50%"
        />
      </div>
    </div>
 
    <!-- 用户下拉框 -->
    <div
      class="userBox"
      v-if="userInfo && isShowUserBox"
      @mouseenter="showUserBox"
      @mouseleave="hiddenUserBox"
    >
      <div class="userName">{{ userInfo.username }}</div>
      <ul>
        <!--   <li class="money">
          <div class="label">余额</div>
          <div class="content">
            <span class="button">充值</span>
            <span class="number">¥0</span>
          </div>
        </li>
 -->
        <li class="personal">
          <div class="label">
            <router-link to="/personalCenter">个人中心</router-link>
          </div>
 
          <div class="content">
            <span class="iconfont">&#xe605;</span> 已实名认证
          </div>
        </li>
 
        <li>
          <div class="label" @click="jump(0)">订单管理</div>
        </li>
 
        <!--  <li>
          <div class="label">产品续费</div>
        </li> -->
 
        <!--  <li>
          <div class="label">未读消息</div>
        </li> -->
 
        <li>
          <div class="label" @click="jump(0, 1)">未支付订单</div>
        </li>
 
        <li>
          <div class="label">
            <router-link to="/manageCenter">管理中心</router-link>
          </div>
        </li>
      </ul>
      <div class="logOut" @click="logOut">退出登录</div>
    </div>
 
    <!-- 输入下拉框 -->
    <div class="inputBox" :class="{ Unlogin: !userInfo }" v-if="isShowBox">
      <div class="hotKey">
        <div class="title">热门搜索</div>
        <ul class="keyCard">
          <li class="keyItem" v-for="(item, index) in hotKeyArr" :key="index">
            {{ item }}
          </li>
          x
        </ul>
      </div>
 
      <div class="historyKey">
        <div class="title colorLight">历史搜索</div>
 
        <ul class="keyCard">
          <li
            class="keyItem"
            v-for="(item, index) in historyKeyArr"
            :key="index"
          >
            {{ item }}
          </li>
        </ul>
      </div>
    </div>
 
    <!-- 遮罩层 -->
    <div class="mask" v-if="isShowBox"></div>
  </div>
</template>
 
<script>
import { logout } from "@/api/login";
 
export default {
  props: {
    opacity: {
      type: Boolean,
      default: true,
    },
  },
  name: "Header",
  created() {
    //尝试从session中拿用户信息
    this.userInfo = JSON.parse(sessionStorage.getItem("userInfo"));
    /*  document.addEventListener("click", () => {
      this.showUserBox = false;
    }); */
  },
  data() {
    return {
      keyWord: "", //输入框内容
      isShow: false, //显示下拉框
      hotKeyArr: ["算法", "智能AI", "云服务", "管理中心", "实时音视频", "短信"], //热门关键词
      historyKeyArr: ["云服务", "算法", "管理服务", "应用"], //历史关键词
      isShowBox: false, //输入下拉框
      userInfo: null, //用户信息
      isShowUserBox: false, //用户信息弹层
      UserTimer: null, // 控制弹层的定时器
    };
  },
  methods: {
    // 控制输入框box
    showInputBox(toggle) {
      this.isShow = toggle;
      this.isShowBox = toggle;
      this.$emit("showInputBox", toggle);
    },
 
    //控制用户信息box
    showUserBox() {
      if (this.UserTimer) {
        clearTimeout(this.UserTimer);
        this.UserTimer = null;
      }
      this.isShowUserBox = true;
    },
    hiddenUserBox() {
      const _this = this;
      this.UserTimer = setTimeout(() => {
        _this.isShowUserBox = false;
      }, 200);
    },
 
    logOut() {
      logout().then(() => {
        sessionStorage.removeItem("loginedInfo");
        sessionStorage.removeItem("expires_in");
        sessionStorage.removeItem("userInfo");
        this.$router.push({
          path: "/login",
        });
        this.$notify({
          title: "提示",
          type: "success",
          message: "退出成功!",
          duration: 2500,
          offset: 57,
        });
      });
    },
 
    jump(id, type) {
      if (type) {
        sessionStorage.setItem("type", type);
      }
      this.$router.push({
        path: "/personalCenter",
        query: {
          id: id,
        },
      });
    },
  },
};
</script>
 
<style lang="scss" scoped>
.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: 62px;
  width: 100%;
  min-width: 1280px;
  background-color: rgba(255, 255, 255, 0.25);
  color: #fff;
  font-size: 14px;
 
  .left {
    display: flex;
    align-items: center;
 
    .logo {
      margin: 0 7px 0 20px;
      cursor: pointer;
    }
 
    .title {
      margin-right: 10px;
      cursor: pointer;
    }
 
    .label {
      margin: 0 20px;
      cursor: pointer;
    }
  }
 
  .right {
    position: relative;
    display: flex;
    align-items: center;
 
    .el-input ::v-deep {
      input {
        height: 62px;
        width: 180px;
        background-color: rgba(255, 255, 255, 0.5);
        border: none;
        border-radius: 0;
        color: #fff;
 
        &::-webkit-input-placeholder {
          color: #fff;
        }
      }
 
      .el-input__suffix {
        padding-top: 23px;
        padding-right: 23px;
      }
 
      .search {
        color: #fff;
        cursor: pointer;
      }
    }
 
    .headerLogin {
      flex-shrink: 0;
      width: 62px;
      height: 62px;
      text-align: center;
      line-height: 62px;
      background-color: rgb(64, 97, 202);
      cursor: pointer;
    }
 
    .register {
      flex-shrink: 0;
      width: 96px;
      height: 62px;
      text-align: center;
      line-height: 62px;
      background: #0065ff;
      cursor: pointer;
    }
 
    .userImg {
      height: 48px;
      width: 48px;
      margin: 0 20px;
    }
  }
 
  &:hover,
  &.showBox,
  &.disOpacity {
    background-color: #fff;
 
    .left {
      .title {
        color: #3d3d3d;
        font-weight: 700;
      }
 
      .label {
        color: #3d3d3d;
        &:hover {
          color: #0065ff;
        }
      }
    }
    .right {
      .el-input ::v-deep {
        input {
          background-color: rgba(245, 247, 250, 0.45);
          color: #3d3d3d;
 
          &::-webkit-input-placeholder {
            color: #999999;
          }
        }
 
        .search {
          color: rgb(32, 119, 254);
        }
      }
 
      .headerLogin {
        background-color: #fff;
        color: #3d3d3d;
      }
    }
  }
 
  &.showBox .right .el-input {
    position: absolute;
    z-index: 4;
    top: -7px;
    right: 88px;
    width: 300px;
    background-color: #fff;
 
    &.Unlogin {
      right: 158px;
    }
 
    ::v-deep input {
      width: 300px;
      background-color: #fff;
    }
 
    .del {
      color: rgb(32, 119, 254);
      margin-left: 30px;
      cursor: pointer;
    }
  }
}
 
.inputBox {
  box-sizing: border-box;
  position: absolute;
  top: 62px;
  right: 88px;
  padding: 12px 20px 8px 20px;
  width: 300px;
  background-color: #fff;
  border-top: 1px solid rgb(204, 204, 204);
  z-index: 4;
 
  &.Unlogin {
    top: 52px;
    right: 158px;
  }
 
  .hotKey,
  .historyKey {
    margin-top: 12px;
 
    .title {
      margin-bottom: 16px;
      font-weight: 700;
      font-size: 14px;
    }
 
    .keyCard {
      display: flex;
      flex-wrap: wrap;
 
      .keyItem {
        display: inline-block;
        margin-right: 12px;
        margin-bottom: 12px;
        padding: 5px 12px;
        color: #5c7399;
        background-color: #e4e9f1;
        font-size: 12px;
        cursor: pointer;
      }
    }
  }
}
 
.mask {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: #000000;
  opacity: 0.2;
  z-index: 3;
}
 
.userBox {
  box-sizing: border-box;
  position: absolute;
  z-index: 10;
  right: 20px;
  top: 64px;
  padding: 0 20px;
  width: 240px;
  height: 327px;
  background-color: #fff;
  box-shadow: 0px 4px 12px rgba(96, 100, 106, 0.12);
  border-radius: 4px;
 
  .userName {
    margin: 20px 0;
    font-weight: bold;
    font-size: 18px;
  }
 
  ul {
    height: 200px;
    border-top: 1px solid #e9ebee;
    border-bottom: 1px solid #e9ebee;
 
    li {
      display: flex;
      justify-content: space-between;
      margin: 20px 0;
      font-size: 14px;
 
      .label {
        cursor: pointer;
        &:hover {
          color: #0065ff;
        }
      }
 
      &.personal .content {
        color: #36b24a;
      }
 
      &.money .content {
        color: #666666;
 
        .button {
          display: inline-block;
          margin-right: 10px;
          width: 34px;
          height: 24px;
          text-align: center;
          line-height: 24px;
          font-size: 12px;
          border: 1px solid #ff6a00;
          color: #ff6a00;
        }
      }
    }
  }
 
  .logOut {
    margin-top: 20px;
    font-size: 16px;
    color: #3d3d3d;
    cursor: pointer;
 
    &:hover {
      color: #0065ff;
    }
  }
}
</style>