index.vue 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  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. this.isGetphone = true;
  168. let n = 60;
  169. this.getPhoneIntval = setInterval(() => {
  170. if (n > 0) {
  171. n--;
  172. this.phoneCode = "重新获取(" + n + "s)";
  173. } else {
  174. this.getPhoneIntval = null;
  175. clearInterval(this.getPhoneIntval);
  176. this.phoneCode = "获取验证码";
  177. this.isGetphone = false;
  178. }
  179. }, 1000);
  180. },
  181. handleReister() {
  182. this.$refs["registerForm"].validate(async (valid) => {
  183. if (valid) {
  184. const param = {
  185. username: this.form.username,
  186. phone: this.form.phone,
  187. password: this.form.password,
  188. phoneCode: this.form.phoneCode,
  189. };
  190. const { msg } = await register(param);
  191. this.$baseMessage(msg, "success");
  192. }
  193. });
  194. },
  195. },
  196. };
  197. </script>
  198. <style lang="scss" scoped>
  199. .register-container {
  200. height: 100vh;
  201. background: url("~@/assets/login_images/background.jpg") center center fixed
  202. no-repeat;
  203. background-size: cover;
  204. .title {
  205. font-size: 54px;
  206. font-weight: 500;
  207. color: rgba(14, 18, 26, 1);
  208. }
  209. .title-tips {
  210. margin-top: 29px;
  211. font-size: 26px;
  212. font-weight: 400;
  213. color: rgba(14, 18, 26, 1);
  214. text-overflow: ellipsis;
  215. white-space: nowrap;
  216. }
  217. .register-btn {
  218. display: inherit;
  219. width: 220px;
  220. height: 60px;
  221. margin-top: 5px;
  222. border: 0;
  223. &:hover {
  224. opacity: 0.9;
  225. }
  226. }
  227. .register-form {
  228. position: relative;
  229. max-width: 100%;
  230. margin: calc((100vh - 499px) / 2) 10% 10%;
  231. overflow: hidden;
  232. .forget-password {
  233. width: 100%;
  234. margin-top: 40px;
  235. text-align: left;
  236. .forget-password {
  237. width: 129px;
  238. height: 19px;
  239. font-size: 20px;
  240. font-weight: 400;
  241. color: rgba(92, 102, 240, 1);
  242. }
  243. }
  244. .per-code {
  245. width: 100px;
  246. height: 36px;
  247. font-size: 20px;
  248. line-height: 36px;
  249. color: #fff;
  250. text-align: center;
  251. cursor: pointer;
  252. background: #bbc1ce;
  253. }
  254. .phone-code {
  255. width: 120px;
  256. height: 36px;
  257. font-size: 14px;
  258. color: #fff;
  259. border-radius: 3px;
  260. }
  261. }
  262. .tips {
  263. margin-bottom: 10px;
  264. font-size: $base-font-size-default;
  265. color: $base-color-white;
  266. span {
  267. &:first-of-type {
  268. margin-right: 16px;
  269. }
  270. }
  271. }
  272. .title-container {
  273. position: relative;
  274. .title {
  275. margin: 0 auto 40px auto;
  276. font-size: 34px;
  277. font-weight: bold;
  278. color: $base-color-blue;
  279. text-align: center;
  280. }
  281. }
  282. .svg-container {
  283. position: absolute;
  284. top: 14px;
  285. left: 15px;
  286. z-index: $base-z-index;
  287. font-size: 16px;
  288. color: #d7dee3;
  289. cursor: pointer;
  290. user-select: none;
  291. }
  292. .show-pwd {
  293. position: absolute;
  294. top: 14px;
  295. right: 25px;
  296. font-size: 16px;
  297. color: $base-font-color;
  298. cursor: pointer;
  299. user-select: none;
  300. }
  301. ::v-deep {
  302. .el-form-item {
  303. padding-right: 0;
  304. margin: 20px 0;
  305. color: #454545;
  306. background: transparent;
  307. border: 1px solid transparent;
  308. border-radius: 2px;
  309. &__content {
  310. min-height: $base-input-height;
  311. line-height: $base-input-height;
  312. }
  313. &__error {
  314. position: absolute;
  315. top: 100%;
  316. left: 18px;
  317. font-size: $base-font-size-small;
  318. line-height: 18px;
  319. color: $base-color-red;
  320. }
  321. }
  322. .el-input {
  323. box-sizing: border-box;
  324. .el-input__count {
  325. .el-input__count-inner {
  326. background: transparent;
  327. }
  328. }
  329. .el-input__prefix {
  330. left: 15px;
  331. line-height: 56px;
  332. .svg-inline--fa {
  333. width: 20px;
  334. }
  335. }
  336. input {
  337. height: 58px;
  338. padding-left: 45px;
  339. font-size: $base-font-size-default;
  340. line-height: 58px;
  341. color: $base-font-color;
  342. background: #f6f4fc;
  343. border: 0;
  344. caret-color: $base-font-color;
  345. }
  346. }
  347. }
  348. }
  349. </style>