index.vue 8.7 KB

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