zuojincheng
2024-10-22 8c1342bb1394dd7e193aaad5b94c49822b3af1df
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
<template>
  <div class="Right">
    <div class="top">
      <div class="isCollapse" @click="toggleIsCollapse">
        <i v-if="!isCollapse" class="el-icon-s-fold"></i>
        <i v-if="isCollapse" class="el-icon-s-unfold"></i>
      </div>
      <div class="sysName">信息化智能化生产管理平台</div>
      <div class="userMenu">
        <span class="hello">您好,{{ name }}!</span>
        <el-button type="text" icon="el-icon-setting" @click="handlePassword"
          >修改密码</el-button
        >
        <el-button type="text" icon="el-icon-switch-button" @click="handleLogin"
          >退出登录</el-button
        >
      </div>
    </div>
    <div class="rightMiddleTags">
      <div class="tagsBox">
        <!-- 首页 -->
        <el-tag
          class="tagsClass"
          sizeType="medium"
          type="info"
          @click="goto('home')"
          :type="$route.name === 'home' ? '' : 'info'"
          >首页</el-tag
        >
        <!-- 非首页 -->
        <el-tag
          class="tagsClass"
          sizeType="medium"
          type="info"
          v-for="(item, index) in tags"
          :key="index"
          @click="goto(item.name)"
          :type="$route.name === item.name ? '' : 'info'"
          closable
          @close="handleTagClose(item.name, index)"
          >{{ item.meta.title }}</el-tag
        >
      </div>
      <div class="tagControl">
        <div class="tagControlItem" @click="handleTagCloseOthers">
          <i class="iconfont icon-guanbiqita"></i><span>关闭其他</span>
        </div>
        <div class="tagControlItem" @click="handleTagCloseAll">
          <i class="iconfont icon-quanbuguanbi"></i><span>全部关闭</span>
        </div>
      </div>
    </div>
    <el-dialog
      title="修改密码"
      :visible.sync="showPass"
      width="600px"
      :before-close="handlePassClose"
    >
      <el-form
        :model="formData"
        :rules="formRules"
        ref="passForm"
        label-width="80px"
      >
        <el-form-item label="用户名" prop="id">
          <el-input style="width:360px" :value="name" disabled></el-input>
        </el-form-item>
        <el-form-item label="用户ID" prop="id" style="display: none;">
          <el-input
            style="width:360px"
            v-model="formData.id"
            disabled
          ></el-input>
        </el-form-item>
        <el-form-item label="原密码" prop="oldPassword">
          <el-input
            style="width:360px"
            v-model="formData.oldPassword"
            clearable
            show-password
          ></el-input>
        </el-form-item>
        <el-form-item label="新密码" prop="newPassword">
          <el-input
            style="width:360px"
            v-model="formData.newPassword"
            clearable
            show-password
          ></el-input>
        </el-form-item>
        <el-form-item label="确认密码" prop="newPassword2">
          <el-input
            style="width:360px"
            v-model="formData.newPassword2"
            clearable
            show-password
          ></el-input>
        </el-form-item>
      </el-form>
      <div class="intro">
        密码修改成功后将退出当前登录,请使用新密码重新登录系统
      </div>
      <div class="intro">
        密码长度必须为6位,可包含字母、数字
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="handlePassClose">取 消</el-button>
        <el-button type="primary" @click="handlePassSubmit">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>
 
<script>
import util from "../util";
import { mapMutations, mapActions } from "vuex";
import { mapState } from "vuex";
 
export default {
  components: {},
  name: "Right",
  props: {
    params: String,
  },
  data() {
    return {
      isCollapse: false,
      showPass: false,
      name: localStorage.getItem("name"),
      formData: {
        id: localStorage.getItem("id"),
        oldPassword: "",
        newPassword: "",
        newPassword2: "",
      },
      formRules: {
        oldPassword: [{ required: true, message: "必填项", trigger: "blur" }],
        newPassword: [{ required: true, message: "必填项", trigger: "blur" }],
        newPassword2: [{ required: true, message: "必填项", trigger: "blur" }],
      },
    };
  },
  computed: {
    ...mapState("cache", ["caches"]),
    tags: function() {
      var that = this;
      var arr = [];
      that.caches.forEach((item) => {
        that.$router.options.routes.forEach((routerItem) => {
          if (item == routerItem.name) {
            arr.push(routerItem);
          }
        });
      });
      return arr;
    },
  },
  mounted() {},
  watch: {
    cache: {
      immediate: true,
      handler() {
        // console.log("cache ->", this.cache);
      },
    },
  },
  methods: {
    ...mapActions("cache", ["addCache", "removeCache", "removeCacheEntry"]),
    ...mapMutations(["setIsRenderTab"]),
    // 跳转路由
    goto: function(path) {
      if (path != this.$route.name) {
        this.$router.push({
          name: path,
        });
      }
    },
    // 切换菜单展示模式: 展开或收起
    toggleIsCollapse() {
      this.isCollapse = !this.isCollapse;
      util.$emit("toggleIsCollapse", this.isCollapse);
    },
    // 退出登录状态
    handleLogin() {
      this.$confirm("此操作将退出登陆, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          localStorage.clear();
          this.$router.push({
            name: "login",
          });
          this.$message({
            type: "success",
            message: "已退出",
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消",
          });
        });
    },
    // 修改密码
    handlePassword: function() {
      this.showPass = true;
    },
    // 关闭修改密码
    handlePassClose: function() {
      this.formData.oldPassword = "";
      this.formData.newPassword = "";
      this.formData.newPassword2 = "";
      this.showPass = false;
      this.$refs["passForm"].resetFields();
    },
    // 提交修改密码
    handlePassSubmit: function() {
      this.$refs["passForm"].validate((valid) => {
        if (valid) {
          this.$confirm("此操作将修改密码并退出登录, 是否继续?", "提示", {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning",
          })
            .then((res) => {
              this.onPassSubmit();
            })
            .catch((err) => {
              this.$message({
                type: "info",
                message: "已取消",
              });
            });
        }
      });
    },
    // 执行修改密码
    onPassSubmit: function() {
      if (this.formData.oldPassword == this.formData.newPassword) {
        this.$message({
          type: "info",
          message: "新密码与原密码重复",
        });
        return;
      }
      if (this.formData.newPassword != this.formData.newPassword2) {
        this.$message({
          type: "info",
          message: "新密码与确认密码不一致",
        });
        return;
      }
      var pwdRegex = new RegExp("^[a-zA-Z0-9]{6,}$");
      if (!pwdRegex.test(this.formData.newPassword)) {
        this.$message({
          type: "info",
          message: "密码长度必须为6位,可包含字母、数字",
        });
        return;
      }
      var that = this;
      var data = this.formData;
      that
        .$axiosAdmin({
          method: "get",
          url: "base/user/changePassword",
          params: data,
        })
        .then((res) => {
          if (res.success) {
            localStorage.clear();
            that.$router.push({
              name: "Login",
            });
            that.$message({
              type: "success",
              message: "请重新登录",
            });
          } else {
            that.$message(res.content);
          }
        })
        .catch((err) => {
          console.log(err);
        });
    },
    // 关闭窗口
    handleTagClose: function(item, index) {
      if (item != this.$route.name) {
        // console.log("关闭窗口", item);
        this.removeCache(item || "");
        return;
      }
      if (this.caches.length == 1) {
        this.goto("home");
        // console.log("关闭唯一窗口,回首页", item);
        this.removeCache(item || "");
        return;
      }
      if (index == this.caches.length - 1) {
        // console.log("关闭末位窗口,去前页", item);
        this.goto(this.caches[index - 1]);
        this.removeCache(item || "");
        return;
      }
      if (item == this.$route.name) {
        this.goto(this.caches[index + 1]);
        // console.log("关闭当前窗口,去后页", item);
        this.removeCache(item || "");
      }
    },
    // 关闭其他
    handleTagCloseOthers: function() {
      var arr = JSON.parse(JSON.stringify(this.caches));
      arr.forEach((item) => {
        if (item != this.$route.name) {
          // console.log(item, '已关闭');
          this.removeCache(item || "");
        }
      });
    },
    // 关闭所有
    handleTagCloseAll: function() {
      this.goto("home");
      var arr = JSON.parse(JSON.stringify(this.caches));
      arr.forEach((item) => {
        // console.log(item, '已关闭');
        this.removeCache(item || "");
      });
    },
  },
};
</script>
 
<style lang="less" scoped>
.Right {
  background-color: #fff;
  padding-right: 1px;
  .top {
    height: 56px;
    line-height: 56px;
    border-bottom: 1px solid #ddd;
    display: flex;
    align-items: center;
    .isCollapse {
      width: 56px;
      height: 56px;
      font-size: 18px;
      text-align: center;
      margin-top: 2px;
    }
    .isCollapse:hover {
      background-color: #eee;
    }
    .sysName {
      font-size: 24px;
      font-weight: 700;
    }
    .userMenu {
      flex-grow: 1;
      padding-right: 20px;
      text-align: right;
    }
  }
  .rightMiddleTags {
    display: flex;
    justify-content: flex-start;
    align-items: center;
    box-shadow: 0px 5px 5px -3px rgba(134, 134, 134, 0.1);
    .tagsBox {
      height: 43px;
      flex-grow: 1;
      background-color: #fff;
      display: flex;
      justify-content: flex-start;
      align-items: center;
      overflow: auto;
      padding-left: 5px;
      .tagsClass {
        margin-right: 5px;
      }
    }
    .tagControl {
      display: flex;
      justify-content: flex-start;
      align-items: center;
      .tagControlItem {
        display: flex;
        justify-content: flex-start;
        align-items: center;
        width: 81px;
        height: 43px;
        line-height: 43px;
        padding: 0 10px;
        background-color: #f4f4f5;
        border-left: 1px solid #e9e9eb;
        border-bottom: 1px solid #e9e9eb;
        color: #909399;
        i {
          margin-right: 5px;
          font-size: 20px;
        }
      }
      .tagControlItem:hover {
        background-color: #e9e9ec;
        cursor: pointer;
      }
    }
  }
}
</style>