Register.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. <template>
  2. <el-container class="register-view">
  3. <div>
  4. <el-form :model="registerForm" status-icon :rules="rules" ref="registerForm" label-width="80px"
  5. class="web-ruleForm">
  6. <div class="register-brand">
  7. <img class="logo" src="../../public/logo.png" />
  8. <div>欢迎成为盒子IM的用户</div>
  9. </div>
  10. <el-form-item label="用户名" prop="userName">
  11. <el-input type="userName" v-model="registerForm.userName" autocomplete="off"
  12. placeholder="用户名(登录使用)"></el-input>
  13. </el-form-item>
  14. <el-form-item label="昵称" prop="nickName">
  15. <el-input type="nickName" v-model="registerForm.nickName" autocomplete="off"
  16. placeholder="昵称"></el-input>
  17. </el-form-item>
  18. <el-form-item label="密码" prop="password">
  19. <el-input type="password" v-model="registerForm.password" autocomplete="off"
  20. placeholder="密码"></el-input>
  21. </el-form-item>
  22. <el-form-item label="确认密码" prop="confirmPassword">
  23. <el-input type="password" v-model="registerForm.confirmPassword" autocomplete="off"
  24. placeholder="确认密码"></el-input>
  25. </el-form-item>
  26. <el-form-item>
  27. <el-button type="primary" @click="submitForm('registerForm')">注册</el-button>
  28. <el-button @click="resetForm('registerForm')">清空</el-button>
  29. </el-form-item>
  30. <div class="to-login">
  31. <router-link to="/login">已有账号,前往登录</router-link>
  32. </div>
  33. </el-form>
  34. </div>
  35. <icp></icp>
  36. </el-container>
  37. </template>
  38. <script>
  39. import Icp from '../components/common/Icp.vue'
  40. export default {
  41. name: "login",
  42. components: {
  43. Icp
  44. },
  45. data() {
  46. var checkUserName = (rule, value, callback) => {
  47. if (!value) {
  48. return callback(new Error('请输入用户名'));
  49. }
  50. callback();
  51. };
  52. var checkNickName = (rule, value, callback) => {
  53. if (!value) {
  54. return callback(new Error('请输入昵称'));
  55. }
  56. callback();
  57. };
  58. var checkPassword = (rule, value, callback) => {
  59. if (value === '') {
  60. return callback(new Error('请输入密码'));
  61. }
  62. callback();
  63. };
  64. var checkConfirmPassword = (rule, value, callback) => {
  65. if (value === '') {
  66. return callback(new Error('请输入密码'));
  67. }
  68. if (value != this.registerForm.password) {
  69. return callback(new Error('两次密码输入不一致'));
  70. }
  71. callback();
  72. };
  73. return {
  74. registerForm: {
  75. userName: '',
  76. nickName: '',
  77. password: '',
  78. confirmPassword: ''
  79. },
  80. rules: {
  81. userName: [{
  82. validator: checkUserName,
  83. trigger: 'blur'
  84. }],
  85. nickName: [{
  86. validator: checkNickName,
  87. trigger: 'blur'
  88. }],
  89. password: [{
  90. validator: checkPassword,
  91. trigger: 'blur'
  92. }],
  93. confirmPassword: [{
  94. validator: checkConfirmPassword,
  95. trigger: 'blur'
  96. }]
  97. }
  98. };
  99. },
  100. methods: {
  101. submitForm(formName) {
  102. this.$refs[formName].validate((valid) => {
  103. if (valid) {
  104. this.$http({
  105. url: "/register",
  106. method: 'post',
  107. data: this.registerForm
  108. })
  109. .then((data) => {
  110. this.$message.success("注册成功!");
  111. })
  112. }
  113. });
  114. },
  115. resetForm(formName) {
  116. this.$refs[formName].resetFields();
  117. }
  118. }
  119. }
  120. </script>
  121. <style scoped lang="scss">
  122. .register-view {
  123. position: fixed;
  124. display: flex;
  125. justify-content: space-around;
  126. align-items: center;
  127. width: 100%;
  128. height: 100%;
  129. background: rgb(232, 242, 255);
  130. .web-ruleForm {
  131. width: 500px;
  132. height: 450px;
  133. padding: 20px;
  134. background: white;
  135. opacity: 0.9;
  136. box-shadow: 0px 0px 1px #ccc;
  137. border-radius: 3px;
  138. overflow: hidden;
  139. border-radius: 3%;
  140. .register-brand {
  141. display: flex;
  142. justify-content: center;
  143. align-items: center;
  144. line-height: 50px;
  145. margin: 20px 0 30px 0;
  146. font-size: 22px;
  147. font-weight: 600;
  148. letter-spacing: 2px;
  149. text-align: center;
  150. text-transform: uppercase;
  151. .logo {
  152. width: 30px;
  153. height: 30px;
  154. margin-right: 10px;
  155. }
  156. }
  157. .to-login {
  158. display: flex;
  159. flex-direction: row-reverse;
  160. line-height: 40px;
  161. text-align: left;
  162. padding-left: 20px;
  163. }
  164. }
  165. }
  166. </style>