PersonalRegistration.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542
  1. <template>
  2. <div class="register">
  3. <div class="container">
  4. <div class="content">
  5. <div class="content-top">
  6. <h3>个人注册</h3>
  7. </div>
  8. <div>
  9. <el-form :model="item" :rules="rules2" ref="item" label-width="100px" class="demo-ruleForm">
  10. <el-form-item prop="vipName">
  11. <el-input type="text" v-model="item.vipName" auto-complete="off" placeholder="会员名"></el-input>
  12. </el-form-item>
  13. <el-form-item prop="password">
  14. <el-input type="password" v-model="item.password" auto-complete="off" placeholder="登录密码"></el-input>
  15. <div class="pwd sm" v-show="showMsgTip1">密码强度 <em></em><em></em><em></em><span>弱</span></div>
  16. <div class="pwd md" v-show="showMsgTip2">密码强度 <em></em><em></em><em></em><span>中</span></div>
  17. <div class="pwd lar" v-show="showMsgTip3">密码强度 <em></em><em></em><em></em><span>强</span></div>
  18. <div class="pwd low" v-show="showMsgTip4">密码强度 <em></em><em></em><em></em></div>
  19. </el-form-item>
  20. <el-form-item prop="confirm">
  21. <el-input type="password" v-model="item.confirm" auto-complete="off" placeholder="密码确认"></el-input>
  22. </el-form-item>
  23. <el-form-item prop="mobile">
  24. <el-input v-model="item.mobile" placeholder="手机号码"></el-input>
  25. <span class="tip" v-show="showMsgTip">单个手机号只能注册一个用户</span>
  26. <span class="tip tip-mobile" v-show="mobileRegister">该手机号已被注册</span>
  27. </el-form-item>
  28. <el-form-item prop="code">
  29. <el-input type="text" v-model="item.code"
  30. v-bind:class="{ active: this.codeErrorChecked }" auto-complete="off" class="msg" placeholder="短信验证码"></el-input>
  31. <el-button type="primary" class="code"
  32. v-show="sendPersonalCode"
  33. @click="getCheckCode"
  34. :disabled="this.checkMobile">获取验证码</el-button>
  35. <el-button type="primary" v-show="!sendPersonalCode" class="code code-send">已发送({{personal_time}}s)</el-button>
  36. <span v-show="codeErrorChecked" class="codeError-tip">验证码输入错误</span>
  37. </el-form-item>
  38. <el-form-item>
  39. <!--<el-button type="primary" @click="submitForm('item')" :disabled="!this.item.vipName || !this.item.password || !this.item.confirm || !this.item.code || !this.checked" class="finish">完成注册</el-button>-->
  40. <a class="btn finish" @click="submit"
  41. :disabled="!this.vipNameChecked || !this.passwordChecked || !this.confirmChecked || !this.mobileChecked || !this.codeChecked || !this.checked">完成注册</a>
  42. </el-form-item>
  43. <el-form-item>
  44. <el-checkbox name="type" v-model="checked" @click="checkboxChecked"></el-checkbox>
  45. <span class="agree">我已阅读并同意 <a href="">《优软云服务条款》</a></span>
  46. </el-form-item>
  47. </el-form>
  48. </div>
  49. </div>
  50. <div class="login">已有账号?<a href="/">立即登录</a></div>
  51. </div>
  52. </div>
  53. </template>
  54. <script>
  55. export default {
  56. name: 'PersonalRegistration',
  57. data () {
  58. var validateName = (rule, value, callback) => {
  59. if (value === '') {
  60. callback(new Error('会员名不能为空'))
  61. this.vipNameChecked = false
  62. } else {
  63. if (this.item.vipName !== '') {
  64. if (value.length < 2 || value.length > 20) {
  65. callback(new Error('请填写合适的会员名称,2~20个字符'))
  66. this.vipNameChecked = false
  67. } else {
  68. this.vipNameChecked = true
  69. }
  70. }
  71. }
  72. callback()
  73. }
  74. var validatePass = (rule, value, callback) => {
  75. if (this.item.password !== '') {
  76. if (value.length <= 20 && value.length >= 8) {
  77. var reg1 = /^(?=.{8,20})(((?=.*[0-9])(?=.*[a-z])(?=.*[A-Z]))|((?=.*[0-9])((?=.*[a-zA-Z]))(?=.*[^a-zA-Z0-9]))).*$/
  78. var reg2 = /^(?=.{8,20})(((?=.*[0-9])(?=.*[a-z]))|((?=.*[0-9])(?=.*[A-Z]))).*$/
  79. if (reg1.test(value)) {
  80. // callback(new Error('密码强度强'))
  81. this.showMsgTip3 = true
  82. this.showMsgTip2 = false
  83. this.showMsgTip1 = false
  84. this.showMsgTip4 = false
  85. this.passwordChecked = true
  86. } else if (reg2.test(value)) {
  87. // callback(new Error('密码强度中'))
  88. this.showMsgTip2 = true
  89. this.showMsgTip3 = false
  90. this.showMsgTip1 = false
  91. this.showMsgTip4 = false
  92. this.passwordChecked = true
  93. } else {
  94. this.showMsgTip1 = true
  95. this.showMsgTip3 = false
  96. this.showMsgTip2 = false
  97. this.showMsgTip4 = false
  98. this.passwordChecked = false
  99. }
  100. } else {
  101. this.showMsgTip3 = false
  102. this.showMsgTip2 = false
  103. this.showMsgTip1 = false
  104. this.showMsgTip4 = true
  105. this.passwordChecked = false
  106. }
  107. }
  108. callback()
  109. }
  110. var validatePassTip = (rule, value, callback) => {
  111. if (value === '') {
  112. callback(new Error('请输入密码'))
  113. this.passwordChecked = false
  114. } else {
  115. if (this.item.password !== '') {
  116. if (value.length <= 20 && value.length >= 8) {
  117. var reg1 = /^(?=.{8,20})(((?=.*[0-9])(?=.*[a-z])(?=.*[A-Z]))|((?=.*[0-9])((?=.*[a-zA-Z]))(?=.*[^a-zA-Z0-9]))).*$/
  118. var reg2 = /^(?=.{8,20})(((?=.*[0-9])(?=.*[a-z]))|((?=.*[0-9])(?=.*[A-Z]))).*$/
  119. if (reg1.test(value)) {
  120. this.passwordChecked = true
  121. } else if (reg2.test(value)) {
  122. this.passwordChecked = true
  123. } else {
  124. callback(new Error('密码须为8-20字符的英文、数字混合'))
  125. this.passwordChecked = false
  126. }
  127. } else {
  128. callback(new Error('密码须为8-20字符的英文、数字混合'))
  129. this.passwordChecked = false
  130. }
  131. }
  132. callback()
  133. }
  134. }
  135. var validatePass2 = (rule, value, callback) => {
  136. if (value === '') {
  137. callback(new Error('请再次输入密码'))
  138. this.confirmChecked = false
  139. } else if (value !== this.item.password) {
  140. callback(new Error('两次输入密码不一致!'))
  141. this.confirmChecked = false
  142. } else {
  143. this.confirmChecked = true
  144. callback()
  145. }
  146. }
  147. var validateMobile = (rule, value, callback) => {
  148. if (value === '') {
  149. callback(new Error('请填写正确的手机号'))
  150. this.showMsgTip = false
  151. this.checkMobile = true
  152. this.mobileRegister = false
  153. this.mobileChecked = false
  154. } else {
  155. if (this.item.mobile !== '') {
  156. var reg = /^1([0-9]{10})$/
  157. if (!reg.test(value)) {
  158. callback(new Error('请填写正确的手机号'))
  159. this.showMsgTip = false
  160. this.checkMobile = true
  161. this.mobileRegister = false
  162. this.mobileChecked = false
  163. } else {
  164. this.$http.get(`/api/user/checkMobile`, {params: {mobile: this.item.mobile, mobileArea: ''}})
  165. .then(response => {
  166. if (response.data.hasRegister) {
  167. this.mobileRegister = true
  168. this.showMsgTip = false
  169. this.checkMobile = true
  170. this.mobileChecked = false
  171. } else {
  172. this.showMsgTip = false
  173. this.checkMobile = false
  174. this.mobileRegister = false
  175. this.mobileChecked = true
  176. }
  177. })
  178. }
  179. }
  180. callback()
  181. }
  182. }
  183. var validateCode = (rule, value, callback) => {
  184. if (value === '') {
  185. callback(new Error('请填写正确的验证码'))
  186. this.codeErrorChecked = false
  187. this.codeChecked = false
  188. } else {
  189. if (this.token !== '') {
  190. if (this.item.code !== '' && this.item.mobile !== '') {
  191. let param = new FormData()
  192. param.append('mobile', this.item.mobile)
  193. param.append('code', this.item.code)
  194. param.append('token', this.token)
  195. let config = {
  196. headers: {'Content-Type': 'multipart/form-data'}
  197. }
  198. this.$http.post(`/sso/personal/register/checkCode`, param, config)
  199. .then(response => {
  200. if (response.data.success) {
  201. this.codeChecked = true
  202. this.codeErrorChecked = false
  203. } else {
  204. this.codeErrorChecked = true
  205. this.codeChecked = false
  206. // callback(new Error('验证码输入错误'))
  207. return Promise.reject(response.data)
  208. }
  209. }).catch(err => {
  210. this.$message.error(err.errMsg)
  211. })
  212. }
  213. } else {}
  214. callback()
  215. }
  216. }
  217. return {
  218. item: {
  219. vipName: '',
  220. password: '',
  221. confirm: '',
  222. mobile: '',
  223. code: ''
  224. },
  225. vipNameChecked: false,
  226. passwordChecked: false,
  227. confirmChecked: false,
  228. mobileChecked: false,
  229. codeChecked: false,
  230. codeErrorChecked: false,
  231. showMsgTip: true,
  232. showMsgTip1: false,
  233. showMsgTip2: false,
  234. showMsgTip3: false,
  235. showMsgTip4: false,
  236. checkMobile: true,
  237. checked: true,
  238. token: '',
  239. mobileRegister: false,
  240. sendPersonalCode: true,
  241. personal_time: 0,
  242. rules2: {
  243. vipName: [
  244. { validator: validateName, trigger: 'blur' }
  245. ],
  246. password: [
  247. { validator: validatePassTip, trigger: 'blur' },
  248. { validator: validatePass, trigger: 'change' }
  249. ],
  250. confirm: [
  251. { required: true, validator: validatePass2, trigger: 'blur' }
  252. ],
  253. mobile: [
  254. { validator: validateMobile, trigger: 'blur' }
  255. ],
  256. code: [
  257. { validator: validateCode, trigger: 'blur' }
  258. ]
  259. }
  260. }
  261. },
  262. methods: {
  263. // 我同意是否被选中
  264. checkboxChecked () {
  265. this.checked = !this.checked
  266. },
  267. // 表单提交
  268. submit () {
  269. if (this.vipNameChecked && this.passwordChecked && this.confirmChecked && this.mobileChecked && this.codeChecked) {
  270. var url = window.location.search
  271. var request = {}
  272. if (url.indexOf('?' !== -1)) {
  273. var str = url.substr(1)
  274. var strs = str.split('&')
  275. for (var i = 0; i < strs.length; i++) {
  276. request[strs[i].split('=')[0]] = decodeURI(strs[i].split('=')[1])
  277. }
  278. }
  279. var appId = request['appId'] || ''
  280. let param = new FormData()
  281. param.append('vipName', this.item.vipName)
  282. param.append('password', this.item.password)
  283. param.append('mobile', this.item.mobile)
  284. // param.append('mobileArea', '')
  285. param.append('appId', appId)
  286. param.append('code', this.item.code)
  287. param.append('token', this.token)
  288. let config = {
  289. headers: {'Content-Type': 'multipart/form-data'}
  290. }
  291. this.$http.post('/sso/personal/register', param, config)
  292. .then(response => {
  293. if (response.data.success) {
  294. } else {
  295. return Promise.reject(response.data)
  296. }
  297. }).catch(err => {
  298. this.$message.error(err.errMsg)
  299. })
  300. }
  301. },
  302. // 获取验证码
  303. // async getCode () {
  304. // let { data } = await this.$http.get(`/sso/personal/register/checkCode`, {params: {mobile: this.item.mobile}})
  305. // this.token = data.token
  306. // },
  307. getCheckCode () {
  308. // this.getCode()
  309. this.$http.get(`/sso/personal/register/checkCode`, {params: {mobile: this.item.mobile}})
  310. .then(response => {
  311. this.token = response.data.token
  312. if (this.token !== '') {
  313. this.$message({
  314. message: '验证码已经发送到您的手机,请注意查收',
  315. type: 'success'
  316. })
  317. this.sendPersonalCode = false
  318. this.personal_time = 60
  319. var personalTime = setInterval(() => {
  320. this.personal_time--
  321. if (this.personal_time <= 0) {
  322. this.sendPersonalCode = true
  323. clearInterval(personalTime)
  324. }
  325. }, 1000)
  326. } else {}
  327. }).catch(err => {
  328. this.$message.error(err.errMsg)
  329. })
  330. }
  331. }
  332. }
  333. </script>
  334. <style lang="scss" scoped>
  335. .register {
  336. padding-bottom: 145px;
  337. margin: 0 auto;
  338. width: 100%;
  339. background: #eee;
  340. .container{
  341. padding-top: 50px;
  342. margin: 0 auto;
  343. width: 980px;
  344. text-align: center;
  345. .content{
  346. padding: 0 50px;
  347. margin: 50px auto 0;
  348. width: 100%;
  349. text-align: center;
  350. background: #fff;
  351. .content-top{
  352. height: 80px;
  353. line-height: 80px;
  354. border-bottom: 1px solid #dcdcdc;
  355. h3{
  356. font-family: 'SimHei';
  357. font-size: 24px;
  358. color: #000;
  359. }
  360. }
  361. form {
  362. padding-bottom: 44px;
  363. margin-top: 35px;
  364. input{
  365. padding: 0 0 0 18px;
  366. width: 360px;
  367. height: 44px;
  368. line-height: 44px;
  369. font-size: 14px;
  370. color: #000;
  371. border-radius: 0;
  372. }
  373. span.help{
  374. position: absolute;
  375. right: -230px;
  376. top:0;
  377. font-size: 12px;
  378. color: #f00;
  379. }
  380. i.fa{
  381. position: absolute;
  382. top: 10px;
  383. right: 18px;
  384. font-size: 24px;
  385. color: #a0a0a0;
  386. cursor: pointer;
  387. }
  388. .pwd {
  389. margin: 6px 0 -15px 0;
  390. text-align: left;
  391. font-size: 13px;
  392. em{
  393. display: inline-block;
  394. margin: 0 8px 2px 0;
  395. width: 24px;
  396. height: 6px;
  397. &:first-child{
  398. margin-left: 10px;
  399. }
  400. }
  401. span{
  402. margin-left: 10px;
  403. font-size: 13px;
  404. }
  405. }
  406. .pwd.sm{
  407. color: #8c8c8c;
  408. em {
  409. background: #bfbfbf;
  410. &:first-child{
  411. background: #ff4e00;
  412. }
  413. }
  414. span{
  415. color: #ff4e00;
  416. }
  417. }
  418. .pwd.md{
  419. color: #8c8c8c;
  420. em {
  421. background: #22ac38;
  422. &:nth-child(3){
  423. background: #bfbfbf;
  424. }
  425. }
  426. span{
  427. color: #22ac38;
  428. }
  429. }
  430. .pwd.lar{
  431. color: #8c8c8c;
  432. em {
  433. background: #00a0e9;
  434. }
  435. span{
  436. color: #00a0e9;
  437. }
  438. }
  439. .pwd.low{
  440. color: #8c8c8c;
  441. em{
  442. background: #bfbfbf;
  443. }
  444. }
  445. span.tip{
  446. position: absolute;
  447. top: 3px;
  448. right: -190px;
  449. font-size: 13px;
  450. color: #8c8c8c;
  451. }
  452. span.tip.tip-mobile{
  453. top: 3px;
  454. right: -118px;
  455. color: #ff4949;
  456. font-size: 12px;
  457. }
  458. span.codeError-tip{
  459. position: absolute;
  460. top: 3px;
  461. right: -105px;
  462. color: #ff4949;
  463. font-size: 12px;
  464. }
  465. input.msg{
  466. float: left;
  467. width: 210px;
  468. }
  469. button.msg{
  470. float: right;
  471. width: 130px;
  472. height: 44px;
  473. font-size: 14px;
  474. color: #5a5a5a;
  475. background: #f4f4f4;
  476. border: 1px solid #dcdcdc;
  477. cursor: pointer;
  478. &:disabled{
  479. cursor: not-allowed ;
  480. opacity: .7;
  481. }
  482. }
  483. span.msg.send{
  484. float: right;
  485. width: 130px;
  486. height: 44px;
  487. line-height: 44px;
  488. font-size: 14px;
  489. background: #d2d2d2;
  490. color: #fff;
  491. border: 1px solid #dcdcdc;
  492. }
  493. input[type='checkbox']{
  494. margin: 0 14px 0 55px;
  495. float: left;
  496. width: 16px;
  497. height: 16px;
  498. }
  499. span.agree{
  500. float: left;
  501. margin: 2px 0 0 10px;
  502. font-size: 14px;
  503. color: #8b8b8b;
  504. a{
  505. color: #0076ad;
  506. }
  507. }
  508. .form-group.agree{
  509. margin: 20px auto 0 !important;
  510. }
  511. .submitBtn {
  512. display: inline-block;
  513. margin-top: 34px;
  514. width: 360px;
  515. height: 44px;
  516. line-height: 44px;
  517. font-size: 16px;
  518. color: #fff;
  519. background: #0076AD;
  520. border-radius: 3px;
  521. border: none;
  522. &:disabled{
  523. cursor: not-allowed ;
  524. opacity: .7;
  525. }
  526. }
  527. }
  528. }
  529. .login{
  530. margin-top: 20px;
  531. font-size: 14px;
  532. color: #8c8c8c;
  533. a{
  534. font-size: 14px;
  535. color: #0076ad;
  536. }
  537. }
  538. }
  539. }
  540. </style>