index.vue 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. <template>
  2. <el-container>
  3. <el-header style="background-color:#545c64">
  4. <el-row type="flex" style="height:100%;" justify="space-between" align="middle">
  5. <div style="color:#fff">
  6. <span class="title" style="font-size: 18px">{{UserInfo.name}}后台管理系统</span>
  7. </div>
  8. <div>
  9. <el-dropdown @command="onUserEdit">
  10. <span class="el-dropdown-link">
  11. <i class="el-icon-user" style="margin-right: 10px"></i>管理员
  12. <i class="el-icon-arrow-down el-icon--right"></i>
  13. </span>
  14. <el-dropdown-menu slot="dropdown">
  15. <el-dropdown-item command="logout" icon="el-icon-caret-left">退出登录</el-dropdown-item>
  16. <el-dropdown-item command="editPwd" icon="el-icon-edit">修改密码</el-dropdown-item>
  17. </el-dropdown-menu>
  18. </el-dropdown>
  19. </div>
  20. </el-row>
  21. </el-header>
  22. <!-- border: 1px solid #ccc -->
  23. <el-container style="height: 100%; ">
  24. <el-aside width="240px">
  25. <el-menu router class="el-menu" background-color="#545c64" text-color="#fff" active-text-color="#ffd04b" :default-active="curPath">
  26. <el-menu-item index="home" route="/">
  27. <i class="el-icon-house"></i>
  28. <span style="font-size: 19px;" slot="title">首页</span>
  29. </el-menu-item>
  30. <el-menu-item index="order" route="order">
  31. <i class="el-icon-edit-outline"></i>
  32. <span style="font-size: 19px;" slot="title">订单管理</span>
  33. </el-menu-item>
  34. <el-menu-item index="message" route="message">
  35. <i class="el-icon-message"></i>
  36. <span style="font-size: 19px;" slot="title">账户日志</span>
  37. </el-menu-item>
  38. <el-menu-item index="oilCard" route="oilCard">
  39. <i class="el-icon-bank-card"></i>
  40. <span style="font-size: 19px;" slot="title">油卡充值</span>
  41. </el-menu-item>
  42. <el-menu-item index="mobileCard" route="mobileCard">
  43. <i class="el-icon-mobile"></i>
  44. <span style="font-size: 19px;" slot="title">手机卡充值</span>
  45. </el-menu-item>
  46. <el-menu-item index="balance" route="balance">
  47. <i class="el-icon-s-order"></i>
  48. <span style="font-size: 19px;" slot="title">充值管理</span>
  49. </el-menu-item>
  50. <el-menu-item index="reconciliation" route="reconciliation">
  51. <i class="el-icon-document-checked"></i>
  52. <span style="font-size: 19px;" slot="title">对账管理</span>
  53. </el-menu-item>
  54. <el-menu-item index="view" route="view">
  55. <i class="el-icon-s-platform"></i>
  56. <span style="font-size: 19px;" slot="title">设置</span>
  57. </el-menu-item>
  58. <el-menu-item index="interfaceDoc" route="interfaceDoc" >
  59. <i class="el-icon-document"></i>
  60. <span style="font-size: 19px;" slot="title">接口文档</span>
  61. </el-menu-item>
  62. </el-menu>
  63. </el-aside>
  64. <el-main class="el-menu" style="min-width:860px;">
  65. <router-view />
  66. </el-main>
  67. <el-dialog title="修改密码" :visible.sync="editVisible" width="50%" @closed="onCloseEditDialog">
  68. <el-form :model="editForm" :rules="editRules" ref="editForm" label-width="120px" class="demo-ruleForm">
  69. <el-form-item label="密码" prop="pwd">
  70. <el-input v-model="editForm.pwd" type="password"></el-input>
  71. </el-form-item>
  72. <el-form-item label="确认密码" prop="rePwd">
  73. <el-input v-model="editForm.rePwd" type="password"></el-input>
  74. </el-form-item>
  75. </el-form>
  76. <span slot="footer" class="dialog-footer">
  77. <el-button @click="onCloseEditDialog">取 消</el-button>
  78. <el-button type="primary" @click="onEditSubmit('editForm')">确认修改</el-button>
  79. </span>
  80. </el-dialog>
  81. </el-container>
  82. </el-container>
  83. </template>
  84. <script>
  85. import {
  86. loginOut,
  87. editPwd
  88. } from "@/api";
  89. import { removeUser } from '@/utils/auth'
  90. // 商家区分
  91. import UserInfo from '@/utils/userInfo'
  92. export default {
  93. name: 'homePage',
  94. created() {
  95. this.curPath = this.$route.name;
  96. },
  97. data() {
  98. return {
  99. curPath: "",
  100. editVisible: false,
  101. editForm: {
  102. pwd: "",
  103. rePwd: "",
  104. },
  105. editRules: {
  106. pwd: [{
  107. required: true,
  108. message: "请输入登录密码",
  109. trigger: "blur",
  110. }, ],
  111. rePwd: [{
  112. required: true,
  113. validator: this.validateRePwd2,
  114. trigger: "blur",
  115. }, ],
  116. },
  117. UserInfo
  118. };
  119. },
  120. methods: {
  121. onCloseEditDialog() {
  122. this.editForm = {};
  123. this.editVisible = false;
  124. this.editPwdId = "";
  125. this.$refs.editForm.resetFields();
  126. },
  127. validateRePwd2(rule, value, callback) {
  128. if (value === "") {
  129. callback(new Error("请再次输入密码"));
  130. } else if (value !== this.editForm.pwd) {
  131. callback(new Error("两次输入密码不一致!"));
  132. } else {
  133. callback();
  134. }
  135. },
  136. onUserEdit(command) {
  137. if (command == "logout") {
  138. this.$confirm("确认退出该账号?", "退出", {
  139. confirmButtonText: "确定",
  140. cancelButtonText: "取消",
  141. type: "warning",
  142. })
  143. .then(() => {
  144. this.onLoginOut();
  145. })
  146. .catch(() => {
  147. return false;
  148. });
  149. } else if (command == "editPwd") {
  150. this.editVisible = true;
  151. }
  152. },
  153. onLoginOut() {
  154. loginOut().then((res) => {
  155. console.log('登出', res);
  156. if (res && res.message == "成功") {
  157. // 删除本地
  158. removeUser('name')
  159. this.$router.replace({
  160. path: "/login",
  161. });
  162. }
  163. });
  164. },
  165. onEditSubmit(formName) {
  166. // const _self = this;
  167. this.$refs[formName].validate(async (valid) => {
  168. if (valid) {
  169. // editPwd({
  170. // new_pw: this.editForm.pwd,
  171. // new_pw2: this.editForm.rePwd,
  172. // }).then((res) => {
  173. // console.log(res);
  174. // if (res && res.message == "成功") {
  175. // this.$message({
  176. // message: "修改成功",
  177. // type: "success",
  178. // center: true,
  179. // duration: 1000,
  180. // onClose: () => {
  181. // this.onCloseEditDialog();
  182. // },
  183. // });
  184. // }
  185. // });
  186. try {
  187. let param = new URLSearchParams()
  188. param.append('new_pw', this.editForm.pwd)
  189. param.append('new_pw2', this.editForm.rePwd)
  190. // const res = await editPwd({new_pw: this.editForm.pwd,new_pw2: this.editForm.rePwd,})
  191. const res = await editPwd(param)
  192. console.log('修改密码', res);
  193. if (res && res.message == "成功") {
  194. this.$message({
  195. message: "修改成功",
  196. type: "success",
  197. center: true,
  198. duration: 1000,
  199. onClose: () => {
  200. this.onCloseEditDialog();
  201. },
  202. });
  203. }
  204. } catch (error) {
  205. console.log(error);
  206. this.$message.error('修改失败')
  207. }
  208. } else {
  209. console.log("error submit!!");
  210. return false;
  211. }
  212. });
  213. },
  214. },
  215. // 监听器
  216. watch: {
  217. '$route': {
  218. handler(newVal) {
  219. // console.log(newVal.name, oldVal.path);
  220. if (newVal) {
  221. this.curPath = newVal.name
  222. }
  223. }
  224. }
  225. }
  226. };
  227. </script>
  228. <style scoped>
  229. .el-menu {
  230. height: calc(100vh - 62px);
  231. }
  232. .el-menu span {
  233. display: inline-block;
  234. /* 小于12px */
  235. /* -webkit-text-size-adjust:none; */
  236. transform:scale(0.83,0.83);
  237. /* transform-origin: left; */
  238. -webkit-transform: scale(0.80);
  239. }
  240. .el-menusize-font{
  241. font-size: 16*0.8px;
  242. }
  243. /deep/.el-aside {
  244. width: 200px;
  245. }
  246. .el-dropdown-link {
  247. color: #409eff;
  248. }
  249. </style>