Navbar.vue 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  1. <template>
  2. <div class="navbar">
  3. <!-- <hamburger :is-active="sidebar.opened" class="hamburger-container" @toggleClick="toggleSideBar" /> -->
  4. <!-- <breadcrumb class="breadcrumb-container" /> -->
  5. <div class="left-menu">
  6. <i class='el-icon-location-information topIcon'></i>
  7. <el-popover placement="top-start"
  8. width="300"
  9. trigger="hover">
  10. <div class="popover-container">
  11. <!-- <p style="color: red">{{ organName }}</p> -->
  12. <el-tag class="navbar_tag" type="info" v-for="item in organNameList" :key="item">{{ item }}</el-tag>
  13. </div>
  14. <span slot="reference">{{ organName.length > 10 ? organName.substr(0, 10) + '...' : organName}}</span>
  15. </el-popover>
  16. </div>
  17. <div class="right-menu">
  18. <div class="msginfo"
  19. v-permission="'/journals'"
  20. @click="gotoRecode">
  21. <img src='@/assets/images/base/base-bell.svg'/>
  22. <!-- <div class="active"></div> -->
  23. </div>
  24. <el-dropdown class="avatar-container"
  25. trigger="click">
  26. <div class="avatar-wrapper">
  27. <img v-if="$store.getters.avatar"
  28. :src="$store.getters.avatar"
  29. class="user-avatar" />
  30. <img v-else
  31. class="user-avatar"
  32. src="@/assets/images/base/placehorder-icon.png" />
  33. <!-- <i class="el-icon-caret-bottom" /> -->
  34. <span>{{ username }}</span>
  35. </div>
  36. <el-dropdown-menu slot="dropdown"
  37. class="user-dropdown">
  38. <!-- divided -->
  39. <el-dropdown-item>
  40. <span style="display:block;"
  41. @click="resetPassWord">修改密码</span>
  42. </el-dropdown-item>
  43. <el-dropdown-item>
  44. <span style="display:block;"
  45. @click="logout">退出</span>
  46. </el-dropdown-item>
  47. </el-dropdown-menu>
  48. </el-dropdown>
  49. </div>
  50. <el-dialog title="修改密码"
  51. width="500px"
  52. append-to-body
  53. :visible.sync="resetVisible">
  54. <el-form :model="resetForm"
  55. label-position='right'
  56. label-width="100px"
  57. ref='pwdForm'>
  58. <el-form-item label="手机号"
  59. prop="phone">
  60. <div>{{this.$store.getters.phone}}</div>
  61. </el-form-item>
  62. <el-form-item label="新密码"
  63. :rules="[{ required: true, message: '密码不能为空',trigger: 'blur'},{pattern:/^[\w]{6,20}$/,message:'密码为6-20位',trigger: 'blur'}]"
  64. prop="password">
  65. <el-input v-model.trim="resetForm.password"
  66. type='password'
  67. style="width:180px"
  68. autocomplete="off"></el-input>
  69. </el-form-item>
  70. <el-form-item label="再次输入"
  71. :rules="[{ required: true, message: '密码不能为空',trigger: 'blur'},{pattern:/^[\w]{6,20}$/,message:'密码为6-20位',trigger: 'blur'}]"
  72. prop="password2">
  73. <el-input v-model.trim="resetForm.password2"
  74. type='password'
  75. style="width:180px"
  76. autocomplete="off"></el-input>
  77. </el-form-item>
  78. <el-form-item label="验证码"
  79. :rules="[{ required: true, message: '验证码不能为空',trigger: 'blur'}]"
  80. prop="authCode"
  81. style="">
  82. <el-input v-model.trim="resetForm.authCode"
  83. style="width:180px"
  84. autocomplete="off"></el-input>
  85. <el-button :disabled="isDisable"
  86. @click="getCode">{{ btnName }}</el-button>
  87. </el-form-item>
  88. </el-form>
  89. <div slot="footer"
  90. class="dialog-footer">
  91. <el-button @click="resetVisible = false">取 消</el-button>
  92. <el-button type="primary"
  93. @click="submitResetPassWord">确 定</el-button>
  94. </div>
  95. </el-dialog>
  96. </div>
  97. </template>
  98. <script>
  99. import qs from 'qs'
  100. import axios from 'axios'
  101. import { mapGetters } from "vuex";
  102. // import Breadcrumb from '@/components/Breadcrumb'
  103. // import Hamburger from '@/components/Hamburger'
  104. import { resetPassword } from '@/api/buildTeam'
  105. export default {
  106. data () {
  107. return {
  108. username: '',
  109. organName: this.$store.getters.organName,
  110. organNameList: [],
  111. resetVisible: false,
  112. resetForm: {
  113. phone: '',
  114. authCode: '',
  115. password: '',
  116. password2: ''
  117. },
  118. isDisable: false, // 是否允许发送验证码
  119. timerCount: 60,
  120. btnName: '获取验证码'
  121. }
  122. },
  123. components: {
  124. // Breadcrumb,
  125. // Hamburger
  126. },
  127. computed: {
  128. ...mapGetters(["sidebar", "avatar"])
  129. },
  130. mounted () {
  131. // 手动加入
  132. this.toggleSideBar();
  133. this.username = this.$store.getters.name;
  134. this.organNameList = this.organName.split(',')
  135. },
  136. methods: {
  137. toggleSideBar () {
  138. this.$store.dispatch("app/toggleSideBar");
  139. },
  140. async logout () {
  141. await this.$store.dispatch("user/logout");
  142. // await this.$store.dispatch("permission/removePermission")
  143. this.$router.push(`/login`);
  144. window.location.reload()
  145. },
  146. gotoRecode () {
  147. this.$router.push('/journal/journal')
  148. },
  149. resetPassWord () {
  150. this.resetVisible = true;
  151. },
  152. submitResetPassWord () {
  153. if (this.resetForm.password !== this.resetForm.password2) {
  154. this.$message.error('两次密码必须相同')
  155. return
  156. }
  157. this.$refs['pwdForm'].validate(res => {
  158. if (res) {
  159. // 发请求
  160. resetPassword({ authCode: this.resetForm.authCode, mobile: this.$store.getters.phone, newPassword: this.resetForm.password }).then(res => {
  161. if (res.code == 200) {
  162. // 修改成功
  163. this.$message.success('修改成功')
  164. this.logout()
  165. }
  166. })
  167. }
  168. })
  169. },
  170. getCode () {
  171. // 获取验证码
  172. if (!this.$store.getters.phone) {
  173. this.$message.error('请输入正确的手机号')
  174. return
  175. }
  176. if (!this.isDisable) {
  177. this.isDisable = true;
  178. // 发请求成功后开启定时器
  179. // 发送验证码
  180. axios.post('/api-web/code/sendSms', qs.stringify({ mobile: this.$store.getters.phone })).then(res => {
  181. if (res.data.code == 200) {
  182. let timer = setInterval(res => {
  183. if (this.timerCount <= 0) {
  184. clearInterval(timer)
  185. this.isDisable = false;
  186. this.btnName = '获取验证码';
  187. this.timerCount = 60;
  188. } else {
  189. this.timerCount--;
  190. this.btnName = `${this.timerCount}s后重试`
  191. }
  192. }, 1000)
  193. }
  194. })
  195. }
  196. }
  197. },
  198. watch: {
  199. resetVisible (val) {
  200. if (!val) {
  201. this.resetForm = {
  202. phone: '',
  203. authCode: '',
  204. password: '',
  205. password2: ''
  206. }
  207. }
  208. }
  209. }
  210. };
  211. </script>
  212. <style lang="scss" scoped>
  213. .navbar_tag {
  214. margin: 0 5px 8px;
  215. }
  216. .popover-container {
  217. max-height: 350px;
  218. overflow-y: scroll;
  219. }
  220. .navbar {
  221. display: flex;
  222. flex-direction: row;
  223. justify-content: space-between;
  224. height: 60px;
  225. overflow: hidden;
  226. position: relative;
  227. background: #fff;
  228. box-shadow: 0px 8px 20px 0px rgba(0, 0, 0, 0.1);
  229. h2 {
  230. font-size: 18px;
  231. line-height: 60px;
  232. margin: 0 0 0 30px;
  233. display: inline-block;
  234. }
  235. .hamburger-container {
  236. line-height: 60px;
  237. height: 100%;
  238. float: left;
  239. cursor: pointer;
  240. transition: background 0.3s;
  241. -webkit-tap-highlight-color: transparent;
  242. &:hover {
  243. background: rgba(0, 0, 0, 0.025);
  244. }
  245. }
  246. .breadcrumb-container {
  247. float: left;
  248. }
  249. .left-menu {
  250. line-height: 60px;
  251. padding-left: 22px;
  252. font-size: 16px;
  253. color: #444;
  254. .topIcon {
  255. width: 20px;
  256. height: 25px;
  257. }
  258. }
  259. .right-menu {
  260. min-width: 204px;
  261. float: right;
  262. height: 100%;
  263. line-height: 60px;
  264. display: flex;
  265. flex-direction: row;
  266. justify-content: flex-start;
  267. &:focus {
  268. outline: none;
  269. }
  270. .msginfo {
  271. display: flex;
  272. flex-direction: row;
  273. justify-content: flex-start;
  274. align-items: center;
  275. margin-right: 34px;
  276. position: relative;
  277. cursor: pointer;
  278. img {
  279. width: 23px;
  280. height: 30px;
  281. }
  282. .active {
  283. position: absolute;
  284. width: 7px;
  285. height: 7px;
  286. background-color: #f97215;
  287. border-radius: 50%;
  288. top: 20px;
  289. right: -4px;
  290. }
  291. }
  292. .right-menu-item {
  293. display: inline-block;
  294. padding: 0 8px;
  295. height: 100%;
  296. font-size: 14px;
  297. color: #5a5e66;
  298. vertical-align: text-bottom;
  299. &.hover-effect {
  300. cursor: pointer;
  301. transition: background 0.3s;
  302. &:hover {
  303. background: rgba(0, 0, 0, 0.025);
  304. }
  305. }
  306. }
  307. .avatar-container {
  308. height: 60px;
  309. margin-right: 42px;
  310. cursor: pointer;
  311. .avatar-wrapper {
  312. position: relative;
  313. display: flex;
  314. flex-direction: row;
  315. justify-content: flex-start;
  316. align-items: center;
  317. span {
  318. margin-left: 15px;
  319. font-size: 14px;
  320. font-weight: 500;
  321. color: rgba(68, 68, 68, 1);
  322. }
  323. .user-avatar {
  324. cursor: pointer;
  325. width: 32px;
  326. height: 32px;
  327. border: 2px solid #f0f2f5;
  328. border-radius: 50%;
  329. }
  330. .el-icon-caret-bottom {
  331. cursor: pointer;
  332. position: absolute;
  333. right: -20px;
  334. top: 25px;
  335. font-size: 14px;
  336. }
  337. }
  338. }
  339. }
  340. }
  341. </style>