register.vue 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662
  1. <template>
  2. <div class="go-register 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. <div>
  11. </div>
  12. <el-form-item prop="mobile" class="mobile">
  13. <el-input v-model="item.mobile"
  14. v-bind:class="{active: mobileRegister}"
  15. placeholder="手机号码"></el-input>
  16. <span class="err-tip-msg tip" v-show="showMsgTip">单个手机号只能注册一个用户</span>
  17. <span class="err-tip-msg tip tip-mobile" v-show="mobileRegister">该手机号已被注册</span>
  18. </el-form-item>
  19. <el-form-item prop="captcha" class="captcha" style="overflow: hidden">
  20. <el-input type="text"
  21. v-model="ImgCode"
  22. auto-complete="off"
  23. class="code-input"
  24. @keyup.enter.native="getCheckCode"></el-input>
  25. <img id="captchaImage2" class="code-img" src="/sso/login/checkCode"/>
  26. <a class="code-click" @click="getCode">看不清换一张</a>
  27. </el-form-item>
  28. <el-form-item prop="code">
  29. <el-input type="text" v-model="item.code"
  30. v-bind:class="{ active: 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">{{codeErrorMsg}}</span>
  37. </el-form-item>
  38. <el-form-item class="agree">
  39. <el-checkbox name="type" v-model="checked" @click="checkboxChecked"></el-checkbox>
  40. <span class="agree" v-if="!agreementUrl || (agreementUrl && (JSON.parse(agreementUrl.terms).isUrl))">我已阅读并同意 <a href="/common/agreement" target="_blank">《优软云服务条款》</a></span>
  41. <span class="agree" v-else>我已阅读并同意<a :href="`/common/cityAgreement/?appId=${this.$route.query.appId}`" target="_blank">《{{JSON.parse(agreementUrl.terms).name || ''}}》</a></span>
  42. </el-form-item>
  43. <el-form-item>
  44. <a class="btn finish" @click="waySubmit">确认注册</a>
  45. </el-form-item>
  46. </el-form>
  47. </div>
  48. </div>
  49. <div class="login">已有账号?<a :href="returnLogin">立即登录</a></div>
  50. <loading v-show="isShowLoading"/>
  51. </div>
  52. </div>
  53. </template>
  54. <script>
  55. import md5 from 'js-md5'
  56. import Loading from '~components/common/loading/Loading.vue'
  57. export default {
  58. name: 'PersonalRegistration',
  59. layout: 'sass',
  60. components: {
  61. Loading
  62. },
  63. data () {
  64. var validateMobile = (rule, value, callback) => {
  65. if (value === '') {
  66. callback(new Error('请填写正确的手机号'))
  67. this.showMsgTip = false
  68. this.checkMobile = true
  69. this.mobileRegister = false
  70. this.mobileChecked = false
  71. } else {
  72. if (this.item.mobile !== '') {
  73. var reg = /^1([0-9]{10})$/
  74. if (!reg.test(value)) {
  75. callback(new Error('请填写正确的手机号'))
  76. this.showMsgTip = false
  77. this.checkMobile = true
  78. this.mobileRegister = false
  79. this.mobileChecked = false
  80. } else {
  81. this.$http.get(`/api/user/checkMobile`, {params: {mobile: this.item.mobile, mobileArea: ''}})
  82. .then(response => {
  83. if (response.data.hasRegister) {
  84. this.mobileRegister = true
  85. this.showMsgTip = false
  86. this.checkMobile = true
  87. this.mobileChecked = false
  88. } else {
  89. this.showMsgTip = false
  90. this.checkMobile = false
  91. this.mobileRegister = false
  92. this.mobileChecked = true
  93. }
  94. })
  95. }
  96. }
  97. callback()
  98. }
  99. }
  100. var validateCode = (rule, value, callback) => {
  101. if (value === '') {
  102. callback(new Error('请填写正确的验证码'))
  103. this.codeErrorChecked = false
  104. this.codeChecked = false
  105. } else {
  106. if (this.item.mobile === '') {
  107. callback(new Error('请先填写正确的手机号'))
  108. } else {
  109. if (this.token) {
  110. if (this.item.code.length === 6) {
  111. let param = new FormData()
  112. param.append('mobile', this.item.mobile)
  113. param.append('code', this.item.code)
  114. param.append('token', this.token)
  115. let config = {
  116. headers: {'Content-Type': 'multipart/form-data'}
  117. }
  118. this.$http.post(`/sso/personal/register/checkCode`, param, config)
  119. .then(response => {
  120. if (response.data.success) {
  121. this.codeChecked = true
  122. this.codeErrorChecked = false
  123. } else {
  124. this.codeErrorChecked = true
  125. this.codeChecked = false
  126. return Promise.reject(response.data)
  127. }
  128. }).catch(err => {
  129. this.codeErrorMsg = err.errMsg
  130. })
  131. } else {
  132. callback(new Error('请输入正确的验证码'))
  133. this.codeChecked = false
  134. this.codeErrorChecked = false
  135. }
  136. } else {
  137. callback(new Error('请先获取验证码'))
  138. this.codeChecked = false
  139. this.codeErrorChecked = false
  140. }
  141. }
  142. callback()
  143. }
  144. }
  145. var validateCodeIsEmpty = (rule, value, callback) => {
  146. if (value === '') {
  147. callback(new Error('请填写正确的验证码'))
  148. this.codeErrorChecked = false
  149. this.codeChecked = false
  150. } else {
  151. if (this.item.mobile === '') {
  152. callback(new Error('请先填写正确的手机号'))
  153. } else {
  154. if (this.token) {
  155. if (this.item.code.length === 6) {
  156. let param = new FormData()
  157. param.append('mobile', this.item.mobile)
  158. param.append('code', this.item.code)
  159. param.append('token', this.token)
  160. let config = {
  161. headers: {'Content-Type': 'multipart/form-data'}
  162. }
  163. this.$http.post(`/sso/personal/register/checkCode`, param, config)
  164. .then(response => {
  165. if (response.data.success) {
  166. this.codeChecked = true
  167. this.codeErrorChecked = false
  168. } else {
  169. this.codeErrorChecked = true
  170. this.codeChecked = false
  171. return Promise.reject(response.data)
  172. }
  173. }).catch(err => {
  174. this.codeErrorMsg = err.errMsg
  175. })
  176. } else {
  177. callback(new Error('请输入正确的验证码'))
  178. this.codeChecked = false
  179. this.codeErrorChecked = false
  180. }
  181. } else {
  182. callback(new Error('请先获取验证码'))
  183. this.codeChecked = false
  184. this.codeErrorChecked = false
  185. }
  186. }
  187. callback()
  188. }
  189. }
  190. return {
  191. speediness: false,
  192. ImgCode: '',
  193. item: {
  194. mobile: '',
  195. code: ''
  196. },
  197. isShowLoading: false,
  198. showPasswordError: false,
  199. mobileChecked: false,
  200. codeChecked: false,
  201. codeErrorChecked: false,
  202. showMsgTip: true,
  203. checkMobile: true,
  204. checked: true,
  205. token: '',
  206. mobileRegister: false,
  207. sendPersonalCode: true,
  208. codeErrorMsg: '',
  209. personal_time: 0,
  210. queryLink: '',
  211. appId: '',
  212. returnLogin: '',
  213. rules2: {
  214. mobile: [
  215. { validator: validateMobile, trigger: 'blur' }
  216. ],
  217. code: [
  218. { validator: validateCode, trigger: 'change' },
  219. { validator: validateCodeIsEmpty, trigger: 'blur' }
  220. ]
  221. }
  222. }
  223. },
  224. mounted () {
  225. // 获取链接
  226. this.$nextTick(() => {
  227. this.getUrl()
  228. this.getCode()
  229. })
  230. },
  231. computed: {
  232. loginStyle () {
  233. return this.$store.state.login.loginStyle.data.content
  234. },
  235. agreementUrl () {
  236. return this.$store.state.login.agreementUrl.data.content
  237. }
  238. },
  239. methods: {
  240. // 获取链接
  241. getUrl () {
  242. var url = window.location.search
  243. var request = {}
  244. var origin = window.location.origin
  245. this.returnLogin = origin + '/sassLogin' + url
  246. if (url.indexOf('?' !== -1)) {
  247. var str = url.substr(1)
  248. var strs = str.split('&')
  249. this.queryLink = str
  250. for (var i = 0; i < strs.length; i++) {
  251. request[strs[i].split('=')[0]] = decodeURI(strs[i].split('=')[1])
  252. }
  253. }
  254. this.appId = request['appId'] || ''
  255. },
  256. // 注册
  257. goRegister () {
  258. window.location.href = `/register/enterpriseRegistration${this.queryLink ? '?' + this.queryLink : ''}`
  259. },
  260. // 我同意是否被选中
  261. checkboxChecked () {
  262. this.checked = !this.checked
  263. },
  264. // 快速登录
  265. waySubmit () {
  266. if (this.mobileChecked && this.codeChecked && this.checked) {
  267. this.isShowLoading = true
  268. let param = new FormData()
  269. param.append('mobile', this.item.mobile)
  270. param.append('appId', this.appId)
  271. param.append('code', this.item.code)
  272. param.append('token', this.token)
  273. param.append('t', this.$route.query.tk ? this.$route.query.tk : '')
  274. if (this.$route.query.baseUrl) {
  275. param.append('baseUrl', this.$route.query.baseUrl)
  276. }
  277. if (this.$route.query.returnURL) {
  278. param.append('returnUrl', this.$route.query.returnURL)
  279. }
  280. let config = {
  281. headers: {'Content-Type': 'multipart/form-data'}
  282. }
  283. this.$http.post('/sso/personal/register/sms', param, config)
  284. .then(response => {
  285. this.isShowLoading = false
  286. if (response.data.success) {
  287. if (response.data.content.type) {
  288. if (response.data.content.type === 'mall') {
  289. let param = response.data.content.data
  290. let a = ''
  291. for (let n in param) {
  292. a += (n + '=' + encodeURIComponent(param[n]) + '&')
  293. }
  294. let params = a.substr(0, a.length - 1)
  295. this.isShowLoading = true
  296. if (response.data.content.currentUrl) {
  297. this.$jsonp(`${response.data.content.currentUrl}?${params}`, {
  298. name: 'successCallback',
  299. timeout: 3000
  300. }, (err, data) => {
  301. if (err) {
  302. this.$message.error('注册成功,请点击下方“立即登录”完成登录')
  303. this.isShowLoading = false
  304. throw err
  305. } else {
  306. this.loginOther(response, params)
  307. }
  308. })
  309. } else {
  310. this.loginOther(response, params, 3000)
  311. }
  312. } else if (response.data.content.type === 'city') {
  313. let param = response.data.content.data
  314. let a = ''
  315. for (let n in param) {
  316. a += (n + '=' + encodeURIComponent(param[n]) + '&')
  317. }
  318. let params = a.substr(0, a.length - 1)
  319. this.isShowLoading = true
  320. if (response.data.content.currentUrl) {
  321. this.$jsonp(`${response.data.content.currentUrl}?${params}`, {
  322. name: 'successCallback',
  323. timeout: 3000
  324. }, (err, data) => {
  325. if (err) {
  326. this.$message.error('注册成功,请点击下方“立即登录”完成登录')
  327. this.isShowLoading = false
  328. throw err
  329. } else {
  330. this.loginCityOther(response, params)
  331. }
  332. })
  333. } else {
  334. this.loginCityOther(response, params, 3000)
  335. }
  336. }
  337. } else {
  338. let userUU = response.data.content.userUU
  339. console.log(userUU)
  340. window.location.href = `/overRegister/${userUU}`
  341. }
  342. } else {
  343. return Promise.reject(response.data)
  344. }
  345. }).catch(err => {
  346. this.$message.error(err.errMsg)
  347. this.isShowLoading = false
  348. this.personal_time = 0
  349. })
  350. } else {
  351. if (!this.item.mobile) {
  352. this.$message.error('手机号不能为空')
  353. } else if (!this.mobileChecked) {
  354. this.$message.error('手机号输入有误,请按提示重新输入')
  355. } else if (!this.token) {
  356. this.$message.error('请先获取验证码')
  357. } else if (!this.item.code) {
  358. this.$message.error('验证码不能为空')
  359. } else if (!this.codeChecked) {
  360. this.$message.error('验证码输入有误,请按提示重新输入')
  361. } else if (!this.checked) {
  362. this.$message.error('您对阅读条款未做勾选')
  363. }
  364. }
  365. },
  366. // 获取验证码
  367. getCode () {
  368. let imgSrc = document.getElementById('captchaImage2')
  369. imgSrc.setAttribute('src', '/sso/resetPwd/checkCaptcha?timestamp=' + (new Date()).valueOf())
  370. },
  371. getCheckCode () {
  372. let md5Code = md5(`{mobile=${this.item.mobile},code=${this.ImgCode},salt=sso}`)
  373. this.isShowLoading = true
  374. this.$http.get(`/sso/personal/register/checkCode`, {params: {mobile: this.item.mobile, timestamp: new Date().getTime() + '', code: this.ImgCode, sign: md5Code}})
  375. .then(response => {
  376. this.isShowLoading = false
  377. if (response.data) {
  378. this.token = response.data.token
  379. if (response.data.errMsg) {
  380. this.$message({
  381. message: response.data.errMsg,
  382. type: 'error'
  383. })
  384. this.ImgCode = ''
  385. this.getCode()
  386. return
  387. }
  388. if (this.token !== '') {
  389. this.$message({
  390. message: '验证码已经发送到您的手机,请注意查收',
  391. type: 'success'
  392. })
  393. this.sendPersonalCode = false
  394. this.personal_time = 60
  395. var personalTime = setInterval(() => {
  396. this.personal_time--
  397. if (this.personal_time <= 0) {
  398. this.sendPersonalCode = true
  399. clearInterval(personalTime)
  400. }
  401. }, 1000)
  402. }
  403. } else {
  404. return Promise.reject(response.data)
  405. }
  406. }).catch(err => {
  407. this.isShowLoading = false
  408. this.$message.error(err.errMsg)
  409. })
  410. },
  411. getJsonp: function (url, timeout = 500) {
  412. return new Promise((resolve, reject) => {
  413. this.$jsonp(url, {
  414. name: 'successCallback',
  415. timeout: timeout
  416. }, function (err, data) {
  417. if (err) {
  418. reject(err)
  419. throw err
  420. } else {
  421. resolve(data)
  422. }
  423. })
  424. })
  425. },
  426. crossAfter (url) {
  427. try {
  428. window.location.href = url
  429. } catch (err) {
  430. console.log(err)
  431. }
  432. },
  433. loginOther (response, a, timeout) {
  434. const crossAfter = this.crossAfter
  435. let promises = []
  436. for (let i in response.data.content.loginUrls) {
  437. if (response.data.content.currentUrl !== response.data.content.loginUrls[i]) {
  438. promises.push(this.getJsonp(`${response.data.content.loginUrls[i]}?${a}`))
  439. }
  440. }
  441. let returnUrl = decodeURIComponent(this.$route.query.returnURL)
  442. Promise.all(promises).then(() => {
  443. crossAfter(returnUrl || 'http://www.ubtob.com', timeout)
  444. }).catch(() => {
  445. crossAfter(returnUrl || 'http://www.ubtob.com', timeout)
  446. })
  447. },
  448. loginCityOther (response, a, timeout) {
  449. const crossAfter = this.crossAfter
  450. let promises = []
  451. for (let i in response.data.content.loginUrls) {
  452. if (response.data.content.currentUrl !== response.data.content.loginUrls[i]) {
  453. promises.push(this.getJsonp(`${response.data.content.loginUrls[i]}?${a}`))
  454. }
  455. }
  456. Promise.all(promises).then(() => {
  457. crossAfter('/overRegister/cityRegisterOver/' + this.$store.state.option.fullPath || '/overRegister/cityRegisterOver/' + this.$store.state.option.fullPath, timeout)
  458. }).catch(() => {
  459. crossAfter('/overRegister/cityRegisterOver/' + this.$store.state.option.fullPath || '/overRegister/cityRegisterOver/' + this.$store.state.option.fullPath, timeout)
  460. })
  461. }
  462. }
  463. }
  464. </script>
  465. <style lang="scss" scoped>
  466. .register {
  467. margin: 0 auto;
  468. width: 100%;
  469. background: #eee;
  470. .container{
  471. padding-top: 50px;
  472. margin: 0 auto;
  473. width: 980px;
  474. text-align: center;
  475. background: #fff;
  476. .content{
  477. padding: 0 50px;
  478. margin: 50px auto 0;
  479. width: 100%;
  480. text-align: center;
  481. .content-top{
  482. position: relative;
  483. height: 80px;
  484. line-height: 80px;
  485. border-bottom: 1px solid #dcdcdc;
  486. h3{
  487. font-family: 'SimHei';
  488. font-size: 24px;
  489. color: #000;
  490. }
  491. a.go{
  492. position: absolute;
  493. top: 0;
  494. right: 0;
  495. font-size: 14px;
  496. i{
  497. margin-right: 3px;
  498. }
  499. }
  500. }
  501. .content-tab{
  502. width: 360px;
  503. margin: 0 auto;
  504. height: 50px;
  505. margin-top: 15px;
  506. color: #999;
  507. span{
  508. display:inline-block;
  509. width:50%;
  510. vertical-align:top;
  511. font-size:20px;
  512. text-align: center;
  513. line-height:40px;
  514. height:40px;
  515. border-bottom:2px solid #fff;
  516. cursor:pointer;
  517. &.speed{
  518. color:#3375a7;
  519. border-bottom:2px solid #3375a7;
  520. }
  521. }
  522. }
  523. form {
  524. padding-bottom: 44px;
  525. margin-top: 15px;
  526. input{
  527. padding: 0 0 0 18px;
  528. width: 360px;
  529. height: 44px;
  530. line-height: 44px;
  531. font-size: 14px;
  532. color: #000;
  533. border-radius: 0;
  534. }
  535. span.help{
  536. position: absolute;
  537. right: -230px;
  538. top:0;
  539. font-size: 12px;
  540. color: #f00;
  541. }
  542. i.fa{
  543. position: absolute;
  544. top: 10px;
  545. right: 18px;
  546. font-size: 24px;
  547. color: #a0a0a0;
  548. cursor: pointer;
  549. }
  550. span.tip{
  551. position: absolute;
  552. top: 40px;
  553. left: 0;
  554. font-size: 12px;
  555. color: #8c8c8c;
  556. &.tip-mobile{
  557. color: #ff4949;
  558. }
  559. }
  560. .el-form-item__error {
  561. position: static;
  562. margin: 0 auto;
  563. text-align: left;
  564. }
  565. span.codeError-tip{
  566. position: absolute;
  567. top: 3px;
  568. left: 378px;
  569. width: 200px;
  570. text-align: left;
  571. color: #ff4949;
  572. font-size: 12px;
  573. }
  574. span.tip.passwordError{
  575. position: absolute;
  576. top: 3px;
  577. left: 380px;
  578. width: 200px;
  579. text-align: left;
  580. color: #ff4949;
  581. font-size: 12px;
  582. }
  583. input.msg{
  584. float: left;
  585. width: 210px;
  586. }
  587. button.msg{
  588. float: right;
  589. width: 130px;
  590. height: 44px;
  591. font-size: 14px;
  592. color: #5a5a5a;
  593. background: #f4f4f4;
  594. border: 1px solid #dcdcdc;
  595. cursor: pointer;
  596. &:disabled{
  597. cursor: not-allowed ;
  598. opacity: .7;
  599. }
  600. }
  601. span.msg.send{
  602. float: right;
  603. width: 130px;
  604. height: 44px;
  605. line-height: 44px;
  606. font-size: 14px;
  607. background: #d2d2d2;
  608. color: #fff;
  609. border: 1px solid #dcdcdc;
  610. }
  611. input[type='checkbox']{
  612. margin: 0 14px 0 55px;
  613. float: left;
  614. width: 16px;
  615. height: 16px;
  616. }
  617. span.agree{
  618. float: left;
  619. margin: 1px 0 0 10px;
  620. font-size: 14px;
  621. color: #8b8b8b;
  622. a{
  623. color: #0076ad;
  624. }
  625. }
  626. .form-group.agree{
  627. margin: 20px auto 0 !important;
  628. }
  629. .submitBtn {
  630. display: inline-block;
  631. width: 360px;
  632. height: 44px;
  633. line-height: 44px;
  634. font-size: 16px;
  635. color: #fff;
  636. background: #0076AD;
  637. border-radius: 3px;
  638. border: none;
  639. &:disabled{
  640. cursor: not-allowed ;
  641. opacity: .7;
  642. }
  643. }
  644. }
  645. }
  646. .login{
  647. margin-top: 20px;
  648. font-size: 14px;
  649. color: #8c8c8c;
  650. a{
  651. font-size: 14px;
  652. color: #0076ad;
  653. }
  654. }
  655. }
  656. }
  657. .footer{
  658. padding: 50px 0;
  659. }
  660. </style>