navBar.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  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. <mission v-if="user.type === '0'"></mission>
  11. </span>
  12. </div>
  13. <el-dropdown @command="handleCommand" style="z-index:99">
  14. <div class="user-profile-body">
  15. <img class="user-avatar" src="https://img.alicdn.com/tfs/TB1ONhloamWBuNjy1XaXXXCbXXa-200-200.png" />
  16. <span class="user-name" v-if="user && user.userid">欢迎,{{ (user && user.name) || '' }}</span>
  17. <span class="user-name" v-else @click="toLogin">请登录</span>
  18. </div>
  19. <el-dropdown-menu class="user-dropdown" slot="dropdown" v-if="user && user.userid">
  20. <el-dropdown-item :divided="true" command="weixin"> <img :src="weixin" style="zoom:0.1" /> 绑定/更绑微信 </el-dropdown-item>
  21. <!-- <el-dropdown-item :divided="true" icon="el-icon-key" command="passwd">
  22. 修改密码
  23. </el-dropdown-item> -->
  24. <el-dropdown-item :divided="true" icon="el-icon-back" command="backHome">
  25. 业务切换
  26. </el-dropdown-item>
  27. <el-dropdown-item :divided="true" icon="el-icon-guide" command="logout">
  28. 退出
  29. </el-dropdown-item>
  30. </el-dropdown-menu>
  31. </el-dropdown>
  32. </div>
  33. </div>
  34. <div>
  35. <def-sel @refresh="toRefresh" :key="defSelKey" v-on="$listeners"></def-sel>
  36. </div>
  37. </el-menu>
  38. <el-dialog title="修改密码" :visible.sync="dialog" center @close="toClose" :destroy-on-close="true">
  39. <data-form :data="info" :fields="fields" :rules="rules" @save="handleSave" :isNew="true"> </data-form>
  40. </el-dialog>
  41. <el-dialog :visible.sync="wxDialog" title="绑定微信" width="30%" center :destroy-on-close="true">
  42. <el-row type="flex" justify="center">
  43. <el-col :span="24" style="text-align:center">
  44. <qrcode exchange="qrcode.bind" v-if="qrUri" :uri="qrUri" :config="config" :qrcode="qrcode" @toReturn="toReturn"> </qrcode>
  45. </el-col>
  46. </el-row>
  47. </el-dialog>
  48. </div>
  49. </template>
  50. <script>
  51. import mission from '@frame/components/mission-icon.vue';
  52. import Vue from 'vue';
  53. import defSel from '@frame/layout/admin/navBar/default-select.vue';
  54. import '@frame/plugins/setting';
  55. import qrcode from '@frame/components/qrcode.vue';
  56. import dataForm from '@frame/components/form';
  57. import { mapState, mapMutations, createNamespacedHelpers } from 'vuex';
  58. import _ from 'lodash';
  59. const { mapActions } = createNamespacedHelpers('login');
  60. export default {
  61. name: 'navBar',
  62. props: {},
  63. components: { dataForm, qrcode, defSel, mission },
  64. data: () => ({
  65. weixin: require('@frame/assets/wechat.png'),
  66. dataUrl: '',
  67. info: {},
  68. dialog: false,
  69. wxDialog: false,
  70. fields: [{ label: '密码', required: true, model: 'passwd', type: 'password', tip: '密码至少6位' }],
  71. rules: {
  72. passwd: [
  73. { required: true, message: '请输入密码' },
  74. { min: 6, message: '密码最少6位', trigger: 'blur' },
  75. ],
  76. },
  77. qrUri: '',
  78. config: {},
  79. qrcode: '',
  80. defSelKey: new Date().getTime(),
  81. }),
  82. created() {},
  83. computed: {
  84. ...mapState(['user']),
  85. },
  86. methods: {
  87. ...mapMutations(['deleteUser', 'changeOption']),
  88. ...mapActions(['login', 'update', 'getQrcode', 'logout']),
  89. async toLogout() {
  90. // 云就业退出
  91. const res = await this.logout(this.user.id);
  92. console.log(res);
  93. if (res.data) {
  94. this.deleteUser();
  95. this.$notify({
  96. title: '注销成功',
  97. type: 'success',
  98. });
  99. console.log(res.data);
  100. window.location.replace(res.data);
  101. }
  102. // this.toLogin();
  103. },
  104. handleCommand(type) {
  105. if (type === 'logout') this.toLogout();
  106. if (type === 'passwd') this.toPasswd();
  107. if (type === 'weixin') this.bind();
  108. if (type === 'backHome') this.backHome();
  109. },
  110. async toLogin() {
  111. this.$router.push({ name: 'login' });
  112. },
  113. toPasswd() {
  114. this.dialog = true;
  115. },
  116. backHome() {
  117. window.location.replace('https://zhjy.jilinjobs.cn:8080/dist/school.html#/navi');
  118. },
  119. toClose() {
  120. this.info = {};
  121. this.dialog = false;
  122. },
  123. async handleSave({ data }) {
  124. data.id = this.user.id;
  125. let res = await this.update(data);
  126. if (this.$checkRes(res, '修改成功', '修改失败')) this.toClose();
  127. },
  128. async bind() {
  129. let res = await this.getQrcode();
  130. this.$set(this, `qrcode`, res);
  131. this.$set(this, `config`, { weixin: Vue.config.weixin, stomp: Vue.config.stomp });
  132. let user_id = this.user.id;
  133. if (!user_id) {
  134. let localuser = localStorage.getItem('user');
  135. if (localuser) {
  136. localuser = JSON.parse(localuser);
  137. user_id = localuser.id;
  138. }
  139. }
  140. let uri = `/api/train/auth?redirect_uri=${Vue.config.weixin.target}/confirm?uid=${user_id}&type=1&qrcode=${res}`;
  141. this.$set(this, `qrUri`, uri);
  142. this.wxDialog = true;
  143. },
  144. toReturn(message) {
  145. this.$notify({
  146. type: 'success',
  147. message: message.body,
  148. });
  149. },
  150. toRefresh() {
  151. this.defSelKey = new Date().getTime();
  152. },
  153. },
  154. };
  155. </script>
  156. <style lang="less" scoped>
  157. .navbar {
  158. height: 4rem;
  159. box-shadow: 0 0.0625rem 0.25rem rgba(0, 21, 41, 0.08);
  160. .user-profile-container {
  161. position: absolute;
  162. right: 1.25rem;
  163. cursor: pointer;
  164. .user-profile-content {
  165. display: flex;
  166. padding: 1.25rem 0;
  167. }
  168. .menu-icons {
  169. display: flex;
  170. align-items: center;
  171. .menu-icon {
  172. padding: 0 0.75rem;
  173. .icon {
  174. display: inline-block;
  175. font-size: 1.125rem;
  176. text-align: center;
  177. }
  178. }
  179. }
  180. .user-profile-body {
  181. position: relative;
  182. display: flex;
  183. flex-direction: row;
  184. align-items: center;
  185. justify-content: center;
  186. text-align: center;
  187. padding-right: 0.875rem;
  188. }
  189. .user-avatar {
  190. width: 1.5rem;
  191. height: 1.5rem;
  192. margin: 0 0.5rem 0 0.75rem;
  193. border-radius: 0.25rem;
  194. }
  195. .user-name {
  196. color: rgba(0, 0, 0, 0.65);
  197. }
  198. .user-department {
  199. font-size: 0.75rem;
  200. color: rgba(102, 102, 102, 0.65);
  201. }
  202. .el-icon-caret-bottom {
  203. position: absolute;
  204. right: 0;
  205. top: 0.8125rem;
  206. font-size: 0.75rem;
  207. }
  208. }
  209. }
  210. </style>