index.vue 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  1. <template>
  2. <div class="layout">
  3. <div class="top">
  4. <img src="@/assets/img/logo.png" alt="" />
  5. <p>石壁龙智慧园区</p>
  6. <div class="top_right">
  7. <div class="user" @click="cut = !cut">
  8. <img src="@/assets/img/user.jpg" alt="" />
  9. <span>{{userName}}</span>
  10. <!-- 下箭头 -->
  11. <div class="pull_down" v-if="cut"></div>
  12. <div class="pull_up" v-else></div>
  13. </div>
  14. <!-- 点击箭头出来的ul -->
  15. <ul class="user_handle" v-show="cut">
  16. <li @click="isShow = true">修改密码</li>
  17. <li @click="outLogin">退出登录</li>
  18. </ul>
  19. </div>
  20. </div>
  21. <div class="con">
  22. <div class="left">
  23. <div class="biaoji">数据管理</div>
  24. <ul>
  25. <li
  26. v-for="item in tab1"
  27. :key="item.id"
  28. :class="{ active: $route.meta.myInd === item.id }"
  29. @click="push(item.url)"
  30. >
  31. {{ item.name }}
  32. </li>
  33. </ul>
  34. <div class="biaoji">系统管理</div>
  35. <ul>
  36. <li
  37. v-for="item in tab2"
  38. :key="item.id"
  39. :class="{ active: $route.meta.myInd === item.id }"
  40. @click="push(item.url)"
  41. >
  42. {{ item.name }}
  43. </li>
  44. </ul>
  45. </div>
  46. <!-- 右侧内容 -->
  47. <div class="right">
  48. <Router-view />
  49. </div>
  50. </div>
  51. <!-- 点击修改密码出现弹窗 -->
  52. <el-dialog title="修改密码" :visible.sync="isShow" @close="btnX()">
  53. <el-form :model="form" label-width="100px" :rules="rules" ref="ruleForm">
  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 slot="footer" class="dialog-footer">
  77. <el-button @click="btnX">取 消</el-button>
  78. <el-button type="primary" @click="btnOk">确 定</el-button>
  79. </div>
  80. </el-dialog> </div>
  81. </template>
  82. <script>
  83. import { encodeStr } from '../../utils/pass'
  84. import { Base64 } from 'js-base64'
  85. import { updatePwd } from '@/apis/login'
  86. export default {
  87. name: 'layout',
  88. components: {},
  89. data () {
  90. // 这里存放数据
  91. const validatePass2 = (rule, value, callback) => {
  92. if (value !== this.form.newPassword) {
  93. callback(new Error('两次输入密码不一致!'))
  94. } else {
  95. callback()
  96. }
  97. }
  98. return {
  99. // 修改密码
  100. form: {
  101. oldPassword: '',
  102. newPassword: '',
  103. checkPass: ''
  104. },
  105. rules: {
  106. checkPass: [
  107. { validator: validatePass2, trigger: 'blur' }
  108. ],
  109. oldPassword: [
  110. { required: true, message: '不能为空', trigger: 'blur' }
  111. ],
  112. newPassword: [
  113. { required: true, message: '不能为空', trigger: 'blur' }, { max: 15, message: '不能超过15个字', trigger: 'blur' }
  114. ]
  115. },
  116. userName: '',
  117. cut: false,
  118. isShow: false,
  119. tab1: [
  120. { name: '整体概况', id: 1, url: '/layout/tab1' },
  121. { name: '鹏城云脑-能耗管理', id: 2, url: '/layout/tab2' },
  122. { name: '鹏城云脑-安防管理', id: 3, url: '/layout/tab3' },
  123. { name: '鹏城云脑-物联网设备', id: 4, url: '/layout/tab4' },
  124. { name: '工地监控', id: 5, url: '/layout/tab5' },
  125. { name: '无人机巡检', id: 6, url: '/layout/tab6' }
  126. ],
  127. tab2: [
  128. { name: '用户管理', id: 7, url: '/layout/tab7' },
  129. { name: '操作日志', id: 8, url: '/layout/tab8' }
  130. ]
  131. }
  132. },
  133. // 监听属性 类似于data概念
  134. computed: {},
  135. // 监控data中的数据变化
  136. watch: {},
  137. // 方法集合
  138. methods: {
  139. // 修改密码点击取消
  140. btnX () {
  141. this.$refs.ruleForm.resetFields()
  142. this.cut = false
  143. this.isShow = false
  144. this.form = {
  145. oldPassword: '',
  146. newPassword: '',
  147. checkPass: ''
  148. }
  149. },
  150. // 修改密码点击确定
  151. async btnOk () {
  152. await this.$refs.ruleForm.validate()
  153. try {
  154. const data = {
  155. oldPassword: encodeStr(Base64.encode(this.form.oldPassword)),
  156. newPassword: encodeStr(Base64.encode(this.form.newPassword))
  157. }
  158. await updatePwd(data)
  159. this.$message.success('修改成功')
  160. localStorage.clear('SWKK_token')
  161. localStorage.clear('SWKK_userInfo')
  162. this.$router.push('/')
  163. } catch (error) {
  164. this.$message.error('旧密码错误')
  165. }
  166. },
  167. push (url) {
  168. this.$router.push(url).catch(() => {})
  169. },
  170. // 点击退出登录
  171. outLogin () {
  172. this.cut = false
  173. this.$confirm('确定退出吗?', '提示', {
  174. confirmButtonText: '确定',
  175. cancelButtonText: '取消',
  176. type: 'warning'
  177. })
  178. .then(() => {
  179. localStorage.clear('SZSBL_token')
  180. localStorage.clear('SZSBL_userName')
  181. this.$router.push('/')
  182. this.$message.success('退出成功!')
  183. })
  184. .catch(() => {
  185. this.$message.info('已取消')
  186. })
  187. }
  188. },
  189. // 生命周期 - 创建完成(可以访问当前this实例)
  190. created () {
  191. // 获取用户名
  192. const res = localStorage.getItem('SZSBL_userName')
  193. this.userName = res
  194. },
  195. // 生命周期 - 挂载完成(可以访问DOM元素)
  196. mounted () {},
  197. beforeCreate () {}, // 生命周期 - 创建之前
  198. beforeMount () {}, // 生命周期 - 挂载之前
  199. beforeUpdate () {}, // 生命周期 - 更新之前
  200. updated () {}, // 生命周期 - 更新之后
  201. beforeDestroy () {}, // 生命周期 - 销毁之前
  202. destroyed () {}, // 生命周期 - 销毁完成
  203. activated () {} // 如果页面有keep-alive缓存功能,这个函数会触发
  204. }
  205. </script>
  206. <style lang='less' scoped>
  207. .layout {
  208. .top {
  209. position: relative;
  210. width: 100%;
  211. min-width: 1800px;
  212. box-shadow: 1px 3px 3px 3px rgb(196, 177, 177);
  213. height: 70px;
  214. background-color: #1482b4;
  215. display: flex;
  216. align-items: center;
  217. & > img {
  218. width: 35px;
  219. height: 35px;
  220. border-radius: 50%;
  221. overflow: hidden;
  222. margin: 0 30px;
  223. }
  224. & > P {
  225. color: #fff;
  226. font-size: 24px;
  227. font-weight: 700;
  228. }
  229. .top_right {
  230. width: 150px;
  231. position: absolute;
  232. right: 30px;
  233. top: 0;
  234. height: 100%;
  235. display: flex;
  236. align-items: center;
  237. justify-content: space-between;
  238. .user {
  239. color: #fff;
  240. cursor: pointer;
  241. position: relative;
  242. display: flex;
  243. align-items: center;
  244. img {
  245. margin-right: 15px;
  246. width: 34px;
  247. height: 34px;
  248. border-radius: 50%;
  249. overflow: hidden;
  250. }
  251. .pull_down {
  252. position: absolute;
  253. right: -25px;
  254. bottom: 10px;
  255. display: inline-block;
  256. width: 0;
  257. height: 0;
  258. border-left: 8px solid transparent;
  259. border-right: 8px solid transparent;
  260. border-bottom: 8px solid #fff;
  261. }
  262. .pull_up {
  263. cursor: pointer;
  264. position: absolute;
  265. right: -25px;
  266. bottom: 10px;
  267. display: inline-block;
  268. width: 0;
  269. height: 0;
  270. border-left: 8px solid transparent;
  271. border-right: 8px solid transparent;
  272. border-top: 8px solid #fff;
  273. }
  274. }
  275. .user_handle {
  276. z-index: 999;
  277. padding: 10px 40px;
  278. position: absolute;
  279. right: 0;
  280. bottom: -90px;
  281. background-color: #1482b4;
  282. li {
  283. color: #fff;
  284. cursor: pointer;
  285. margin: 10px 0;
  286. }
  287. li:hover {
  288. color: #dc3545;
  289. }
  290. }
  291. }
  292. }
  293. .con {
  294. display: flex;
  295. width: 100%;
  296. padding: 30px 30px 0;
  297. height: calc(100vh - 100px);
  298. }
  299. .left {
  300. min-width: 220px;
  301. width: 220px;
  302. height: 100%;
  303. background-color: #fff;
  304. padding-top: 15px;
  305. .biaoji {
  306. height: 40px;
  307. background-color: #1482b4;
  308. width: 90%;
  309. border-radius: 0 40px 40px 0;
  310. color: #fff;
  311. font-weight: 700;
  312. font-size: 20px;
  313. line-height: 40px;
  314. padding-left: 50px;
  315. }
  316. ul {
  317. li {
  318. cursor: pointer;
  319. padding-left: 50px;
  320. margin: 40px 0;
  321. &:hover {
  322. color: #1482b4;
  323. }
  324. }
  325. .active {
  326. color: #1482b4;
  327. }
  328. }
  329. }
  330. .right {
  331. padding: 20px;
  332. min-width: 1500px;
  333. flex: 1;
  334. margin-left: 30px;
  335. background-color: #fff;
  336. height: 100%;
  337. }
  338. }
  339. </style>