index.vue 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <template>
  2. <view style="padding: 30rpx;">
  3. <uni-forms ref="formRef" :modelValue="formData" :rules="formRules" validateTrigger="bind" label-width="80px" label-align="right" label-position="left">
  4. <uni-forms-item name="password" label="新密码" required>
  5. <uni-easyinput v-model="formData.password" type="password" placeholder="请输入新密码"></uni-easyinput>
  6. </uni-forms-item>
  7. <uni-forms-item name="passwordConfirm" label="二次确认" required>
  8. <uni-easyinput v-model="formData.passwordConfirm" type="password" placeholder="请再次输入新密码"></uni-easyinput>
  9. </uni-forms-item>
  10. </uni-forms>
  11. <button class="send-button" @tap="handleSubmit">提 交</button>
  12. </view>
  13. </template>
  14. <script setup>
  15. import { ref, unref } from 'vue'
  16. import { password } from '@/utils/validate'
  17. import { userStore } from '@/store/user'
  18. import { entUpdatePassword } from '@/api/enterprise'
  19. const user = userStore()
  20. const formRef = ref(null)
  21. const formData = ref({
  22. id: user?.userInfo?.id,
  23. password: null,
  24. passwordConfirm: null
  25. })
  26. const formRules = {
  27. password,
  28. passwordConfirm: {
  29. rules: [
  30. { required: true, errorMessage: '请再次输入密码' },
  31. {
  32. validateFunction: function(rule, value, data, callback) {
  33. if (value !== data.password) callback('两次输入的密码不一致')
  34. return true
  35. }
  36. }
  37. ]
  38. }
  39. }
  40. // 提交
  41. const handleSubmit = async () => {
  42. const valid = await unref(formRef).validate()
  43. if (!valid) return
  44. uni.showLoading({ title: '提交中' })
  45. try {
  46. await entUpdatePassword(formData.value)
  47. uni.hideLoading()
  48. uni.showToast({
  49. title: '修改成功',
  50. icon: 'success'
  51. })
  52. setTimeout(() => {
  53. uni.navigateBack({ delta: 1 })
  54. }, 1000)
  55. } catch {
  56. uni.hideLoading()
  57. }
  58. }
  59. </script>
  60. <style scoped lang="scss">
  61. </style>