From 444dfc33846bf68f40b743672a5e5edecbcc6720 Mon Sep 17 00:00:00 2001 From: paolo Date: Fri, 2 Nov 2018 23:22:16 +0100 Subject: [PATCH] Altra conversione in Typescript , partendo da un progetto di esempio funzionante... 2 --- package.json | 1 + quasar.conf.js | 2 +- src/components/Header.vue | 2 +- src/plugins/vee-validate.js | 5 +++ src/router/routes.ts | 4 +- src/store/modules/user.ts | 44 +++++++++--------- src/views/login/requestresetpwd.vue | 2 +- src/views/login/signin.vue | 2 +- src/views/login/signup.vue | 3 +- src/views/login/test.vue | 47 +++++++++++++++++++ src/views/login/updatepassword.vue | 2 +- src/views/login/vreg.vue | 2 +- tsconfig.json | 70 ++++++++++++++++------------- tslint.json | 24 +++++++--- yarn.lock | 5 +++ 15 files changed, 148 insertions(+), 67 deletions(-) create mode 100644 src/plugins/vee-validate.js create mode 100644 src/views/login/test.vue diff --git a/package.json b/package.json index d308dea..f383d6a 100644 --- a/package.json +++ b/package.json @@ -27,6 +27,7 @@ "axios": "^0.18.0", "bcryptjs": "^2.4.3", "dotenv": "^6.1.0", + "vee-validate": "^2.1.2", "vue-i18n": "^8.1.0", "vue-property-decorator": "^7.2.0", "vuelidate": "^0.7.4", diff --git a/quasar.conf.js b/quasar.conf.js index f16927c..fae4d2e 100644 --- a/quasar.conf.js +++ b/quasar.conf.js @@ -26,7 +26,7 @@ module.exports = function (ctx) { store: 'src/store/index.ts' }, // app plugins (/src/plugins) - plugins: ['i18n', 'axios', 'vuelidate'], + plugins: ['i18n', 'axios', 'vee-validate'], css: [ 'app.styl' ], diff --git a/src/components/Header.vue b/src/components/Header.vue index b4aa068..1264829 100644 --- a/src/components/Header.vue +++ b/src/components/Header.vue @@ -57,7 +57,7 @@ import drawer from '../layouts/drawer/drawer.vue' import messagePopover from '../layouts/toolbar/messagePopover.vue' - import user from '../store/modules/user'; + // import user from '../store/modules/user'; import * as types from '../store/mutation-types' diff --git a/src/plugins/vee-validate.js b/src/plugins/vee-validate.js new file mode 100644 index 0000000..d849de1 --- /dev/null +++ b/src/plugins/vee-validate.js @@ -0,0 +1,5 @@ +import VeeValidate from "vee-validate"; + +export default ({ Vue }) => { + Vue.use(VeeValidate, { inject: false }) +} diff --git a/src/router/routes.ts b/src/router/routes.ts index e32f872..1ad5b98 100644 --- a/src/router/routes.ts +++ b/src/router/routes.ts @@ -2,7 +2,9 @@ import { RouteConfig } from 'vue-router' const routes: RouteConfig[] = [ { path: '/', component: () => import('@/pages/Index.vue'), meta: { name: 'Home' } }, -/* { path: '/signup', component: () => import('@/views/login/signup.vue'), meta: { name: 'Registration' } }, + { path: '/test', component: () => import('@/views/login/test.vue'), meta: { name: 'Test' } }, + /* + { path: '/signup', component: () => import('@/views/login/signup.vue'), meta: { name: 'Registration' } }, { path: '/signin', component: () => import('@/views/login/signin.vue'), meta: { name: 'Login' } }, { path: '/vreg', component: () => import('@/views/login/vreg.vue'), meta: { name: 'Verify Reg' } }, { diff --git a/src/store/modules/user.ts b/src/store/modules/user.ts index b00cac1..f4e7f44 100644 --- a/src/store/modules/user.ts +++ b/src/store/modules/user.ts @@ -3,7 +3,7 @@ import Vuex from 'vuex' import { Module, VuexModule, Mutation, MutationAction, Action, getModule } from 'vuex-module-decorators' -let bcrypt = require('bcryptjs') +const bcrypt = require('bcryptjs') import * as types from '@/store/mutation-types' import { serv_constants } from '@/store/modules/serv_constants' @@ -22,8 +22,8 @@ export const ErroriMongoDb = { Vue.use(Vuex) -@Module -export default class User extends VuexModule implements IUserState { // Non occorrono i getters, basta questi qui: +@Module({ dynamic: true, store, name: 'user' }) +class User extends VuexModule { _id: IUserState['_id'] = '' email: IUserState['email'] = '' username: IUserState['username'] = '' @@ -37,7 +37,7 @@ export default class User extends VuexModule implements IUserState { // Non oc verifiedEmail: IUserState['verifiedEmail'] = false servercode: number = 0 - getlang (): any { + getlang(): any { if (this.lang !== '') { return this.lang } else { @@ -45,9 +45,9 @@ export default class User extends VuexModule implements IUserState { // Non oc } } - sendRequest (url: string, method: string, mydata: any) { + sendRequest(url: string, method: string, mydata: any) { console.log('LANG ' + this.getlang()) - let mytok: string = this.getTok() + const mytok: string = this.getTok() const authHeader = new Headers() authHeader.append('content-type', 'application/json') @@ -65,7 +65,7 @@ export default class User extends VuexModule implements IUserState { // Non oc } - getTok () { + getTok() { if (this.tokens) { if (typeof this.tokens[0] !== 'undefined') { return this.tokens[0].token @@ -78,22 +78,22 @@ export default class User extends VuexModule implements IUserState { // Non oc } @MutationAction({ mutate: [types.USER_PASSWORD] }) - async setpassword (newstr: string) { + async setpassword(newstr: string) { return { password: newstr } } @MutationAction({ mutate: [types.USER_EMAIL] }) - async setemail (newstr: string) { + async setemail(newstr: string) { return { email: newstr } } @MutationAction({ mutate: [types.USER_LANG] }) - async setlang (newstr: string) { + async setlang(newstr: string) { return { lang: newstr } } @Mutation - authUser (data: IUserState) { + authUser(data: IUserState) { this.username = data.username this.userId = data.userId this.idToken = data.idToken @@ -104,7 +104,7 @@ export default class User extends VuexModule implements IUserState { // Non oc } @Mutation - UpdatePwd (data: IIdToken) { + UpdatePwd(data: IIdToken) { this.idToken = data.idToken if (!this.tokens) { this.tokens = [] @@ -113,12 +113,12 @@ export default class User extends VuexModule implements IUserState { // Non oc } @Mutation - setServerCode (servercode: number) { + setServerCode(servercode: number) { this.servercode = servercode } @Mutation - clearAuthData (): void { + clearAuthData(): void { this.username = '' this.tokens = [] this.idToken = '' @@ -127,7 +127,7 @@ export default class User extends VuexModule implements IUserState { // Non oc } @Action({ commit: types.USER_UPDATEPWD }) - resetpwd (paramquery: IUserState) { + resetpwd(paramquery: IUserState) { let call = process.env.MONGODB_HOST + '/updatepwd' console.log('CALL ' + call) @@ -172,7 +172,7 @@ export default class User extends VuexModule implements IUserState { // Non oc } @Action({ commit: types.USER_REQUESTRESETPWD }) - requestpwd (paramquery: IUserState) { + requestpwd(paramquery: IUserState) { let call = process.env.MONGODB_HOST + '/requestnewpwd' console.log('CALL ' + call) @@ -210,7 +210,7 @@ export default class User extends VuexModule implements IUserState { // Non oc } @Action({ commit: types.USER_VREG }) - vreg (paramquery: ILinkReg) { + vreg(paramquery: ILinkReg) { let call = process.env.MONGODB_HOST + '/vreg' console.log('CALL ' + call) @@ -251,7 +251,7 @@ export default class User extends VuexModule implements IUserState { // Non oc } @Action({ commit: types.USER_VREG }) - signup (authData: IUserState) { + signup(authData: IUserState) { let call = process.env.MONGODB_HOST + '/users' console.log('CALL ' + call) @@ -347,7 +347,7 @@ export default class User extends VuexModule implements IUserState { // Non oc } @Action({ commit: types.USER_SIGNIN }) - signin (authData: IUserState) { + signin(authData: IUserState) { let call = process.env.MONGODB_HOST + '/users/login' console.log('LOGIN ' + call) @@ -447,7 +447,7 @@ export default class User extends VuexModule implements IUserState { // Non oc } @Action({ commit: types.USER_AUTOLOGIN }) - autologin () { + autologin() { const token = localStorage.getItem('token') if (!token) { return @@ -470,7 +470,7 @@ export default class User extends VuexModule implements IUserState { // Non oc } @Action({ commit: types.USER_LOGOUT }) - logout () { + logout() { let call = process.env.MONGODB_HOST + '/users/me/token' console.log('CALL ' + call) @@ -503,3 +503,5 @@ export default class User extends VuexModule implements IUserState { // Non oc } } + +export const UserModule = getModule(User.prototype) diff --git a/src/views/login/requestresetpwd.vue b/src/views/login/requestresetpwd.vue index 4b8eced..f214aec 100644 --- a/src/views/login/requestresetpwd.vue +++ b/src/views/login/requestresetpwd.vue @@ -50,7 +50,7 @@ import {mapActions} from 'vuex' import * as types from '../../store/mutation-types' - import {ErroriMongoDb} from '../../store/modules/user' + //import {ErroriMongoDb} from '../../store/modules/user' import {serv_constants} from '../../store/modules/serv_constants'; diff --git a/src/views/login/signin.vue b/src/views/login/signin.vue index baf9d81..b042860 100644 --- a/src/views/login/signin.vue +++ b/src/views/login/signin.vue @@ -64,7 +64,7 @@ import {mapGetters, mapActions} from 'vuex' import * as types from '../../store/mutation-types' - import {ErroriMongoDb} from '../../store/modules/user' + //import {ErroriMongoDb} from '../../store/modules/user' import {serv_constants} from "../../store/modules/serv_constants"; import axios from 'axios'; diff --git a/src/views/login/signup.vue b/src/views/login/signup.vue index bab63b8..6872e8a 100644 --- a/src/views/login/signup.vue +++ b/src/views/login/signup.vue @@ -93,6 +93,7 @@ diff --git a/src/views/login/updatepassword.vue b/src/views/login/updatepassword.vue index e737a2e..7a1bc53 100644 --- a/src/views/login/updatepassword.vue +++ b/src/views/login/updatepassword.vue @@ -60,7 +60,7 @@ import {mapActions} from 'vuex' import * as types from '../../store/mutation-types' - import {ErroriMongoDb} from '../../store/modules/user' + //import {ErroriMongoDb} from '../../store/modules/user' import {serv_constants} from '../../store/modules/serv_constants'; diff --git a/src/views/login/vreg.vue b/src/views/login/vreg.vue index 80607b7..56c2c99 100644 --- a/src/views/login/vreg.vue +++ b/src/views/login/vreg.vue @@ -32,7 +32,7 @@ import {mapActions} from 'vuex' import * as types from '../../store/mutation-types' - import {ErroriMongoDb} from '../../store/modules/user' + //import {ErroriMongoDb} from '../../store/modules/user' import {serv_constants} from '../../store/modules/serv_constants'; diff --git a/tsconfig.json b/tsconfig.json index dc81744..b61e6cb 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,35 +1,41 @@ { "compilerOptions": { - "target": "es5", - "module": "esnext", - "strict": true, - "esModuleInterop": true, - "sourceMap": true, - "experimentalDecorators": true, - "noImplicitAny": true, - "moduleResolution": "node", - "lib": [ - "es2015", - "dom" - ], - "baseUrl": ".", - "paths": { - "~/*": ["./*"], - "@/*": ["src/*"] - }, - "types": [ - "node", - "jest" - ] - }, - "include": [ - "src/**/*.ts", - "src/**/*.vue", - "test/**/*.ts" - ], - "exclude": [ - ".quasar", - "dist", - "node_modules" - ] + "target": "esnext", + "module": "esnext", + "strict": true, + "jsx": "preserve", + "importHelpers": true, + "moduleResolution": "node", + "experimentalDecorators": true, + "esModuleInterop": true, + "allowSyntheticDefaultImports": true, + "sourceMap": true, + "baseUrl": "./", + "types": [ + "node", + "jest" + ], + "paths": { + "@/*": [ + "src/*" + ] + }, + "lib": [ + "esnext", + "dom", + "dom.iterable", + "scripthost" + ] + }, + "include": [ + "src/**/*.ts", + "src/**/*.tsx", + "src/**/*.vue", + "tests/**/*.ts", + "tests/**/*.tsx", + "config/**/*.ts" + ], + "exclude": [ + "node_modules" + ] } diff --git a/tslint.json b/tslint.json index 7d39516..864a616 100644 --- a/tslint.json +++ b/tslint.json @@ -1,13 +1,25 @@ { "defaultSeverity": "warning", "extends": [ - "tslint-config-standard" + "tslint:recommended" ], + "linterOptions": { + "exclude": [ + "node_modules/**" + ] + }, "rules": { - /*"semicolon": [ - true, - "always", - "ignore-bound-class-methods" - ]*/ + "semicolon": [true, "never"], + "trailing-comma": [true, {"multiline": "never", "singleline": "never"}], + "quotemark": [true, "single"], + "indent": [true, "spaces", 2], + "interface-name": false, + "ordered-imports": false, + "object-literal-sort-keys": false, + "max-line-length": false, + "member-access": false, + "no-console": [true, "warning"], + "no-consecutive-blank-lines": false, + "no-empty": false } } diff --git a/yarn.lock b/yarn.lock index 8376242..de631ff 100644 --- a/yarn.lock +++ b/yarn.lock @@ -9021,6 +9021,11 @@ vary@~1.1.2: resolved "https://registry.yarnpkg.com/vary/-/vary-1.1.2.tgz#2299f02c6ded30d4a5961b0b9f74524a18f634fc" integrity sha1-IpnwLG3tMNSllhsLn3RSShj2NPw= +vee-validate@^2.1.2: + version "2.1.2" + resolved "https://registry.yarnpkg.com/vee-validate/-/vee-validate-2.1.2.tgz#4dc99bbca1358d2cee2b8d0fe7ebd59ab968de08" + integrity sha512-6Gr7jxXRnRhAg4QKedWF2mqtJ5MF6os8OBUtWS4XTOyGMbwa1UsJOPogqxEJA1qNqf5fUwqr/uP5Vs1zVyHSxA== + vendors@^1.0.0: version "1.0.2" resolved "https://registry.yarnpkg.com/vendors/-/vendors-1.0.2.tgz#7fcb5eef9f5623b156bcea89ec37d63676f21801"