gaoshp
2024-03-25 b8694d86aea1a9154af99ee3e67ce4e6114aa091
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
<template>
    <el-form ref="loginForm" :model="form" :rules="rules" label-width="0" size="large" @keyup.enter="login" class="login-form">
        <el-form-item prop="user">
            <el-input v-model="form.user" prefix-icon="el-icon-user" clearable :placeholder="$t('login.userPlaceholder')" class="inputHeight">
            </el-input>
        </el-form-item>
        <el-form-item prop="password">
            <el-input v-model="form.password" prefix-icon="el-icon-lock" clearable show-password :placeholder="$t('login.PWPlaceholder')" class="inputHeight"></el-input>
        </el-form-item>
        <el-form-item>
            <el-button type="primary" style="width: 100%;" :loading="islogin" @click="login">{{ $t('login.signIn') }}</el-button>
        </el-form-item>
    </el-form>
</template>
 
<script>
    export default {
        data() {
            return {
                userType: 'admin',
                form: {
                    user: "admin",
                    password: "123456",
                    autologin: false
                },
                rules: {
                    user: [
                        {required: true, message: this.$t('login.userError'), trigger: 'blur'}
                    ],
                    password: [
                        {required: true, message: this.$t('login.PWError'), trigger: 'blur'}
                    ]
                },
                islogin: false,
            }
        },
        watch:{
            userType(val){
                if(val == 'admin'){
                    this.form.user = 'admin'
                    this.form.password = 'admin'
                }else if(val == 'user'){
                    this.form.user = 'user'
                    this.form.password = 'user'
                }
            }
        },
        mounted() {
            //this.$HTTP.get('/api/blade-sync/outer-app-config/appStatus')
        },
        methods: {
            async login(){
                var validate = await this.$refs.loginForm.validate().catch(()=>{})
                if(!validate){ return false }
                this.islogin = true
                var data = {
                    username: this.form.user,
                    //password: this.$TOOL.crypto.MD5(this.form.password)
                    password: this.form.password,
                    tenantId: "000000",
                    grant_type: "password",
                    scope: "all"
                }
                //获取菜单
                // var menu = null
                // if(this.form.user == 'admin'){
                //     menu = await this.$API.system.menu.myMenus.get()
                // }else{
                //     menu = await this.$API.demo.menu.get()
                // }
                // if(menu.code == 200){
                //     if(menu.data.menu.length==0){
                //         this.islogin = false
                //         this.$alert("当前用户无任何菜单权限,请联系系统管理员", "无权限访问", {
                //             type: 'error',
                //             center: true
                //         })
                //         return false
                //     }
                //     this.$TOOL.data.set("MENU", menu.data.menu)
                //     this.$TOOL.data.set("PERMISSIONS", menu.data.permissions)
                //     this.$TOOL.data.set("DASHBOARDGRID", menu.data.dashboardGrid)
                // }else{
                //     this.islogin = false
                //     this.$message.warning(menu.message)
                //     return false
                // }
 
                // this.$router.replace({
                //     path: '/'
                // })
                // this.$message.success("Login Success 登录成功")
                // this.islogin = false
 
 
 
                await this.$HTTP.postJ("/api/blade-auth/oauth/token",data).then(res=> {
                    if(res.user_id) {
                        //获取token
                        this.$TOOL.cookie.set("TOKEN", res.access_token, {
                            expires: this.form.autologin? 24*60*60 : 0
                        })
                        res.userName = res.user_name;
                        res.role = ["SA", "admin", "Auditor"];
                        res.dashboard = "0";
                        res.userId =  "1";
                        this.$TOOL.data.set("USER_INFO", res);
                        //获取菜单
                        
                        
                    }else {
                        this.islogin = false;
                        this.$message({
                          showClose: true,
                          message: res.error_description,
                          type: 'error'
                        });
                    }
                })
                await this.$API.system.menu.myMenus.get().then(resp=> {
                            console.log('>>>>>>')
                            if(resp.data.menu.length==0){
                                this.islogin = false
                                this.$alert("当前用户无任何菜单权限,请联系系统管理员", "无权限访问", {
                                    type: 'error',
                                    center: true
                                })
                                return false
                            }
                            this.$TOOL.data.set("MENU", resp.data.menu)
                            this.$TOOL.data.set("PERMISSIONS", resp.data.permissions)
                            this.$TOOL.data.set("DASHBOARDGRID", resp.data.dashboardGrid)
 
                        });
                        this.$router.replace({
                            path: '/'
                        })
                        this.$message.success("Login Success 登录成功")
                        this.islogin = false
            },
        }
    }
</script>
 
<style>
.login-form {margin: 0 auto;margin-top: 46px;width: 354px;}
.inputHeight {height: 60px;line-height: 60px;}
</style>