register.vue 20 KB

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