navBar.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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. <qrcode exchange="qrcode.bind" :uri="qrUri" :config="config" :qrcode="qrcode" @toReturn="toReturn"></qrcode>
  41. </el-col>
  42. </el-row>
  43. </el-dialog>
  44. </div>
  45. </template>
  46. <script>
  47. import Vue from 'vue';
  48. import '@frame/plugins/setting';
  49. import qrcode from '@frame/components/qrcode.vue';
  50. import dataForm from '@frame/components/form';
  51. import { mapState, mapMutations, createNamespacedHelpers } from 'vuex';
  52. import _ from 'lodash';
  53. const { mapActions } = createNamespacedHelpers('login');
  54. export default {
  55. name: 'navBar',
  56. props: {},
  57. components: { dataForm, qrcode },
  58. data: () => ({
  59. weixin: require('@frame/assets/wechat.png'),
  60. dataUrl: '',
  61. info: {},
  62. dialog: false,
  63. wxDialog: false,
  64. fields: [{ label: '密码', required: true, model: 'passwd', type: 'password', tip: '密码至少6位' }],
  65. rules: {
  66. passwd: [
  67. { required: true, message: '请输入密码' },
  68. { min: 6, message: '密码最少6位', trigger: 'blur' },
  69. ],
  70. },
  71. qrUri: '',
  72. config: {},
  73. qrcode: '',
  74. }),
  75. created() {},
  76. computed: {
  77. ...mapState(['user']),
  78. },
  79. methods: {
  80. ...mapMutations(['deleteUser']),
  81. ...mapActions(['login', 'update', 'getQrcode']),
  82. async toLogout() {
  83. this.deleteUser();
  84. this.$notify({
  85. title: '注销成功',
  86. type: 'success',
  87. });
  88. this.toLogin();
  89. },
  90. handleCommand(type) {
  91. if (type === 'logout') this.toLogout();
  92. if (type === 'passwd') this.toPasswd();
  93. if (type === 'weixin') this.bind();
  94. },
  95. async toLogin() {
  96. this.$router.push({ name: 'login' });
  97. },
  98. toPasswd() {
  99. this.dialog = true;
  100. },
  101. toClose() {
  102. this.info = {};
  103. this.dialog = false;
  104. },
  105. async handleSave({ data }) {
  106. data.id = this.user.id;
  107. let res = await this.update(data);
  108. if (this.$checkRes(res, '修改成功', '修改失败')) this.toClose();
  109. },
  110. async bind() {
  111. let res = await this.getQrcode();
  112. this.$set(this, `qrcode`, res);
  113. this.$set(this, `config`, { weixin: Vue.config.weixin, stomp: Vue.config.stomp });
  114. let uri = `/api/train/auth?redirect_uri=${Vue.config.weixin.target}/confirm&uid=${this.user.id}&type=1&qrcode=${res}`;
  115. this.$set(this, `qrUri`, uri);
  116. this.wxDialog = true;
  117. },
  118. toReturn(message) {
  119. this.$notify({
  120. type: 'success',
  121. message: message.body,
  122. });
  123. },
  124. },
  125. };
  126. </script>
  127. <style lang="less" scoped>
  128. .navbar {
  129. height: 4rem;
  130. box-shadow: 0 0.0625rem 0.25rem rgba(0, 21, 41, 0.08);
  131. .user-profile-container {
  132. position: absolute;
  133. right: 1.25rem;
  134. cursor: pointer;
  135. .user-profile-content {
  136. display: flex;
  137. padding: 1.25rem 0;
  138. }
  139. .menu-icons {
  140. display: flex;
  141. align-items: center;
  142. .menu-icon {
  143. padding: 0 0.75rem;
  144. .icon {
  145. display: inline-block;
  146. font-size: 1.125rem;
  147. text-align: center;
  148. }
  149. }
  150. }
  151. .user-profile-body {
  152. position: relative;
  153. display: flex;
  154. flex-direction: row;
  155. align-items: center;
  156. justify-content: center;
  157. text-align: center;
  158. padding-right: 0.875rem;
  159. }
  160. .user-avatar {
  161. width: 1.5rem;
  162. height: 1.5rem;
  163. margin: 0 0.5rem 0 0.75rem;
  164. border-radius: 0.25rem;
  165. }
  166. .user-name {
  167. color: rgba(0, 0, 0, 0.65);
  168. }
  169. .user-department {
  170. font-size: 0.75rem;
  171. color: rgba(102, 102, 102, 0.65);
  172. }
  173. .el-icon-caret-bottom {
  174. position: absolute;
  175. right: 0;
  176. top: 0.8125rem;
  177. font-size: 0.75rem;
  178. }
  179. }
  180. }
  181. </style>