admin.vue 10 KB

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