index.vue 9.3 KB

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