Altra conversione in Typescript , partendo da un progetto di esempio funzionante...

This commit is contained in:
paolo
2018-11-02 22:15:48 +01:00
parent 6b00f242ee
commit 899e412949
14 changed files with 315 additions and 294 deletions

View File

@@ -50,7 +50,7 @@
import {mapActions} from 'vuex'
import * as types from '../../store/mutation-types'
import {Errori_MongoDb} from '../../store/modules/user'
import {ErroriMongoDb} from '../../store/modules/user'
import {serv_constants} from '../../store/modules/serv_constants';

View File

@@ -64,7 +64,7 @@
import {mapGetters, mapActions} from 'vuex'
import * as types from '../../store/mutation-types'
import {Errori_MongoDb} from '../../store/modules/user'
import {ErroriMongoDb} from '../../store/modules/user'
import {serv_constants} from "../../store/modules/serv_constants";
import axios from 'axios';
@@ -128,7 +128,7 @@
},
checkErrors(riscode) {
//console.log("RIS = " + riscode);
if (riscode === Errori_MongoDb.OK) {
if (riscode === ErroriMongoDb.OK) {
this.showNotif({type: 'positive', message: this.$t('login.completato')});
this.$router.push('/');
} else if (riscode === serv_constants.RIS_CODE_LOGIN_ERR) {

View File

@@ -92,10 +92,7 @@
</div>
</template>
<script lang="ts">
import Vue from 'vue'
import { Component, Prop, Watch } from 'vue-property-decorator'
<script>
import {
required,
email,
@@ -107,55 +104,17 @@
requiredUnless
} from 'vuelidate/lib/validators'
import { validationMixin } from 'vuelidate';
import { mapGetters, mapActions } from 'vuex'
import {mapGetters, mapActions} from 'vuex'
import * as types from '../../store/mutation-types'
import { Errori_MongoDb } from '../../store/modules/user'
import {ErroriMongoDb} from '../../store/modules/user'
import axios from 'axios';
import { Loading, QSpinnerFacebook, QSpinnerGears } from 'quasar'
import {Loading, QSpinnerFacebook, QSpinnerGears} from 'quasar'
@Component({
mixins: [validationMixin],
validations: {
isAsync: true,
form: {
email: {
required, email,
isUnique: value => {
if (value === '') return true;
return axios.get(process.env.MONGODB_HOST + '/email/' + value)
.then(res => {
return (res.status !== 200)
}).catch((e) => {
return true;
})
}
},
password: { required, minLength: minLength(8), maxLength: maxLength(20) },
username: {
required, minLength: minLength(6), maxLength: maxLength(20),
isUnique: value => {
if (value === '') return true;
return axios.get(process.env.MONGODB_HOST + '/users/' + value)
.then(res => {
return (res.status !== 200)
}).catch((e) => {
return true;
})
}
},
repeatPassword: {
sameAsPassword: sameAs('password')
},
terms: { required },
}
},
data () {
export default {
data() {
return {
url: process.env.VUE_APP_URL,
form: {
@@ -181,18 +140,53 @@
'getUserServer',
'getServerCode',
]),
env () {
env() {
return env
},
},
validations: {
isAsync: true,
form: {
email: {
required, email,
isUnique: value => {
if (value === '') return true;
return axios.get(process.env.MONGODB_HOST + '/email/' + value)
.then(res => {
return (res.status !== 200)
}).catch((e) => {
return true;
})
}
},
password: {required, minLength: minLength(8), maxLength: maxLength(20)},
username: {
required, minLength: minLength(6), maxLength: maxLength(20),
isUnique: value => {
if (value === '') return true;
return axios.get(process.env.MONGODB_HOST + '/users/' + value)
.then(res => {
return (res.status !== 200)
}).catch((e) => {
return true;
})
}
},
repeatPassword: {
sameAsPassword: sameAs('password')
},
terms: {required},
}
},
methods: {
...mapActions("user", {
signup: types.USER_SIGNUP,
}),
showNotif (msg) {
showNotif(msg) {
this.$q.notify(msg)
},
errorMsg (cosa, item) {
errorMsg(cosa, item) {
try {
if (!item.$error) return '';
if (item.$params.email && !item.email) return this.$t('reg.err.email');
@@ -220,20 +214,20 @@
//console.log("ERR : " + error);
}
},
checkErrors (riscode) {
checkErrors(riscode) {
//console.log("RIS = " + riscode);
if (riscode === Errori_MongoDb.DUPLICATE_EMAIL_ID) {
if (riscode === ErroriMongoDb.DUPLICATE_EMAIL_ID) {
this.showNotif(this.$t('reg.err.duplicate_email'));
} else if (riscode === Errori_MongoDb.DUPLICATE_USERNAME_ID) {
} else if (riscode === ErroriMongoDb.DUPLICATE_USERNAME_ID) {
this.showNotif(this.$t('reg.err.duplicate_username'));
} else if (riscode === Errori_MongoDb.OK) {
} else if (riscode === ErroriMongoDb.OK) {
this.$router.push('/');
} else {
this.showNotif("Errore num " + riscode);
}
},
submit () {
submit() {
this.$v.form.$touch();
this.duplicate_email = false;
@@ -249,14 +243,14 @@
return
}
this.$q.loading.show({ message: this.$t('reg.incorso') });
this.$q.loading.show({message: this.$t('reg.incorso')});
console.log(this.form);
this.signup(this.form)
.then((riscode) => {
this.checkErrors(riscode);
this.$q.loading.hide();
}).catch((error: string) => {
}).catch(error => {
console.log("ERROR = " + error);
this.$q.loading.hide();
});
@@ -265,11 +259,7 @@
// ...
}
},
})
export default class Signup extends Vue {
}
</script>
<style scoped>
@@ -279,5 +269,3 @@
max-width: 450px;
}
</style>

View File

@@ -60,7 +60,7 @@
import {mapActions} from 'vuex'
import * as types from '../../store/mutation-types'
import {Errori_MongoDb} from '../../store/modules/user'
import {ErroriMongoDb} from '../../store/modules/user'
import {serv_constants} from '../../store/modules/serv_constants';

View File

@@ -32,7 +32,7 @@
import {mapActions} from 'vuex'
import * as types from '../../store/mutation-types'
import {Errori_MongoDb} from '../../store/modules/user'
import {ErroriMongoDb} from '../../store/modules/user'
import {serv_constants} from '../../store/modules/serv_constants';