index.vue 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  1. <template>
  2. <div class="register-container">
  3. <el-alert
  4. v-if="nodeEnv !== 'development'"
  5. title="beautiful boys and girls欢迎加入vue-admin-beautifulQQ群:972435319"
  6. type="success"
  7. :closable="false"
  8. style="position: fixed"
  9. ></el-alert>
  10. <el-row>
  11. <el-col :xs="24" :sm="24" :md="12" :lg="16" :xl="16">
  12. <div style="color: transparent">占位符</div>
  13. </el-col>
  14. <el-col :xs="24" :sm="24" :md="12" :lg="8" :xl="8">
  15. <el-form
  16. ref="registerForm"
  17. :model="form"
  18. class="register-form"
  19. :rules="registerRules"
  20. size="mini"
  21. >
  22. <el-form-item prop="username">
  23. <el-input
  24. v-model.trim="form.username"
  25. v-focus
  26. style="margin-top: 20px"
  27. type="text"
  28. placeholder="请输入用户名"
  29. auto-complete="off"
  30. >
  31. <vab-icon slot="prefix" :icon="['fas', 'user-alt']"></vab-icon>
  32. </el-input>
  33. </el-form-item>
  34. <el-form-item prop="phone">
  35. <el-input
  36. v-model.trim="form.phone"
  37. type="text"
  38. placeholder="请输入手机号"
  39. maxlength="11"
  40. show-word-limit
  41. autocomplete="off"
  42. >
  43. <vab-icon slot="prefix" :icon="['fas', 'mobile-alt']"></vab-icon>
  44. </el-input>
  45. </el-form-item>
  46. <el-form-item prop="phoneCode" style="position: relative">
  47. <el-input
  48. v-model.trim="form.phoneCode"
  49. type="text"
  50. placeholder="手机验证码"
  51. >
  52. <vab-icon
  53. slot="prefix"
  54. :icon="['fas', 'envelope-open']"
  55. ></vab-icon>
  56. </el-input>
  57. <el-button
  58. type="primary"
  59. class="show-pwd phone-code"
  60. :disabled="isGetphone"
  61. @click="getPhoneCode"
  62. >
  63. {{ phoneCode }}
  64. </el-button>
  65. </el-form-item>
  66. <el-form-item prop="password">
  67. <el-input
  68. v-model.trim="form.password"
  69. type="password"
  70. placeholder="设置密码"
  71. autocomplete="new-password"
  72. >
  73. <vab-icon slot="prefix" :icon="['fas', 'unlock']"></vab-icon>
  74. </el-input>
  75. </el-form-item>
  76. <el-form-item>
  77. <el-button
  78. class="register-btn"
  79. type="primary"
  80. @click.native.prevent="handleReister"
  81. >
  82. 注册
  83. </el-button>
  84. <router-link to="/login">
  85. <div style="margin-top: 20px">登录</div>
  86. </router-link>
  87. </el-form-item>
  88. </el-form>
  89. </el-col>
  90. </el-row>
  91. </div>
  92. </template>
  93. <script>
  94. import { isPassword, isPhone } from '@/utils/validate'
  95. import { register } from '@/api/user'
  96. export default {
  97. username: 'Register',
  98. directives: {
  99. focus: {
  100. inserted(el) {
  101. el.querySelector('input').focus()
  102. },
  103. },
  104. },
  105. data() {
  106. const validateusername = (rule, value, callback) => {
  107. if ('' == value) {
  108. callback(new Error('用户名不能为空'))
  109. } else {
  110. callback()
  111. }
  112. }
  113. const validatePassword = (rule, value, callback) => {
  114. if (!isPassword(value)) {
  115. callback(new Error('密码不能少于6位'))
  116. } else {
  117. callback()
  118. }
  119. }
  120. const validatePhone = (rule, value, callback) => {
  121. if (!isPhone(value)) {
  122. callback(new Error('请输入正确的手机号'))
  123. } else {
  124. callback()
  125. }
  126. }
  127. return {
  128. isGetphone: false,
  129. getPhoneIntval: null,
  130. phoneCode: '获取验证码',
  131. showRegister: false,
  132. nodeEnv: process.env.NODE_ENV,
  133. title: this.$baseTitle,
  134. form: {},
  135. registerRules: {
  136. username: [
  137. { required: true, trigger: 'blur', message: '请输入用户名' },
  138. { max: 20, trigger: 'blur', message: '最多不能超过20个字' },
  139. { validator: validateusername, trigger: 'blur' },
  140. ],
  141. phone: [
  142. { required: true, trigger: 'blur', message: '请输入手机号码' },
  143. { validator: validatePhone, trigger: 'blur' },
  144. ],
  145. password: [
  146. { required: true, trigger: 'blur', message: '请输入密码' },
  147. { validator: validatePassword, trigger: 'blur' },
  148. ],
  149. phoneCode: [
  150. { required: true, trigger: 'blur', message: '请输入手机验证码' },
  151. ],
  152. },
  153. loading: false,
  154. passwordType: 'password',
  155. }
  156. },
  157. created() {
  158. document.body.style.overflow = 'hidden'
  159. },
  160. beforeDestroy() {
  161. document.body.style.overflow = 'auto'
  162. this.getPhoneIntval = null
  163. clearInterval(this.getPhoneIntval)
  164. },
  165. methods: {
  166. getPhoneCode() {
  167. if (!isPhone(this.form.phone)) {
  168. //this.$baseMessage('请输入手机号', 'error')
  169. this.$refs['registerForm'].validateField('phone')
  170. return
  171. }
  172. this.isGetphone = true
  173. let n = 60
  174. this.getPhoneIntval = setInterval(() => {
  175. if (n > 0) {
  176. n--
  177. this.phoneCode = '重新获取(' + n + 's)'
  178. } else {
  179. this.getPhoneIntval = null
  180. clearInterval(this.getPhoneIntval)
  181. this.phoneCode = '获取验证码'
  182. this.isGetphone = false
  183. }
  184. }, 1000)
  185. },
  186. handleReister() {
  187. this.$refs['registerForm'].validate(async (valid) => {
  188. if (valid) {
  189. const param = {
  190. username: this.form.username,
  191. phone: this.form.phone,
  192. password: this.form.password,
  193. phoneCode: this.form.phoneCode,
  194. }
  195. const { msg } = await register(param)
  196. this.$baseMessage(msg, 'success')
  197. }
  198. })
  199. },
  200. },
  201. }
  202. </script>
  203. <style lang="scss" scoped>
  204. .register-container {
  205. height: 100vh;
  206. background: url('~@/assets/login_images/background.jpg') center center fixed
  207. no-repeat;
  208. background-size: cover;
  209. .title {
  210. font-size: 54px;
  211. font-weight: 500;
  212. color: rgba(14, 18, 26, 1);
  213. }
  214. .title-tips {
  215. margin-top: 29px;
  216. font-size: 26px;
  217. font-weight: 400;
  218. color: rgba(14, 18, 26, 1);
  219. text-overflow: ellipsis;
  220. white-space: nowrap;
  221. }
  222. .register-btn {
  223. display: inherit;
  224. width: 220px;
  225. height: 60px;
  226. margin-top: 5px;
  227. border: 0;
  228. &:hover {
  229. opacity: 0.9;
  230. }
  231. }
  232. .register-form {
  233. position: relative;
  234. max-width: 100%;
  235. margin: calc((100vh - 499px) / 2) 10% 10%;
  236. overflow: hidden;
  237. .forget-password {
  238. width: 100%;
  239. margin-top: 40px;
  240. text-align: left;
  241. .forget-password {
  242. width: 129px;
  243. height: 19px;
  244. font-size: 20px;
  245. font-weight: 400;
  246. color: rgba(92, 102, 240, 1);
  247. }
  248. }
  249. .per-code {
  250. width: 100px;
  251. height: 36px;
  252. font-size: 20px;
  253. line-height: 36px;
  254. color: #fff;
  255. text-align: center;
  256. cursor: pointer;
  257. background: #bbc1ce;
  258. }
  259. .phone-code {
  260. width: 120px;
  261. height: 36px;
  262. font-size: 14px;
  263. color: #fff;
  264. border-radius: 3px;
  265. }
  266. }
  267. .tips {
  268. margin-bottom: 10px;
  269. font-size: $base-font-size-default;
  270. color: $base-color-white;
  271. span {
  272. &:first-of-type {
  273. margin-right: 16px;
  274. }
  275. }
  276. }
  277. .title-container {
  278. position: relative;
  279. .title {
  280. margin: 0 auto 40px auto;
  281. font-size: 34px;
  282. font-weight: bold;
  283. color: $base-color-blue;
  284. text-align: center;
  285. }
  286. }
  287. .svg-container {
  288. position: absolute;
  289. top: 14px;
  290. left: 15px;
  291. z-index: $base-z-index;
  292. font-size: 16px;
  293. color: #d7dee3;
  294. cursor: pointer;
  295. user-select: none;
  296. }
  297. .show-pwd {
  298. position: absolute;
  299. top: 14px;
  300. right: 25px;
  301. font-size: 16px;
  302. color: $base-font-color;
  303. cursor: pointer;
  304. user-select: none;
  305. }
  306. ::v-deep {
  307. .el-form-item {
  308. padding-right: 0;
  309. margin: 20px 0;
  310. color: #454545;
  311. background: transparent;
  312. border: 1px solid transparent;
  313. border-radius: 2px;
  314. &__content {
  315. min-height: $base-input-height;
  316. line-height: $base-input-height;
  317. }
  318. &__error {
  319. position: absolute;
  320. top: 100%;
  321. left: 18px;
  322. font-size: $base-font-size-small;
  323. line-height: 18px;
  324. color: $base-color-red;
  325. }
  326. }
  327. .el-input {
  328. box-sizing: border-box;
  329. .el-input__count {
  330. .el-input__count-inner {
  331. background: transparent;
  332. }
  333. }
  334. .el-input__prefix {
  335. left: 15px;
  336. line-height: 56px;
  337. .svg-inline--fa {
  338. width: 20px;
  339. }
  340. }
  341. input {
  342. height: 58px;
  343. padding-left: 45px;
  344. font-size: $base-font-size-default;
  345. line-height: 58px;
  346. color: $base-font-color;
  347. background: #f6f4fc;
  348. border: 0;
  349. caret-color: $base-font-color;
  350. }
  351. }
  352. }
  353. }
  354. </style>