PersonalRegistration.vue 20 KB

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