Index.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562
  1. <template>
  2. <el-container style="height: 100%">
  3. <el-header>
  4. <div class="navbarBtn">
  5. <!-- 用户 -->
  6. <div class="userinfo">
  7. <img src="@/assets/images/12.jpg" class="userheadImg" alt="">
  8. <el-dropdown trigger="click" @command="dropdownHandle" placement="top">
  9. <span class="el-dropdown-link" style="cursor: pointer;color:#fff;">
  10. {{ username }}
  11. <i class="el-icon-arrow-down el-icon--right"></i>
  12. </span>
  13. <el-dropdown-menu slot="dropdown">
  14. <el-dropdown-item command="personMsg">个人中心</el-dropdown-item>
  15. <el-dropdown-item command="editPwd">修改密码</el-dropdown-item>
  16. <el-dropdown-item command="outSys">退出</el-dropdown-item>
  17. </el-dropdown-menu>
  18. </el-dropdown>
  19. </div>
  20. <!-- 标题 -->
  21. <div class="caption">
  22. <div class="tit">农业植保监测系统 智慧农业信息化</div>
  23. <div>Agricultural plant protection monitoring system intelligent agricultural informatization</div>
  24. </div>
  25. </div>
  26. </el-header>
  27. <!-- 修改密码对话框 -->
  28. <el-dialog
  29. title="重置密码"
  30. :visible.sync="resetPassDialogVisible"
  31. width="500px"
  32. @close="resetPassDialogClosed">
  33. <el-form
  34. ref="resetPassFormRef"
  35. :model="resetPassForm"
  36. label-width="90px"
  37. :rules="resetPassFormRules"
  38. >
  39. <el-form-item label="原始密码 : " prop="oldPass">
  40. <el-input type="password" v-model="resetPassForm.oldPass"></el-input>
  41. </el-form-item>
  42. <el-form-item label="新密码 : " prop="newPass">
  43. <el-input type="password" v-model="resetPassForm.newPass"></el-input>
  44. </el-form-item>
  45. <el-form-item label="确认新密码 : " prop="checkNewPass">
  46. <el-input
  47. type="password"
  48. v-model="resetPassForm.checkNewPass"
  49. ></el-input>
  50. </el-form-item>
  51. </el-form>
  52. <span slot="footer" class="dialog-footer">
  53. <el-button @click="resetPassDialogVisible = false">取 消</el-button>
  54. <el-button type="primary" @click="resetPassSubm">确认</el-button>
  55. </span>
  56. </el-dialog>
  57. <el-container style="overflow: auto">
  58. <!-- 菜单 -->
  59. <el-aside width="200px">
  60. <el-menu
  61. :default-openeds="menuOpeneds"
  62. :default-active="$route.path"
  63. :collapse-transition="false"
  64. class="el-menu-vertical-demo"
  65. unique-opened
  66. :router="isRouter"
  67. active-text-color="#fff"
  68. >
  69. <el-menu-item
  70. :index="selHome()"
  71. v-for="item in menuList1"
  72. :key="item.pur_id"
  73. >
  74. <i class="iconfont icon-shouye"></i>
  75. <span slot="title">{{ item.purview_name }}</span>
  76. </el-menu-item>
  77. <el-submenu
  78. :index="item.pur_id.toString()"
  79. v-for="item in menuList2"
  80. :key="item.pur_id"
  81. >
  82. <template slot="title">
  83. <i :class="iconObj[item.pur_id]"></i>
  84. <span>{{ item.purview_name }}</span>
  85. </template>
  86. <el-menu-item
  87. :index="menuIndex(subItem.menu)"
  88. v-for="subItem in item.children"
  89. :key="subItem.pur_id"
  90. @click="saveNavState('/index/' + subItem.menu)"
  91. >
  92. <template slot="title">
  93. <span>{{ subItem.purview_name }}</span>
  94. </template>
  95. </el-menu-item>
  96. </el-submenu>
  97. </el-menu>
  98. </el-aside>
  99. <el-container>
  100. <el-main>
  101. <router-view></router-view>
  102. </el-main>
  103. </el-container>
  104. </el-container>
  105. </el-container>
  106. </template>
  107. <script>
  108. export default {
  109. data() {
  110. var validateNewPass = (rule, value, callback) => {
  111. if (value === '') {
  112. callback(new Error('请输入新密码'))
  113. } else {
  114. if (this.resetPassForm.checkPass !== '') {
  115. this.$refs.resetPassFormRef.validateField('checkNewPass')
  116. }
  117. callback()
  118. }
  119. }
  120. var validateCheckPass = (rule, value, callback) => {
  121. if (value === '') {
  122. callback(new Error('请再次输入密码'))
  123. } else if (value !== this.resetPassForm.newPass) {
  124. callback(new Error('两次输入密码不一致!'))
  125. } else {
  126. callback()
  127. }
  128. }
  129. return {
  130. // refresh: true, //控制整个页面刷新
  131. isCollapse: true,
  132. widthHover: '0px',
  133. isRouter: true,
  134. // 被激活导航地址
  135. // activePath:this.$store.state.activePath,
  136. changeHomedialogVisible: false,
  137. iconObj: {
  138. 20: 'iconfont icon-shujuzhanshi',
  139. 22: 'iconfont icon-shebei',
  140. 25: 'iconfont icon-jidi',
  141. 28: 'iconfont icon-xitong',
  142. 36: 'iconfont icon-cebaoguanli',
  143. 40: 'iconfont icon-huanjingjiance',
  144. 42: 'iconfont icon-jiankong',
  145. 44: 'iconfont icon-fangzhi',
  146. 46: 'iconfont icon-nongchangguanli',
  147. 48: 'iconfont icon-nongshiguanli',
  148. 58: 'iconfont icon-suyuan',
  149. 124: 'iconfont icon-zhuanjia',
  150. 129: 'iconfont icon-shouhou'
  151. },
  152. homeList: [
  153. {
  154. img: require('@/assets/images/home/1.jpg'),
  155. name: '首页一',
  156. url: '/index/home'
  157. },
  158. {
  159. img: require('@/assets/images/home/2.jpg'),
  160. name: '首页二',
  161. url: '/index/mapView'
  162. },
  163. {
  164. img: require('@/assets/images/home/3.jpg'),
  165. name: '首页三',
  166. url: '/index/home02'
  167. }
  168. ],
  169. menuList1: [], //首页菜单
  170. menuList2: [], //出首页的其他菜单
  171. // 被激活导航地址
  172. // activePath:'',
  173. username: '',
  174. userHeadImg: '',
  175. resetPassDialogVisible: false,
  176. resetPassForm: {
  177. oldPass: '',
  178. newPass: '',
  179. checkNewPass: ''
  180. },
  181. resetPassFormRules: {
  182. oldPass: [
  183. { required: true, message: '请输入原始密码', trigger: 'blur' }
  184. ],
  185. newPass: [{ validator: validateNewPass, trigger: 'blur' }],
  186. checkNewPass: [{ validator: validateCheckPass, trigger: 'blur' }]
  187. },
  188. menuOpeneds: []
  189. }
  190. },
  191. created: function () {
  192. // this.username = localStorage.getItem('username')
  193. // this.getNavList()
  194. // this.activePath=window.sessionStorage.getItem('activePath')
  195. // document.body.className = window.sessionStorage.getItem('bodyCalss')
  196. },
  197. computed: {
  198. activePath: function () {
  199. return this.$store.state.activePath
  200. },
  201. homePath: function () {
  202. return this.$store.state.homePath
  203. }
  204. },
  205. watch: {
  206. '$route.path': function (newVal) {
  207. if (
  208. newVal == '/index/home' ||
  209. newVal == '/index/home02' ||
  210. newVal == '/index/mapView'
  211. ) {
  212. this.menuOpeneds = []
  213. }
  214. }
  215. },
  216. mounted() {
  217. // this.$EventBus.$on('refresh', (data) => {
  218. // console.log('bus')
  219. // this.refresh = false
  220. // this.$nextTick( ()=> {
  221. // this.refresh = true
  222. // })
  223. // })
  224. this.username = localStorage.getItem('username')
  225. this.getNavList()
  226. },
  227. methods: {
  228. dropdownHandle(command){
  229. if(command == 'editPwd'){
  230. this.changePass()
  231. }else if(command == 'outSys'){
  232. this.outSys()
  233. }else{
  234. this.$router.push({ path: command })
  235. }
  236. },
  237. getNavList() {
  238. this.$axios({
  239. method: 'POST',
  240. url: '/api/api_gateway?method=user.login.user_login_info'
  241. }).then((res) => {
  242. if (res.data.message == '') {
  243. let navList = res.data.data.children
  244. navList.forEach((item) => {
  245. if (item.children) {
  246. this.menuList2.push(item)
  247. } else {
  248. this.menuList1.push(item)
  249. }
  250. })
  251. let firstPage = '' //左侧菜单第一项
  252. if (this.menuList1.length > 0) {
  253. firstPage = this.menuList1[0].menu
  254. } else {
  255. firstPage = this.menuList2[0].children[0].menu
  256. }
  257. this.$EventBus.$emit('firstPage', firstPage) //第一个页面
  258. let userType = res.data.data.myuser_type //用户类型
  259. let userName = res.data.data.username //用户名
  260. localStorage.setItem(
  261. 'lastEnter',
  262. this.formatTime(res.data.data.user_login_time * 1000)
  263. )
  264. window.sessionStorage.setItem('myuser_type', userType)
  265. this.$EventBus.$emit('userName', userName) //事件总线
  266. }
  267. })
  268. },
  269. changeHome(index) {
  270. this.changeHomedialogVisible = false
  271. var url = this.homeList[index].url
  272. sessionStorage.setItem('selHome', url) //保存选择的首页路由
  273. this.$router.push({ path: url })
  274. },
  275. changeHomeDialogClosed(done) {
  276. // this.$confirm('确认关闭?')
  277. // .then(_ => {
  278. // done();
  279. // })
  280. // .catch(_ => {});
  281. },
  282. dropdownHandle(command) {
  283. if (command == 'editPwd') {
  284. this.changePass()
  285. } else if (command == 'outSys') {
  286. this.outSys()
  287. } else {
  288. this.$router.push({ path: command })
  289. }
  290. },
  291. handleCommand(command) {
  292. // this.$message('click on item ' + command);
  293. document.body.className = 'custom-' + command
  294. window.sessionStorage.setItem('bodyCalss', 'custom-' + command)
  295. },
  296. outSys() {
  297. this.$axios({
  298. method: 'POST',
  299. url: '/api/api_gateway?method=user.login.logout_user'
  300. }).then((res) => {
  301. if (res.data.message == '') {
  302. window.localStorage.removeItem('isLogin')
  303. window.localStorage.removeItem('session')
  304. this.$router.push('/login')
  305. // window.sessionStorage.setItem('activePath', '/index/home')
  306. }
  307. })
  308. },
  309. changePass() {
  310. this.resetPassDialogVisible = true
  311. },
  312. resetPassDialogClosed() {},
  313. resetPassSubm() {
  314. this.$refs.resetPassFormRef.validate((valid) => {
  315. if (!valid) return
  316. this.$axios({
  317. method: 'POST',
  318. url: '/api/api_gateway?method=user.login.changepwd',
  319. data: this.qs.stringify({
  320. old_password: this.resetPassForm.oldPass,
  321. new_password: this.resetPassForm.newPass,
  322. confirm_password: this.resetPassForm.checkNewPass
  323. })
  324. }).then((res) => {
  325. if (res.data.message == '') {
  326. this.$message({
  327. message: '密码修改成功!',
  328. type: 'success'
  329. })
  330. this.resetPassDialogVisible = false
  331. }
  332. })
  333. })
  334. },
  335. collapseFun() {
  336. this.isCollapse = !this.isCollapse
  337. return this.isCollapse
  338. },
  339. menuIndex(menu) {
  340. if (menu == 'bFourSituations') {
  341. return ''
  342. } else if (menu == 'equipDistribute') {
  343. return ''
  344. } else if (menu == 'bCbd') {
  345. return ''
  346. } else if (menu == 'bQxz') {
  347. return ''
  348. } else if (menu == 'bSy') {
  349. return ''
  350. } else if (menu == 'bBzy') {
  351. return ''
  352. } else {
  353. return '/index/' + menu
  354. }
  355. },
  356. //保存菜单的激活地址
  357. saveNavState(activePath) {
  358. // let path='/'+activePath.split('/')[activePath.split('/').length-1]
  359. let path = activePath.slice(6)
  360. // console.log(path)
  361. // console.log(activePath)
  362. if (activePath == '/index/bFourSituations') {
  363. // this.$router.replace('/index/home')
  364. this.BFourSituations(path) //跳转到大数据平台
  365. } else if (activePath == '/index/equipDistribute') {
  366. // this.$router.push('/index/home')
  367. this.BFourSituations(path) //跳转到大数据平台
  368. } else if (activePath == '/index/bCbd') {
  369. this.BFourSituations(path) //跳转到大数据平台
  370. // this.$router.push('/index/home')
  371. } else if (activePath == '/index/bQxz') {
  372. // this.$router.push('/index/home')
  373. this.BFourSituations(path) //跳转到大数据平台
  374. } else if (activePath == '/index/bSy') {
  375. // this.$router.push('/index/home')
  376. this.BFourSituations(path) //跳转到大数据平台
  377. } else if (activePath == '/index/bBzy') {
  378. // this.$router.push('/index/home')
  379. this.BFourSituations(path) //跳转到大数据平台
  380. }
  381. },
  382. BFourSituations(path) {
  383. const { href } = this.$router.resolve({
  384. path: path
  385. })
  386. window.open(href, '_blank')
  387. },
  388. selHome() {
  389. let selHome = sessionStorage.getItem('selHome')
  390. if (selHome) {
  391. return selHome
  392. } else {
  393. return '/index/home'
  394. }
  395. },
  396. goBD(path) {
  397. const { href } = this.$router.resolve({
  398. path: path
  399. })
  400. window.open(href, '_blank')
  401. }
  402. }
  403. }
  404. </script>
  405. <style scoped lang="less">
  406. @keyframes ringing {
  407. 0% {
  408. transform: rotate(-15deg);
  409. }
  410. 2% {
  411. transform: rotate(15deg);
  412. }
  413. 12%,
  414. 4% {
  415. transform: rotate(-18deg);
  416. }
  417. 14%,
  418. 6% {
  419. transform: rotate(18deg);
  420. }
  421. 8% {
  422. transform: rotate(-22deg);
  423. }
  424. 10% {
  425. transform: rotate(22deg);
  426. }
  427. 16% {
  428. transform: rotate(-12deg);
  429. }
  430. 18% {
  431. transform: rotate(12deg);
  432. }
  433. 20% {
  434. transform: rotate(0);
  435. }
  436. }
  437. .el-header {
  438. height: 189px !important;
  439. background: url(../../static/images/headBj.png) no-repeat center;
  440. background-size: 100% 100%;
  441. .navbarBtn{
  442. color: #fff;
  443. .userinfo{
  444. text-align: right;
  445. margin-top: 10px;
  446. .userheadImg{
  447. width: 35px;
  448. height: 35px;
  449. border-radius: 50%;
  450. vertical-align: middle;
  451. margin-right: 6px;
  452. }
  453. }
  454. .caption{
  455. margin-top: 7px;
  456. text-align: center;
  457. font-size: 16px;
  458. letter-spacing: .5px;
  459. .tit{
  460. font-size: 20px;
  461. line-height: 46px;
  462. font-weight: 700;
  463. letter-spacing: 7px;
  464. }
  465. }
  466. }
  467. }
  468. /deep/.el-dropdown-menu__item{
  469. padding: 0 10px;
  470. }
  471. .el-popper.newsDropdown {
  472. padding: 0;
  473. margin: 0;
  474. h5 {
  475. background: #35a478;
  476. color: #fff;
  477. padding: 15px;
  478. text-transform: uppercase;
  479. font-size: 11px;
  480. margin: 0;
  481. }
  482. /deep/.popper__arrow {
  483. border-bottom-color: #35a478;
  484. &::after {
  485. border-bottom-color: #35a478;
  486. }
  487. }
  488. ul {
  489. border: 1px solid #ddd;
  490. border-top: 0;
  491. padding: 0 10px;
  492. .news {
  493. display: block;
  494. margin: 0;
  495. float: none;
  496. background: none;
  497. padding: 5px 5px;
  498. border-bottom: 1px solid #eee;
  499. .txtContent {
  500. max-width: 250px;
  501. white-space: nowrap;
  502. overflow: hidden;
  503. text-overflow: ellipsis;
  504. display: inline-block;
  505. min-width: 250px;
  506. // display: flex;
  507. a {
  508. color: #333;
  509. font-size: 12px;
  510. padding: 7px 10px;
  511. -moz-border-radius: 2px;
  512. -webkit-border-radius: 2px;
  513. border-radius: 2px;
  514. -moz-transition: all 0.2s ease-out 0s;
  515. -webkit-transition: all 0.2s ease-out 0s;
  516. transition: all 0.2s ease-out 0s;
  517. }
  518. a:hover {
  519. background: none;
  520. color: #428bca;
  521. text-decoration: none;
  522. }
  523. }
  524. }
  525. }
  526. }
  527. .sysAside {
  528. position: absolute;
  529. z-index: 999;
  530. left: 0;
  531. top: 60px;
  532. bottom: 0;
  533. z-index: 999;
  534. transition: all 0.5s;
  535. }
  536. .el-aside {
  537. // background-color: #3D4C5A;
  538. color: #333;
  539. // line-height: 200px;
  540. // .el-menu-item.is-active{background:#17BB89!important}
  541. // .el-submenu__title i{color:#fff}
  542. .el-menu {
  543. border: none;
  544. }
  545. }
  546. .changeHomeItem {
  547. text-align: center;
  548. img {
  549. width: 100%;
  550. height: 110px;
  551. }
  552. .tit {
  553. margin-top: 10px;
  554. }
  555. }
  556. </style>