Navbar.vue 10 KB

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