Altra conversione in Typescript (3).
primo test semplice...
This commit is contained in:
@@ -1,13 +1,13 @@
|
||||
import Vue from 'vue';
|
||||
import Vuex from 'vuex';
|
||||
import Vue from 'vue'
|
||||
import Vuex from 'vuex'
|
||||
|
||||
import { IUserState } from '@/types';
|
||||
import { IUserState } from '@/types'
|
||||
|
||||
Vue.use(Vuex);
|
||||
Vue.use(Vuex)
|
||||
|
||||
export interface IRootState {
|
||||
user: IUserState;
|
||||
role: IRootState;
|
||||
user: IUserState
|
||||
role: IRootState
|
||||
}
|
||||
|
||||
export default new Vuex.Store<IRootState>({});
|
||||
export default new Vuex.Store<IRootState>({})
|
||||
|
||||
@@ -1,59 +1,62 @@
|
||||
/*
|
||||
import Vue from 'vue'
|
||||
import Vuex from 'vuex'
|
||||
|
||||
Vue.use(Vuex);
|
||||
import { Module, VuexModule, Mutation, MutationAction, Action, getModule } from 'vuex-module-decorators'
|
||||
|
||||
import * as types from '../mutation-types'
|
||||
import * as types from '@/store/mutation-types'
|
||||
|
||||
export const state = {
|
||||
conta: 0,
|
||||
deferredPrompt: null,
|
||||
isLoginPage: false,
|
||||
layoutNeeded: true,
|
||||
mobileMode: false,
|
||||
menuCollapse: true,
|
||||
posts: [{title:'titolo 1'}, {title:'titolo 2'}],
|
||||
import store from '@/store'
|
||||
|
||||
};
|
||||
Vue.use(Vuex)
|
||||
|
||||
export const getters = {
|
||||
getConta: state => state.conta,
|
||||
getDeferredPrompt: state => state.deferredPrompt,
|
||||
getIsLoginPage: state => state.isLoginPage,
|
||||
getLayoutNeeded: state => state.layoutNeeded,
|
||||
getMobileMode: state => state.mobileMode,
|
||||
getMenuCollapse: state => state.menuCollapse,
|
||||
getPosts: state => state.posts,
|
||||
};
|
||||
|
||||
|
||||
export const mutations = {
|
||||
[types.SET_VALUE]: (state, payload) => { state.conta = payload; },
|
||||
[types.SET_DEFFERED_PROMPT]: (state, payload) => { state.deferredPrompt = payload; },
|
||||
[types.SET_LOGIN_PAGE]: (state, payload) => { state.isLoginPage = payload; },
|
||||
[types.SET_LAYOUT_NEEDED]: (state, payload) => { state.layoutNeeded = payload; },
|
||||
[types.SET_MOBILE_MODE]: (state, payload) => { state.mobileMode = payload; },
|
||||
[types.SET_MENU_COLLAPSED]: (state, payload) => { state.menuCollapse = payload; },
|
||||
[types.SET_POSTS]: (state, payload) => { state.posts = payload; },
|
||||
};
|
||||
|
||||
|
||||
export const actions = {
|
||||
[types.SET_VALUE]: ({commit}, payload) => { commit(types.SET_VALUE, payload) },
|
||||
[types.SET_DEFFERED_PROMPT]: ({commit}, payload) => { commit(types.SET_DEFFERED_PROMPT, payload) },
|
||||
[types.SET_LOGIN_PAGE]: ({commit}, payload) => { commit(types.SET_LOGIN_PAGE, payload) },
|
||||
[types.SET_LAYOUT_NEEDED]: ({commit}, payload) => { commit(types.SET_LAYOUT_NEEDED, payload) },
|
||||
[types.SET_MOBILE_MODE]: ({commit}, payload) => { commit(types.SET_MOBILE_MODE, payload) },
|
||||
[types.SET_MENU_COLLAPSED]: ({commit}, payload) => { commit(types.SET_MENU_COLLAPSED, payload) },
|
||||
[types.SET_POSTS]: ({commit}, payload) => { commit(types.SET_POSTS, payload) },
|
||||
};
|
||||
|
||||
export default {
|
||||
namespaced: true,
|
||||
state,
|
||||
getters,
|
||||
mutations,
|
||||
actions
|
||||
export interface IGlob {
|
||||
conta: number
|
||||
isLoginPage: boolean
|
||||
layoutNeeded: boolean
|
||||
mobileMode: boolean
|
||||
menuCollapse: boolean
|
||||
posts: string[]
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
@Module({ dynamic: true, store, name: 'glob' })
|
||||
class Glob extends VuexModule { // Non occorrono i getters, basta questi qui:
|
||||
conta = 0
|
||||
isLoginPage = false
|
||||
layoutNeeded = true
|
||||
mobileMode = false
|
||||
menuCollapse = true
|
||||
posts = []
|
||||
|
||||
getConta() {
|
||||
return this.conta
|
||||
}
|
||||
|
||||
getIsLoginPage() {
|
||||
return this.isLoginPage
|
||||
}
|
||||
|
||||
getLayoutNeeded() {
|
||||
return this.layoutNeeded
|
||||
}
|
||||
|
||||
getMobileMode() {
|
||||
return this.mobileMode
|
||||
}
|
||||
|
||||
getMenuCollapse() {
|
||||
return this.menuCollapse
|
||||
}
|
||||
|
||||
getPosts() {
|
||||
return this.posts
|
||||
}
|
||||
|
||||
@MutationAction({ mutate: ['conta'] })
|
||||
async setConta(num: number) {
|
||||
return { conta: num }
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export const GlobModule = getModule(Glob.prototype)
|
||||
|
||||
@@ -23,7 +23,7 @@ export const ErroriMongoDb = {
|
||||
Vue.use(Vuex)
|
||||
|
||||
@Module({ dynamic: true, store, name: 'user' })
|
||||
class User extends VuexModule {
|
||||
class User extends VuexModule implements IUserState { // Non occorrono i getters, basta questi qui:
|
||||
_id: IUserState['_id'] = ''
|
||||
email: IUserState['email'] = ''
|
||||
username: IUserState['username'] = ''
|
||||
@@ -37,7 +37,7 @@ class User extends VuexModule {
|
||||
verifiedEmail: IUserState['verifiedEmail'] = false
|
||||
servercode: number = 0
|
||||
|
||||
getlang(): any {
|
||||
getlang (): any {
|
||||
if (this.lang !== '') {
|
||||
return this.lang
|
||||
} else {
|
||||
@@ -45,9 +45,9 @@ class User extends VuexModule {
|
||||
}
|
||||
}
|
||||
|
||||
sendRequest(url: string, method: string, mydata: any) {
|
||||
sendRequest (url: string, method: string, mydata: any) {
|
||||
console.log('LANG ' + this.getlang())
|
||||
const mytok: string = this.getTok()
|
||||
let mytok: string = this.getTok()
|
||||
|
||||
const authHeader = new Headers()
|
||||
authHeader.append('content-type', 'application/json')
|
||||
@@ -65,7 +65,7 @@ class User extends VuexModule {
|
||||
|
||||
}
|
||||
|
||||
getTok() {
|
||||
getTok () {
|
||||
if (this.tokens) {
|
||||
if (typeof this.tokens[0] !== 'undefined') {
|
||||
return this.tokens[0].token
|
||||
@@ -78,22 +78,22 @@ class User extends VuexModule {
|
||||
}
|
||||
|
||||
@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 @@ class User extends VuexModule {
|
||||
}
|
||||
|
||||
@Mutation
|
||||
UpdatePwd(data: IIdToken) {
|
||||
UpdatePwd (data: IIdToken) {
|
||||
this.idToken = data.idToken
|
||||
if (!this.tokens) {
|
||||
this.tokens = []
|
||||
@@ -113,12 +113,12 @@ class User extends VuexModule {
|
||||
}
|
||||
|
||||
@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 @@ class User extends VuexModule {
|
||||
}
|
||||
|
||||
@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 @@ class User extends VuexModule {
|
||||
}
|
||||
|
||||
@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 @@ class User extends VuexModule {
|
||||
}
|
||||
|
||||
@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 @@ class User extends VuexModule {
|
||||
}
|
||||
|
||||
@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 @@ class User extends VuexModule {
|
||||
}
|
||||
|
||||
@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 @@ class User extends VuexModule {
|
||||
}
|
||||
|
||||
@Action({ commit: types.USER_AUTOLOGIN })
|
||||
autologin() {
|
||||
autologin () {
|
||||
const token = localStorage.getItem('token')
|
||||
if (!token) {
|
||||
return
|
||||
@@ -470,7 +470,7 @@ class User extends VuexModule {
|
||||
}
|
||||
|
||||
@Action({ commit: types.USER_LOGOUT })
|
||||
logout() {
|
||||
logout () {
|
||||
|
||||
let call = process.env.MONGODB_HOST + '/users/me/token'
|
||||
console.log('CALL ' + call)
|
||||
Reference in New Issue
Block a user