Home.vue 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628
  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-badge class="itemNew" :value="unreadCount[3]" :hidden="unreadCount[3] == 0">
  18. <i class="el-icon-message-solid" style="font-size:24px" v-popover:popover1></i>
  19. <!-- 消息中心 -->
  20. <el-popover ref="popover1" placement="bottom" width="400" trigger="hover" popper-class="popover-self">
  21. <!-- 消息盒子中间部分 -->
  22. <el-tabs v-model="activePage" @tab-click="handleClick" stretch>
  23. <!-- 审批的页面 -->
  24. <el-tab-pane name="0">
  25. <span slot="label">
  26. <span v-if="unreadCount[0] == 0">审批</span>
  27. <span v-else>审批({{unreadCount[0]}})</span>
  28. </span>
  29. <div class="popover-item" v-if="popoverData[0].length == 0">暂无审批消息</div>
  30. <div class="popover-item" v-for="item in popoverData[0]">
  31. <div
  32. style="cursor: pointer;"
  33. @click="locationHerf(item.id, item.refId, item.noticeType, item.belongType)"
  34. >
  35. <p class="popover-title">
  36. <span v-if="item.isRead == 1" class="isRead">{{item.projectName}}</span>
  37. <span v-else>{{item.projectName}}</span>
  38. </p>
  39. <p v-if="item.isRead == 1" class="isRead">{{item.content}}</p>
  40. <p v-else>{{item.content}}</p>
  41. </div>
  42. </div>
  43. </el-tab-pane>
  44. <!-- 警告的页面 -->
  45. <el-tab-pane name="1">
  46. <span slot="label">
  47. <span v-if="unreadCount[1] == 0">警告</span>
  48. <span v-else>警告({{unreadCount[1]}})</span>
  49. </span>
  50. <div class="popover-item" v-if="popoverData[1].length == 0">暂无警告消息</div>
  51. <div class="popover-item" v-for="item in popoverData[1]">
  52. <div
  53. style="cursor: pointer;"
  54. @click="locationHerf(item.id, item.refId, item.noticeType, null)"
  55. >
  56. <p class="popover-title">
  57. <span v-if="item.isRead == 1" class="isRead">{{item.projectName}}</span>
  58. <span v-else>{{item.projectName}}</span>
  59. </p>
  60. <p v-if="item.isRead == 1" class="isRead">{{item.content}}</p>
  61. <p v-else>{{item.content}}</p>
  62. </div>
  63. </div>
  64. </el-tab-pane>
  65. <!-- 保养的页面 -->
  66. <el-tab-pane name="2">
  67. <span slot="label">
  68. <span v-if="unreadCount[2] == 0">保养</span>
  69. <span v-else>保养({{unreadCount[2]}})</span>
  70. </span>
  71. <div class="popover-item" v-if="popoverData[2].length == 0">暂无保养消息</div>
  72. <div class="popover-item" v-for="item in popoverData[2]">
  73. <div
  74. style="cursor: pointer;"
  75. @click="locationHerf(item.id, item.refId, item.noticeType, null)"
  76. >
  77. <p class="popover-title">
  78. <span v-if="item.isRead == 1" class="isRead">{{item.projectName}}</span>
  79. <span v-else>{{item.projectName}}</span>
  80. </p>
  81. <p v-if="item.isRead == 1" class="isRead">{{item.content}}</p>
  82. <p v-else>{{item.content}}</p>
  83. </div>
  84. </div>
  85. </el-tab-pane>
  86. </el-tabs>
  87. <!-- 查看全部的按钮 -->
  88. <router-link :to="'/message'" tag="div" class="popover-button">查看全部</router-link>
  89. </el-popover>
  90. </el-badge>
  91. <el-dropdown trigger="hover">
  92. <span class="el-dropdown-link userinfo-inner">
  93. <img src="../assets/image/userHead.png" />
  94. {{sysUserName}}
  95. </span>
  96. <el-dropdown-menu slot="dropdown">
  97. <el-dropdown-item @click.native="reset">修改密码</el-dropdown-item>
  98. <el-dropdown-item @click.native="editInfoOpen">修改信息</el-dropdown-item>
  99. <el-dropdown-item divided @click.native="logout">退出登录</el-dropdown-item>
  100. </el-dropdown-menu>
  101. </el-dropdown>
  102. </el-col>
  103. </el-col>
  104. <el-col :span="24" class="main">
  105. <aside :class="collapsed?'menu-collapsed':'menu-expanded'">
  106. <!--导航菜单-->
  107. <el-menu :default-active="$route.path" class="el-menu-vertical-demo" unique-opened router v-if="!collapsed">
  108. <template v-for="(item,index) in $router.options.routes" v-if="!item.hidden">
  109. <el-submenu :index="index+''" v-if="!item.leaf">
  110. <template slot="title">
  111. <i :class="item.iconCls"></i>
  112. <span class="itemName">{{item.name}}</span>
  113. </template>
  114. <el-menu-item v-for="child in item.children" :index="child.path" :key="child.path" v-if="!child.hidden">{{child.name}}</el-menu-item>
  115. </el-submenu>
  116. <el-menu-item v-if="item.leaf && item.children.length > 0" :index="item.children[0].path">
  117. <i :class="item.iconCls"></i> {{item.children[0].name}}
  118. </el-menu-item>
  119. </template>
  120. </el-menu>
  121. <!--导航菜单-折叠后-->
  122. <ul class="el-menu el-menu-vertical-demo collapsed" v-if="collapsed" ref="menuCollapsed">
  123. <li v-for="(item,index) in $router.options.routes" v-if="!item.hidden" class="el-submenu item" :style="{overflow:!item.leaf?'':'hidden'}">
  124. <template v-if="!item.leaf">
  125. <div class="el-submenu__title" style="padding-left: 20px;" @mouseover="showMenu(index,true)" @mouseout="showMenu(index,false)">
  126. <i :class="item.iconCls"></i>
  127. </div>
  128. <ul class="el-menu submenu" :class="'submenu-hook-'+index" @mouseover="showMenu(index,true)" @mouseout="showMenu(index,false)">
  129. <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>
  130. </ul>
  131. </template>
  132. <template v-else>
  133. <li class="el-submenu">
  134. <div class="el-submenu__title el-menu-item" :class="$route.path==item.children[0].path?'is-active':''" @click="$router.push(item.children[0].path)"
  135. style="padding-left: 20px;height: 56px;line-height: 56px;padding: 0 20px;">
  136. <i :class="item.iconCls"></i>
  137. </div>
  138. </li>
  139. </template>
  140. </li>
  141. </ul>
  142. </aside>
  143. <section class="content-container">
  144. <div class="grid-content bg-purple-light">
  145. <el-col :span="24" class="content-wrapper">
  146. <transition name="fade" mode="out-in">
  147. <router-view></router-view>
  148. </transition>
  149. </el-col>
  150. </div>
  151. <!--修改密码-->
  152. <el-dialog title="修改密码" width='450px' v-if="editPassWord" :visible.sync="editPassWord" :close-on-click-modal="false" customClass="customWidth">
  153. <el-form :model="addForm" label-width="80px" :rules="passRule" ref="addForm">
  154. <el-form-item label="新密码" prop="password">
  155. <el-input v-model="addForm.password" autocomplete="off" placeholder="请输入新密码" show-password></el-input>
  156. </el-form-item>
  157. </el-form>
  158. <div slot="footer" class="dialog-footer">
  159. <el-button @click.native="editPassWord = false">取消</el-button>
  160. <el-button type="primary" @click.native="resetPwd" :loading="editLoading">提交</el-button>
  161. </div>
  162. </el-dialog>
  163. <!--修改信息-->
  164. <el-dialog title="修改信息" width='450px' v-if="editInformation" :visible.sync="editInformation" :close-on-click-modal="false" customClass="customWidth">
  165. <el-form :model="editInfoForm" label-width="80px" :rules="passRule" ref="editInfoForm">
  166. <el-form-item label="姓名" prop="username">
  167. <el-input v-model="editInfoForm.username" autocomplete="off" placeholder="请输入姓名"></el-input>
  168. </el-form-item>
  169. </el-form>
  170. <el-form :model="editInfoForm" label-width="80px" :rules="passRule" ref="editInfoForm">
  171. <el-form-item label="手机号" prop="mobile">
  172. <el-input v-model="editInfoForm.mobile" autocomplete="off" placeholder="请输入手机号" :disabled="true"></el-input>
  173. </el-form-item>
  174. </el-form>
  175. <div slot="footer" class="dialog-footer">
  176. <el-button @click.native="editInformation = false">取消</el-button>
  177. <el-button type="primary" @click.native="editInfo" :loading="editLoading2">提交</el-button>
  178. </div>
  179. </el-dialog>
  180. </section>
  181. </el-col>
  182. </el-row>
  183. </template>
  184. <script>
  185. export default {
  186. data() {
  187. return {
  188. user: sessionStorage.getItem("user"),
  189. sysName: "工时管家",
  190. collapsed: false,
  191. sysUserName: "",
  192. editInformation: false,
  193. editPassWord: false,
  194. editLoading: false,
  195. editLoading2: false,
  196. addForm: {
  197. id: "",
  198. password: ""
  199. },
  200. editInfoForm: {
  201. id: "",
  202. username: "",
  203. mobile: "",
  204. companyName: ""
  205. },
  206. passRule: {
  207. password: [{ required: true, message: "请输入新密码", trigger: "blur" }],
  208. username: [{ required: true, message: "请输入姓名", trigger: "blur" }]
  209. },
  210. //消息数据
  211. popoverData: ["", "", ""],
  212. unreadCount: [],
  213. activePage: 0,
  214. //时间
  215. activeDate: new Date()
  216. };
  217. },
  218. methods: {
  219. //退出登录
  220. logout: function() {
  221. var _this = this;
  222. this.$confirm("确认退出吗?", "提示", {
  223. //type: 'warning'
  224. }).then(() => {
  225. sessionStorage.removeItem("user");
  226. _this.$router.push("/login");
  227. });
  228. },
  229. //折叠导航栏
  230. collapse: function() {
  231. this.collapsed = !this.collapsed;
  232. },
  233. showMenu(i, status) {
  234. this.$refs.menuCollapsed.getElementsByClassName(
  235. "submenu-hook-" + i
  236. )[0].style.display = status ? "block" : "none";
  237. },
  238. //打开编辑信息界面
  239. editInfoOpen() {
  240. this.editInformation = true;
  241. this.editInfoForm.id = JSON.parse(sessionStorage.getItem("user")).id;
  242. this.editInfoForm.username = JSON.parse(
  243. sessionStorage.getItem("user")
  244. ).username;
  245. this.editInfoForm.mobile = JSON.parse(
  246. sessionStorage.getItem("user")
  247. ).account;
  248. this.editInfoForm.companyName = JSON.parse(
  249. sessionStorage.getItem("user")
  250. ).companyName;
  251. },
  252. //编辑信息
  253. editInfo() {
  254. this.$refs.editInfoForm.validate(valid => {
  255. if (valid) {
  256. this.editLoading2 = true;
  257. this.http.post(
  258. this.port.pwd.resetPwd,
  259. { id: this.editInfoForm.id, username: this.editInfoForm.username },
  260. res => {
  261. this.editLoading2 = false;
  262. this.editInformation = false;
  263. if (res.code == "ok") {
  264. this.$message({
  265. message: "修改成功",
  266. type: "success"
  267. });
  268. //读取并覆盖session storage
  269. var userObject = JSON.parse(sessionStorage.getItem("user"));
  270. userObject.username = this.editInfoForm.username;
  271. sessionStorage.setItem("user", JSON.stringify(userObject));
  272. this.sysUserName = this.editInfoForm.username;
  273. } else {
  274. this.$message({
  275. message: res.msg,
  276. type: "error"
  277. });
  278. }
  279. },
  280. error => {
  281. this.editLoading2 = false;
  282. this.editInformation = false;
  283. this.$message({
  284. message: error,
  285. type: "error"
  286. });
  287. }
  288. );
  289. }
  290. });
  291. },
  292. reset() {
  293. this.editPassWord = true;
  294. this.addForm.id = JSON.parse(sessionStorage.getItem("user")).id;
  295. this.addForm.account = JSON.parse(sessionStorage.getItem("user")).account;
  296. },
  297. resetPwd() {
  298. this.$refs.addForm.validate(valid => {
  299. if (valid) {
  300. this.editLoading = true;
  301. this.http.post(
  302. this.port.pwd.resetPwd,
  303. this.addForm,
  304. res => {
  305. this.editLoading = false;
  306. this.editPassWord = false;
  307. if (res.code == "ok") {
  308. this.$message({
  309. message: "修改成功,请重新登录",
  310. type: "success"
  311. });
  312. this.$router.push("/login");
  313. } else {
  314. this.$message({
  315. message: res.msg,
  316. type: "error"
  317. });
  318. }
  319. },
  320. error => {
  321. this.editLoading = false;
  322. this.editPassWord = false;
  323. this.$message({
  324. message: error,
  325. type: "error"
  326. });
  327. }
  328. );
  329. }
  330. });
  331. },
  332. //读取消息提示
  333. loadNotice() {
  334. this.http.post(
  335. this.port.notice.list,
  336. {
  337. pageNum: 1,
  338. pageSize: 5
  339. },
  340. res => {
  341. if (res.code == "ok") {
  342. this.popoverData = [];
  343. this.popoverData.push(res.data[0].approvelList.list);
  344. this.popoverData.push(res.data[1].matainList.list);
  345. this.popoverData.push(res.data[2].emergencyList.list);
  346. this.unreadCount = [];
  347. this.unreadCount.push(res.data[0].isNotReadCount);
  348. this.unreadCount.push(res.data[1].isNotReadCount);
  349. this.unreadCount.push(res.data[2].isNotReadCount);
  350. this.unreadCount.push(
  351. this.unreadCount[0] + this.unreadCount[1] + this.unreadCount[2]
  352. );
  353. } else {
  354. this.$message({
  355. message: res.msg,
  356. type: "error"
  357. });
  358. }
  359. },
  360. error => {
  361. this.$message({
  362. message: error,
  363. type: "error"
  364. });
  365. }
  366. );
  367. },
  368. //点击消息的跳转
  369. locationHerf(id, refid, type, approval) {
  370. this.http.post(
  371. this.port.notice.read,
  372. {
  373. id: id
  374. },
  375. res => {
  376. if (res.code == "ok") {
  377. //重新读取一次消息
  378. this.loadNotice();
  379. } else {
  380. this.$message({
  381. message: res.msg,
  382. type: "error"
  383. });
  384. }
  385. },
  386. error => {
  387. this.$message({
  388. message: error,
  389. type: "error"
  390. });
  391. }
  392. );
  393. //本页面再点的话强制转移一下
  394. var currentRoute = this.$route.path.split("/");
  395. if (currentRoute.length == 4 && currentRoute[1] == "moldList") {
  396. this.$router.go(0);
  397. }
  398. if (type == 0) {
  399. //审批 跳转到模具详情
  400. this.$router.push("/moldList/" + refid + "/" + approval);
  401. } else if (type == 1) {
  402. //警告 跳转到运行监测
  403. this.$router.push("/detection");
  404. } else if (type == 2) {
  405. //保养 跳转到运行监测详情
  406. this.$router.push("/detection/" + refid);
  407. }
  408. },
  409. //标签页面切换时
  410. handleClick(tab, event) {
  411. this.activeTab = tab.name;
  412. }
  413. },
  414. mounted() {
  415. if (this.user) {
  416. var user = JSON.parse(this.user);
  417. this.user = user;
  418. this.sysUserName = user.username || "";
  419. this.loadNotice();
  420. } else {
  421. this.$router.push("/login");
  422. }
  423. }
  424. };
  425. </script>
  426. <style scoped lang="scss">
  427. .el-menu-vertical-demo i {
  428. margin-right: 10px;
  429. }
  430. .container {
  431. position: absolute;
  432. top: 0px;
  433. bottom: 0px;
  434. width: 100%;
  435. .header {
  436. height: 60px;
  437. line-height: 60px;
  438. background: #20a0ff;
  439. color: #fff;
  440. .userinfo {
  441. text-align: right;
  442. padding-right: 35px;
  443. float: right;
  444. .userinfo-inner {
  445. cursor: pointer;
  446. color: #fff;
  447. img {
  448. width: 40px;
  449. height: 40px;
  450. border-radius: 20px;
  451. margin: 10px 10px 10px 10px;
  452. float: left;
  453. }
  454. }
  455. .itemNew {
  456. height: 25px;
  457. margin-right: 25px;
  458. i {
  459. vertical-align: top;
  460. }
  461. }
  462. }
  463. .logo {
  464. height: 60px;
  465. font-size: 21px;
  466. padding-left: 20px;
  467. padding-right: 20px;
  468. border-color: rgba(238, 241, 146, 0.3);
  469. border-right-width: 1px;
  470. border-right-style: solid;
  471. img {
  472. width: 40px;
  473. float: left;
  474. margin: 10px 10px 10px 18px;
  475. }
  476. img.headImg {
  477. margin: 0;
  478. width: 40px;
  479. height: 40px;
  480. margin: 10px 0 0 10px;
  481. }
  482. .logo-sys {
  483. height: 100%;
  484. line-height: 100%;
  485. img.headImg {
  486. width: 40px;
  487. height: 40px;
  488. margin: 10px 0 0 10px;
  489. vertical-align: middle;
  490. }
  491. span {
  492. display: inline-block;
  493. height: 100%;
  494. line-height: 100%;
  495. margin-left: 15px;
  496. margin: 20px 0 0 15px;
  497. vertical-align: middle;
  498. }
  499. }
  500. .txt {
  501. color: #fff;
  502. }
  503. }
  504. .logo-width {
  505. width: 230px;
  506. }
  507. .logo-collapse-width {
  508. width: 60px;
  509. }
  510. .tools {
  511. padding: 0px 23px;
  512. width: 14px;
  513. height: 60px;
  514. line-height: 60px;
  515. cursor: pointer;
  516. }
  517. }
  518. .main {
  519. display: flex;
  520. position: absolute;
  521. top: 60px;
  522. bottom: 0px;
  523. overflow: hidden;
  524. aside {
  525. flex: 0 0 230px;
  526. width: 230px;
  527. .el-menu {
  528. height: 100%;
  529. }
  530. .collapsed {
  531. width: 60px;
  532. .item {
  533. position: relative;
  534. }
  535. .submenu {
  536. position: absolute;
  537. top: 0px;
  538. left: 60px;
  539. z-index: 99999;
  540. height: auto;
  541. display: none;
  542. }
  543. }
  544. }
  545. .menu-collapsed {
  546. flex: 0 0 60px;
  547. width: 60px;
  548. }
  549. .menu-expanded {
  550. flex: 0 0 230px;
  551. width: 230px;
  552. }
  553. .content-container {
  554. flex: 1;
  555. width: 80%;
  556. padding: 10px;
  557. overflow-y: auto;
  558. .breadcrumb-container {
  559. .title {
  560. width: 200px;
  561. float: left;
  562. color: #475669;
  563. }
  564. .breadcrumb-inner {
  565. float: right;
  566. }
  567. }
  568. .content-wrapper {
  569. background-color: #fff;
  570. box-sizing: border-box;
  571. }
  572. }
  573. }
  574. }
  575. .popover-item {
  576. padding: 10px;
  577. border-bottom: 1px #eee solid;
  578. }
  579. .popover-item > div > p {
  580. margin: 0;
  581. line-height: 18px;
  582. }
  583. .popover-title {
  584. color: #409eff;
  585. padding-bottom: 8px;
  586. }
  587. .popover-type {
  588. color: #aaa;
  589. font-size: 8px;
  590. float: right;
  591. }
  592. .popover-button {
  593. font-weight: 900;
  594. padding: 10px;
  595. text-align: center;
  596. cursor: pointer;
  597. }
  598. .isRead {
  599. color: #999 !important;
  600. }
  601. </style>