index.vue 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  1. <template>
  2. <el-container class="outter-container">
  3. <el-header>
  4. <h3>
  5. <img src="../../assets/logo.png" height="50" />
  6. </h3>
  7. <div class="user-info">
  8. <i class="el-icon-s-custom"></i>
  9. <span v-html="user.realName" style="margin-right:10px;"></span>
  10. <a href="#" @click="openChangePwDialog()" style="margin-right:10px;">修改密码</a>
  11. <a href="#" @click="logout()">退出</a>
  12. </div>
  13. <div style="position:absolute;bottom:0px;left:255px;right:185px;">
  14. <tags-view />
  15. </div>
  16. </el-header>
  17. <el-container>
  18. <el-aside :width="sidebarWidth" :height="sidebarHeight" v-loading="loading" class="sidebar">
  19. <div class="sidebar-collpase-btn" @click="collapse=!collapse" style="cursor:pointer">
  20. <i :class="sidbarHandlerClass"></i>
  21. </div>
  22. <el-menu
  23. class="el-menu-vertical-demo"
  24. @open="handleOpen"
  25. @close="handleClose"
  26. @select="handleSelect"
  27. :collapse="collapse"
  28. :unique-opened="true"
  29. :collapse-transition="false"
  30. >
  31. <menu-tree-item :routes="menuList"></menu-tree-item>
  32. </el-menu>
  33. </el-aside>
  34. <el-main>
  35. <!-- <router-view /> -->
  36. <app-main />
  37. </el-main>
  38. <el-dialog
  39. title="修改密码"
  40. :visible.sync="dialogFormVisible"
  41. :modal-append-to-body="false"
  42. :close-on-click-modal="false"
  43. width="20%"
  44. :before-close="colseChange"
  45. >
  46. <el-form ref="form" :model="form" :rules="ruleValidate">
  47. <el-form-item label="旧密码" prop="oldPassword">
  48. <el-input
  49. v-model="form.oldPassword"
  50. placeholder="请输入新密码"
  51. style="width:100%"
  52. show-password
  53. ></el-input>
  54. </el-form-item>
  55. <el-form-item label="新密码" prop="newPassword">
  56. <el-input
  57. v-model="form.newPassword"
  58. placeholder="请输入新密码"
  59. style="width:100%"
  60. show-password
  61. ></el-input>
  62. </el-form-item>
  63. <el-form-item label="重复新密码" prop="newPasswordTwo">
  64. <el-input
  65. v-model="form.newPasswordTwo"
  66. placeholder="请输入新密码"
  67. style="width:100%"
  68. show-password
  69. ></el-input>
  70. </el-form-item>
  71. </el-form>
  72. <div slot="footer" class="dialog-footer">
  73. <el-button @click="colseChange">取 消</el-button>
  74. <el-button type="primary" @click="changePw">确 定</el-button>
  75. </div>
  76. </el-dialog>
  77. </el-container>
  78. </el-container>
  79. </template>
  80. <script>
  81. import MenuTreeItem from "@/components/MenuTreeItem";
  82. import AppMain from './AppMain';
  83. import TagsView from './TagsView';
  84. import menuApi from "@/api/sys/menu";
  85. import userApi from "@/api/sys/user";
  86. export default {
  87. components: {
  88. "menu-tree-item": MenuTreeItem,
  89. "app-main": AppMain,
  90. "tags-view": TagsView
  91. },
  92. data() {
  93. let samePassword = (rule, value, callback) => {
  94. var self = this;
  95. var newPasswordTwo = value;
  96. var newPassword = self.form.newPassword;
  97. if (newPassword != newPasswordTwo) {
  98. return callback(new Error("两次密码输入不相同"));
  99. } else {
  100. return callback();
  101. }
  102. };
  103. return {
  104. ruleValidate: {
  105. oldPassword: [{ required: true, message: "不能为空", trigger: "blur" }],
  106. newPassword: [{ required: true, message: "不能为空", trigger: "blur" }],
  107. newPasswordTwo: [
  108. {
  109. required: true,
  110. message: "不能为空",
  111. trigger: "blur"
  112. },
  113. {
  114. validator: samePassword,
  115. trigger: "blur"
  116. }
  117. ]
  118. },
  119. menuList: [],
  120. loading: false,
  121. collapse: false,
  122. user: {},
  123. dialogFormVisible: false,
  124. form: {
  125. oldPassword: "",
  126. newPassword: "",
  127. newPasswordTwo: ""
  128. },
  129. sidebarHeight: window.innerHeight
  130. };
  131. },
  132. computed: {
  133. sidebarWidth() {
  134. return !this.collapse ? "200px" : "64px";
  135. },
  136. sidbarHandlerClass() {
  137. return {
  138. iconfont: true,
  139. "icon-icon_left_arrow": this.collapse,
  140. "icon-icon_right_arrow": !this.collapse
  141. };
  142. }
  143. },
  144. methods: {
  145. handleOpen(key, keyPath) {
  146. console.log(key, keyPath);
  147. },
  148. handleClose(key, keyPath) {
  149. console.log(key, keyPath);
  150. },
  151. handleSelect(key, keyPath) {
  152. //console.log(key, keyPath);
  153. this.$router.push({ path: key });
  154. },
  155. logout() {
  156. this.$store.dispatch("user/logout").then(() => {
  157. this.$router.push({ path: "/login" });
  158. });
  159. },
  160. openChangePwDialog() {
  161. var self = this;
  162. self.dialogFormVisible = true;
  163. },
  164. changePw() {
  165. var self = this;
  166. this.$refs["form"].validate(valid => {
  167. if (valid) {
  168. var formData = new FormData();
  169. formData.append("oldPassword", self.form.oldPassword);
  170. formData.append("newPassword", self.form.newPassword);
  171. userApi.changeLoginPassword(formData).then(function(response) {
  172. var jsonData = response.data;
  173. if (jsonData.result) {
  174. self.dialogFormVisible = false;
  175. self.form.oldPassword = "";
  176. self.form.newPassword = "";
  177. self.form.newPasswordTwo = "";
  178. self.$message({
  179. type: "success",
  180. message: "修改成功,下次登录生效!"
  181. });
  182. } else {
  183. self.$message({
  184. type: "warning",
  185. message: jsonData.message
  186. });
  187. }
  188. });
  189. }
  190. });
  191. },
  192. colseChange() {
  193. var self = this;
  194. self.form.oldPassword = "";
  195. self.form.newPassword = "";
  196. self.form.newPasswordTwo = "";
  197. self.dialogFormVisible = false;
  198. this.$refs["form"].resetFields();
  199. }
  200. },
  201. mounted() {
  202. this.loading = true;
  203. userApi.userInfo().then(resp => {
  204. if (resp.data.result) {
  205. this.user = resp.data.data;
  206. }
  207. });
  208. menuApi
  209. .getMenuTree()
  210. .then(response => {
  211. console.log(response);
  212. var jsonData = response.data;
  213. this.menuList = jsonData.data;
  214. this.loading = false;
  215. })
  216. .catch(exception => {
  217. this.$message.error(exception + "");
  218. this.loading = false;
  219. });
  220. }
  221. };
  222. </script>
  223. <style lang="scss" scoped>
  224. .outter-container {
  225. flex: 1;
  226. }
  227. .el-header {
  228. position: relative;
  229. background-color: #fff;
  230. color: #333;
  231. text-align: left;
  232. // border-bottom: 2px solid rgb(36,61,162);
  233. border-bottom: 2px solid #00aaff;
  234. }
  235. .el-header h3 {
  236. margin: 5px;
  237. padding: 0px;
  238. }
  239. .el-aside {
  240. color: #333;
  241. text-align: center;
  242. display: flex;
  243. flex-direction: column;
  244. }
  245. .el-aside .el-menu {
  246. flex: 1;
  247. background-color: rgb(238, 238, 238);
  248. }
  249. .el-main {
  250. background-color: #fff;
  251. color: #333;
  252. text-align: center;
  253. padding: 0px;
  254. position: relative;
  255. }
  256. .el-menu-vertical-demo {
  257. text-align: left;
  258. }
  259. .user-info {
  260. position: absolute;
  261. right: 20px;
  262. bottom: 10px;
  263. font-size: 14px;
  264. line-height: 30px;
  265. a {
  266. color: blue;
  267. cursor: pointer;
  268. text-decoration: none;
  269. }
  270. a:hover {
  271. text-decoration: underline;
  272. }
  273. }
  274. .sidebar {
  275. position: relative;
  276. overflow: visible !important;
  277. }
  278. .sidebar-collpase-btn {
  279. position: absolute;
  280. width: 12px;
  281. height: 53px;
  282. border-radius: 0px 10px 10px 0px;
  283. top: 200px;
  284. right: -12px;
  285. background-color: #eeeeee;
  286. z-index: 1000;
  287. padding-top: 30px;
  288. padding-right: 4px;
  289. color: black;
  290. font-weight: bold;
  291. }
  292. .menu-wrapper{
  293. position: absolute;
  294. top:0px;
  295. bottom:0px;
  296. left:0px;
  297. right:0px;
  298. overflow: auto;
  299. display: flex;
  300. flex-direction: column;
  301. }
  302. </style>