navBar.vue 5.7 KB

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