navBar.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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" style="z-index:99">
  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 user_id = this.user.id;
  119. if (!user_id) {
  120. let localuser = localStorage.getItem('user');
  121. if (localuser) {
  122. localuser = JSON.parse(localuser);
  123. user_id = localuser.id;
  124. }
  125. }
  126. let uri = `/api/train/auth?redirect_uri=${Vue.config.weixin.target}/student/confirm?uid=${user_id}&type=1&qrcode=${res}`;
  127. this.$set(this, `qrUri`, uri);
  128. this.wxDialog = true;
  129. },
  130. toReturn(message) {
  131. this.$notify({
  132. type: 'success',
  133. message: message.body,
  134. });
  135. },
  136. },
  137. };
  138. </script>
  139. <style lang="less" scoped>
  140. .navbar {
  141. height: 4rem;
  142. box-shadow: 0 0.0625rem 0.25rem rgba(0, 21, 41, 0.08);
  143. .user-profile-container {
  144. position: absolute;
  145. right: 1.25rem;
  146. cursor: pointer;
  147. .user-profile-content {
  148. display: flex;
  149. padding: 1.25rem 0;
  150. }
  151. .menu-icons {
  152. display: flex;
  153. align-items: center;
  154. .menu-icon {
  155. padding: 0 0.75rem;
  156. .icon {
  157. display: inline-block;
  158. font-size: 1.125rem;
  159. text-align: center;
  160. }
  161. }
  162. }
  163. .user-profile-body {
  164. position: relative;
  165. display: flex;
  166. flex-direction: row;
  167. align-items: center;
  168. justify-content: center;
  169. text-align: center;
  170. padding-right: 0.875rem;
  171. }
  172. .user-avatar {
  173. width: 1.5rem;
  174. height: 1.5rem;
  175. margin: 0 0.5rem 0 0.75rem;
  176. border-radius: 0.25rem;
  177. }
  178. .user-name {
  179. color: rgba(0, 0, 0, 0.65);
  180. }
  181. .user-department {
  182. font-size: 0.75rem;
  183. color: rgba(102, 102, 102, 0.65);
  184. }
  185. .el-icon-caret-bottom {
  186. position: absolute;
  187. right: 0;
  188. top: 0.8125rem;
  189. font-size: 0.75rem;
  190. }
  191. }
  192. }
  193. </style>