<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>
|