Navbar.vue 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. <template>
  2. <div style="height: 100%">
  3. <div v-show="isLogin" class="left-menu">
  4. <div style="background-color: #0053cb;width: 60px;height: 60px;display: inline-block">
  5. <span class="c-icon collapse-btn" @click="toggleSideBar">
  6. <i-ant-design-unordered-list-outlined/>
  7. </span>
  8. </div>
  9. <div class="title">
  10. <el-avatar class="title-logo" shape="square" :size="32" :src="logo"></el-avatar>
  11. <span class="title-content">智慧运营管理中心</span>
  12. </div>
  13. <el-select class="select-btn" v-model="value">
  14. <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value">
  15. </el-option>
  16. </el-select>
  17. </div>
  18. <div v-show="isLogin" class="right-menu">
  19. <div class="header-btn">
  20. <span class="c-icon" style="margin: 10px 4px;padding: 6px 10px 0">
  21. <i-ant-design-desktop-outlined/>
  22. </span>
  23. <span class="c-icon" style="margin: 10px 4px;padding: 6px 10px 0">
  24. <i-ant-design-mobile-outlined/>
  25. </span>
  26. <span class="c-icon" style="margin: 10px 4px;padding: 6px 10px 0">
  27. <i-ant-design-question-circle-outlined/>
  28. </span>
  29. <el-avatar :size="30"
  30. style="vertical-align: top;margin: 15px 0 0 15px;background-color: #fde3cf;color: #f56a00">
  31. <span style="font-size: 20px;display: inline-block;margin-top: 3px">
  32. <i-ant-design-user-outlined/>
  33. </span>
  34. </el-avatar>
  35. <el-dropdown class="userinfo" @command="handleCommand">
  36. <span class="el-dropdown-link">
  37. <span style="vertical-align: middle;font-size: 20px;margin-right: 4px">
  38. <i-ant-design-user-outlined/>
  39. </span>
  40. {{ $store.state.user.userInfo.user_name }}
  41. </span>
  42. <el-dropdown-menu slot="dropdown">
  43. <el-dropdown-item command="updPwd">修改密码</el-dropdown-item>
  44. <el-dropdown-item command="logout">退出登录</el-dropdown-item>
  45. </el-dropdown-menu>
  46. </el-dropdown>
  47. </div>
  48. </div>
  49. <el-dialog v-if="showUpdPwd" width="500px" :visible="true" title="修改密码">
  50. <el-form ref="updPwdForm" :model="updPwdForm" :rules="updPwdFormRules" label-position="right" label-width="90px">
  51. <el-form-item label="原密码:" prop="oldPwd">
  52. <el-input v-model="updPwdForm.oldPwd" type="password" show-password/>
  53. </el-form-item>
  54. <el-form-item label="新密码:" prop="password">
  55. <el-input v-model="updPwdForm.password" type="password" show-password/>
  56. </el-form-item>
  57. <el-form-item label="确认密码:" prop="confirmPwd">
  58. <el-input v-model="updPwdForm.confirmPwd" type="password" show-password/>
  59. </el-form-item>
  60. </el-form>
  61. <template #footer>
  62. <div style="width: 100%;text-align: center">
  63. <el-button style="width: 80px;height: 30px;padding: 0" @click="showUpdPwd=false">取消</el-button>
  64. <el-button type="primary" style="width: 80px;height: 30px;padding: 0" @click="updPwd">确定</el-button>
  65. </div>
  66. </template>
  67. </el-dialog>
  68. </div>
  69. </template>
  70. <script>
  71. import hamburger from '@/components/Hamburger/index'
  72. import logo from '@/assets/background/logo.png'
  73. import {updPwd} from "@/api/user/user";
  74. export default {
  75. components: {hamburger},
  76. props: {
  77. leftVisible: Boolean,
  78. //isLogin: Boolean,
  79. },
  80. data() {
  81. let validatePass = (rule, value, callback) => {
  82. if (value === '') {
  83. callback(new Error('请输入密码'));
  84. } else {
  85. if (this.updPwdForm.confirmPwd !== '') {
  86. this.$refs.updPwdForm.validateField('confirmPwd');
  87. }
  88. callback();
  89. }
  90. };
  91. let validatePass2 = (rule, value, callback) => {
  92. if (value === '') {
  93. callback(new Error('请再次输入密码'));
  94. } else if (value !== this.updPwdForm.password) {
  95. callback(new Error('两次输入密码不一致!'));
  96. } else {
  97. callback();
  98. }
  99. };
  100. return {
  101. logo,
  102. showUpdPwd: false,
  103. value: '1',
  104. options: [
  105. {
  106. label: '主语国际3号楼',
  107. value: '1'
  108. }
  109. ],
  110. updPwdForm: {
  111. oldPwd: '',
  112. password: '',
  113. confirmPwd: '',
  114. },
  115. updPwdFormRules: {
  116. oldPwd: [
  117. { required: true, message: '请输入旧密码', trigger: 'change' }
  118. ],
  119. password: [
  120. { validator: validatePass, required: true, trigger: 'change' }
  121. ],
  122. confirmPwd: [
  123. { validator: validatePass2, required: true, trigger: 'change' }
  124. ],
  125. },
  126. isLogin: true,
  127. opened: false,
  128. name: "test",
  129. circleUrl: "https://cube.elemecdn.com/0/88/03b0d39583f48206768a7534e55bcpng.png",
  130. isCollapse: false,
  131. tips: {
  132. labtap: require('@/assets/tips/diannao@3x.png'),
  133. phone: require('@/assets/tips/shouji-4@3x.png'),
  134. help: require('@/assets/tips/help@3x.png'),
  135. notification: require('@/assets/tips/tongzhi@3x.png')
  136. }
  137. }
  138. },
  139. mounted() {
  140. this.$emit('collapseControl', this.isCollapse);
  141. },
  142. methods: {
  143. toggleSideBar() {
  144. this.isCollapse = !this.isCollapse;
  145. this.$emit('collapseControl', this.isCollapse);
  146. },
  147. handleCommand(command) {
  148. if (command == 'logout') {
  149. this.logout()
  150. } else if (command == 'updPwd') {
  151. this.showUpdPwd = true;
  152. this.updPwdForm = {
  153. oldPwd: '',
  154. password: '',
  155. confirmPwd: '',
  156. }
  157. }
  158. },
  159. updPwd() {
  160. this.$refs.updPwdForm.validate(valid=>{
  161. if (valid) {
  162. let user = this.$store.state.user.userInfo
  163. updPwd(user.id, user.user_name, this.updPwdForm.password).then(res=>{
  164. let data = res.data;
  165. if (data.code==0) {
  166. this.$message.success('修改成功');
  167. } else {
  168. this.$message.error(data.message);
  169. }
  170. })
  171. }
  172. })
  173. },
  174. logout() {
  175. this.$store.state.token = '';
  176. localStorage.removeItem('Authorization');
  177. localStorage.removeItem('UserInfo');
  178. localStorage.clear();
  179. this.$router.push('/login')
  180. }
  181. }
  182. }
  183. </script>
  184. <style lang="less" scoped>
  185. .left-menu {
  186. //float: left;
  187. display: inline-block;
  188. cursor: default;
  189. text-align: left;
  190. height: 100%;
  191. line-height: 35px;
  192. width: 50%;
  193. color: white;
  194. .collapse-btn {
  195. margin: 7px;
  196. cursor: pointer;
  197. &:hover {
  198. background: #0043a3;
  199. }
  200. }
  201. .title {
  202. display: inline-block;
  203. vertical-align: top;
  204. line-height: 60px;
  205. color: white;
  206. margin-left: 15px;
  207. .title-logo {
  208. vertical-align: top;
  209. margin-top: 15px;
  210. margin-right: 18px;
  211. background-color: transparent;
  212. }
  213. .title-content {
  214. font-size: 22px;
  215. letter-spacing: 8px;
  216. }
  217. }
  218. .select-btn {
  219. width: 180px;
  220. color: white;
  221. font-size: 16px;
  222. text-align: center;
  223. margin-left: 15px;
  224. margin-top: 15px;
  225. display: inline-block;
  226. vertical-align: top;
  227. /deep/ .el-input__inner {
  228. background-color: #0062c4;
  229. height: 32px !important;
  230. padding-left: 20px;
  231. color: white;
  232. border: none;
  233. border-radius: 20px;
  234. }
  235. }
  236. }
  237. .right-menu {
  238. display: inline-block;
  239. vertical-align: top;
  240. width: 50%;
  241. text-align: right;
  242. .header-btn {
  243. }
  244. .userinfo {
  245. cursor: default;
  246. color: white;
  247. vertical-align: top;
  248. line-height: 20px;
  249. margin-top: 15px;
  250. margin-right: 20px;
  251. font-size: 18px;
  252. padding: 6px 15px;
  253. margin-left: 5px;
  254. border-radius: 20px;
  255. &:hover {
  256. background: #3c9cd3;
  257. }
  258. }
  259. }
  260. </style>