index.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <!-- -->
  2. <template>
  3. <v-card class="pa-5 d-flex flex-column align-center" :class="{'card-box': !props.hideWidth}" :elevation="props.elevation">
  4. <div class="resume-header mt-15 mb-8" style="width: 700px;">
  5. <div class="resume-title">修改登录密码</div>
  6. </div>
  7. <CtForm ref="CtFormRef" :items="formItems" style="width: 700px;"></CtForm>
  8. <div class="mb-15">
  9. <v-btn class="buttons mt-5" color="primary" :loading="loading" @click.stop="handleCommit">保存</v-btn>
  10. <v-btn v-if="!props.hideGoBack" class="mt-3" color="primary" variant="text" @click="router.go(-1)">返回</v-btn>
  11. </div>
  12. </v-card>
  13. <Loading :visible="overlay"></Loading>
  14. </template>
  15. <script setup>
  16. import { ref } from 'vue'
  17. import Snackbar from '@/plugins/snackbar'
  18. // import { useI18n } from '@/hooks/web/useI18n'
  19. import { useRouter } from 'vue-router'; const router = useRouter()
  20. import { entUpdatePassword } from '@/api/enterprise'
  21. const props = defineProps({
  22. entChangePassword: {
  23. type: Boolean,
  24. default: false
  25. },
  26. hideGoBack: {
  27. type: Boolean,
  28. default: false
  29. },
  30. hideWidth: {
  31. type: Boolean,
  32. default: false
  33. },
  34. elevation: {
  35. type: String,
  36. default: '2'
  37. }
  38. })
  39. defineOptions({name: 'staff-changePassword'})
  40. // const { t } = useI18n() // 强制修改密码不能使用
  41. const CtFormRef = ref()
  42. const formItems = ref({
  43. options: [
  44. {
  45. type: 'text',
  46. key: 'password',
  47. value: '',
  48. label: '请输入新密码 *',
  49. rules: [
  50. value => {
  51. if (value) return true
  52. return '请输入新密码'
  53. },
  54. value => {
  55. if (!(/^[\s]+$/.test(value))) return true
  56. return '请输入新密码'
  57. }
  58. ]
  59. },
  60. {
  61. type: 'text',
  62. key: 'passwordConfirm',
  63. value: '',
  64. label: '请再次输入新密码 *',
  65. rules: [
  66. value => {
  67. if (value) return true
  68. return '请再次输入新密码'
  69. },
  70. value => {
  71. if (!(/^[\s]+$/.test(value))) return true
  72. return '请再次输入新密码'
  73. }
  74. ]
  75. },
  76. ]
  77. })
  78. const loading = ref(false)
  79. const handleCommit = async () => {
  80. const { valid } = await CtFormRef.value.formRef.validate()
  81. if (!valid) return
  82. const params = {}
  83. const baseInfo = JSON.parse(localStorage.getItem('entBaseInfo') || "null") || null
  84. if (baseInfo?.id) params.id = baseInfo.id
  85. formItems.value.options.forEach(e => { params[e.key] = e.value })
  86. // 邮箱登录密码校验
  87. if (params.password !== params.passwordConfirm) return Snackbar.warning('两次输入的密码不一致,请确认')
  88. loading.value = true
  89. await entUpdatePassword(params)
  90. Snackbar.success('修改成功')
  91. if (props.entChangePassword) {
  92. localStorage.setItem('entUpdatePassword', 'doNotNeedChange')
  93. setTimeout(() => {
  94. loading.value = false
  95. window.location.href = '/recruit/enterprise'
  96. }, 1500)
  97. } else {
  98. loading.value = false
  99. router.go(-1)
  100. }
  101. }
  102. </script>
  103. <style lang="scss" scoped>
  104. </style>