Modifypassword.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541
  1. <!-- -->
  2. <template>
  3. <div class="Modify Modifypassword">
  4. <el-dialog
  5. :title="$t('Key88')"
  6. :visible.sync="dialogVisible"
  7. top="80px"
  8. width="570px"
  9. :show-close="false"
  10. >
  11. <div class="registration2">
  12. <div class="form">
  13. <el-form :model="ruleForm" :rules="rules" ref="ruleForm">
  14. <el-form-item prop="oldpassword">
  15. <span slot="label" class="lable">
  16. <img src="../../assets/login/singin9.png" alt="" />
  17. <span>旧密码</span>
  18. </span>
  19. <el-input
  20. v-model.trim="ruleForm.oldpassword"
  21. placeholder="请输入旧密码"
  22. :type="oldpasswordType"
  23. />
  24. <img
  25. v-show="oldpasswordType == 'password'"
  26. @click="lookParssowrd(0)"
  27. class="rightimg"
  28. src="../../assets/login/password1.png"
  29. alt=""
  30. />
  31. <img
  32. v-show="oldpasswordType == 'text'"
  33. @click="lookParssowrd(0)"
  34. class="rightimg"
  35. src="../../assets/login/password2.png"
  36. alt=""
  37. />
  38. </el-form-item>
  39. <el-form-item prop="password">
  40. <span slot="label" class="lable">
  41. <img src="../../assets/login/singin9.png" alt="" />
  42. <span> 新密码 </span>
  43. </span>
  44. <el-input
  45. v-model.trim="ruleForm.password"
  46. placeholder="请输入新密码"
  47. :type="passwordType"
  48. />
  49. <img
  50. v-show="passwordType == 'password'"
  51. @click="lookParssowrd(1)"
  52. class="rightimg"
  53. src="../../assets/login/password1.png"
  54. alt=""
  55. />
  56. <img
  57. v-show="passwordType == 'text'"
  58. @click="lookParssowrd(1)"
  59. class="rightimg"
  60. src="../../assets/login/password2.png"
  61. alt=""
  62. />
  63. <p :class="passwordError ? 'textRed' : 'psswordHint'">
  64. <!-- 请输入8-12位大写字母、小写字母和数字组合。 -->
  65. {{ $t("Key121") }}
  66. </p>
  67. </el-form-item>
  68. <el-form-item prop="Twopassword">
  69. <span slot="label" class="lable" style="width: 200px">
  70. <img src="../../assets/login/singin9.png" alt="" />
  71. <span>重复密码</span>
  72. </span>
  73. <el-input
  74. v-model.trim="ruleForm.Twopassword"
  75. placeholder="请重复输入新密码"
  76. :type="twoPasswordType"
  77. />
  78. <img
  79. v-show="twoPasswordType == 'password'"
  80. @click="lookParssowrd(2)"
  81. class="rightimg"
  82. src="../../assets/login/password1.png"
  83. alt=""
  84. />
  85. <img
  86. v-show="twoPasswordType == 'text'"
  87. @click="lookParssowrd(2)"
  88. class="rightimg"
  89. src="../../assets/login/password2.png"
  90. alt=""
  91. />
  92. <p :class="passwordErrorTwo ? 'textRed' : 'psswordHint'">
  93. <!-- 请再次输入密码,必须和新密码一致。 -->
  94. {{ $t("Key122") }}
  95. </p>
  96. </el-form-item>
  97. <el-divider></el-divider>
  98. <el-form-item style="margin-bottom: 0">
  99. <button
  100. type="button"
  101. @click.prevent="submitForm()"
  102. class="footer-btn-sure"
  103. >
  104. <!-- 确定 -->{{ $t("Key94") }}
  105. </button>
  106. <button
  107. type="button"
  108. @click.prevent="dialogVisible = false"
  109. class="footer-btn-cancle"
  110. >
  111. <!-- 取消 -->{{ $t("Key83") }}
  112. </button>
  113. </el-form-item>
  114. </el-form>
  115. </div>
  116. </div>
  117. </el-dialog>
  118. </div>
  119. </template>
  120. <script>
  121. import { getContent } from "@/api/ajax";
  122. import Cookies from "js-cookie";
  123. import { removeToken } from "@/utils/auth";
  124. export default {
  125. name: "Modifymailbox",
  126. components: {},
  127. data() {
  128. var basePassword = (rule, value, callback) => {
  129. let _this = this;
  130. if (value === "") {
  131. callback(new Error("请输入旧密码")); //
  132. } else if (value == _this.ruleForm.password) {
  133. callback(new Error(_this.$t("Key210"))); //"新旧密码一致!"
  134. } else {
  135. callback();
  136. }
  137. };
  138. var validatePassword = (rule, value, callback) => {
  139. let _this = this;
  140. if (value === "") {
  141. callback(new Error("请输入新密码"));
  142. } else {
  143. if (value.length < 8) {
  144. callback(new Error("密码至少8位"));
  145. } else if (value.length > 12) {
  146. callback(new Error("密码最多12位"));
  147. } else {
  148. if (this.ruleForm.oldpassword !== "") {
  149. this.$refs.ruleForm.validateField("oldpassword");
  150. if (value == _this.ruleForm.oldpassword) {
  151. callback(new Error(_this.$t("Key210")));
  152. }
  153. }
  154. if (this.ruleForm.Twopassword !== "") {
  155. this.$refs.ruleForm.validateField("Twopassword");
  156. }
  157. if (
  158. !/[A-Z]/.test(value) ||
  159. !/[a-z]/.test(value) ||
  160. !/[0-9]/.test(value)
  161. ) {
  162. callback(new Error("密码必须是大写字母、小写字母和数字的组合。"));
  163. }
  164. callback();
  165. }
  166. }
  167. };
  168. var validateTwoPassword = (rule, value, callback) => {
  169. let _this = this;
  170. if (value === "") {
  171. callback(new Error("请再次输入密码"));
  172. } else if (value !== _this.ruleForm.password) {
  173. callback(new Error(_this.$t("Key211"))); //两次输入密码不一致!
  174. } else {
  175. callback();
  176. }
  177. };
  178. return {
  179. dialogVisible: false,
  180. oldpasswordType: "password",
  181. passwordType: "password",
  182. twoPasswordType: "password",
  183. passwordError: false,
  184. passwordErrorTwo: false,
  185. ruleForm: {
  186. oldpassword: "",
  187. password: "",
  188. Twopassword: "",
  189. },
  190. rules: {
  191. oldpassword: [
  192. {
  193. validator: basePassword,
  194. trigger: "blur",
  195. },
  196. ],
  197. password: [
  198. {
  199. validator: validatePassword,
  200. trigger: "blur",
  201. },
  202. ],
  203. Twopassword: [
  204. {
  205. validator: validateTwoPassword,
  206. trigger: "blur",
  207. },
  208. ],
  209. },
  210. };
  211. },
  212. computed: {},
  213. watch: {},
  214. //方法集合
  215. methods: {
  216. changeShow() {
  217. this.dialogVisible = true;
  218. },
  219. // 去除空格
  220. trimInput(key) {
  221. this.ruleForm[key] = this.ruleForm[key].trim();
  222. },
  223. // 查看密码
  224. lookParssowrd(number) {
  225. if (number == 0) {
  226. if (this.oldpasswordType == "text") {
  227. this.oldpasswordType = "password";
  228. } else {
  229. this.oldpasswordType = "text";
  230. }
  231. } else if (number == 1) {
  232. if (this.passwordType == "text") {
  233. this.passwordType = "password";
  234. } else {
  235. this.passwordType = "text";
  236. }
  237. } else {
  238. if (this.twoPasswordType == "text") {
  239. this.twoPasswordType = "password";
  240. } else {
  241. this.twoPasswordType = "text";
  242. }
  243. }
  244. },
  245. // 验证密码
  246. changePassword() {
  247. if (this.ruleForm.password) {
  248. let reg = /^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d]{8,12}$/;
  249. let result = reg.test(this.ruleForm.password);
  250. if (result) {
  251. this.passwordError = false;
  252. } else {
  253. this.passwordError = true;
  254. }
  255. }
  256. },
  257. // 验证第二次密码是否一样
  258. Changetowpassword() {
  259. if (this.ruleForm.Twopassword) {
  260. if (this.ruleForm.Twopassword != this.ruleForm.password) {
  261. this.passwordErrorTwo = true;
  262. return;
  263. } else {
  264. this.passwordErrorTwo = false;
  265. }
  266. }
  267. },
  268. submitForm() {
  269. this.$refs.ruleForm.validate((valid) => {
  270. if (valid) {
  271. this.onSubmit();
  272. } else {
  273. console.log("error submit!!");
  274. return false;
  275. }
  276. });
  277. },
  278. onSubmit() {
  279. let MethodName = "user_manager-UpdateMyPassword";
  280. let data = {
  281. password_old: this.ruleForm.oldpassword,
  282. password_new: this.ruleForm.password,
  283. };
  284. getContent(MethodName, data).then((res) => {
  285. this.dialogVisible = false;
  286. this.$message.success("密码更改成功,请重新登录");
  287. setTimeout(() => {
  288. removeToken();
  289. Cookies.remove("userMessage");
  290. Cookies.remove("session_id");
  291. Cookies.remove("user_code");
  292. Cookies.remove("user_type");
  293. this.$router.replace({ path: "/login" });
  294. }, 1000);
  295. });
  296. },
  297. },
  298. //生命周期 - 创建完成(可以访问当前this实例)
  299. created() {},
  300. //生命周期 - 挂载完成(可以访问DOM元素)
  301. mounted() {},
  302. beforeCreate() {}, //生命周期 - 创建之前
  303. beforeMount() {}, //生命周期 - 挂载之前
  304. beforeUpdate() {}, //生命周期 - 更新之前
  305. updated() {}, //生命周期 - 更新之后
  306. beforeDestroy() {}, //生命周期 - 销毁之前
  307. destroyed() {}, //生命周期 - 销毁完成
  308. activated() {}, //如果页面有keep-alive缓存功能,这个函数会触发
  309. };
  310. </script>
  311. <style lang="scss" scoped>
  312. /* @import url(); 引入css类 */
  313. .registration2 {
  314. width: 100%;
  315. .title {
  316. // height: 60px;
  317. // line-height: 60px;
  318. p {
  319. margin: 0;
  320. padding: 0;
  321. }
  322. .p1 {
  323. font-size: 24px;
  324. color: #ff9900;
  325. }
  326. .p2 {
  327. margin-top: 40px;
  328. font-size: 20px;
  329. color: #000000;
  330. }
  331. }
  332. .form {
  333. .title2 {
  334. font-weight: 600;
  335. font-size: 20px;
  336. color: #000000;
  337. margin: 20px 0;
  338. }
  339. hr {
  340. margin: 0;
  341. width: 474px;
  342. height: 1px;
  343. background: #d9d9d9;
  344. }
  345. .el-input,
  346. .el-select {
  347. width: 334px;
  348. }
  349. .el-form-item {
  350. width: 100%;
  351. display: flex;
  352. .lable {
  353. display: inline-block;
  354. width: 120px !important;
  355. text-align: left;
  356. img {
  357. width: 24px;
  358. vertical-align: middle;
  359. }
  360. span {
  361. margin-left: 10px;
  362. }
  363. }
  364. &.el-form-item__content {
  365. width: 100% !important;
  366. }
  367. }
  368. // .el-form-item::after {
  369. // content: "*";
  370. // color: red;
  371. // position: relative;
  372. // left: 5px;
  373. // top: 10px;
  374. // }
  375. .getVerification {
  376. width: 116px;
  377. height: 40px;
  378. margin-left: 16px;
  379. border-radius: 4px;
  380. cursor: pointer;
  381. box-sizing: border-box;
  382. background: #ff9900;
  383. border: 1px solid #ff9900;
  384. color: white;
  385. }
  386. .footer-btn {
  387. &-sure {
  388. width: 100%;
  389. height: 48px;
  390. border-radius: 4px;
  391. cursor: pointer;
  392. box-sizing: border-box;
  393. background: #ff9900;
  394. border: 1px solid #ff9900;
  395. font-weight: bold;
  396. font-size: 18px;
  397. text-align: center;
  398. color: #ffffff;
  399. margin-bottom: 16px;
  400. }
  401. &-cancle {
  402. width: 100%;
  403. height: 48px;
  404. border-radius: 4px;
  405. cursor: pointer;
  406. box-sizing: border-box;
  407. background: #fff;
  408. border: 1px solid rgba(0, 0, 0, 0.15);
  409. font-size: 18px;
  410. text-align: center;
  411. color: #2c2c2c;
  412. }
  413. }
  414. .waitTime {
  415. width: 116px;
  416. height: 40px;
  417. margin-left: 16px;
  418. border-radius: 4px;
  419. cursor: pointer;
  420. box-sizing: border-box;
  421. background: #f0f0f0;
  422. color: black;
  423. border: none;
  424. }
  425. .rightimg {
  426. width: 24px;
  427. position: absolute;
  428. right: 16px;
  429. top: 10px;
  430. cursor: pointer;
  431. }
  432. .psswordHint {
  433. width: 334px;
  434. margin: 0;
  435. padding: 0;
  436. font-size: 14px;
  437. color: #000000;
  438. opacity: 0.3;
  439. line-height: 20px;
  440. margin-top: 5px;
  441. }
  442. .textRed {
  443. width: 334px;
  444. margin: 0;
  445. padding: 0;
  446. font-size: 14px;
  447. color: red;
  448. opacity: 1;
  449. line-height: 20px;
  450. margin-top: 5px;
  451. }
  452. .sumit {
  453. width: 474px;
  454. text-align: right;
  455. button {
  456. width: 337px;
  457. height: 48px;
  458. background: #ff9900;
  459. border-radius: 4px;
  460. cursor: pointer;
  461. border: none;
  462. outline: none;
  463. color: white;
  464. img {
  465. vertical-align: middle;
  466. animation: rotated 1s linear infinite;
  467. }
  468. }
  469. }
  470. .agreementAndRemeberMeAndForgetparssword {
  471. width: 474px;
  472. display: flex;
  473. justify-content: flex-end;
  474. > div {
  475. margin: 20px 0;
  476. width: 334px;
  477. position: relative;
  478. }
  479. .agreement {
  480. span {
  481. color: #ff9900;
  482. }
  483. }
  484. }
  485. .remeberMeAndForgetparssword {
  486. p {
  487. margin: 0;
  488. color: #ff9900;
  489. cursor: pointer;
  490. text-align: right;
  491. }
  492. }
  493. .Noafter::after {
  494. content: "";
  495. }
  496. }
  497. @keyframes rotated {
  498. 0% {
  499. transform: rotateZ(0deg);
  500. }
  501. 100% {
  502. transform: rotateZ(360deg);
  503. }
  504. }
  505. }
  506. </style>
  507. <style lang="scss">
  508. .form {
  509. .el-form-item__content {
  510. width: 100%;
  511. }
  512. }
  513. .Modify {
  514. .el-dialog {
  515. box-shadow: 0px 2px 8px rgba(0, 0, 0, 0.15);
  516. border-radius: 8px;
  517. }
  518. .el-dialog__header {
  519. padding: 48px 48px 32px 48px;
  520. .el-dialog__title {
  521. font-weight: bold;
  522. font-size: 20px;
  523. line-height: 150%;
  524. color: #000000;
  525. }
  526. }
  527. .el-dialog__body {
  528. padding: 0px 48px 30px;
  529. }
  530. }
  531. .Modifypassword {
  532. .el-input__inner {
  533. padding-right: 40px;
  534. }
  535. }
  536. </style>