register.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. <template>
  2. <div id="userLayout" class="user-layout-wrapper">
  3. <div class="container">
  4. <div class="top">
  5. <div class="desc">
  6. <img class="logo_login" src="@/assets/logo_login.png" alt="" />
  7. </div>
  8. <div class="header">
  9. <a href="/">
  10. <!-- <img src="~@/assets/logo.png" class="logo" alt="logo" /> -->
  11. <span class="title">Gin-Vue-Admin</span>
  12. </a>
  13. </div>
  14. </div>
  15. <div class="main">
  16. <el-form
  17. :model="registerForm"
  18. :rules="rules"
  19. ref="registerForm"
  20. @keyup.enter.native="submitForm"
  21. >
  22. <el-form-item prop="username">
  23. <el-input
  24. placeholder="请输入用户名"
  25. v-model="registerForm.username"
  26. >
  27. <i
  28. class="el-input__icon el-icon-user"
  29. slot="suffix"
  30. ></i></el-input>
  31. </el-form-item>
  32. <el-form-item prop="password">
  33. <el-input
  34. :type="lock === 'lock' ? 'password' : 'text'"
  35. placeholder="请输入密码"
  36. v-model="registerForm.password"
  37. >
  38. <i
  39. :class="'el-input__icon el-icon-' + lock"
  40. @click="changeLock"
  41. slot="suffix"
  42. ></i>
  43. </el-input>
  44. </el-form-item>
  45. <el-form-item prop="rePassword" style="position:relative">
  46. <el-input
  47. :type="lock==='lock'?'password':'text'"
  48. placeholder="请再次输入密码"
  49. v-model="registerForm.rePassword"
  50. >
  51. <i :class="'el-input__icon el-icon-' + lock" @click="changeLock" slot="suffix"></i>
  52. </el-input>
  53. </el-form-item>
  54. <el-form-item>
  55. <el-button type="primary" @click="submitForm" style="width:100%"
  56. >注 册</el-button
  57. >
  58. </el-form-item>
  59. </el-form>
  60. </div>
  61. <div class="footer">
  62. <div class="links">
  63. <a href="http://doc.henrongyi.top/"
  64. ><img src="@/assets/docs.png" class="link-icon"
  65. /></a>
  66. <a href="https://www.yuque.com/flipped-aurora/"
  67. ><img src="@/assets/yuque.png" class="link-icon"
  68. /></a>
  69. <a href="https://github.com/flipped-aurora/gin-vue-admin"
  70. ><img src="@/assets/github.png" class="link-icon"
  71. /></a>
  72. <a href="https://space.bilibili.com/322210472"
  73. ><img src="@/assets/video.png" class="link-icon"
  74. /></a>
  75. </div>
  76. <div class="copyright">
  77. Copyright &copy; 2020 💖flipped-aurora
  78. </div>
  79. </div>
  80. </div>
  81. </div>
  82. </template>
  83. <script>
  84. import { mapActions } from 'vuex'
  85. import { register } from '@/api/user'
  86. export default {
  87. name: 'Register',
  88. data() {
  89. const ratioPassword = (rule, value, callback) => {
  90. if (value != this.registerForm.password) {
  91. return callback(new Error('两次密码不同'))
  92. } else {
  93. callback()
  94. }
  95. }
  96. const checkUsername = (rule, value, callback) => {
  97. if (value.length < 5 || value.length > 12) {
  98. return callback(new Error('请输入正确的用户名'))
  99. } else {
  100. callback()
  101. }
  102. }
  103. const checkPassword = (rule, value, callback) => {
  104. if (value.length < 6 || value.length > 12) {
  105. return callback(new Error('请输入正确的密码'))
  106. } else {
  107. callback()
  108. }
  109. }
  110. return {
  111. lock: 'lock',
  112. registerForm: {
  113. username: '',
  114. password: '',
  115. rePassword: ''
  116. },
  117. rules: {
  118. username: [{ validator: checkUsername, trigger: 'blur' }],
  119. password: [{ validator: checkPassword, trigger: 'blur' }],
  120. rePassword: [{ validator: ratioPassword, trigger: 'blur' }]
  121. }
  122. }
  123. },
  124. methods: {
  125. ...mapActions('user', ['LoginIn']),
  126. async submitForm() {
  127. this.$refs.registerForm.validate(async v => {
  128. if (v) {
  129. const res = await register(this.registerForm)
  130. if (res.code == 0) {
  131. this.$message({
  132. type: 'success',
  133. message: '注册成功',
  134. showClose: true
  135. })
  136. this.$router.push({name:"login"})
  137. }
  138. } else {
  139. this.$message({
  140. type: 'error',
  141. message: '请正确填写注册信息',
  142. showClose: true
  143. })
  144. return false
  145. }
  146. })
  147. },
  148. changeLock() {
  149. this.lock === 'lock' ? (this.lock = 'unlock') : (this.lock = 'lock')
  150. }
  151. }
  152. }
  153. </script>
  154. <style scoped lang="scss">
  155. .login-register-box {
  156. height: 100vh;
  157. .login-box {
  158. width: 40vw;
  159. position: absolute;
  160. left: 50%;
  161. margin-left: -22vw;
  162. top: 5vh;
  163. .logo {
  164. height: 35vh;
  165. width: 35vh;
  166. }
  167. }
  168. }
  169. .link-icon {
  170. width: 20px;
  171. min-width: 20px;
  172. height: 20px;
  173. border-radius: 10px;
  174. }
  175. .vPic {
  176. width: 33%;
  177. height: 38px;
  178. float: right !important;
  179. img {
  180. cursor: pointer;
  181. vertical-align: middle;
  182. }
  183. }
  184. .logo_login {
  185. width: 100px;
  186. }
  187. #userLayout.user-layout-wrapper {
  188. height: 100%;
  189. position: relative;
  190. &.mobile {
  191. .container {
  192. .main {
  193. max-width: 368px;
  194. width: 98%;
  195. }
  196. }
  197. }
  198. .container {
  199. width: 100%;
  200. min-height: 100%;
  201. background: #f0f2f5 url(~@/assets/background.svg) no-repeat 50%;
  202. background-size: 100%;
  203. padding: 110px 0 144px;
  204. a {
  205. text-decoration: none;
  206. }
  207. .top {
  208. text-align: center;
  209. margin-top: -40px;
  210. .header {
  211. height: 44px;
  212. line-height: 44px;
  213. margin-bottom: 30px;
  214. .badge {
  215. position: absolute;
  216. display: inline-block;
  217. line-height: 1;
  218. vertical-align: middle;
  219. margin-left: -12px;
  220. margin-top: -10px;
  221. opacity: 0.8;
  222. }
  223. .logo {
  224. height: 44px;
  225. vertical-align: top;
  226. margin-right: 16px;
  227. border-style: none;
  228. }
  229. .title {
  230. font-size: 33px;
  231. color: rgba(0, 0, 0, 0.85);
  232. font-family: Avenir, "Helvetica Neue", Arial, Helvetica, sans-serif;
  233. font-weight: 600;
  234. position: relative;
  235. top: 2px;
  236. }
  237. }
  238. .desc {
  239. font-size: 14px;
  240. color: rgba(0, 0, 0, 0.45);
  241. margin-top: 12px;
  242. }
  243. }
  244. .main {
  245. min-width: 260px;
  246. width: 368px;
  247. margin: 0 auto;
  248. }
  249. .footer {
  250. position: relative;
  251. width: 100%;
  252. margin: 40px 0 0 0;
  253. text-align: center;
  254. .links {
  255. margin-bottom: 8px;
  256. font-size: 14px;
  257. a {
  258. color: rgba(0, 0, 0, 0.45);
  259. transition: all 0.3s;
  260. &:not(:last-child) {
  261. margin-right: 80px;
  262. }
  263. }
  264. }
  265. .copyright {
  266. color: rgba(0, 0, 0, 0.45);
  267. font-size: 14px;
  268. }
  269. }
  270. }
  271. }
  272. </style>