zhoushihao
2024-06-26 5a84728f49a5c708d21212b1a395bd62684efd48
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
<script setup lang="ts">
  import {useRouter,useRoute} from 'vue-router'
  import { reactive, ref } from 'vue'
  import type { FormProps,FormInstance, FormRules } from 'element-plus'
  import {ElMessage,ElMessageBox} from "element-plus";
  import request from "@/utils/request";
import { Lock,Avatar } from '@element-plus/icons-vue'
  // import {Avatar, UserFilled} from "@element-plus/icons-vue";
 
  import { useI18n } from 'vue-i18n'
  const { t } = useI18n()
  let language = ref(localStorage.getItem('lang') || 'zh')
 
  const router = useRouter()
  const route = useRoute()
  let loginLoadings= ref(false)
  const labelPosition = ref<FormProps['labelPosition']>('right')
 
  //注册用户参数
  const register = reactive({
    userName: '',
    // loginName: '',
    passWord: '',
    confirmPassword:''
  })
 
  /*方法*/
  const checkName = (rule: any, value: any, callback: any) => {
    if (value.trim() === '') {
      callback(new Error(t('login.namea')))
    }else if(value.length>16){
      callback(new Error(t('login.len')))
    }else{
      callback()
    }
  }
 
  const checkPassword = (rule: any, value: any, callback: any) => {
    if (value.trim() === '') {
      callback(new Error(t('login.passnull')))
    }else if(value.length>16 || value.length<6){
      callback(new Error(t('login.leng')))
    }else{
      callback()
    }
  }
 
  const checkConfirmPassword = (rule: any, value: any, callback: any) => {
    if (value.trim() === '') {
      callback(new Error(t('login.spwn')))
    }else if(value !== register.passWord){
      callback(new Error(t('login.depass')))
    }else if(value.length>16 || value.length<6){
      callback(new Error(t('login.leng')))
    }else{
      callback()
    }
  }
 
  const ruleFormRef  = ref<FormInstance>()
  const rules = reactive<FormRules<typeof register>>({
    userName: [{ validator: checkName, trigger: 'blur' }],
    passWord:[{ validator: checkPassword, trigger: 'blur' }],
    confirmPassword:[{ validator: checkConfirmPassword, trigger: 'blur' }],
    // loginName: [{ validator: validateString, trigger: 'blur' }]
  })
 
  const submitForm = (formEl: FormInstance | undefined) => {
    if (!formEl) return
    formEl.validate((valid) => {
      if (valid) {
        loginLoadings.value=true
        request.post('/user/register',
            register).then((res) => {
          if(res['code']==200){
            console.log(res.data)
            ElMessageBox.alert(
                `<strong>用户:<i style="color: #1890FF;">'${res.data.userName}</i>'
                 <br>账号ID:<i style="color: #1890FF;">${res.data.loginName}</i> </strong>`,
                '注册提示:',
                {
                  dangerouslyUseHTMLString: true,
                  confirmButtonText: '登陆',
                  center: true,
                }
            ).then(()=>{
              router.push({
                path:'/login',
                query: {
                  id: res.data.loginName
                }
              })
            })
 
            ElMessage.success(t('register.registerSuccessful'))
            loginLoadings.value=false
          } else {
            ElMessage.error(res['msg'])
            return false
          }
        }).catch(error => {
          ElMessage.error(t('main.connectErr'))
          loginLoadings.value=false
          return false
        })
      }
    })
  }
  const toLogin = () => {
              router.push({
                path:'/login',
              })
  }
</script>
 
<template>
  
  <div class="mainDiv" >
    <div id="main-login">
     <div>
      <div style="position: absolute; left: 8vw; top: 6vw; ">
        <img src="../../src/assets/3.png">
      </div> 
       <div style="position: absolute; left: 15vw; top: 22vw; font-size: 55px;color: rgba(29, 33, 41, 1);">
        {{ $t('northglassMESsystem') }}
      </div>
    </div>
    <div id="div-login">
        <el-form
            @submit.native.prevent
            ref="ruleFormRef"
            :model="register"
            status-icon
            :rules="rules"
            label-width="75px"
        >
          <div id="title">{{ $t('register.newuserregister') }}</div>
        <div id="center">
            <!-- <div style="color: rgba(78, 89, 105, 1);margin-bottom: 10px;">姓名</div> -->
          <el-form-item prop="userName" :label="$t('register.name')">
            <el-input
            style="width: 200px;"
                v-model="register.userName"
                type="text"
                autocomplete="off"
                :prefix-icon="Avatar"
                :placeholder="$t('register.inputname')"
            />
          </el-form-item>
            <!-- <div style="color: rgba(78, 89, 105, 1);margin-bottom: 10px;">密码</div> -->
          <el-form-item prop="passWord" :label="$t('register.password')">
            <el-input
            style="width: 200px;"
                v-model="register.passWord"
                type="password"
                autocomplete="off"
                :prefix-icon="Lock"
                :placeholder="$t('register.pwErr')"
                show-password
            />
          </el-form-item>
            <!-- <div style="color: rgba(78, 89, 105, 1);margin-bottom: 10px;">确认密码</div> -->
          <el-form-item prop="confirmPassword" :label="$t('register.passwordation')">
            <el-input
            style="width: 200px;"
                v-model="register.confirmPassword" 
                type="password"
                :prefix-icon="Lock"
                autocomplete="off"
                show-password
                :placeholder="$t('register.pwErration')"
            />
          </el-form-item>
          <el-form-item id="submitForm">
            <el-button
            :loading="loginLoadings"
                type="primary"
                @click="submitForm(ruleFormRef)"
                plain
            >{{ $t('register.registration') }}
            </el-button>
            <el-button
                type="primary"
                @click="toLogin"
                plain
            >{{ $t('register.false') }}
            </el-button>
 
          </el-form-item>
        </div>
        </el-form>
      </div>
</div>
</div>
</template>
 
<style scoped>
#div-login{
  margin-top: 5%;
  /* margin-top: 20%; */
  /* margin-left: 650px; */
  background-color: #fff;
  border-radius: 4px;
  float: right;
  width: 40%;
  height: 60%;
  min-width: 318px;
  box-shadow: 0 8px 16px 0 rgba(0,0,0,0), 0 6px 5px 0 rgba(0,0,0,0.19);
}
 
#center{
  margin-top: 45px;
  margin-left: 100px;
}
.mainDiv{
  overflow: hidden;
  min-width: 718px;
  background-image: url("../../src/assets/background.jpg");
 
}
#main-login{
  margin: 150px auto 0 auto;
  height: 70vh;
  width: 80vw;
}
#submitForm{
  margin-top: 30px;
  margin-left: -10px;
}
#title{
  font-size: 25px;
  text-align: center;
  margin-top: 10px;
}
</style>