navBar.vue 6.5 KB

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