PersonalRegistration.vue 19 KB

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