Home.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463
  1. <template>
  2. <el-row class="container">
  3. <el-col :span="24" class="header">
  4. <el-col :span="10" class="logo" :class="collapsed?'logo-collapse-width':'logo-width'" :style="collapsed?'padding:0':''">
  5. <img v-if="collapsed" class="headImg" src="../assets/image/head_logo.png" />
  6. <div v-else class="logo-sys">
  7. <img class="headImg" src="../assets/image/head_logo.png" />
  8. <span>{{sysName}}</span>
  9. </div>
  10. </el-col>
  11. <el-col :span="10">
  12. <div class="tools" @click.prevent="collapse">
  13. <i class="fa fa-align-justify"></i>
  14. </div>
  15. </el-col>
  16. <el-col :span="6" class="userinfo">
  17. <el-dropdown trigger="hover">
  18. <span class="el-dropdown-link userinfo-inner">
  19. <img src="../assets/image/userHead.png" />
  20. {{sysUserName}}
  21. </span>
  22. <el-dropdown-menu slot="dropdown">
  23. <el-dropdown-item @click.native="reset">修改密码</el-dropdown-item>
  24. <el-dropdown-item @click.native="editInfoOpen">修改信息</el-dropdown-item>
  25. <el-dropdown-item divided @click.native="logout">退出登录</el-dropdown-item>
  26. </el-dropdown-menu>
  27. </el-dropdown>
  28. </el-col>
  29. </el-col>
  30. <el-col :span="24" class="main">
  31. <aside :class="collapsed?'menu-collapsed':'menu-expanded'">
  32. <!--导航菜单-->
  33. <el-menu :default-active="$route.path" class="el-menu-vertical-demo" unique-opened router v-if="!collapsed">
  34. <template v-for="(item,index) in $router.options.routes" v-if="!item.hidden">
  35. <el-submenu :index="index+''" v-if="!item.leaf">
  36. <template slot="title">
  37. <i :class="item.iconCls"></i>
  38. <span class="itemName">{{item.name}}</span>
  39. </template>
  40. <el-menu-item v-for="child in item.children" :index="child.path" :key="child.path" v-if="!child.hidden">{{child.name}}</el-menu-item>
  41. </el-submenu>
  42. <el-menu-item v-if="item.leaf && item.children.length > 0" :index="item.children[0].path">
  43. <i :class="item.iconCls"></i> {{item.children[0].name}}
  44. </el-menu-item>
  45. </template>
  46. </el-menu>
  47. <!--导航菜单-折叠后-->
  48. <ul class="el-menu el-menu-vertical-demo collapsed" v-if="collapsed" ref="menuCollapsed">
  49. <li v-for="(item,index) in $router.options.routes" v-if="!item.hidden" class="el-submenu item" :style="{overflow:!item.leaf?'':'hidden'}">
  50. <template v-if="!item.leaf">
  51. <div class="el-submenu__title" style="padding-left: 20px;" @mouseover="showMenu(index,true)" @mouseout="showMenu(index,false)">
  52. <i :class="item.iconCls"></i>
  53. </div>
  54. <ul class="el-menu submenu" :class="'submenu-hook-'+index" @mouseover="showMenu(index,true)" @mouseout="showMenu(index,false)">
  55. <li v-for="child in item.children" v-if="!child.hidden" :key="child.path" class="el-menu-item" style="padding-left: 40px;" :class="$route.path==child.path?'is-active':''" @click="$router.push(child.path)">{{child.name}}</li>
  56. </ul>
  57. </template>
  58. <template v-else>
  59. <li class="el-submenu">
  60. <div class="el-submenu__title el-menu-item" :class="$route.path==item.children[0].path?'is-active':''" @click="$router.push(item.children[0].path)"
  61. style="padding-left: 20px;height: 56px;line-height: 56px;padding: 0 20px;">
  62. <i :class="item.iconCls"></i>
  63. </div>
  64. </li>
  65. </template>
  66. </li>
  67. </ul>
  68. </aside>
  69. <section class="content-container">
  70. <div class="grid-content bg-purple-light">
  71. <el-col :span="24" class="content-wrapper">
  72. <transition name="fade" mode="out-in">
  73. <router-view></router-view>
  74. </transition>
  75. </el-col>
  76. </div>
  77. <!--修改密码-->
  78. <el-dialog title="修改密码" width='450px' v-if="editPassWord" :visible.sync="editPassWord" :close-on-click-modal="false" customClass="customWidth">
  79. <el-form :model="addForm" label-width="80px" :rules="passRule" ref="addForm">
  80. <el-form-item label="新密码" prop="password">
  81. <el-input v-model="addForm.password" autocomplete="off" placeholder="请输入新密码" show-password></el-input>
  82. </el-form-item>
  83. </el-form>
  84. <div slot="footer" class="dialog-footer">
  85. <el-button @click.native="editPassWord = false">取消</el-button>
  86. <el-button type="primary" @click.native="resetPwd" :loading="editLoading">提交</el-button>
  87. </div>
  88. </el-dialog>
  89. <!--修改信息-->
  90. <el-dialog title="修改信息" width='450px' v-if="editInformation" :visible.sync="editInformation" :close-on-click-modal="false" customClass="customWidth">
  91. <el-form :model="editInfoForm" label-width="80px" :rules="passRule" ref="editInfoForm">
  92. <el-form-item label="姓名" prop="username">
  93. <el-input v-model="editInfoForm.username" autocomplete="off" placeholder="请输入姓名"></el-input>
  94. </el-form-item>
  95. </el-form>
  96. <el-form :model="editInfoForm" label-width="80px" :rules="passRule" ref="editInfoForm">
  97. <el-form-item label="手机号" prop="mobile">
  98. <el-input v-model="editInfoForm.mobile" autocomplete="off" placeholder="请输入手机号" :disabled="true"></el-input>
  99. </el-form-item>
  100. </el-form>
  101. <div slot="footer" class="dialog-footer">
  102. <el-button @click.native="editInformation = false">取消</el-button>
  103. <el-button type="primary" @click.native="editInfo" :loading="editLoading2">提交</el-button>
  104. </div>
  105. </el-dialog>
  106. </section>
  107. </el-col>
  108. </el-row>
  109. </template>
  110. <script>
  111. export default {
  112. data() {
  113. return {
  114. user: sessionStorage.getItem("user"),
  115. sysName: "工时管家",
  116. collapsed: false,
  117. sysUserName: "",
  118. editInformation: false,
  119. editPassWord: false,
  120. editLoading: false,
  121. editLoading2: false,
  122. addForm: {
  123. id: "",
  124. password: ""
  125. },
  126. editInfoForm: {
  127. id: "",
  128. username: "",
  129. mobile: "",
  130. companyName: ""
  131. },
  132. passRule: {
  133. password: [{ required: true, message: "请输入新密码", trigger: "blur" }],
  134. username: [{ required: true, message: "请输入姓名", trigger: "blur" }]
  135. },
  136. //时间
  137. activeDate: new Date()
  138. };
  139. },
  140. methods: {
  141. //退出登录
  142. logout: function() {
  143. var _this = this;
  144. this.$confirm("确认退出吗?", "提示", {
  145. //type: 'warning'
  146. }).then(() => {
  147. sessionStorage.removeItem("user");
  148. _this.$router.push("/login");
  149. });
  150. },
  151. //折叠导航栏
  152. collapse: function() {
  153. this.collapsed = !this.collapsed;
  154. },
  155. showMenu(i, status) {
  156. this.$refs.menuCollapsed.getElementsByClassName(
  157. "submenu-hook-" + i
  158. )[0].style.display = status ? "block" : "none";
  159. },
  160. //打开编辑信息界面
  161. editInfoOpen() {
  162. this.editInformation = true;
  163. this.editInfoForm.id = JSON.parse(sessionStorage.getItem("user")).id;
  164. this.editInfoForm.username = JSON.parse(
  165. sessionStorage.getItem("user")
  166. ).username;
  167. this.editInfoForm.mobile = JSON.parse(
  168. sessionStorage.getItem("user")
  169. ).account;
  170. this.editInfoForm.companyName = JSON.parse(
  171. sessionStorage.getItem("user")
  172. ).companyName;
  173. },
  174. //编辑信息
  175. editInfo() {
  176. this.$refs.editInfoForm.validate(valid => {
  177. if (valid) {
  178. this.editLoading2 = true;
  179. this.http.post(
  180. this.port.pwd.resetPwd,
  181. { id: this.editInfoForm.id, username: this.editInfoForm.username },
  182. res => {
  183. this.editLoading2 = false;
  184. this.editInformation = false;
  185. if (res.code == "ok") {
  186. this.$message({
  187. message: "修改成功",
  188. type: "success"
  189. });
  190. //读取并覆盖session storage
  191. var userObject = JSON.parse(sessionStorage.getItem("user"));
  192. userObject.username = this.editInfoForm.username;
  193. sessionStorage.setItem("user", JSON.stringify(userObject));
  194. this.sysUserName = this.editInfoForm.username;
  195. } else {
  196. this.$message({
  197. message: res.msg,
  198. type: "error"
  199. });
  200. }
  201. },
  202. error => {
  203. this.editLoading2 = false;
  204. this.editInformation = false;
  205. this.$message({
  206. message: error,
  207. type: "error"
  208. });
  209. }
  210. );
  211. }
  212. });
  213. },
  214. reset() {
  215. this.editPassWord = true;
  216. this.addForm.id = JSON.parse(sessionStorage.getItem("user")).id;
  217. this.addForm.account = JSON.parse(sessionStorage.getItem("user")).account;
  218. },
  219. resetPwd() {
  220. this.$refs.addForm.validate(valid => {
  221. if (valid) {
  222. this.editLoading = true;
  223. this.http.post(
  224. this.port.pwd.resetPwd,
  225. this.addForm,
  226. res => {
  227. this.editLoading = false;
  228. this.editPassWord = false;
  229. if (res.code == "ok") {
  230. this.$message({
  231. message: "修改成功,请重新登录",
  232. type: "success"
  233. });
  234. this.$router.push("/login");
  235. } else {
  236. this.$message({
  237. message: res.msg,
  238. type: "error"
  239. });
  240. }
  241. },
  242. error => {
  243. this.editLoading = false;
  244. this.editPassWord = false;
  245. this.$message({
  246. message: error,
  247. type: "error"
  248. });
  249. }
  250. );
  251. }
  252. });
  253. },
  254. },
  255. mounted() {
  256. if (this.user) {
  257. var user = JSON.parse(this.user);
  258. this.user = user;
  259. this.sysUserName = user.name || "";
  260. } else {
  261. this.$router.push("/login");
  262. }
  263. }
  264. };
  265. </script>
  266. <style scoped lang="scss">
  267. .el-menu-vertical-demo i {
  268. margin-right: 10px;
  269. }
  270. .container {
  271. position: absolute;
  272. top: 0px;
  273. bottom: 0px;
  274. width: 100%;
  275. .header {
  276. height: 60px;
  277. line-height: 60px;
  278. background: #20a0ff;
  279. color: #fff;
  280. .userinfo {
  281. text-align: right;
  282. padding-right: 35px;
  283. float: right;
  284. .userinfo-inner {
  285. cursor: pointer;
  286. color: #fff;
  287. img {
  288. width: 40px;
  289. height: 40px;
  290. border-radius: 20px;
  291. margin: 10px 10px 10px 10px;
  292. float: left;
  293. }
  294. }
  295. .itemNew {
  296. height: 25px;
  297. margin-right: 25px;
  298. i {
  299. vertical-align: top;
  300. }
  301. }
  302. }
  303. .logo {
  304. height: 60px;
  305. font-size: 21px;
  306. padding-left: 20px;
  307. padding-right: 20px;
  308. border-color: rgba(238, 241, 146, 0.3);
  309. border-right-width: 1px;
  310. border-right-style: solid;
  311. img {
  312. width: 40px;
  313. float: left;
  314. margin: 10px 10px 10px 18px;
  315. }
  316. img.headImg {
  317. margin: 0;
  318. width: 40px;
  319. height: 40px;
  320. margin: 10px 0 0 10px;
  321. }
  322. .logo-sys {
  323. height: 100%;
  324. line-height: 100%;
  325. img.headImg {
  326. width: 40px;
  327. height: 40px;
  328. margin: 10px 0 0 10px;
  329. vertical-align: middle;
  330. }
  331. span {
  332. display: inline-block;
  333. height: 100%;
  334. line-height: 100%;
  335. margin-left: 15px;
  336. margin: 20px 0 0 15px;
  337. vertical-align: middle;
  338. }
  339. }
  340. .txt {
  341. color: #fff;
  342. }
  343. }
  344. .logo-width {
  345. width: 230px;
  346. }
  347. .logo-collapse-width {
  348. width: 60px;
  349. }
  350. .tools {
  351. padding: 0px 23px;
  352. width: 14px;
  353. height: 60px;
  354. line-height: 60px;
  355. cursor: pointer;
  356. }
  357. }
  358. .main {
  359. display: flex;
  360. position: absolute;
  361. top: 60px;
  362. bottom: 0px;
  363. overflow: hidden;
  364. aside {
  365. flex: 0 0 230px;
  366. width: 230px;
  367. .el-menu {
  368. height: 100%;
  369. }
  370. .collapsed {
  371. width: 60px;
  372. .item {
  373. position: relative;
  374. }
  375. .submenu {
  376. position: absolute;
  377. top: 0px;
  378. left: 60px;
  379. z-index: 99999;
  380. height: auto;
  381. display: none;
  382. }
  383. }
  384. }
  385. .menu-collapsed {
  386. flex: 0 0 60px;
  387. width: 60px;
  388. }
  389. .menu-expanded {
  390. flex: 0 0 230px;
  391. width: 230px;
  392. }
  393. .content-container {
  394. flex: 1;
  395. width: 80%;
  396. padding: 10px;
  397. overflow-y: auto;
  398. .breadcrumb-container {
  399. .title {
  400. width: 200px;
  401. float: left;
  402. color: #475669;
  403. }
  404. .breadcrumb-inner {
  405. float: right;
  406. }
  407. }
  408. .content-wrapper {
  409. background-color: #fff;
  410. box-sizing: border-box;
  411. }
  412. }
  413. }
  414. }
  415. .popover-item {
  416. padding: 10px;
  417. border-bottom: 1px #eee solid;
  418. }
  419. .popover-item > div > p {
  420. margin: 0;
  421. line-height: 18px;
  422. }
  423. .popover-title {
  424. color: #409eff;
  425. padding-bottom: 8px;
  426. }
  427. .popover-type {
  428. color: #aaa;
  429. font-size: 8px;
  430. float: right;
  431. }
  432. .popover-button {
  433. font-weight: 900;
  434. padding: 10px;
  435. text-align: center;
  436. cursor: pointer;
  437. }
  438. .isRead {
  439. color: #999 !important;
  440. }
  441. </style>