+
+ 管理品台
+
+
-
-
-
-
- {{route.name}}
-
-
-
-
-
-
-
-
-
-
-
-
- 修改昵称
- 退出
-
-
-
-
-
+
+
+
+
+ {{route.name}}
+
+
+
+
+
+
+
+
+
+
+ 修改昵称
+ 退出
+
+
+
+
+
+
+
diff --git a/src/views/home/pages/login/login.less b/src/views/home/pages/login/login.less
index e050be5..f7a2421 100644
--- a/src/views/home/pages/login/login.less
+++ b/src/views/home/pages/login/login.less
@@ -90,10 +90,10 @@
margin-left: 7px;
}
}
- .slideSty .slide-verify {
- margin: 13px auto 0 auto;
- width: 350px !important;
- }
+.slideSty .slide-verify {
+ margin: 13px auto 0 auto;
+ width: 350px !important;
+}
.slideSty .slide-verify-slider {
width: 100% !important;
}
diff --git a/src/views/home/pages/login/login.ts b/src/views/home/pages/login/login.ts
index a736267..d461c4b 100644
--- a/src/views/home/pages/login/login.ts
+++ b/src/views/home/pages/login/login.ts
@@ -32,72 +32,51 @@ declare let window: Window
}
})
export default class Login extends HomeParent {
- @Action('Login') Login;
- public context : ActionContext
+ // @Action('Login') Login
+
public provider:any
public web3:Web3
public chainId:number
public account:string
public nonce:string
+ public isLogin:boolean
- public async btn(){
- if (!this.$store.getters.step){
- try {
+ public created(){
+ if (store.state.token){
+ this.isLogin = true
+ }else {
+ this.isLogin = false
+ }
+ }
+
+ public async doLogin(){
+ // let apiHost = process.env.NODE_ENV !== 'production' ? process.env.VUE_APP_API_HOST : document.location.host;
+ // let scheme = document.location.protocol;
+ // console.log(scheme + "//" + apiHost);return
+ if (!this.isLogin){
+ try{
await this.connect()
await this.checkNance()
} catch (err) {
Message({
message: err.message,
type: 'error',
- duration: 5 * 1000
+ duration: 3 * 1000,
})
Promise.reject(err)
}
+ }else {
+ Message({
+ message: '已经登录过了!',
+ type: 'warning',
+ duration:2*1000,
+ onClose:()=>{
+ this.goPage('home')
+ }
+ })
}
}
-
-
-
-
- public get accessToken(): string {
- let token: string = this.$route.query.access_token as string;
- return token;
- }
-
- public rules: object = {
- username: [{required: true, trigger: 'blur', message: "请输入登录名"}],
- password: [{required: true, trigger: 'blur', message: "请输入登录密码"}],
- }
-
- public created() {
- // if(!this.accessToken) {
- // this._getData();
- // }
- }
-
- private _getData(): void {
- this.$http.get(Url.WORK_LOGIN).then(res => {
- window["WwLogin"]({
- id: "loginPage",
- goto: res.data
- })
- })
- }
-
- // public doLogin(): void {
- // let form: Form = this.$refs["login"] as Form;
- // form.validate((valid: boolean) => {
- // if (!valid) {
- // return;
- // }
- // // this.Login(this.form).then((user) => {
- // // this.goPage("home");
- // // }).catch((msg: string) => {
- // // this.error(msg);
- // // })
- // });
- // }
private async login( account, chainId, nonce) {
nonce += ''
const tips = 'This signature is only used for verify your account'
@@ -134,21 +113,26 @@ export default class Login extends HomeParent {
net_id: chainId
}
const res:any = await Http_login(authData)
- if (!res.errcode && res.token) {
- store.commit('set_token',res.token)
- console.log(store.getters)
+ if (res.code == 200) {
+ store.commit('set_token',res.data.token)
+ this.goPage("home");
}
}
private async checkNance() {
try {
+ // store.commit('del_nonce');return
let nonce = store.getters.nonce
if (!nonce) {
let params = {account:this.account, net_id:this.chainId}
+ // await this.$http.get(Url.GET_NONCE,params).then(res => {
+ // console.log(res.data)
+ // })
const res:any = await Http_getNonce(params);
- store.commit('set_nonce',res.nonce)
- this.nonce = res.nonce
+ // console.log('@@@',res)
+ store.commit('set_nonce',res.data)
+ this.nonce = res.data
}
- this.login(this.account,this.chainId,this.nonce)
+ this.login(this.account,this.chainId,store.getters.nonce)
} catch (err) {
Promise.reject(err)
}
diff --git a/src/views/home/pages/login/login.vue b/src/views/home/pages/login/login.vue
index b1ede5f..e9e5ab5 100644
--- a/src/views/home/pages/login/login.vue
+++ b/src/views/home/pages/login/login.vue
@@ -2,7 +2,7 @@
系统
-
diff --git a/src/views/home/router/index.ts b/src/views/home/router/index.ts
index 4605019..82670cf 100644
--- a/src/views/home/router/index.ts
+++ b/src/views/home/router/index.ts
@@ -12,26 +12,29 @@ const routes : Array
= [
]
const router = new VueRouter({
- base : "/dashboard/",
+ // base : "/dashboard/",
mode : "history",
routes,
})
function setTitle(title : string) : void {
- window.document.title = title;
+ window.document.title = '管理平台';
}
router.beforeEach((to, from, next) => {
LoadingBar.start();
- let title : string = process.env.VUE_APP_TITLE;
- setTitle(to.meta.title + '-' + title);
- let token : string = to.query.access_token as string;
- if (token) {
- Store.commit(Types.SET_USER_TOKEN, token);
- next({name : to.name === 'login'? 'home' : to.name})
- return;
+ if (to.path === '/login') {
+ next();
+ } else {
+ // 从本地存储里获取token
+ let token = Store.state.token as string
+ // 判断token是否为空如果为空则跳转到登录页 如果有则放行
+ if (!token) {
+ next({path:'/login'});
+ } else {
+ next();
+ }
}
- next();
})
router.afterEach((to, from) => {
diff --git a/src/views/home/store/index.ts b/src/views/home/store/index.ts
index d629e56..a113f5a 100644
--- a/src/views/home/store/index.ts
+++ b/src/views/home/store/index.ts
@@ -15,7 +15,6 @@ export default new Vuex.Store({
getters : {
token : (state : StateInterface) => state.user.token,
user : (state : StateInterface) => state.user.user,
- step:state => state.step,
nonce:state => state.nonce
},
modules : {
@@ -42,13 +41,17 @@ export default new Vuex.Store({
state.nonce = nonce
// sessionStorage.nonce = nonce
},
+ del_nonce(state) {
+ state.nonce = ''
+ // sessionStorage.nonce = nonce
+ },
set_token(state, token) {
state.token = token
- sessionStorage.token = token
+ // sessionStorage.token = token
},
del_token(state) {
state.token = ''
- sessionStorage.removeItem('token')
+ // sessionStorage.removeItem('token')
}
}
})
diff --git a/src/views/home/store/user.ts b/src/views/home/store/user.ts
index ac03407..b9e6201 100644
--- a/src/views/home/store/user.ts
+++ b/src/views/home/store/user.ts
@@ -9,7 +9,6 @@ const sprintf = require('sprintf-js');
export interface UserState {
user : UserInterface,
token : string | undefined,
- isLogin : boolean,
}
export default {
@@ -22,17 +21,15 @@ export default {
},
actions : {
Login(context : ActionContext, form : any) {
- return Http.post(Url.LOGIN, form).then((res : ResponseInterface) => {
- context.commit(Types.SET_USER_INFO, res.data);
- context.commit(Types.SET_USER_TOKEN, res.data.access_token);
- return Promise.resolve(res.data);
- }).catch((err : string) => {
- return Promise.reject(err);
- })
+ // return Http.post(Url.LOGIN, form).then((res : ResponseInterface) => {
+ // context.commit(Types.SET_USER_INFO, res.data);
+ // context.commit(Types.SET_USER_TOKEN, res.data.access_token);
+ // return Promise.resolve(res.data);
+ // }).catch((err : string) => {
+ // return Promise.reject(err);
+ // })
},
- getMenus() {
- // return Http.get()
- }
+
},
mutations : {
[Types.SET_USER_INFO](state : UserState, user : UserInterface) {
@@ -40,7 +37,7 @@ export default {
},
[Types.SET_USER_TOKEN](state : UserState, token : string) {
state.token = token;
- state.isLogin = token.length > 0;
+ // state.isLogin = token.length > 0;
},
}
}
\ No newline at end of file