All files / src/components/UI Auth-form.vue

0% Statements 0/66
0% Branches 0/30
0% Functions 0/34
0% Lines 0/66

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203                                                                                                                                                                                                                                                                                                                                                                                                                     
<template>
  <v-dialog
    v-model="menuAuthDialog"
    persistent
    width="400"
  >
    <template v-slot:activator="{ props }">
      <v-btn
        v-bind="props"
        append-icon="mdi-login"
        color="black_and_white"
      >
        <template v-slot:prepend>
          <v-icon color="black_and_white"></v-icon>
        </template>
          Войти
        <template v-slot:append>
          <v-icon color="black_and_white"/>
        </template>
      </v-btn>
    </template>
      
    <v-card @keyup.enter="logging">
      <v-card-title>
        <span class="text-h5">Вход в портал</span>
      </v-card-title>
      <v-card-text>
        <v-container>
          <v-row>
            <v-col cols="12" class="py-0">
              <v-text-field
                v-model="anon.username"
               
                label="Логин"
                variant="underlined"
                :error-messages="errorer('username')"
              />
            </v-col>
            <v-col cols="12" class="py-0">
              <v-text-field
          
                :type="eyeshow ? 'text' : 'password'"
                v-model="anon.password"
                label="Пароль"
                variant="underlined"
               
                :error-messages="errorer('password')"
                @click:append-inner="eyeshow= !eyeshow"
              >
              <template v-slot:append-inner>
                <v-icon size="x-small" :icon="eyeshow ? 'mdi-eye' : 'mdi-eye-off'" @click="eyeshow= !eyeshow">
                </v-icon>
              </template>
 
              </v-text-field>
            </v-col>
          </v-row>
        </v-container>
      </v-card-text>
      <v-card-actions>
      <v-spacer/>
        <v-btn
          color="modal_btn"
          variant="text"
          @click="menuAuthDialog = false"
        >
          Отмена
        </v-btn>
        <v-btn
          color="modal_btn"
          variant="text"
          @click="logging"
          
        >
          Войти
 
        </v-btn>
      </v-card-actions>
 
      <v-progress-linear location="bottom" v-show="AppStore.loading && !alert" absolute indeterminate></v-progress-linear>
    
    </v-card>
    <v-alert
                width = "400"
                position="fixed"
                class="bottom-alertauth bgerroralert"
             
                type="error"
                density="compact"
                title="Ошибка авторизации"
                
                v-model="alert"
                
               
                closable
            >
            <template v-slot:prepend>
              <v-icon icon="mdi-alert-outline" class="pt-1"/>
            </template>
          </v-alert>
  </v-dialog>
 
  
</template>
 
<script>
import {useAccountStore} from '@/store/AccountStore'
import {useAppStore} from '@/store/app'
import { useVuelidate } from '@vuelidate/core'
import { required, helpers } from '@vuelidate/validators'
import { ref, reactive, computed, onMounted } from 'vue'

const req= helpers.withMessage('Обязательное поле', required)

export default {
  
  setup(props, context){
   
    const accountStore = useAccountStore()
    const AppStore= useAppStore()
    const menuAuthDialog = ref(false)
    const err = ref('')
    const alert = ref(false)
    const eyeshow = ref(false)
    

    const anon=reactive({
      username:"9966-00-",
      password:""
    })

    const rules = computed(()=> {
      return {
      username: { req, latin: helpers.withMessage(()=> 'Логин имееет вид "0000-00-000"', (value) => /(\d{4,4}[-]\d{2,2}[-]\d{3,3})+$/.test(value.toString()))}, // Matches state.firstName
      password: { req } // Matches state.lastName
      }
    }
    )

    const v$ = useVuelidate(rules, anon)
  
    const errorer = (field) => {
      let errors = v$.value[field].$error?v$.value[field].$errors[0].$message:''
      return errors
    }
 
    const logging=async()=>{
          if (!v$.value.$error) {
            
            try {
              await accountStore.logging(anon)
            }
            catch {
              AppStore.loading = false
              alert.value=true
             
              err.value = 'Ошибка авторизации'
         
           
            }
              
            
          }
          else {
            console.log(true);
          }
    }
 
    onMounted(() => {
      v$.value.$validate()
    })

    return {
      accountStore,
      AppStore,
      menuAuthDialog,
      anon,
      v$,
      logging,
      errorer,
      alert,
      err,
      eyeshow
    
    }
  }
}
</script>
 
<style>
.bottom-alertauth {
  top: 57vh;
    /* left: 38vw; */
}
 
.bottom-alertauth .v-alert-title {
font-size: 1.0rem;
}
/* , rgba(163, 5, 5, 0.8) */
.bgerroralert {
  background: linear-gradient(to top right, rgba(8, 4, 6, 0.8), rgba(90, 25, 50, 0.8), rgba(133, 5, 5, 0.8), rgba(192, 70, 70, 0.8));
}
</style>