register.vue 20 KB

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