index.vue 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  1. <!-- -->
  2. <template>
  3. <div class="layout">
  4. <div class="top" @mouseleave="isShow = 0">
  5. <div class="left">
  6. <img src="@/assets/img/logo.png" alt="" />
  7. <h2>馆藏管理系统</h2>
  8. <div
  9. class="box"
  10. @mouseenter="isShow = index"
  11. v-for="(item, index) in tabList"
  12. :key="index"
  13. >
  14. <a
  15. @click="toHome(index)"
  16. :class="{ active: $route.meta.myInd === index }"
  17. >
  18. {{ item.name }}
  19. <ul v-show="isShow === index" @mouseenter="isShow = index">
  20. <li
  21. v-for="(val, ind) in item.son"
  22. :key="ind"
  23. @click="skip(item, val.id,val.name)"
  24. >
  25. {{ val.name }}
  26. </li>
  27. </ul>
  28. </a>
  29. </div>
  30. <!-- <router-link to="/layout/holding0" :class='{active:$route.meta.myInd===1}'>馆藏管理
  31. <ul>
  32. <li>藏品登记</li>
  33. </ul>
  34. </router-link>
  35. <router-link to="/layout/collect0" :class='{active:$route.meta.myInd===2}'>征集品管理</router-link>
  36. <router-link to="/layout/statistics0" :class='{active:$route.meta.myInd===3}'>库房管理</router-link>
  37. <router-link to="/layout/system0" :class='{active:$route.meta.myInd===4}'>系统管理</router-link> -->
  38. </div>
  39. <div class="right">
  40. <div class="img">
  41. <img src="@/assets/img/user1.jpg" alt="" />
  42. </div>
  43. <span>{{ userData.realName }}</span>
  44. <span class="loginOut" @click="isShowPass=!isShowPass">修改密码</span>
  45. <span class="loginOut" @click="loginOut">退出登录</span>
  46. <!-- 修改密码 -->
  47. <div class="editPass" v-show="isShowPass">
  48. <el-form
  49. :model="form"
  50. label-width="100px"
  51. :rules="rules"
  52. ref="ruleForm"
  53. >
  54. <el-form-item label="旧密码:" prop="oldPassword">
  55. <el-input
  56. v-model="form.oldPassword"
  57. placeholder="请输入"
  58. show-password
  59. ></el-input>
  60. </el-form-item>
  61. <el-form-item label="新密码:" prop="newPassword">
  62. <el-input
  63. v-model="form.newPassword"
  64. placeholder="请输入"
  65. show-password
  66. ></el-input>
  67. </el-form-item>
  68. <el-form-item label="确定新密码:" prop="checkPass">
  69. <el-input
  70. v-model="form.checkPass"
  71. placeholder="请输入"
  72. show-password
  73. ></el-input>
  74. </el-form-item>
  75. </el-form>
  76. <div class="button">
  77. <el-button size="small" type="primary" @click="editPass">确 定</el-button>
  78. <el-button size="small" @click="isShowPass=!isShowPass">取 消</el-button>
  79. </div>
  80. </div>
  81. </div>
  82. </div>
  83. <Router-view />
  84. </div>
  85. </template>
  86. <script>
  87. import { loginOut, editPass } from '@/apis/home'
  88. export default {
  89. name: 'Layout',
  90. // import引入的组件需要注入到对象中才能使用
  91. components: {},
  92. data () {
  93. // 这里存放数据
  94. const validatePass2 = (rule, value, callback) => {
  95. if (value !== this.form.newPassword) {
  96. callback(new Error('两次输入密码不一致!'))
  97. } else {
  98. callback()
  99. }
  100. }
  101. return {
  102. isShowPass: false,
  103. // 修改密码
  104. form: {
  105. oldPassword: '',
  106. newPassword: '',
  107. checkPass: ''
  108. },
  109. // 用户信息
  110. userData: {},
  111. // 控制子菜单显示
  112. isShow: 0,
  113. tabList: [
  114. {
  115. name: '首页',
  116. push: '/layout/home'
  117. },
  118. {
  119. name: '馆藏管理',
  120. push: '/layout/holding',
  121. son: [
  122. { name: '藏品登记', id: 0 },
  123. { name: '藏品总账', id: 3 },
  124. { name: '入库管理', id: 1 },
  125. { name: '出库管理', id: 2 },
  126. { name: '藏品修改', id: 4 },
  127. { name: '藏品注销', id: 5 }
  128. ]
  129. },
  130. // {
  131. // name: '征集管理',
  132. // push: '/layout/collect',
  133. // son: [
  134. // { name: '征集品总账', id: 0 },
  135. // { name: '征集品提用', id: 1 },
  136. // { name: '征集品修改', id: 3 },
  137. // { name: '征集品注销', id: 2 }
  138. // ]
  139. // },
  140. {
  141. name: '库房管理',
  142. push: '/layout/statistics',
  143. son: [
  144. { name: '库房设置', id: 0 },
  145. { name: '统计报表', id: 1 }
  146. ]
  147. },
  148. {
  149. name: '系统管理',
  150. push: '/layout/system',
  151. son: [
  152. { name: '用户管理', id: 2 },
  153. { name: '系统日志', id: 1 }
  154. ]
  155. }
  156. ],
  157. rules: {
  158. checkPass: [
  159. { validator: validatePass2, trigger: 'blur' }
  160. ],
  161. oldPassword: [
  162. { required: true, message: '不能为空', trigger: 'blur' }
  163. ],
  164. newPassword: [
  165. { required: true, message: '不能为空', trigger: 'blur' }
  166. ]
  167. }
  168. }
  169. },
  170. // 监听属性 类似于data概念
  171. computed: {},
  172. // 监控data中的数据变化
  173. watch: {},
  174. // 方法集合
  175. methods: {
  176. // 点击修改密码
  177. async editPass () {
  178. try {
  179. await this.$refs.ruleForm.validate()
  180. await editPass(this.form)
  181. this.$message.success('修改成功')
  182. // 发请求,清空数据
  183. await loginOut()
  184. localStorage.removeItem('daliCK')
  185. localStorage.removeItem('daliCK_token')
  186. this.$router.push('/login')
  187. } catch (error) {
  188. this.$message.error('旧密码错误')
  189. }
  190. },
  191. // 退出登录
  192. loginOut () {
  193. this.$confirm('确定退出码?', '提示', {
  194. confirmButtonText: '确定',
  195. cancelButtonText: '取消',
  196. type: 'warning'
  197. })
  198. .then(async () => {
  199. // 发请求,清空数据
  200. await loginOut()
  201. localStorage.removeItem('daliCK')
  202. localStorage.removeItem('daliCK_token')
  203. this.$router.push('/login')
  204. this.$message({
  205. type: 'success',
  206. message: '退出成功!'
  207. })
  208. })
  209. .catch(() => {
  210. this.$message({
  211. type: 'info',
  212. message: '已取消.'
  213. })
  214. })
  215. },
  216. skip (item, ind, name) {
  217. this.$router.push(item.push + ind).catch(() => {})
  218. this.isShow = 0
  219. // 如果从别的tab栏点击藏品总账,就自动刷新页面获取最新信息 location.reload(true)
  220. this.$nextTick(() => {
  221. setTimeout(() => {
  222. if (name === '藏品总账' || name === '征集品总账') location.reload(true)
  223. }, 500)
  224. })
  225. },
  226. toHome (index) {
  227. if (index === 0) this.$router.push('/layout/home').catch(() => {})
  228. }
  229. },
  230. // 生命周期 - 创建完成(可以访问当前this实例)
  231. created () {},
  232. // 生命周期 - 挂载完成(可以访问DOM元素)
  233. mounted () {
  234. // 进来显示用户信息
  235. const userData = localStorage.getItem('daliCK')
  236. this.userData = JSON.parse(userData).user
  237. // 获取用户角色权限标识
  238. let temp = localStorage.getItem('daliCK')
  239. temp = JSON.parse(temp)
  240. if (temp) {
  241. const temp2 = temp.role[0]
  242. if (temp2 !== 'sys_admin') this.tabList.pop() // 不是超级管理员
  243. }
  244. },
  245. beforeCreate () {}, // 生命周期 - 创建之前
  246. beforeMount () {}, // 生命周期 - 挂载之前
  247. beforeUpdate () {}, // 生命周期 - 更新之前
  248. updated () {}, // 生命周期 - 更新之后
  249. beforeDestroy () {}, // 生命周期 - 销毁之前
  250. destroyed () {}, // 生命周期 - 销毁完成
  251. activated () {} // 如果页面有keep-alive缓存功能,这个函数会触发
  252. }
  253. </script>
  254. <style lang='less' scoped>
  255. .layout {
  256. .top {
  257. min-width: 1142px;
  258. display: flex;
  259. justify-content: space-between;
  260. width: 100%;
  261. height: 68px;
  262. background-color: #001529;
  263. }
  264. .left {
  265. .active {
  266. color: #fff;
  267. }
  268. display: flex;
  269. align-items: center;
  270. & > img {
  271. margin-left: 15px;
  272. }
  273. h2 {
  274. color: #fff;
  275. margin-right: 30px;
  276. }
  277. .active {
  278. color: #fff;
  279. }
  280. .box {
  281. position: relative;
  282. cursor: pointer;
  283. margin: 0 30px;
  284. ul {
  285. z-index: 9999;
  286. position: absolute;
  287. top: 43px;
  288. left: -32px;
  289. background-color: #001529;
  290. li {
  291. width: 130px;
  292. height: 50px;
  293. line-height: 50px;
  294. text-align: center;
  295. color: #a5acb3;
  296. font-size: 14px;
  297. }
  298. li:hover {
  299. background-color: #1890ff;
  300. color: #fff;
  301. }
  302. }
  303. }
  304. .box:hover a {
  305. color: #fff;
  306. }
  307. }
  308. .right {
  309. position: relative;
  310. .editPass {
  311. .button{
  312. width: 100%;
  313. display: flex;
  314. justify-content: center;
  315. }
  316. /deep/.el-form-item__label{
  317. color: #fff;
  318. }
  319. padding: 20px;
  320. z-index: 9999;
  321. position: absolute;
  322. top: 68px;
  323. right: 0px;
  324. width: 300px;
  325. // background: rgba(0,0,0,.8);
  326. background-color: #001529;
  327. }
  328. .loginOut {
  329. cursor: pointer;
  330. }
  331. display: flex;
  332. align-items: center;
  333. margin-right: 50px;
  334. .img {
  335. width: 40px;
  336. height: 40px;
  337. border-radius: 50%;
  338. overflow: hidden;
  339. img {
  340. width: 100%;
  341. height: 100%;
  342. }
  343. }
  344. & > span {
  345. margin-left: 15px;
  346. }
  347. }
  348. }
  349. </style>