changePsw.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. <script lang='ts' setup>
  2. import type { FormInstance, FormRules } from 'element-plus'
  3. import { passwordRegular } from '~/enums/regEnum'
  4. import { resetOrChangePasswordApi } from '~/api/model/user'
  5. const ruleFormRef = ref<FormInstance>()
  6. const params = ref({
  7. oldPassword: '',
  8. newPassword: '',
  9. confirmPassword: '',
  10. })
  11. const rules = ref<FormRules>({
  12. oldPassword: [
  13. {
  14. required: true,
  15. trigger: 'change',
  16. validator: (rule, value, callback) => {
  17. if (value) {
  18. if (passwordRegular.test(value))
  19. callback()
  20. else
  21. callback(new Error('Please enter password that matches the rules'))
  22. }
  23. else { callback(new Error('Old password must be filled in')) }
  24. },
  25. },
  26. ],
  27. newPassword: [
  28. {
  29. required: true,
  30. trigger: 'change',
  31. validator: (rule, value, callback) => {
  32. if (value) {
  33. if (passwordRegular.test(value))
  34. callback()
  35. else
  36. callback(new Error('Please enter password that matches the rules'))
  37. }
  38. else { callback(new Error('New password must be filled in')) }
  39. },
  40. },
  41. ],
  42. confirmPassword: [
  43. {
  44. required: true,
  45. trigger: 'change',
  46. validator: (rule, value, callback) => {
  47. if (value) {
  48. if (passwordRegular.test(value))
  49. callback()
  50. else
  51. callback(new Error('Please enter password that matches the rules'))
  52. }
  53. else { callback(new Error('Password must be filled in')) }
  54. },
  55. },
  56. ],
  57. })
  58. async function submitForm(formEl: FormInstance | undefined) {
  59. if (!formEl)
  60. return
  61. await formEl.validate(async (valid, fields) => {
  62. if (valid) {
  63. try {
  64. await resetOrChangePasswordApi(params.value)
  65. ElMessage.success('Password updated successfully')
  66. }
  67. catch (error) {
  68. console.log('error', error)
  69. }
  70. }
  71. else { console.log('error submit!', fields) }
  72. })
  73. }
  74. </script>
  75. <template>
  76. <div class="flex w-100% justify-center">
  77. <div>
  78. <div class="fw-700 mb-30px text-20px text-#333">
  79. Change Password
  80. </div>
  81. <el-form
  82. ref="ruleFormRef"
  83. :model="params"
  84. :rules="rules"
  85. label-width="auto"
  86. size="default"
  87. status-icon
  88. >
  89. <el-form-item
  90. label="Old Password"
  91. class="custom-form-item w-500px"
  92. prop="oldPassword"
  93. >
  94. <el-popover
  95. placement="right"
  96. :width="270"
  97. class="!text-#5B463E !text-16px"
  98. trigger="hover"
  99. content="6-20 characters, contain letters numbers or symbols only"
  100. >
  101. <template #reference>
  102. <el-input v-model="params.oldPassword" :show-password="true" placeholder="Please enter old password" class="h-50px" />
  103. </template>
  104. </el-popover>
  105. </el-form-item>
  106. <el-form-item
  107. label="New Password"
  108. class="custom-form-item w-500px"
  109. prop="newPassword"
  110. >
  111. <el-popover
  112. placement="right"
  113. :width="270"
  114. class="!text-#5B463E !text-16px"
  115. trigger="hover"
  116. content="6-20 characters, contain letters numbers or symbols only"
  117. >
  118. <template #reference>
  119. <el-input v-model="params.newPassword" :show-password="true" placeholder="Please enter new password" class="h-50px" />
  120. </template>
  121. </el-popover>
  122. </el-form-item>
  123. <el-form-item
  124. label="Confirm New Password"
  125. class="custom-form-item w-500px"
  126. prop="confirmPassword"
  127. >
  128. <el-popover
  129. placement="right"
  130. :width="270"
  131. class="!text-#5B463E !text-16px"
  132. trigger="hover"
  133. content="6-20 characters, contain letters numbers or symbols only"
  134. >
  135. <template #reference>
  136. <el-input v-model="params.confirmPassword" :show-password="true" placeholder="Please confirm new password" class="h-50px" />
  137. </template>
  138. </el-popover>
  139. </el-form-item>
  140. <el-form-item>
  141. <el-button plain class="!bg-#C58C64 !text-#fff !w-500px !h-50px !text-18px !fw-500 !b-rd-6px " @click="submitForm(ruleFormRef)">
  142. Submit
  143. </el-button>
  144. </el-form-item>
  145. </el-form>
  146. </div>
  147. </div>
  148. </template>
  149. <style lang="less" scoped>
  150. :deep(.custom-form-item) {
  151. margin-bottom: 30px;
  152. display: block !important;
  153. .el-form-item__content{
  154. .el-input{
  155. .el-select{
  156. .el-select__wrapper{
  157. height: 50px!important;
  158. background-color: #fff!important;
  159. }
  160. }
  161. }
  162. }
  163. .el-form-item__label-wrap {
  164. margin-left: unset!important;
  165. .el-form-item__label {
  166. margin-bottom: 5px;
  167. font-size: 16px !important;
  168. color: #333 !important;
  169. }
  170. }
  171. &.custom-form-item-hidden-label {
  172. width: 270px;
  173. &:last-child {
  174. .el-form-item__label-wrap {
  175. opacity: 0;
  176. }
  177. }
  178. }
  179. }
  180. </style>