change-password.vue 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  1. <template>
  2. <div class="change-password pagePadding">
  3. <div class="change">
  4. <div class="title">
  5. 设置新登录密码
  6. <el-popover
  7. placement="top"
  8. title="初始密码:"
  9. width="200"
  10. trigger="click"
  11. content="dingding123"
  12. >
  13. <i class="el-icon-info" slot="reference"></i>
  14. </el-popover>
  15. </div>
  16. <el-form
  17. ref="loginForm"
  18. :model="loginForm"
  19. :rules="loginRules"
  20. class="login-form"
  21. autocomplete="on"
  22. label-position="right"
  23. label-width="100px"
  24. >
  25. <el-form-item prop="oldPassword" label="旧密码:">
  26. <el-input
  27. ref="oldPassword"
  28. v-model="loginForm.oldPassword"
  29. placeholder="旧密码"
  30. name="oldPassword"
  31. type="password"
  32. tabindex="1"
  33. autocomplete="on"
  34. />
  35. </el-form-item>
  36. <el-form-item prop="newPassword" label="新密码:">
  37. <el-input
  38. ref="newPassword"
  39. v-model="loginForm.newPassword"
  40. placeholder="新密码"
  41. name="newPassword"
  42. type="password"
  43. tabindex="1"
  44. autocomplete="on"
  45. />
  46. </el-form-item>
  47. <el-form-item prop="confirmPassword" label="确认密码:">
  48. <el-input
  49. ref="confirmPassword"
  50. v-model="loginForm.confirmPassword"
  51. placeholder="确认密码"
  52. name="confirmPassword"
  53. type="password"
  54. tabindex="1"
  55. autocomplete="on"
  56. />
  57. </el-form-item>
  58. <el-button
  59. :loading="loading"
  60. type="primary"
  61. round
  62. style="width: 98%; margin: 15px 0 0 5%"
  63. @click.native.prevent="handleLogin"
  64. >确认修改</el-button
  65. >
  66. </el-form>
  67. </div>
  68. </div>
  69. </template>
  70. <script>
  71. import { isnumber, isAlphanumeric, validAlphabets } from "@/utils/validate";
  72. import asyncRequest from "@/apis/service/user/index";
  73. import resToken from "@/mixins/resToken";
  74. export default {
  75. name: "Login",
  76. mixins:[resToken],
  77. data() {
  78. const validateOldPassword = (rule, value, callback) => {
  79. if (value === "") {
  80. callback(new Error("旧密码不能为空!"));
  81. } else {
  82. if (!isAlphanumeric(value)) {
  83. callback(new Error("旧密码为6-18位数字字母组合!"));
  84. } else if (value.length < 6 || value.length > 18) {
  85. callback(new Error("旧密码为6-18位数字字母组合!"));
  86. } else if (isnumber(value)) {
  87. callback(new Error("旧密码不能为纯数字!"));
  88. } else if (validAlphabets(value)) {
  89. callback(new Error("旧密码不能为纯字母!"));
  90. } else {
  91. callback();
  92. }
  93. }
  94. };
  95. const validateNewPassword = (rule, value, callback) => {
  96. if (value === "") {
  97. callback(new Error("新密码不能为空!"));
  98. } else {
  99. if (this.loginForm.oldPassword === value) {
  100. callback(new Error("新密码不能与旧密码一致!"));
  101. } else {
  102. if (!isAlphanumeric(value)) {
  103. callback(new Error("新密码为6-18位数字字母组合!"));
  104. } else if (value.length < 6 || value.length > 18) {
  105. callback(new Error("新密码为6-18位数字字母组合!"));
  106. } else if (isnumber(value)) {
  107. callback(new Error("新密码不能为纯数字!"));
  108. } else if (validAlphabets(value)) {
  109. callback(new Error("新密码不能为纯字母!"));
  110. } else {
  111. callback();
  112. }
  113. }
  114. }
  115. };
  116. const validateConfirmPassword = (rule, value, callback) => {
  117. if (value === "") {
  118. callback(new Error("确认密码不能为空!"));
  119. } else {
  120. if (this.loginForm.newPassword !== value) {
  121. callback(new Error("确认密码与新密码不一致!"));
  122. } else {
  123. callback();
  124. }
  125. }
  126. };
  127. return {
  128. loginForm: {
  129. oldPassword: "",
  130. newPassword: "",
  131. confirmPassword: "",
  132. },
  133. loginRules: {
  134. oldPassword: [
  135. { required: true, trigger: "blur", validator: validateOldPassword },
  136. ],
  137. newPassword: [
  138. { required: true, trigger: "blur", validator: validateNewPassword },
  139. ],
  140. confirmPassword: [
  141. {
  142. required: true,
  143. trigger: "blur",
  144. validator: validateConfirmPassword,
  145. },
  146. ],
  147. },
  148. loading: false,
  149. otherQuery: {},
  150. };
  151. },
  152. methods: {
  153. async handleLogin() {
  154. this.$refs.loginForm.validate(async (valid) => {
  155. if (valid) {
  156. if (!this.loading) {
  157. this.loading = true;
  158. const model = {
  159. oldpwd: this.loginForm.oldPassword,
  160. newpwd: this.loginForm.newPassword,
  161. };
  162. asyncRequest.setpwd(model).then(async (res) => {
  163. if (res && res.code === 0) {
  164. this.loading = false;
  165. this.$message.success(res.message);
  166. await this.logout();
  167. } else if (res && res.code >= 100 && res.code <= 104) {
  168. await this.logout();
  169. } else {
  170. this.$message.warning(res.message);
  171. this.loading = false;
  172. }
  173. });
  174. }
  175. } else {
  176. console.log("error submit!!");
  177. return false;
  178. }
  179. });
  180. },
  181. },
  182. };
  183. </script>
  184. <style lang="scss">
  185. .change-password {
  186. background: rgba(242, 242, 242, 1);
  187. background: #f2f2f2;
  188. min-height: 100%;
  189. width: 100%;
  190. height: 100%;
  191. overflow: hidden;
  192. position: absolute;
  193. z-index: 2;
  194. box-sizing: border-box;
  195. .change {
  196. padding: 0 18% 0 0;
  197. .title {
  198. border-width: 0px;
  199. width: 100%;
  200. height: 140px;
  201. display: flex;
  202. font-weight: 400;
  203. font-style: normal;
  204. font-size: 22px;
  205. text-align: left;
  206. padding: 0;
  207. padding: 60px 0 0 100px;
  208. width: 100%;
  209. box-sizing: border-box;
  210. }
  211. }
  212. }
  213. /* 修复input 背景不协调 和光标变色 */
  214. /* Detail see https://github.com/PanJiaChen/vue-element-admin/pull/927 */
  215. // $bg: #283443;
  216. // $light_gray: #fff;
  217. // $cursor: #fff;
  218. // @supports (-webkit-mask: none) and (not (cater-color: $cursor)) {
  219. // .change-password .el-input input {
  220. // color: $cursor;
  221. // }
  222. // }
  223. // /* reset element-ui css */
  224. // .change-password {
  225. // .el-input {
  226. // display: inline-block;
  227. // height: 47px;
  228. // width: 260px;
  229. // // background: rgba(243, 244, 245, 1);
  230. // // border-radius: 24px;
  231. // input {
  232. // background: transparent;
  233. // border: 0px;
  234. // -webkit-appearance: none;
  235. // border-radius: 0px;
  236. // padding: 12px 5px 12px 15px;
  237. // color: $light_gray;
  238. // height: 47px;
  239. // caret-color: $cursor;
  240. // color: #000;
  241. // &:-webkit-autofill {
  242. // box-shadow: 0 0 0px 1000px $bg inset !important;
  243. // -webkit-text-fill-color: $cursor !important;
  244. // }
  245. // }
  246. // }
  247. // .el-form-item {
  248. // border: 1px solid rgba(255, 255, 255, 0.1);
  249. // // background: rgba(0, 0, 0, 0.1);
  250. // // border-radius: 5px;
  251. // color: #454545;
  252. // }
  253. // }
  254. </style>
  255. <style lang="scss" scoped>
  256. $bg: rgba(242, 242, 242, 1);
  257. $dark_gray: #889aa4;
  258. $light_gray: #eee;
  259. .change-password {
  260. min-height: 100%;
  261. width: 100%;
  262. height: 100%;
  263. // background-color: $bg;
  264. overflow: hidden;
  265. position: absolute;
  266. z-index: 2;
  267. // background: #fff;
  268. .login-form {
  269. position: relative;
  270. width: 415px;
  271. max-width: 100%;
  272. height: 100%;
  273. padding: 50px 35px 150px 35px;
  274. margin: 0 auto;
  275. overflow: hidden;
  276. .el-form-item__label {
  277. height: 49px;
  278. line-height: 49px;
  279. }
  280. }
  281. // .tips {
  282. // font-size: 14px;
  283. // color: #fff;
  284. // margin-bottom: 10px;
  285. // span {
  286. // &:first-of-type {
  287. // margin-right: 16px;
  288. // }
  289. // }
  290. // }
  291. // .svg-container {
  292. // padding: 6px 5px 6px 15px;
  293. // color: $dark_gray;
  294. // vertical-align: middle;
  295. // width: 30px;
  296. // display: inline-block;
  297. // }
  298. // .show-pwd {
  299. // position: absolute;
  300. // right: 10px;
  301. // top: 7px;
  302. // font-size: 16px;
  303. // color: $dark_gray;
  304. // cursor: pointer;
  305. // user-select: none;
  306. // }
  307. // .thirdparty-button {
  308. // position: absolute;
  309. // right: 0;
  310. // bottom: 6px;
  311. // }
  312. // @media only screen and (max-width: 470px) {
  313. // .thirdparty-button {
  314. // display: none;
  315. // }
  316. // }
  317. }
  318. </style>