longyvfengyun
2023-12-25 d8d792a6842832e8f6af6604274c438b25053afe
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
<template>
    <el-form
        label-position="top"
        class="params-dialog">
        <el-row>
            <el-col :span="6"><div style="visibility: hidden">1</div></el-col>
            <el-col :span="12">
                <el-form-item label="用户名">
                    <el-input
                        type="text"
                        placeholder="请输入用户名"
                        resize="none"
                        v-model="userName"></el-input>
                </el-form-item>
            </el-col>
            <el-col :span="6"></el-col>
        </el-row>
        <div class="form-footer">
            <three-btn @click="confirmBindUser">绑定用户</three-btn>
        </div>
    </el-form>
</template>
 
<script>
import SoftUKey from "@/assets/js/tools/SoftUKey";
import SoftKey3W from "@/assets/js/Syunew3";
export default {
    name: "BindStep3",
    props: {
      id: {
          type: String,
          default: ""
      }
    },
    data() {
        return {
            userName: "",
            softUKey: new SoftUKey(SoftKey3W)
        }
    },
    methods: {
        confirmBindUser() {
            let userName = this.userName.trim();
            let id = this.id.trim();
            if(!userName) {
                this.$layer.msg("用户名不能为空");
                return;
            }
            if(!id) {
                this.$layer.msg("uKey的信息不能为空");
                return;
            }
            this.$confirm('确定绑定'+this.userName,'系统提示', {
                type: 'info',
            }).then(()=>{
                this.checkUser(userName, id);
            }).catch(error=>{})
        },
        /**
         * 校验用户是否已经绑定用户
         * @param name  用户名
         * @param id    ukey的信息
         */
        checkUser(name, id) {
            let loading = this.$layer.loading();
            this.$apis.uKey.getUKeyByUName(name).then(res=>{
                let rs = JSON.parse(res.data.result);
                if(rs.code == 1) {
                    this.$layer.msg(name+"已经绑定ukey");
                    // 关闭等待框
                    this.$layer.close(loading);
                }else if(rs.code == -1){
                    this.$layer.msg(name+"用户不存在,请检查输入的用户名");
                    // 关闭等待框
                    this.$layer.close(loading);
                }else {
                    this.softUKey.setUserName(name, this.setUserNameRs);
                    // 关闭等待框
                    this.$layer.close(loading);
 
                }
            }).catch(error=>{
                // 关闭等待框
                this.$layer.close(loading);
                console.log(error);
            });
        },
        setUserNameRs(result) {
            let name = result.userName;
            let id = this.id.trim();
            let publicX = result.PubKeyX;
            let publicY = result.PubKeyY;
            let loading = this.$layer.loading();
            this.bindUkey(name, id, publicX, publicY, loading);
        },
        /**
         * 绑定用户
         * @param name 用户名
         * @param id    ukey的信息
         * @param loading 加载等待框
         */
        bindUkey(name, id, publicX, publicY, loading) {
            if(!loading) {
                loading = this.$layer.loading();
            }
            this.$apis.uKey.bindUKey(name, id, publicX, publicY).then(res=>{
                let rs = JSON.parse(res.data.result);
                if(rs.code == 1) {
                    this.$layer.msg('绑定成功');
                    this.$emit('next');
                }else {
                    this.$layer.msg('绑定失败');
                }
                // 关闭等待框
                this.$layer.close(loading);
            }).catch(error=>{
                // 关闭等待框
                this.$layer.close(loading);
                console.log(error);
            });
        }
    },
}
</script>
 
<style scoped>
 
</style>