index.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. <template>
  2. <div class="app-wrapper">
  3. <sidebar class="sidebar-container" id="sidebar-containers" @leup="leuper" />
  4. <div class="main-container">
  5. <navbar />
  6. <app-main id="main-containers" />
  7. </div>
  8. <!--修改密码弹框-->
  9. <Dialog width="496px" customClass="dataStoreInfoDialog" :flag="pwdflag">
  10. <div class="dialog-public-background">
  11. <div class="title">修改密码</div>
  12. <div class="content">
  13. <el-form :model="dataForm" :rules="dataRules" ref="dataForm" class="demo-dataForm">
  14. <el-form-item label="旧密码" prop="old">
  15. <el-input size="medium" placeholder="请输入旧密码" show-password v-model="dataForm.old"></el-input>
  16. </el-form-item>
  17. <el-form-item label="新密码" prop="new">
  18. <el-input size="medium" placeholder="请输入新密码" show-password v-model="dataForm.new"></el-input>
  19. </el-form-item>
  20. <el-form-item label="再次确认新密码" prop="again">
  21. <el-input size="medium" placeholder="请再次确认新密码" show-password v-model="dataForm.again"></el-input>
  22. </el-form-item>
  23. </el-form>
  24. </div>
  25. <div class="foot center t30">
  26. <el-button size="medium" type="primary" @click="addSubmit('dataForm')" class="r24">保存</el-button>
  27. <el-button size="medium" @click="resetForm('dataForm')">取消</el-button>
  28. </div>
  29. </div>
  30. </Dialog>
  31. <!--退出弹框-->
  32. <Dialog :flag="outflag">
  33. <div class="airportInfoDialog">
  34. <div class="flx">退出系统</div>
  35. <div class="content">是否确认退出系统?</div>
  36. <div class="foot right t30" style="margin-top: 24px">
  37. <el-button size="medium" class="r25 r26" @click="outQd" type="primary">确定</el-button>
  38. <el-button size="medium" @click="outQx" class="r26">取消</el-button>
  39. </div>
  40. </div>
  41. </Dialog>
  42. </div>
  43. </template>
  44. <script>
  45. import { Navbar, Sidebar, AppMain } from "./components";
  46. import ResizeMixin from "./mixin/ResizeHandler";
  47. import { mapGetters } from "vuex";
  48. import { changePassword } from "@/api/newLogin";
  49. import { removeToken } from "@/utils/auth";
  50. import Dialog from "@/layout/components/Dialog";
  51. import MD5 from 'blueimp-md5'
  52. export default {
  53. name: "Layout",
  54. components: {
  55. Navbar,
  56. Sidebar,
  57. AppMain,
  58. Dialog,
  59. },
  60. mixins: [ResizeMixin],
  61. data () {
  62. return {
  63. dataForm: {
  64. //数据项表单
  65. old: "",
  66. new: "",
  67. again: "",
  68. },
  69. // leup: true,
  70. dataRules: {
  71. //数据项表单验证
  72. old: [{ required: true, message: "请输入旧密码", trigger: "blur" }],
  73. new: [{ required: true, message: "请输入新密码", trigger: "blur" }],
  74. again: [
  75. { required: true, message: "请再次确认新密码", trigger: "blur" },
  76. ],
  77. },
  78. };
  79. },
  80. computed: {
  81. ...mapGetters(["pwdflag", "outflag", "name"]),
  82. },
  83. mounted () {
  84. this.leuper(true)
  85. },
  86. methods: {
  87. leuper (data) {
  88. if (data) {
  89. document.getElementById("sidebar-containers").style.width = "208px";
  90. document.getElementById("main-containers").style.paddingLeft = "208px";
  91. document.getElementById("navbar_lowers").style.paddingLeft = "208px";
  92. this.$store.dispatch('app/expandSidebar', true)
  93. } else {
  94. document.getElementById("sidebar-containers").style.width = "56px";
  95. document.getElementById("main-containers").style.paddingLeft = "56px";
  96. document.getElementById("navbar_lowers").style.paddingLeft = "56px";
  97. this.$store.dispatch('app/expandSidebar', false)
  98. }
  99. },
  100. // eveclk() {
  101. // document.getElementById("sidebar-container").style.width = "150px";
  102. // this.leup = true;
  103. // // document.getElementById("main-containers").style.paddingLeft = "50px";
  104. // },
  105. // upLeft() {
  106. // document.getElementById("sidebar-container").style.width = "48px";
  107. // this.leup = false;
  108. // // document.getElementById("main-containers").style.paddingLeft = "30px";
  109. // },
  110. //存储数据项-提交
  111. addSubmit (formName) {
  112. this.$refs[formName].validate((valid) => {
  113. if (valid) {
  114. if (this.dataForm.new !== this.dataForm.again) {
  115. this.$message.error("两次输入的密码不一致,请重新输入");
  116. return false;
  117. }
  118. this.editPwd();
  119. } else {
  120. console.log("error submit!!");
  121. return false;
  122. }
  123. });
  124. },
  125. //存储数据项-取消
  126. resetForm (formName) {
  127. this.$store.dispatch("app/togglePwdflag", false);
  128. this.$refs[formName].resetFields();
  129. },
  130. //退出系统-取消
  131. outQx () {
  132. this.$store.dispatch("app/toggleOutflag", false);
  133. },
  134. //退出系统-确定
  135. async outQd () {
  136. if (this.name == '匿名用户') {
  137. removeToken();
  138. sessionStorage.clear();
  139. this.$store.dispatch("app/toggleOutflag", false);
  140. this.$router.push(`/login?redirect=${this.$route.fullPath}`);
  141. location.reload();
  142. } else {
  143. sessionStorage.removeItem("userName");
  144. this.$store.dispatch("app/toggleOutflag", false);
  145. const res = await this.$store.dispatch("user/logout");
  146. this.$router.push(`/login?redirect=${this.$route.fullPath}`);
  147. }
  148. },
  149. //修改密码
  150. async editPwd () {
  151. try {
  152. const res = await changePassword({
  153. username: this.name,
  154. originPassword: MD5(this.dataForm.old),
  155. // passwd: MD5(this.dataForm.again),
  156. newPassword: this.dataForm.again,
  157. // newPassword: MD5(this.dataForm.again),
  158. });
  159. if (res.code == 0) {
  160. this.$message.success(res.message);
  161. this.$store.dispatch("app/togglePwdflag", false);
  162. setTimeout(() => {
  163. this.outQd();
  164. }, 2000);
  165. } else {
  166. this.$message.error(res.message);
  167. }
  168. } catch (error) {
  169. console.log("出错了", error);
  170. }
  171. },
  172. },
  173. };
  174. </script>
  175. <style lang="scss" scoped>
  176. @import "~@/styles/mixin.scss";
  177. @import "~@/styles/variables.scss";
  178. .app-wrapper {
  179. @include clearfix;
  180. position: relative;
  181. height: 100%;
  182. width: 100%;
  183. &.mobile.openSidebar {
  184. position: fixed;
  185. top: 0;
  186. }
  187. }
  188. .drawer-bg {
  189. background: #000;
  190. opacity: 0.3;
  191. width: 100%;
  192. top: 0;
  193. height: 100%;
  194. position: absolute;
  195. z-index: 999;
  196. }
  197. .fixed-header {
  198. position: fixed;
  199. top: 0;
  200. right: 0;
  201. z-index: 9;
  202. width: calc(100% - #{$sideBarWidth});
  203. transition: width 0.28s;
  204. }
  205. .hideSidebar .fixed-header {
  206. width: calc(100% - 54px);
  207. }
  208. .mobile .fixed-header {
  209. width: 100%;
  210. }
  211. </style>