resetPassword.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. <template>
  2. <el-dialog
  3. v-loading="loading"
  4. :title="title"
  5. :center="true"
  6. align="left"
  7. top="25vh"
  8. width="600px"
  9. :close-on-click-modal="false"
  10. :visible.sync="showModelThis"
  11. element-loading-text="拼命加载中"
  12. element-loading-spinner="el-icon-loading"
  13. element-loading-background="rgba(0, 0, 0, 0.8)"
  14. @close="closeModel"
  15. >
  16. <el-card style="margin-top:-20px">
  17. <el-row :gutter="10">
  18. <el-col :span="24">
  19. <el-form
  20. ref="ruleForm"
  21. :model="ruleForm"
  22. status-icon
  23. :rules="rulesThis"
  24. label-width="110px"
  25. class="demo-ruleForm"
  26. >
  27. <el-form-item prop="password" label="新密码:">
  28. <el-input
  29. ref="password"
  30. v-model="ruleForm.password"
  31. placeholder="新密码"
  32. name="password"
  33. type="password"
  34. maxlength="6"
  35. tabindex="1"
  36. autocomplete="on"
  37. />
  38. </el-form-item>
  39. <el-form-item prop="confirmPassword" label="确认密码:">
  40. <el-input
  41. ref="confirmPassword"
  42. v-model="ruleForm.confirmPassword"
  43. placeholder="确认密码"
  44. name="confirmPassword"
  45. type="password"
  46. tabindex="1"
  47. maxlength="6"
  48. autocomplete="on"
  49. />
  50. </el-form-item>
  51. </el-form>
  52. </el-col>
  53. <el-col :span="24" style="text-align: right">
  54. <el-button type="primary" @click="submitForm">保 存 </el-button>
  55. <el-button @click="showModelThis = false">{{
  56. isDetail ? "关 闭" : "取 消"
  57. }}</el-button>
  58. </el-col>
  59. </el-row>
  60. </el-card>
  61. </el-dialog>
  62. </template>
  63. <script>
  64. import asyncRequest from "@/apis/service/mobile/park";
  65. import { isnumber, isAlphanumeric, validAlphabets } from "@/utils/validate";
  66. import resToken from "@/mixins/resToken";
  67. export default {
  68. name: "Account",
  69. props: ["showModel", "id", "isDetail"],
  70. mixins: [resToken],
  71. data() {
  72. const validateNewPassword = (rule, value, callback) => {
  73. if (value === "") {
  74. callback(new Error("新密码不能为空!"));
  75. } else {
  76. if (value.length !== 6) {
  77. callback(new Error("密码为2位字母+4位数字!"));
  78. } else {
  79. let a = value.slice(0, 2);
  80. let b = value.slice(2, 4);
  81. if (!isnumber(b)) {
  82. callback(new Error("密码为2位字母+4位数字!"));
  83. } else if (!validAlphabets(a)) {
  84. callback(new Error("密码为2位字母+4位数字!"));
  85. } else {
  86. callback();
  87. }
  88. }
  89. }
  90. };
  91. const validateConfirmPassword = (rule, value, callback) => {
  92. if (value === "") {
  93. callback(new Error("确认密码不能为空!"));
  94. } else {
  95. if (this.ruleForm.password !== value) {
  96. callback(new Error("确认密码与新密码不一致!"));
  97. } else {
  98. callback();
  99. }
  100. }
  101. };
  102. return {
  103. roleList: [],
  104. loading: false,
  105. title: "重置密码",
  106. showModelThis: this.showModel,
  107. ruleForm: {
  108. id: this.id,
  109. password: "",
  110. confirmPassword: "",
  111. },
  112. rulesThis: this.rules,
  113. rules: {
  114. password: [
  115. { required: true, trigger: "blur", validator: validateNewPassword },
  116. ],
  117. confirmPassword: [
  118. {
  119. required: true,
  120. trigger: "blur",
  121. validator: validateConfirmPassword,
  122. },
  123. ],
  124. },
  125. };
  126. },
  127. watch: {
  128. showModel: function (val) {
  129. this.showModelThis = val;
  130. if (val) {
  131. this.initForm();
  132. }
  133. },
  134. showModelThis(val) {
  135. if (!val) {
  136. this.$emit("cancel");
  137. }
  138. },
  139. },
  140. methods: {
  141. closeModel() {
  142. console.log("closeModel!!");
  143. },
  144. async initForm() {
  145. this.rulesThis = this.rules;
  146. await this.resetForm();
  147. },
  148. async resetForm() {
  149. // 重置
  150. await this.$nextTick(() => {
  151. if (this.$refs.ruleForm) {
  152. this.$refs.ruleForm.resetFields();
  153. this.$refs.ruleForm.clearValidate();
  154. this.ruleForm = {
  155. id: this.id,
  156. password: "",
  157. confirmPassword: "",
  158. };
  159. }
  160. });
  161. },
  162. async submitForm() {
  163. await this.$refs.ruleForm.validate(async (valid) => {
  164. if (valid) {
  165. this.loading = true;
  166. let obj = JSON.parse(JSON.stringify(this.ruleForm));
  167. delete obj["confirmPassword"];
  168. const res = await asyncRequest.setpwd(obj);
  169. this.loading = false;
  170. if (res && res.code === 0) {
  171. this.$notify.success({
  172. title: "密码修改成功!",
  173. message: "",
  174. });
  175. this.showModelThis = false;
  176. // 刷新
  177. this.$emit("refresh");
  178. } else if (res && res.code >= 100 && res.code <= 104) {
  179. await this.logout();
  180. } else {
  181. this.$message.warning(res.message);
  182. }
  183. } else {
  184. console.log("error submit!!");
  185. return false;
  186. }
  187. });
  188. },
  189. },
  190. };
  191. </script>
  192. <style lang="scss" scoped>
  193. .account {
  194. }
  195. </style>