index.vue 8.7 KB

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