register.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598
  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. console.log(this.$route.params.baseUrl)
  274. if (this.mobileChecked && this.codeChecked && this.checked) {
  275. this.isShowLoading = true
  276. let param = new FormData()
  277. param.append('mobile', this.item.mobile)
  278. param.append('appId', this.appId)
  279. param.append('code', this.item.code)
  280. param.append('token', this.token)
  281. param.append('t', this.$route.query.tk ? this.$route.query.tk : '')
  282. if (this.$route.query.baseUrl) {
  283. param.append('baseUrl', this.$route.query.baseUrl)
  284. }
  285. if (this.$route.query.returnURL) {
  286. param.append('returnUrl', this.$route.query.returnURL)
  287. }
  288. let config = {
  289. headers: {'Content-Type': 'multipart/form-data'}
  290. }
  291. this.$http.post('/sso/personal/register/sms', param, config)
  292. .then(response => {
  293. this.isShowLoading = false
  294. if (response.data.success) {
  295. this.isSuccess = false
  296. this.isShowLoading = false
  297. this.getJsonp(decodeURIComponent(this.$route.query.baseUrl))
  298. } else {
  299. return Promise.reject(response.data)
  300. }
  301. }).catch(err => {
  302. this.$message.error(err.errMsg)
  303. this.isShowLoading = false
  304. this.personal_time = 0
  305. })
  306. } else {
  307. if (!this.item.mobile) {
  308. this.$message.error('手机号不能为空')
  309. } else if (!this.mobileChecked) {
  310. this.$message.error('手机号输入有误,请按提示重新输入')
  311. } else if (!this.token) {
  312. this.$message.error('请先获取验证码')
  313. } else if (!this.item.code) {
  314. this.$message.error('验证码不能为空')
  315. } else if (!this.codeChecked) {
  316. this.$message.error('验证码输入有误,请按提示重新输入')
  317. } else if (!this.checked) {
  318. this.$message.error('您对阅读条款未做勾选')
  319. }
  320. }
  321. },
  322. // 获取验证码
  323. getCode () {
  324. let imgSrc = document.getElementById('captchaImage2')
  325. imgSrc.setAttribute('src', '/sso/resetPwd/checkCaptcha?timestamp=' + (new Date()).valueOf())
  326. },
  327. getCheckCode () {
  328. let md5Code = md5(`{mobile=${this.item.mobile},code=${this.ImgCode},salt=sso}`)
  329. this.isShowLoading = true
  330. this.$http.get(`/sso/personal/register/checkCode`, {params: {mobile: this.item.mobile, timestamp: new Date().getTime() + '', code: this.ImgCode, sign: md5Code}})
  331. .then(response => {
  332. this.isShowLoading = false
  333. if (response.data) {
  334. this.token = response.data.token
  335. if (response.data.errMsg) {
  336. this.$message({
  337. message: response.data.errMsg,
  338. type: 'error'
  339. })
  340. this.ImgCode = ''
  341. this.getCode()
  342. return
  343. }
  344. if (this.token !== '') {
  345. this.$message({
  346. message: '验证码已经发送到您的手机,请注意查收',
  347. type: 'success'
  348. })
  349. this.sendPersonalCode = false
  350. this.personal_time = 60
  351. var personalTime = setInterval(() => {
  352. this.personal_time--
  353. if (this.personal_time <= 0) {
  354. this.sendPersonalCode = true
  355. clearInterval(personalTime)
  356. }
  357. }, 1000)
  358. }
  359. } else {
  360. return Promise.reject(response.data)
  361. }
  362. }).catch(err => {
  363. this.isShowLoading = false
  364. this.$message.error(err.errMsg)
  365. })
  366. },
  367. getJsonp: function (url, timeout = 500) {
  368. return new Promise((resolve, reject) => {
  369. this.$jsonp(url, {
  370. name: 'successCallback',
  371. timeout: timeout
  372. }, function (err, data) {
  373. if (err) {
  374. reject(err)
  375. throw err
  376. } else {
  377. resolve(data)
  378. }
  379. })
  380. })
  381. }
  382. }
  383. }
  384. </script>
  385. <style lang="scss" scoped>
  386. .go-register {
  387. position: relative;
  388. bottom: -50px;
  389. margin: 0 auto;
  390. width: 100%;
  391. background: #eee;
  392. .container{
  393. padding-top: 38px!important;
  394. margin: 0 auto;
  395. width: 980px;
  396. text-align: center;
  397. background: #fff;
  398. .content{
  399. padding: 0 50px;
  400. margin: 50px auto 0;
  401. width: 100%;
  402. text-align: center;
  403. .register-success {
  404. padding-top: 40px;
  405. width: 100%;
  406. height: 380px;
  407. i.icon-zhucechenggong1{
  408. font-size: 148px;
  409. color: #00BB00;
  410. }
  411. p{
  412. margin-top: 20px;
  413. font-size: 28px;
  414. color: #333;
  415. }
  416. }
  417. .content-top{
  418. position: relative;
  419. height: 80px;
  420. line-height: 80px;
  421. border-bottom: 1px solid #dcdcdc;
  422. h3{
  423. font-family: 'SimHei';
  424. font-size: 24px;
  425. color: #000;
  426. }
  427. a.go{
  428. position: absolute;
  429. top: 0;
  430. right: 0;
  431. font-size: 14px;
  432. i{
  433. margin-right: 3px;
  434. }
  435. }
  436. }
  437. .content-tab{
  438. width: 360px;
  439. margin: 0 auto;
  440. height: 50px;
  441. margin-top: 15px;
  442. color: #999;
  443. span{
  444. display:inline-block;
  445. width:50%;
  446. vertical-align:top;
  447. font-size:20px;
  448. text-align: center;
  449. line-height:40px;
  450. height:40px;
  451. border-bottom:2px solid #fff;
  452. cursor:pointer;
  453. &.speed{
  454. color:#3375a7;
  455. border-bottom:2px solid #3375a7;
  456. }
  457. }
  458. }
  459. form {
  460. padding-bottom: 44px;
  461. margin-top: 15px;
  462. input{
  463. padding: 0 0 0 18px;
  464. width: 360px;
  465. height: 44px;
  466. line-height: 44px;
  467. font-size: 14px;
  468. color: #000;
  469. border-radius: 0;
  470. }
  471. span.help{
  472. position: absolute;
  473. right: -230px;
  474. top:0;
  475. font-size: 12px;
  476. color: #f00;
  477. }
  478. i.fa{
  479. position: absolute;
  480. top: 10px;
  481. right: 18px;
  482. font-size: 24px;
  483. color: #a0a0a0;
  484. cursor: pointer;
  485. }
  486. span.tip{
  487. position: absolute;
  488. top: 40px;
  489. left: 0;
  490. font-size: 12px;
  491. color: #8c8c8c;
  492. &.tip-mobile{
  493. color: #ff4949;
  494. }
  495. }
  496. .el-form-item__error {
  497. position: static;
  498. margin: 0 auto;
  499. text-align: left;
  500. }
  501. span.codeError-tip{
  502. position: absolute;
  503. top: 3px;
  504. left: 378px;
  505. width: 200px;
  506. text-align: left;
  507. color: #ff4949;
  508. font-size: 12px;
  509. }
  510. span.tip.passwordError{
  511. position: absolute;
  512. top: 3px;
  513. left: 380px;
  514. width: 200px;
  515. text-align: left;
  516. color: #ff4949;
  517. font-size: 12px;
  518. }
  519. input.msg{
  520. float: left;
  521. width: 210px;
  522. }
  523. button.msg{
  524. float: right;
  525. width: 130px;
  526. height: 44px;
  527. font-size: 14px;
  528. color: #5a5a5a;
  529. background: #f4f4f4;
  530. border: 1px solid #dcdcdc;
  531. cursor: pointer;
  532. &:disabled{
  533. cursor: not-allowed ;
  534. opacity: .7;
  535. }
  536. }
  537. span.msg.send{
  538. float: right;
  539. width: 130px;
  540. height: 44px;
  541. line-height: 44px;
  542. font-size: 14px;
  543. background: #d2d2d2;
  544. color: #fff;
  545. border: 1px solid #dcdcdc;
  546. }
  547. input[type='checkbox']{
  548. margin: 0 14px 0 55px;
  549. float: left;
  550. width: 16px;
  551. height: 16px;
  552. }
  553. span.agree{
  554. float: left;
  555. margin: 1px 0 0 10px;
  556. font-size: 14px;
  557. color: #8b8b8b;
  558. a{
  559. color: #0076ad;
  560. }
  561. }
  562. .form-group.agree{
  563. margin: 20px auto 0 !important;
  564. }
  565. .submitBtn {
  566. display: inline-block;
  567. width: 360px;
  568. height: 44px;
  569. line-height: 44px;
  570. font-size: 16px;
  571. color: #fff;
  572. background: #0076AD;
  573. border-radius: 3px;
  574. border: none;
  575. &:disabled{
  576. cursor: not-allowed ;
  577. opacity: .7;
  578. }
  579. }
  580. }
  581. }
  582. .login{
  583. margin-top: 20px;
  584. font-size: 14px;
  585. color: #8c8c8c;
  586. a{
  587. font-size: 14px;
  588. color: #0076ad;
  589. }
  590. }
  591. }
  592. }
  593. .footer{
  594. padding: 50px 0;
  595. }
  596. </style>