register.vue 23 KB

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