jc.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438
  1. <template>
  2. <div
  3. style="height: 100%; width: 100%;"
  4. @click="checkTimeOut()"
  5. @mouseenter="checkTimeOut()"
  6. @mousemove="checkTimeOut()"
  7. >
  8. <el-container class="admin-container">
  9. <!--页面头部(上边)-->
  10. <el-header>
  11. <div class="admin-logo-container">
  12. <!-- <img
  13. class="admin-logo"
  14. src="../assets/img/admin.jpg"
  15. alt=""
  16. > -->
  17. <span >安徽省农产品质量安全监测系统</span>
  18. </div>
  19. <div class="right-function-container">
  20. <el-button @click="logout">
  21. 退出
  22. </el-button>
  23. </div>
  24. </el-header>
  25. <!--页面主体部分-->
  26. <el-container>
  27. <!--页面侧边栏(左边)-->
  28. <el-aside style="width: 210px;">
  29. <!-- 页面左侧菜单区域-->
  30. <el-menu
  31. :default-active="$route.path"
  32. background-color="#EEF1F6"
  33. text-color="#48576a"
  34. active-text-color="#31B404"
  35. :collapse-transition="false"
  36. :router="true"
  37. >
  38. <!-- <el-menu-item
  39. index="/admin"
  40. @click="addTab('系统首页', '/admin')"
  41. >
  42. <i class="el-icon-s-home" />
  43. <span slot="title">系统首页</span>
  44. </el-menu-item> -->
  45. <!-- 一级菜单-->
  46. <el-submenu
  47. :index="index+''"
  48. v-for="(item, index) in menuList"
  49. :key="index"
  50. >
  51. <!-- 一级菜单模板区-->
  52. <template slot="title">
  53. <!-- 图标-->
  54. <i :class="item.icon" />
  55. <!-- 文本-->
  56. <span>{{ item.subMenuName }}</span>
  57. </template>
  58. <!-- 二级菜单-->
  59. <el-menu-item
  60. :index="subItem.path+''"
  61. v-for="subItem in item.children"
  62. :key="subItem.id"
  63. @click="addTab(subItem.subMenuName, subItem.path)"
  64. >
  65. <!-- 二级菜单模板区-->
  66. <template slot="title">
  67. <!-- 图标-->
  68. <i class="el-icon-bangzhu" />
  69. <!-- 文本-->
  70. <span>{{ subItem.subMenuName }}</span>
  71. </template>
  72. </el-menu-item>
  73. </el-submenu>
  74. </el-menu>
  75. </el-aside>
  76. <!-- 页面主内容(右边)-->
  77. <el-main>
  78. <el-tabs
  79. v-model="activeTabas"
  80. type="card"
  81. @tab-remove="removeTab"
  82. @tab-click="tabClick"
  83. >
  84. <el-tab-pane
  85. v-for="item in Tabs"
  86. :key="item.name"
  87. :label="item.title"
  88. :name="item.name"
  89. :closable="item.isClose"
  90. >
  91. <el-container>
  92. <el-main>
  93. <el-card shadow="always">
  94. <!-- 内容显示-->
  95. <router-view :key="item.name" />
  96. </el-card>
  97. </el-main>
  98. </el-container>
  99. </el-tab-pane>
  100. </el-tabs>
  101. </el-main>
  102. </el-container>
  103. </el-container>
  104. </div>
  105. </template>
  106. <script>
  107. export default {
  108. name: 'jc',
  109. data () {
  110. return {
  111. lastTime: null, // 最后一次点击的时间
  112. currentTime: null, // 当前点击的时间
  113. timeOut: 30 * 60 * 1000, // 设置超时时间: 30分钟
  114. /** tabs标签相关属性 */
  115. // 当前打开的tabs名称
  116. activeTabas: '/jc',
  117. Tabs: [],
  118. // 左侧菜单数据
  119. menuList: []
  120. }
  121. },
  122. watch: {
  123. /** 监听,当路由发生变化的时候执行(防止用户手动更换地址导致tabs的面板变动却不切换相应的tabs) */
  124. '$route.path': function () {
  125. var iindex = -1
  126. var jindex = -1
  127. for (let i = 0; i < this.menuList.length; i++) {
  128. for (let j = 0; j < this.menuList[i].children.length; j++) {
  129. if (this.menuList[i].children[j].path == this.$route.path) {
  130. iindex = i
  131. jindex = j
  132. break
  133. }
  134. }
  135. }
  136. this.addTab(this.menuList[iindex].children[jindex].subMenuName, this.$route.path)
  137. }
  138. },
  139. created () {
  140. this.lastTime = new Date().getTime() // 网页第一次打开时,记录当前时间
  141. // 保证admin中的页面刷新后重置到/admin路由下
  142. if (this.$route.path !== '/jc/routineMonitor') this.$router.push('/jc/routineMonitor')
  143. let groupname = window.sessionStorage.getItem('groupname')
  144. let data1 = []
  145. let data = [
  146. // {
  147. // // icon: 'el-icon-user-solid',
  148. // subMenuName: '监测模型',
  149. // children: [{
  150. // id: '1-1',
  151. // subMenuName: '模型配置',
  152. // path: '/jc/jcobj'
  153. // }
  154. // ]
  155. // },
  156. {
  157. // icon: 'el-icon-user-solid',
  158. subMenuName: '主体信息',
  159. children: [{
  160. id: '1-1',
  161. subMenuName: '信息维护',
  162. path: '/jc/subjectInformation'
  163. }
  164. ]
  165. },
  166. // {
  167. // // icon: 'el-icon-s-custom',
  168. // subMenuName: '牵头单位',
  169. // children: [
  170. // // {
  171. // // id: '2-1',
  172. // // subMenuName: '退回任务',
  173. // // path: '/admin/'
  174. // // },
  175. // {
  176. // id: '2-2',
  177. // subMenuName: '例行监测',
  178. // path: '/jc/routineMonitorqt'
  179. // }
  180. // ,{
  181. // id: '2-3',
  182. // subMenuName: '专项监测',
  183. // path: '/jc/specialMonitorqt'
  184. // },
  185. // // {
  186. // // id: '2-5',
  187. // // subMenuName: '监测信息汇总',
  188. // // path: '/admin/'
  189. // // },{
  190. // // id: '2-6',
  191. // // subMenuName: '承担任务报告下载',
  192. // // path: '/admin/'
  193. // // },{
  194. // // id: '2-7',
  195. // // subMenuName: '项目总结报告上传',
  196. // // path: '/admin/'
  197. // // },{
  198. // // id: '2-8',
  199. // // subMenuName: '项目总结报告管理',
  200. // // path: '/admin/'
  201. // // },{
  202. // // id: '2-9',
  203. // // subMenuName: '系统报表',
  204. // // path: '/admin/'
  205. // // }
  206. // ]
  207. // },
  208. {
  209. // icon: 'el-icon-s-data',
  210. subMenuName: '承担单位',
  211. children: [
  212. // {
  213. // id: '3-1',
  214. // subMenuName: '退回任务',
  215. // path: '/admin/'
  216. // },
  217. // {
  218. // id: '3-2',
  219. // subMenuName: '抽样计划',
  220. // path: '/admin/'
  221. // },
  222. {
  223. id: '3-3',
  224. subMenuName: '例行监测',
  225. path: '/jc/routineMonitor'
  226. },
  227. {
  228. id: '3-4',
  229. subMenuName: '专项监测',
  230. path: '/jc/specialMonitorcd'
  231. }
  232. ,{
  233. id: '3-5',
  234. subMenuName: '退回任务',
  235. path: '/jc/returnTaskcd'
  236. },
  237. //{
  238. // id: '3-6',
  239. // subMenuName: '报告汇总',
  240. // path: '/admin/'
  241. // },{
  242. // id: '3-7',
  243. // subMenuName: '问题单据',
  244. // path: '/admin/'
  245. // },{
  246. // id: '3-8',
  247. // subMenuName: '委托检测',
  248. // path: '/admin/'
  249. // },{
  250. // id: '3-9',
  251. // subMenuName: '复检任务',
  252. // path: '/admin/'
  253. // },
  254. ]
  255. },]
  256. this.menuList = data
  257. },
  258. mounted:function(){
  259. this.addTab("例行监测",'/jc/routineMonitor')
  260. },
  261. methods: {
  262. handleOpen (index) {
  263. console.log(index)
  264. },
  265. /** tabs标签相关函数 */
  266. // tab切换时,动态的切换路由
  267. tabClick (tab) {
  268. if (this.$route.path == tab.name) return
  269. this.$router.push(tab.name)
  270. },
  271. addTab (title, name) {
  272. for (let i = 0; i < this.Tabs.length; i++) {
  273. if (this.Tabs[i].name == name) {
  274. this.activeTabas = name
  275. return
  276. }
  277. }
  278. this.Tabs.push({
  279. title: title,
  280. name: name,
  281. isClose: 'closable'
  282. })
  283. this.activeTabas = name
  284. },
  285. removeTab (targetName) {
  286. const tabs = this.Tabs
  287. let activeName = this.activeTabas
  288. if (activeName == targetName) {
  289. tabs.forEach((tab, index) => {
  290. if (tab.name == targetName) {
  291. const nextTab = tabs[index + 1] || tabs[index - 1]
  292. if (nextTab) {
  293. activeName = nextTab.name
  294. }
  295. }
  296. })
  297. }
  298. this.activeTabas = activeName
  299. this.$router.push(activeName)
  300. this.Tabs = tabs.filter(tab => tab.name !== targetName)
  301. },
  302. /** 设置用户为登出状态 */
  303. async logout () {
  304. // const formData = { 'token': window.sessionStorage.getItem('token') }
  305. // // 提交登出请求
  306. // const result = await this.$http.post('/loginOut', formData)
  307. // if (result.data.code == 0) {
  308. // 清除seesion信息
  309. window.sessionStorage.clear()
  310. this.$router.push('/login')
  311. // }
  312. },
  313. async checkTimeOut () {
  314. this.currentTime = new Date().getTime() // 记录这次点击的时间
  315. // 如果当前页面不是登录,初始化界面就可以执行是否退出
  316. if (!(this.$route.path == '/login')) {
  317. /** 判断是否因为超时可以退出 */
  318. // 判断时间是否过期(判断上次最后一次点击的时间和这次点击的时间间隔是否大于10分钟)
  319. var isExit = this.currentTime - this.lastTime > this.timeOut
  320. if (isExit) {
  321. isExit = false
  322. // 这里写状态已过期后执行的操作
  323. this.lastTime = new Date().getTime() // 如果在10分钟内点击,则把这次点击的时间记录覆盖掉之前存的最后一次点击的时间
  324. this.$router.push('/login')
  325. // 设置用户为登出状态
  326. // const formData = {
  327. // 'token': window.sessionStorage.getItem('token')
  328. // }
  329. // 提交登出请求
  330. // const result = await this.$http.post('login_out', formData)
  331. // if (result.data.code == 0) {
  332. // // 清除seesion信息
  333. // window.sessionStorage.removeItem('token')
  334. // }
  335. // this.$message({
  336. // message: '长时间未操作,请重新登录',
  337. // type: 'warning',
  338. // showClose: true,
  339. // center: true
  340. // })
  341. } else {
  342. /** 判断是否因为用户未登录可以退出 */
  343. // const token = window.sessionStorage.getItem('token')
  344. // if (token == null || token == undefined || token == '') {
  345. // this.$router.push('/login')
  346. // this.$message({
  347. // message: '用户未登录,请重新登录',
  348. // type: 'warning',
  349. // showClose: true,
  350. // center: true
  351. // })
  352. // }
  353. this.lastTime = new Date().getTime() // 如果在10分钟内点击,则把这次点击的时间记录覆盖掉之前存的最后一次点击的时间
  354. }
  355. } else {
  356. this.lastTime = new Date().getTime() // 如果在10分钟内点击,则把这次点击的时间记录覆盖掉之前存的最后一次点击的时间
  357. }
  358. }
  359. }
  360. }
  361. </script>
  362. <style lang="less" scoped>
  363. .admin-container {
  364. height: 100%;
  365. // overflow: hidden;
  366. }
  367. .el-main {
  368. padding-top: 8px !important;
  369. }
  370. // .el-menu-item.is-active {
  371. // // background-color: #3ace04 !important;
  372. // }
  373. // .admin-logo-container {
  374. // // border-color: #5EB9DE;
  375. // // border-right-width: 1px;
  376. // // border-right-style: solid;
  377. // }
  378. .admin-logo {
  379. margin-left: 5px;
  380. height: 55px;
  381. width: 55px;
  382. /*自动等比缩放*/
  383. background-size: 100% 100%;
  384. }
  385. .el-header {
  386. background-color: #31B404;
  387. width: 100%;
  388. color: white;
  389. font-size: 25px;
  390. display: flex;
  391. padding-left: 0;
  392. }
  393. .admin-logo-container {
  394. display: flex;
  395. align-items: center;
  396. span {
  397. margin-left: 15px;
  398. }
  399. }
  400. .el-aside {
  401. // width: 200px;
  402. background-color: #EEF1F6;
  403. }
  404. .toggle-button-container {
  405. width: 180px;
  406. display: flex;
  407. justify-content: left;
  408. }
  409. // .toggle-button {
  410. // width: 50px;
  411. // line-height: 60px;
  412. // color: #fff;
  413. // text-align: center;
  414. // cursor: pointer;
  415. // }
  416. .right-function-container {
  417. width: 400px;
  418. line-height: 50px;
  419. text-align: right;
  420. position: absolute;
  421. right: 15px;
  422. }
  423. </style>