SignUp.vue 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  1. <template>
  2. <div class="login" @click='$refs.verify.show = false'>
  3. <div style="height:50px;"></div>
  4. <div class="logo-box">
  5. <img
  6. width="80"
  7. :src="logoImg"
  8. @click="$router.push('/')"
  9. />
  10. <div style="margin-left: 50px">注册</div>
  11. </div>
  12. <div class="login-container">
  13. <!-- 注册 -->
  14. <Form
  15. ref="formRegist"
  16. :model="formRegist"
  17. :rules="ruleInline"
  18. style="width:300px;"
  19. >
  20. <FormItem prop="username">
  21. <i-input
  22. type="text"
  23. v-model="formRegist.username"
  24. clearable
  25. placeholder="用户名"
  26. >
  27. <Icon type="md-person" slot="prepend"></Icon>
  28. </i-input>
  29. </FormItem>
  30. <FormItem prop="password">
  31. <i-input
  32. type="password"
  33. v-model="formRegist.password"
  34. clearable
  35. placeholder="请输入大于6位密码"
  36. >
  37. <Icon type="md-lock" slot="prepend"> </Icon>
  38. </i-input>
  39. </FormItem>
  40. <FormItem prop="mobilePhone">
  41. <i-input
  42. type="text"
  43. v-model="formRegist.mobilePhone"
  44. clearable
  45. placeholder="手机号"
  46. >
  47. <Icon type="md-phone-portrait" slot="prepend"></Icon>
  48. </i-input>
  49. </FormItem>
  50. <FormItem prop="code">
  51. <i-input
  52. type="text"
  53. v-model="formRegist.code"
  54. clearable
  55. placeholder="手机验证码"
  56. >
  57. <Icon
  58. type="ios-text-outline"
  59. style="font-weight: bold"
  60. slot="prepend"
  61. />
  62. <Button slot="append" @click="sendCode">{{ codeMsg }}</Button>
  63. </i-input>
  64. </FormItem>
  65. <FormItem>
  66. <Button @click="verifyBtnClick" long :type="verifyStatus?'success':'default'">{{verifyStatus?'验证通过':'点击完成安全验证'}}</Button>
  67. </FormItem>
  68. <FormItem>
  69. <Button type="error" size="large" @click="handleRegist" long
  70. >注册</Button
  71. >
  72. </FormItem>
  73. <FormItem><span class="color999 ml_20">,表示您同意《<router-link to="/article?id=1371992704333905920" target="_blank">商城用户协议</router-link>》</span></FormItem>
  74. </Form>
  75. <!-- 拼图验证码 -->
  76. <Verify
  77. ref="verify"
  78. class="verify-con"
  79. :verifyType="verifyType"
  80. @change="verifyChange"
  81. ></Verify>
  82. <div class="login-btn">已有账号?<a @click="$router.push('login')">立即登录</a></div>
  83. </div>
  84. <div class="foot">
  85. <Row type="flex" justify="space-around" class="help">
  86. <router-link to="/article" class="item" target="_blank">帮助</router-link>
  87. <router-link to="/article?id=1371779927900160000" class="item" target="_blank">隐私</router-link>
  88. <router-link to="/article?id=1371992704333905920" class="item" target="_blank">条款</router-link>
  89. </Row>
  90. <Row type="flex" justify="center" class="copyright">
  91. Copyright © 2021 - Present
  92. <a href="http://nanyue6688.com" target="_blank" style="margin: 0 5px">南粤商城</a>
  93. 版权所有
  94. </Row>
  95. </div>
  96. </div>
  97. </template>
  98. <script>
  99. import * as RegExp from '@/plugins/RegExp.js';
  100. import { md5 } from '@/plugins/md5.js';
  101. import * as apiLogin from '@/api/login.js';
  102. import { sendSms } from '@/api/common.js';
  103. import Verify from '@/components/verify';
  104. export default {
  105. name: 'Login',
  106. components: { Verify },
  107. data () {
  108. return {
  109. formRegist: {
  110. // 注册表单
  111. mobilePhone: '',
  112. code: '',
  113. username: '',
  114. password: ''
  115. },
  116. ruleInline: {
  117. // 验证规则
  118. username: [{ required: true, message: '请输入用户名' }],
  119. password: [
  120. { required: true, message: '请输入密码' },
  121. { type: 'string', min: 6, message: '密码不能少于6位' }
  122. ],
  123. mobilePhone: [
  124. { required: true, message: '请输入手机号码' },
  125. {
  126. pattern: RegExp.mobile,
  127. trigger: 'blur',
  128. message: '请输入正确的手机号'
  129. }
  130. ],
  131. code: [{ required: true, message: '请输入手机验证码' }]
  132. },
  133. verifyStatus: false, // 是否验证通过
  134. verifyType: 'REGISTER', // 验证状态
  135. codeMsg: '发送验证码', // 提示文字
  136. interval: '', // 定时器
  137. time: 60, // 倒计时
  138. logoImg: '' // logo图
  139. };
  140. },
  141. methods: {
  142. // 注册
  143. handleRegist () {
  144. this.$refs.formRegist.validate((valid) => {
  145. if (valid) {
  146. let data = JSON.parse(JSON.stringify(this.formRegist));
  147. data.password = md5(data.password);
  148. apiLogin.regist(data).then((res) => {
  149. if (res.success) {
  150. this.$Message.success('注册成功!');
  151. this.$router.push('login');
  152. } else {
  153. this.$Message.warning(res.message);
  154. }
  155. });
  156. } else {}
  157. });
  158. },
  159. sendCode () {
  160. if (this.time === 60) {
  161. if (this.formRegist.mobilePhone === '') {
  162. this.$Message.warning('请先填写手机号');
  163. return;
  164. }
  165. if (!this.verifyStatus) {
  166. this.$Message.warning('请先完成安全验证');
  167. return;
  168. }
  169. let params = {
  170. mobile: this.formRegist.mobilePhone,
  171. verificationEnums: 'REGISTER'
  172. };
  173. sendSms(params).then(res => {
  174. if (res.success) {
  175. this.$Message.success('验证码发送成功');
  176. let that = this;
  177. this.interval = setInterval(() => {
  178. that.time--;
  179. if (that.time === 0) {
  180. that.time = 60;
  181. that.codeMsg = '重新发送';
  182. that.verifyStatus = false;
  183. clearInterval(that.interval);
  184. } else {
  185. that.codeMsg = that.time;
  186. }
  187. }, 1000);
  188. } else {
  189. this.$Message.warning(res.message);
  190. }
  191. });
  192. }
  193. },
  194. handleCancel () {
  195. this.$refs.formRegist.resetFields();
  196. },
  197. verifyChange (con) {
  198. if (!con.status) return;
  199. this.$refs.verify.show = false;
  200. this.verifyStatus = true;
  201. },
  202. verifyBtnClick () {
  203. if (!this.verifyStatus) {
  204. this.$refs.verify.init();
  205. }
  206. }
  207. },
  208. mounted () {
  209. this.$refs.formRegist.resetFields();
  210. this.logoImg = this.Cookies.getItem('logo')
  211. },
  212. watch: {
  213. }
  214. };
  215. </script>
  216. <style scoped lang="scss">
  217. .logo-box {
  218. width: 600px;
  219. height: 80px;
  220. margin: 0 auto;
  221. display: flex;
  222. align-items: center;
  223. img {
  224. width: 80px;
  225. cursor: pointer;
  226. }
  227. div {
  228. font-size: 20px;
  229. margin-top: 10px;
  230. }
  231. }
  232. .login-container {
  233. border-top: 2px solid $theme_color;
  234. position: relative;
  235. margin: 0 auto;
  236. width: 600px;
  237. background-color: #fff;
  238. padding: 20px 150px;
  239. .login-btn{
  240. position: absolute;
  241. right: 20px;
  242. top: -45px;
  243. }
  244. }
  245. .verify-con{
  246. position: absolute;
  247. left: 140px;
  248. top: 80px;
  249. z-index: 10;
  250. }
  251. .other-login {
  252. margin: 0 auto;
  253. .ivu-icon {
  254. font-size: 24px;
  255. }
  256. }
  257. .regist {
  258. display: flex;
  259. justify-content: flex-end;
  260. margin-top: -10px;
  261. span {
  262. margin-left: 10px;
  263. &:hover {
  264. cursor: pointer;
  265. color: $theme_color;
  266. }
  267. }
  268. }
  269. .foot {
  270. position: fixed;
  271. bottom: 4vh;
  272. width: 368px;
  273. left: calc(50% - 184px);
  274. color: rgba(0, 0, 0, 0.45);
  275. font-size: 14px;
  276. .help {
  277. margin: 0 auto;
  278. margin-bottom: 1vh;
  279. width: 60%;
  280. .item {
  281. color: rgba(0, 0, 0, 0.45);
  282. }
  283. :hover {
  284. color: rgba(0, 0, 0, 0.65);
  285. }
  286. }
  287. }
  288. </style>