Home.vue 27 KB

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