PersonalRegistration.vue 18 KB

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