he wei
2025-04-25 53310b6f8b2274c3d68674648446451761edea21
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
149
150
151
<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 class="label" 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">
      <el-button type="primary"  @click="confirmBindUser">绑定用户</el-button>
    </div>
  </el-form>
</template>
 
<script>
    import SoftUKey from "@/utils/SoftUKey";
    import SoftKey3W from "@/utils/Syunew3";
    import useElement from '@/hooks/useElement.js';
 
    const { $loading, $confirm, $message } = useElement();
    import {
        getUKeyByUName,
        bindUKey,
    } from "@/api/user";
    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) {
                    $message("用户名不能为空");
                    return;
                }
                if (!id) {
                    $message("uKey的信息不能为空");
                    return;
                }
                $confirm('绑定' + this.userName, () => {
                    this.checkUser(userName, id);
                });
            },
            /**
             * 校验用户是否已经绑定用户
             * @param name  用户名
             * @param id    ukey的信息
             */
            checkUser(name, id) {
                let loading = $loading();
                getUKeyByUName(name).then(res => {
                    // 1:已经绑定ukey,0:用户不存在 -1:可以绑定
 
                    let { code, msg } = res;
                    loading.close();
                    if (code == 1) {
                        $message(msg);
                    } else if (code == 0) {
                        $message(msg);
                    } else {
                        this.softUKey.setUserName(name, this.setUserNameRs);
                    }
 
                }).catch(error => {
                    // 关闭等待框
                    loading.close();
                    console.log(error);
                });
            },
            setUserNameRs(result) {
                let name = result.userName;
                let id = this.id.trim();
                let publicX = result.PubKeyX;
                let publicY = result.PubKeyY;
                let loading = $loading();
                this.bindUkey(name, id, publicX, publicY, loading);
            },
            /**
             * 绑定用户
             * @param name 用户名
             * @param id    ukey的信息
             * @param loading 加载等待框
             */
            bindUkey(name, id, publicX, publicY, loading) {
                if (!loading) {
                    loading = $loading();
                }
                bindUKey(name, id, publicX, publicY).then(res => {
                    let { code, data } = res;
                    if (code && data) {
                        $message('绑定成功');
                        this.$emit('next');
                    } else {
                        $message('绑定失败');
                    }
                    // 关闭等待框
                    loading.close();
                }).catch(error => {
                    // 关闭等待框
                    loading.close();
                    console.log(error);
                });
            }
        },
    }
</script>
 
<style scoped lang="scss">
.label {
  padding: 4px;
  color: #153953;
  background: transparent;
  font-size: 12px;
  font-weight: bold;
 
  :deep(.el-input) {
    width: 100%;
  }
 
  :deep(.el-input__wrapper) {
    padding: 0;
  }
 
  :deep(.el-input__inner) {
    border-color: #dcdfe6;
    color: #153953;
    background-color: #cccccc;
  }
}
 
 
.form-footer {
  text-align: right;
}
</style>