admin.vue 11 KB

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