updatePwd.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. <template>
  2. <div class="container">
  3. <div class="title">
  4. Change the password
  5. <div></div>
  6. </div>
  7. <div class="form" :class="{ 'mobile-form': !pcShow }">
  8. <n-form ref="formRef" label-placement="left" label-align="left" :model="form" :rules="rules" size="large" require-mark-placement="left">
  9. <n-form-item label="Password:" path="newPassword">
  10. <n-input v-model:value="form.newPassword" @input="handlePasswordInput" type="password" show-password-on="click" placeholder="Please enter the password" />
  11. </n-form-item>
  12. <n-form-item label="Confirmpassword:" path="confirmNewPassword" ref="confirmPasswordRef">
  13. <n-input v-model:value="form.confirmNewPassword" type="password" show-password-on="click" placeholder="Please confirm to enter the password" />
  14. </n-form-item>
  15. </n-form>
  16. <n-button class="login-btn" attr-type="button" type="info" color="#18A058" @click="handleSure">
  17. {{ submitLoading ? "Checking" : "Confirm" }}
  18. </n-button>
  19. </div>
  20. </div>
  21. </template>
  22. <script lang="ts" setup>
  23. import { ref, reactive, onMounted } from "vue";
  24. import {
  25. // NForm,
  26. // NFormItem,
  27. // NInput,
  28. // NButton,
  29. // FormRules,
  30. // FormItemRule,
  31. createDiscreteApi,
  32. } from "naive-ui";
  33. import { useRouter, useRoute } from "vue-router";
  34. import { useUserStore } from "@/store/user";
  35. const router = useRouter();
  36. const userStore = useUserStore();
  37. const pcShow = ref(true);
  38. onMounted(() => {
  39. pcShow.value = !isMobile();
  40. handleUrl();
  41. });
  42. const emit = defineEmits(["closeSginDialog"]);
  43. const message = createDiscreteApi(["message"]);
  44. const formRef = ref();
  45. const confirmPasswordRef = ref();
  46. const form: forgot = reactive({
  47. uuid: "",
  48. newPassword: "",
  49. confirmNewPassword: "",
  50. });
  51. const submitLoading = ref(false);
  52. const Api = ref<any>(updatePwd_Api);
  53. const confirmPasswordValidate = (
  54. rule: FormItemRule,
  55. value: string
  56. ): boolean => {
  57. return value && value == form.newPassword;
  58. };
  59. const rules: FormRules = {
  60. newPassword: [
  61. {
  62. required: true,
  63. message: "请输入密码",
  64. trigger: ["input", "blur", "password-input"],
  65. },
  66. ],
  67. confirmNewPassword: [
  68. {
  69. required: true,
  70. message: "请输入密码",
  71. trigger: ["input", "blur"],
  72. },
  73. {
  74. required: true,
  75. validator: confirmPasswordValidate,
  76. message: "两次密码输入不一致",
  77. trigger: ["blur", "password-input"],
  78. },
  79. ],
  80. };
  81. const handlePasswordInput = () => {
  82. if (form.confirmNewPassword) {
  83. confirmPasswordRef.value?.validate({ trigger: "password-input" });
  84. }
  85. };
  86. const handleSure = () => {
  87. formRef.value?.validate(async (errors: any) => {
  88. if (!errors) {
  89. submitLoading.value = true;
  90. const params = JSON.parse(JSON.stringify(form));
  91. params.newPassword = encryptByBase64(params.newPassword);
  92. params.confirmNewPassword = encryptByBase64(params.confirmNewPassword);
  93. const { code, data } = await Api.value(params);
  94. if (code === 200) {
  95. userStore.setToken(data?.token);
  96. userStore.setUserInfo(data?.user);
  97. router.push("/");
  98. }
  99. submitLoading.value = false;
  100. }
  101. });
  102. };
  103. const handleUrl = () => {
  104. if (typeof window !== "undefined") {
  105. const queryUrl = window.location.search;
  106. const queryStr = queryUrl?.split("?")[1];
  107. const queryParams = queryStr?.split("&");
  108. let obj = {};
  109. if (queryParams && queryParams.length > 0) {
  110. for (let item of queryParams) {
  111. let arr = item.split("=");
  112. obj[arr[0]] = arr[1];
  113. }
  114. }
  115. if (obj.uuid) {
  116. form.uuid = obj.uuid;
  117. Api.value = forget_Api;
  118. } else {
  119. Api.value = updatePwd_Api;
  120. }
  121. }
  122. };
  123. </script>
  124. <style lang="scss" scoped>
  125. .container {
  126. padding: 30px 58px 55px;
  127. background: #ffffff;
  128. border-radius: 20px;
  129. .title {
  130. font-size: 38px;
  131. font-family: Arial, Arial-Bold;
  132. font-weight: 700;
  133. text-align: center;
  134. color: #1a1a1a;
  135. > div {
  136. width: 71px;
  137. height: 6px;
  138. background: linear-gradient(90deg, #719d59 2%, #479f82 98%);
  139. border-radius: 3px;
  140. margin: auto;
  141. }
  142. }
  143. .form {
  144. .login-btn {
  145. width: 100%;
  146. height: 58px;
  147. background: linear-gradient(90deg, #60ab91, #84a86c);
  148. border-radius: 8px;
  149. font-size: 18px;
  150. margin-top: 10px;
  151. :deep(.n-button__content) {
  152. display: block;
  153. }
  154. }
  155. }
  156. .mobile-form {
  157. top: 60%;
  158. width: 85%;
  159. padding: 20px;
  160. }
  161. // .n-form {
  162. // :deep(.n-form-item-label__text) {
  163. // color: #1a1a1a;
  164. // font-size: 16px;
  165. // }
  166. // .n-input {
  167. // border-radius: 8px;
  168. // }
  169. // }
  170. .n-form {
  171. margin-top: 30px;
  172. }
  173. :deep(.n-form-item-blank) {
  174. border-bottom: 1px solid #e6e6e6;
  175. }
  176. :deep(.n-form-item-label) {
  177. color: #666666;
  178. font-size: var(--size-14);
  179. font-family: Microsoft YaHei, Microsoft YaHei-Regular;
  180. line-height: var(--size-20);
  181. padding: 10px 10px 10px 0;
  182. border-bottom: 1px solid #e6e6e6;
  183. }
  184. :deep(.n-form-item-label__text) {
  185. height: 30px;
  186. }
  187. :deep(.n-input-wrapper) {
  188. font-size: var(--size-14);
  189. font-family: Microsoft YaHei, Microsoft YaHei-Regular;
  190. line-height: var(--size-20);
  191. padding: 0px 0 10px;
  192. }
  193. :deep(.n-form-item-blank--error .n-input) {
  194. --n-border-error: var(--size-1) solid transparent !important;
  195. --n-border-focus-error: var(--size-1) solid transparent !important;
  196. --n-border-hover-error: var(--size-1) solid transparent !important;
  197. --n-box-shadow-focus-error: var(--size-1) solid transparent !important;
  198. }
  199. :deep(input::-ms-reveal) {
  200. display: none;
  201. }
  202. }
  203. </style>