passwordPage.vue 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <template>
  2. <v-form ref="passwordForm" @submit.prevent>
  3. <v-text-field v-model="loginData.phone" placeholder="请输入手机号" color="primary" variant="outlined" density="compact" :rules="phoneRules" validate-on="input">
  4. <template v-slot:prepend-inner>
  5. <span class="d-flex">
  6. <v-icon icon="mdi-cellphone" size="20"></v-icon>
  7. <span class="d-flex" id="menu-activator">
  8. <span class="phone-number">{{ currentArea }}</span>
  9. <v-icon size="20">mdi-chevron-down</v-icon>
  10. </span>
  11. <v-menu activator="#menu-activator">
  12. <v-list>
  13. <v-list-item v-for="(item, index) in items" :key="index" :value="index" @click="handleChangeCurrentArea(item)">
  14. <v-list-item-title>{{ item.label }}</v-list-item-title>
  15. </v-list-item>
  16. </v-list>
  17. </v-menu>
  18. </span>
  19. </template>
  20. </v-text-field>
  21. <v-text-field
  22. v-model="loginData.password"
  23. placeholder="请输入密码"
  24. variant="outlined"
  25. density="compact"
  26. color="primary"
  27. prepend-inner-icon="mdi-lock-outline"
  28. :append-inner-icon="passwordType ? 'mdi-eye-outline' : 'mdi-eye-off-outline'"
  29. :type="passwordType ? 'text' : 'password'"
  30. :rules="[v=> !!v || '请填写密码']"
  31. @click:append-inner="passwordType = !passwordType"
  32. ></v-text-field>
  33. </v-form>
  34. </template>
  35. <script setup name="passwordPage">
  36. import { ref, reactive } from 'vue'
  37. defineOptions({ name: 'password-form' })
  38. const passwordType = ref(false)
  39. const phoneRules = ref([
  40. value => {
  41. if (value) return true
  42. return '请输入手机号'
  43. },
  44. value => {
  45. if (value?.length <= 11 && /^1[3456789]\d{9}$/.test(value)) return true
  46. return '请输入正确的手机号码'
  47. }
  48. ])
  49. // 手机号区域
  50. const currentArea = ref('0086')
  51. const items = [
  52. { label: '中国大陆-0086', value: '0086' }
  53. ]
  54. const handleChangeCurrentArea = (e) => {
  55. currentArea.value = e.value
  56. }
  57. const loginData = reactive({
  58. phone: '13229740091',
  59. password: '1111'
  60. })
  61. const passwordForm = ref()
  62. defineExpose({
  63. loginData,
  64. passwordForm
  65. })
  66. </script>