<script setup lang="ts">
|
import {useRouter,useRoute} from 'vue-router'
|
import {onMounted, reactive, ref} from 'vue'
|
import type { FormProps,FormInstance, FormRules } from 'element-plus'
|
import {ElMessage,ElMessageBox} from "element-plus";
|
import request from "@/utils/request";
|
import {Avatar, UserFilled} from "@element-plus/icons-vue";
|
|
const router = useRouter()
|
const route = useRoute()
|
let loginLoadings= ref(false)
|
const labelPosition = ref<FormProps['labelPosition']>('right')
|
|
//注册用户参数
|
const register = reactive({
|
customerId: '',
|
loginName: '',
|
password: '',
|
confirmPassword:''
|
})
|
const customerList = ref([])
|
|
/*方法*/
|
onMounted(()=>{
|
getCustomerList()
|
})
|
|
const getCustomerList = () => {
|
request.post(`/customer/getCustomerList`).then((res) => {
|
console.log(res.data)
|
customerList.value = res.data
|
})
|
}
|
|
|
|
const checkCustomerId = (rule: any, value: any, callback: any) => {
|
if (value === '') {
|
callback(new Error('客户未选择'))
|
}else{
|
callback()
|
}
|
}
|
|
const checkName = (rule: any, value: any, callback: any) => {
|
if (value.trim() === '') {
|
callback(new Error('登录名不能为空'))
|
}else if(value.length>11){
|
callback(new Error('长度不能超过11'))
|
}else{
|
callback()
|
}
|
}
|
|
const checkPassword = (rule: any, value: any, callback: any) => {
|
if (value.trim() === '') {
|
callback(new Error('密码不能为空'))
|
}else if(value.length>16 || value.length<6){
|
callback(new Error('密码长度不能低于6或超过16'))
|
}else{
|
callback()
|
}
|
}
|
|
const checkConfirmPassword = (rule: any, value: any, callback: any) => {
|
if (value.trim() === '') {
|
callback(new Error('确认密码不能为空'))
|
}else if(value !== register.password){
|
callback(new Error('两次密码不相同'))
|
}else if(value.length>16 || value.length<6){
|
callback(new Error('密码长度不能低于6或超过16'))
|
}else{
|
callback()
|
}
|
}
|
|
const ruleFormRef = ref<FormInstance>()
|
const rules = reactive<FormRules<typeof register>>({
|
customerId: [{ validator: checkCustomerId, trigger: 'blur' }],
|
loginName: [{ validator: checkName, trigger: 'blur' }],
|
password:[{ validator: checkPassword, trigger: 'blur' }],
|
confirmPassword:[{ validator: checkConfirmPassword, trigger: 'blur' }],
|
})
|
|
const submitForm = (formEl: FormInstance | undefined) => {
|
if (!formEl) return
|
formEl.validate((valid) => {
|
if (valid) {
|
loginLoadings.value=true
|
//register.password = btoa(register.password)
|
request.post('/customerUserLogin/register',
|
register).then((res) => {
|
if(res['code']==200 && res['data'] ==true){
|
ElMessage.success(`注册成功`)
|
} else {
|
ElMessage.error("注册失败,请检查用户名或此客户已存在")
|
return false
|
}
|
}).catch(error => {
|
ElMessage.error("服务器连接失败")
|
return false
|
}).then(() => {
|
loginLoadings.value=false
|
//register.password = atob(register.password)
|
})
|
}
|
})
|
}
|
|
|
|
</script>
|
|
<template>
|
<h2 style="color: #1890FF">
|
<span>
|
<el-icon><UserFilled /></el-icon>
|
<p>北玻ERP客户查询系统注册</p>
|
</span>
|
</h2>
|
<div id="main-div">
|
|
<div id="register">
|
<el-form
|
:label-position="labelPosition"
|
label-width="100px"
|
:model="register"
|
ref="ruleFormRef"
|
status-icon
|
:rules="rules"
|
>
|
<el-form-item label="客户选择:" prop="customerId">
|
<!-- <el-input v-model="register.customerId" />-->
|
<el-select v-model="register.customerId" placeholder="" filterable>
|
<el-option v-for="item in customerList"
|
:value="item['id']"
|
:label="item['customerName']" />
|
</el-select>
|
</el-form-item>
|
<el-form-item label="登录名:" prop="loginName">
|
<el-input v-model="register.loginName" />
|
</el-form-item>
|
<el-form-item label="密码:" prop="password">
|
<el-input type="password" v-model="register.password" />
|
</el-form-item>
|
<el-form-item label="确认密码:" prop="confirmPassword">
|
<el-input type="password" v-model="register.confirmPassword" />
|
</el-form-item>
|
<el-form-item >
|
<el-button
|
:loading="loginLoadings"
|
type="primary"
|
@click="submitForm(ruleFormRef)"
|
>注册
|
</el-button>
|
</el-form-item>
|
</el-form>
|
</div>
|
</div>
|
|
</template>
|
|
<style scoped>
|
#main-div{
|
//overflow: hidden;
|
position: absolute;
|
left:50%;
|
top:55%;
|
transform: translate(-50%, -50%);
|
|
width: 50vw;
|
height: 50vh;
|
min-width: 320px;
|
|
}
|
h2{
|
text-align: center;
|
width: 100vw;
|
}
|
#register{
|
background-color: #FAFAFA;
|
width: 100%;
|
height: 100%;
|
border-radius: 12px;
|
box-shadow: 0 8px 16px 0 rgba(0,0,0,0), 0 6px 5px 0 rgba(0,0,0,0.19);
|
display:flex;
|
align-items:center;
|
justify-content:center;
|
}
|
.el-form{
|
max-width: 300px;
|
}
|
|
</style>
|