navBar.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. <template>
  2. <div id="navBar">
  3. <el-menu class="navbar" mode="horizontal">
  4. <div class="user-profile-container">
  5. <div class="user-profile-content">
  6. <!-- <div class="menu-icons">
  7. <span class="menu-icon"><i class="el-icon-search icon"></i></span>
  8. <span class="menu-icon"><i class="el-icon-message icon"></i></span>
  9. <span class="menu-icon">
  10. <el-badge is-dot class="item">
  11. <i class="el-icon-bell icon"></i>
  12. </el-badge>
  13. </span>
  14. </div> -->
  15. <el-dropdown @command="handleCommand">
  16. <div class="user-profile-body">
  17. <img class="user-avatar" src="https://img.alicdn.com/tfs/TB1ONhloamWBuNjy1XaXXXCbXXa-200-200.png" />
  18. <span class="user-name" v-if="user && user.userid">欢迎,{{ (user && user.name) || '' }}</span>
  19. <span class="user-name" v-else @click="toLogin">请登录</span>
  20. </div>
  21. <el-dropdown-menu class="user-dropdown" slot="dropdown" v-if="user && user.userid">
  22. <el-dropdown-item :divided="true" command="weixin"> <img :src="weixin" style="zoom:0.1" /> 绑定/更绑微信 </el-dropdown-item>
  23. <el-dropdown-item :divided="true" icon="el-icon-key" command="passwd">
  24. 修改密码
  25. </el-dropdown-item>
  26. <el-dropdown-item :divided="true" icon="el-icon-guide" command="logout">
  27. 退出
  28. </el-dropdown-item>
  29. </el-dropdown-menu>
  30. </el-dropdown>
  31. </div>
  32. </div>
  33. </el-menu>
  34. <el-dialog title="修改密码" :visible.sync="dialog" center @close="toClose" :destroy-on-close="true">
  35. <data-form :data="info" :fields="fields" :rules="rules" @save="handleSave" :isNew="true"> </data-form>
  36. </el-dialog>
  37. <el-dialog :visible.sync="wxDialog" title="绑定微信" width="30%" center :destroy-on-close="true">
  38. <el-row type="flex" justify="center">
  39. <el-col :span="24" style="text-align:center">
  40. <img :src="dataUrl" />
  41. </el-col>
  42. </el-row>
  43. </el-dialog>
  44. </div>
  45. </template>
  46. <script>
  47. import QRCode from 'qrcode';
  48. import dataForm from '@frame/components/form';
  49. import { mapState, mapMutations, createNamespacedHelpers } from 'vuex';
  50. import _ from 'lodash';
  51. const { mapActions } = createNamespacedHelpers('login');
  52. export default {
  53. name: 'navBar',
  54. props: {},
  55. components: { dataForm },
  56. data: () => ({
  57. weixin: require('@frame/assets/wechat.png'),
  58. dataUrl: '',
  59. info: {},
  60. dialog: false,
  61. wxDialog: false,
  62. fields: [{ label: '密码', required: true, model: 'passwd', type: 'password', tip: '密码至少6位' }],
  63. rules: {
  64. passwd: [
  65. { required: true, message: '请输入密码' },
  66. { min: 6, message: '密码最少6位', trigger: 'blur' },
  67. ],
  68. },
  69. }),
  70. created() {},
  71. computed: {
  72. ...mapState(['user']),
  73. },
  74. methods: {
  75. ...mapMutations(['deleteUser']),
  76. ...mapActions(['login', 'update']),
  77. async toLogout() {
  78. this.deleteUser();
  79. this.$notify({
  80. title: '注销成功',
  81. type: 'success',
  82. });
  83. this.toLogin();
  84. },
  85. handleCommand(type) {
  86. if (type === 'logout') this.toLogout();
  87. if (type === 'passwd') this.toPasswd();
  88. if (type === 'weixin') this.bind();
  89. },
  90. async toLogin() {
  91. this.$router.push({ name: 'login' });
  92. },
  93. toPasswd() {
  94. this.dialog = true;
  95. },
  96. toClose() {
  97. this.info = {};
  98. this.dialog = false;
  99. },
  100. async handleSave({ data }) {
  101. data.id = this.user.id;
  102. let res = await this.update(data);
  103. if (this.$checkRes(res, '修改成功', '修改失败')) this.toClose();
  104. },
  105. async bind() {
  106. let uri = `http://free.liaoningdoupo.com/api/train/authtest?redirect_uri=http://10.16.10.7:8001/confirm&uid=${this.user.id}&type=1`;
  107. this.dataUrl = await QRCode.toDataURL(uri);
  108. this.wxDialog = true;
  109. },
  110. },
  111. };
  112. </script>
  113. <style lang="less" scoped>
  114. .navbar {
  115. height: 4rem;
  116. box-shadow: 0 0.0625rem 0.25rem rgba(0, 21, 41, 0.08);
  117. .user-profile-container {
  118. position: absolute;
  119. right: 1.25rem;
  120. cursor: pointer;
  121. .user-profile-content {
  122. display: flex;
  123. padding: 1.25rem 0;
  124. }
  125. .menu-icons {
  126. display: flex;
  127. align-items: center;
  128. .menu-icon {
  129. padding: 0 0.75rem;
  130. .icon {
  131. display: inline-block;
  132. font-size: 1.125rem;
  133. text-align: center;
  134. }
  135. }
  136. }
  137. .user-profile-body {
  138. position: relative;
  139. display: flex;
  140. flex-direction: row;
  141. align-items: center;
  142. justify-content: center;
  143. text-align: center;
  144. padding-right: 0.875rem;
  145. }
  146. .user-avatar {
  147. width: 1.5rem;
  148. height: 1.5rem;
  149. margin: 0 0.5rem 0 0.75rem;
  150. border-radius: 0.25rem;
  151. }
  152. .user-name {
  153. color: rgba(0, 0, 0, 0.65);
  154. }
  155. .user-department {
  156. font-size: 0.75rem;
  157. color: rgba(102, 102, 102, 0.65);
  158. }
  159. .el-icon-caret-bottom {
  160. position: absolute;
  161. right: 0;
  162. top: 0.8125rem;
  163. font-size: 0.75rem;
  164. }
  165. }
  166. }
  167. </style>