From 5a8b94e6177fda4ff1c60ddc44c74b429801da14 Mon Sep 17 00:00:00 2001 From: hujiabin Date: Tue, 19 Jul 2022 13:05:59 +0800 Subject: [PATCH] add metemask-login --- src/components/page.ts | 2 - src/views/home/pages/home/home.less | 87 ----------- src/views/home/pages/home/home.ts | 184 ++++------------------- src/views/home/pages/home/home.vue | 198 +++---------------------- src/views/home/pages/layout/layout.ts | 74 +++------ src/views/home/pages/layout/layout.vue | 90 +++++------ src/views/home/pages/login/login.less | 8 +- src/views/home/pages/login/login.ts | 60 ++------ src/views/home/pages/login/login.vue | 2 +- src/views/home/router/index.ts | 23 +-- src/views/home/store/user.ts | 3 +- 11 files changed, 141 insertions(+), 590 deletions(-) diff --git a/src/components/page.ts b/src/components/page.ts index a52e7fc..af30551 100644 --- a/src/components/page.ts +++ b/src/components/page.ts @@ -8,8 +8,6 @@ import { import { Table, TableColumn } from "view-design"; import Events from "@/utils/Events"; import { TableExportCsvParams } from "view-design/types/table"; -import { stringify } from "postcss"; -import Project from "@/views/home/pages/project/project"; @Component diff --git a/src/views/home/pages/home/home.less b/src/views/home/pages/home/home.less index 95779f9..e69de29 100644 --- a/src/views/home/pages/home/home.less +++ b/src/views/home/pages/home/home.less @@ -1,87 +0,0 @@ -.boxx{ - margin: 0 0 18px 20px; - font-size: 40px -} -.demo-split1{ - height: 450px; - -} -.demo-split-pane1{ - padding: 10px; - -} -.demo-split{ - height: 680px; - margin-top: 50px; - background-color: #FFFFFF; - -} -.demo-split-pane{ - padding: 10px; - //border: 1px solid red; -} -.demo-split-pane.no-padding{ - height: 680px; - padding: 0; -} -.tag{ - background-color: #374151; - color: white; - padding: 8px 100px 8px 20px; - -} - -.arrow1 { - padding: 15px 0; - margin-left: 20px; - &-wrap { - //margin: 0 auto; - width: 120px; - height: 34px; - background-image: linear-gradient(to right, #227190 , #63c7ed); - color: #FFFFFF; - line-height: 34px; - text-align: start; - position: relative; - &::after { - content: ''; - position: absolute; - right: -34px; - border: 17px solid transparent; - border-left: 17px solid #63c7ed; - } - } -} -.arrow2 { - padding: 15px 0; - margin-left: 20px; - &-wrap { - //margin: 0 auto; - width: 180px; - height: 34px; - background-image: linear-gradient(to right, #008B8B , #7FFFD4); - color: #FFFFFF; - line-height: 34px; - text-align: start; - position: relative; - &::after { - content: ''; - position: absolute; - right: -34px; - border: 17px solid transparent; - border-left: 17px solid #7FFFD4; - } - } -} - -.progress:hover:before{ - content:attr(content); - background:#585e6b; - color:#fff; - padding:.8em 1em; - position:absolute; - bottom: -35px; - border-radius: 5px; - margin-left:30%; - -} diff --git a/src/views/home/pages/home/home.ts b/src/views/home/pages/home/home.ts index 76ba243..16957b0 100644 --- a/src/views/home/pages/home/home.ts +++ b/src/views/home/pages/home/home.ts @@ -9,184 +9,58 @@ import { import HomeParent from "@/views/home/Common/HomeParent"; import CustomPage from "@/components/page.vue"; import SvgIcon from '@/components/SvgIcon.vue' -import * as echarts from 'echarts' +import { TableColumn } from "view-design" + @Component({ components : { - SvgIcon + SvgIcon,CustomPage } }) export default class Home extends HomeParent { name : string = 'home' - public scriptList :any = [{ script_name: undefined, date: undefined,content:undefined}]; - public projectList :any = [{ product_name: undefined, date: undefined}] - public myChart; - public cardProductData:object = { - product_count_trashed:undefined, - product_today:undefined, - day_rate:undefined, - day_icon:undefined, - week_rate:undefined, - week_icon:undefined, + public noDataText = '没有数据的提示语' + public List :any = [] + public columns: TableColumn[] = [{ + width: 80, + key: 'id', + align: 'center', + }, { + title: "名称", + key: "name" + }, { + title: "TAPD", + key: "tapd_id" + }, { + title: "操作", + slot: "operation" + }] + + public total: number = 0; + public search: { page: number, size: number , keywords? : string } = { + page: 1, size: 10 , keywords : "" } - public cardScriptData:object = { - script_week:undefined, - use_rate:undefined - } - public cardTaskData:object = { - day_rate:undefined, - task_count:undefined, - task_month_sum:undefined - } - public userNumber:number=0; public created() { // this._getData() // this._getScriptLog() // this._getProductLog() + this.List = [ + {id:1,name:'tom',tapd_id:10086}, + {id:2,name:'jam',tapd_id:10086}, + {id:3,name:'any',tapd_id:10086}, + {id:4,name:'som',tapd_id:10086}, + ] } - private createChart(data) { - this.myChart = echarts.init(this.$refs['myChart'] as HTMLCanvasElement); - this.myChart.setOption(this.option(data)); - this.myChart.on('updateAxisPointer', (event)=> { - const xAxisInfo = event.axesInfo[0]; - if (xAxisInfo) { - const dimension = xAxisInfo.value + 1; - this.myChart.setOption({ - series: { - id: 'pie', - label: { - formatter: '{b}: {@[' + dimension + ']} ({d}%)' - }, - encode: { - value: dimension, - tooltip: dimension - } - } - }); - } - }); - } - public shortcut(str){ - this._push({name:str}) - } - - private option(data) { - return { - legend: {}, - tooltip: { - trigger: 'axis', - showContent: false - }, - dataset: { - source: data - }, - xAxis: { type: 'category' }, - yAxis: { gridIndex: 0 }, - grid: { top: '55%' }, - series: [ - { - type: 'line', - smooth: true, - seriesLayoutBy: 'row', - emphasis: { focus: 'series' } - }, - { - type: 'line', - smooth: true, - seriesLayoutBy: 'row', - emphasis: { focus: 'series' } - }, - { - type: 'line', - smooth: true, - seriesLayoutBy: 'row', - emphasis: { focus: 'series' } - }, - { - type: 'line', - smooth: true, - seriesLayoutBy: 'row', - emphasis: { focus: 'series' } - }, - { - type: 'pie', - id: 'pie', - radius: '30%', - center: ['50%', '25%'], - emphasis: { - focus: 'self' - }, - label: { - formatter: '{b}: {@2012} ({d}%)' - }, - encode: { - itemName: 'product', - value: '2012', - tooltip: '2012' - } - } - ] - } - } private _getData():void{ - this.$http.get(Url.OVERVIEW).then((res)=>{ - this.createChart(res.data.recent_task_logs) - this.cardProductData = this.alterProduct(res.data.card_data.product) - this.cardTaskData = this.alterTask(res.data.card_data.task) - this.cardScriptData = this.alterScript(res.data.card_data.script) - this.userNumber = res.data.card_data.user - - }).catch((msg:string)=>{ - this.error(msg) - }) } - private _getScriptLog():void{ - this.$http.get(Url.OVERVIEW_SCRIPT).then((res)=>{ - this.scriptList = res.data - }).catch((msg:string)=>{ - this.error(msg) - }) - } - private _getProductLog():void{ - this.$http.get(Url.OVERVIEW_PRODUCT).then((res)=>{ - this.projectList = res.data - }).catch((msg:string)=>{ - this.error(msg) - }) - } - private alterProduct(data):object{ - return { - product_count_trashed:data.product_count_trashed, - product_today:data.product_today, - day_rate:data.product_yesterday==0?'(昨日无构建)':Math.abs(Math.floor(((parseInt(data.product_today)-parseInt(data.product_yesterday)) / parseInt(data.product_yesterday ))*100))+'%', - day_icon:parseInt(data.product_today) > parseInt(data.product_yesterday)?1:2, - week_rate:Math.abs(Math.floor(((parseInt(data.product_current_week)-parseInt(data.product_last_week)) / parseInt(data.product_last_week ))*100))+'%', - week_icon:parseInt(data.product_current_week) > parseInt(data.product_last_week)?1:2, - } - } - - private alterTask(data):object{ - return { - task_count:data.task_count, - task_month_sum:data.task_month_sum, - day_rate:Math.abs(Math.floor((parseInt(data.task_end_sum)/ parseInt(data.task_logs_sum ))*100)) - } - } - - private alterScript(data):object{ - return { - script_week:data.script_week, - use_rate:Math.abs(Math.floor((parseInt(data.script_used)/ parseInt(data.script_count ))*100))+'%' - } - } } \ No newline at end of file diff --git a/src/views/home/pages/home/home.vue b/src/views/home/pages/home/home.vue index 6aeca3d..61225ac 100644 --- a/src/views/home/pages/home/home.vue +++ b/src/views/home/pages/home/home.vue @@ -1,184 +1,20 @@ + - - - \ No newline at end of file + \ No newline at end of file diff --git a/src/views/home/pages/layout/layout.ts b/src/views/home/pages/layout/layout.ts index 715caad..eb484a8 100644 --- a/src/views/home/pages/layout/layout.ts +++ b/src/views/home/pages/layout/layout.ts @@ -11,6 +11,7 @@ import HomeParent, { BreadItem } from "@/views/home/Common/HomeParent"; import { EVENT_TYPE, MenuInterface, ProjectInterface } from "@/views/home/Common/Types"; import { Route, RouteRecord } from "vue-router"; import { Menu } from "view-design"; +import store from "@/views/home/store"; @@ -51,53 +52,16 @@ export default class Layout extends HomeParent { public onDropdownEvent(name: string): void { switch (name) { case "logout" : this.logout();break; - case "updateName" : this.updateName();break; + // case "updateName" : this.updateName();break; } } public logout() { - this.$http.get(Url.LOGOUT).then(res => { - this._push('/login') - }); + store.commit('del_token') + this.goPage("login"); } - public updateName(){ - let self = this; - this.$Modal.confirm({ - title:"修改昵称", - render: function(h) { - return h('Input', { - props: { - value: self.$store.getters.user.name, - autofocus: true, - placeholder: 'Please enter your name...' - }, - on: { - input: (val) => { - this.value = val; - } - } - }) - }, - onOk :function() { - self.onVisibleChange(true) - if (!this.value || this.value == self.$store.getters.user.name || this.value == '') { - return; - } - let data = {name:this.value}; - self.$http.put(Url.UPDATE_MY_NAME,data).then(res=>{ - self.success('修改成功',()=>{ - self.$store.getters.user.name = res.data.name - let obj = JSON.parse(window.localStorage.getItem('home')); - obj.user.user.name = res.data.name - window.localStorage.setItem('home',JSON.stringify(obj)); - }) - }).catch((err)=>{ - self.error(err) - }) - } - }) - } + /** * 跳转页面时关闭dropdown @@ -117,24 +81,20 @@ export default class Layout extends HomeParent { private _getMyMenu() { - this.myMenus = [ - {id:1,name:'用户管理',url:'/user',children:[ - {id:2,name:'用户列表',url:'/user/list',children:[]}, - {id:3,name:'用户权限',url:'/user/node',children:[]}, - {id:4,name:'用户菜单',url:'/user/menu',children:[]}, - ]}, - {id:5,name:'表格',url:'/table',children:[ - {id:6,name:'普通表格',url:'/table/base',children:[]}, - {id:7,name:'复杂表格',url:'/table/complex',children:[]}, - ]} - ] + this.myMenus = [ + {id:1,name:'用户管理',url:'/user',children:[ + {id:2,name:'用户列表',url:'/user/list',children:[]}, + {id:3,name:'用户权限',url:'/user/node',children:[]}, + {id:4,name:'用户菜单',url:'/user/menu',children:[]}, + ]}, + {id:5,name:'表格',url:'/table',children:[ + {id:6,name:'普通表格',url:'/table/base',children:[]}, + {id:7,name:'复杂表格',url:'/table/complex',children:[]}, + ]} + ] } - private _getMyProject() { - this.$http.get(Url.MY_PROJECT).then(res => { - this.myProject = res.data; - }); - } + private _parseTreeData(list: any[]) { return list.map((item: any) => { diff --git a/src/views/home/pages/layout/layout.vue b/src/views/home/pages/layout/layout.vue index 0c29733..8155c53 100644 --- a/src/views/home/pages/layout/layout.vue +++ b/src/views/home/pages/layout/layout.vue @@ -1,53 +1,53 @@ 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..8d354bf 100644 --- a/src/views/home/pages/login/login.ts +++ b/src/views/home/pages/login/login.ts @@ -39,9 +39,10 @@ export default class Login extends HomeParent { public chainId:number public account:string public nonce:string + public isLogin:boolean = store.state.token.length > 0 - public async btn(){ - if (!this.$store.getters.step){ + public async doLogin(){ + if (!this.isLogin){ try { await this.connect() await this.checkNance() @@ -49,55 +50,22 @@ export default class Login extends HomeParent { 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' @@ -136,7 +104,7 @@ export default class Login extends HomeParent { const res:any = await Http_login(authData) if (!res.errcode && res.token) { store.commit('set_token',res.token) - console.log(store.getters) + this.goPage("home"); } } private async checkNance() { 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/user.ts b/src/views/home/store/user.ts index ac03407..36a4a22 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 { @@ -40,7 +39,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