index.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515
  1. <template>
  2. <div class="f-main">
  3. <div class="content-top">
  4. <p>个人注册</p>
  5. <a class="go" @click="goRegister"><i class="fa fa-long-arrow-right"></i>企业注册</a>
  6. </div>
  7. <div class="content-tab">
  8. <span :class="{speed: speediness === false}" @click="clickWay(false)">用户名注册</span>
  9. <span :class="{speed: speediness === true}" @click="clickWay(true)">手机号注册</span>
  10. </div>
  11. <div class="f-form">
  12. <div class="page-part" v-if="!speediness">
  13. <mt-field :state="state.vipName"
  14. placeholder="会员名"
  15. :attr="{ maxlength: 20 }"
  16. v-model="vipName"></mt-field>
  17. </div>
  18. <div class="page-part" v-if="!speediness">
  19. <mt-field :state="state.password"
  20. placeholder="密码"
  21. :attr="{ maxlength: 20 }"
  22. v-model="password"
  23. @input.native="codePwd"
  24. type="password"></mt-field>
  25. <template v-if="password">
  26. <p class="pwd">密码强度 <em :class="{sm:step === '弱', md: step === '中', ld:step === '强'}"></em> <em :class="{md: step === '中', ld:step === '强'}"></em> <em :class="{ld:step === '强'}"></em> <span :class="{smstep:step === '弱', mdstep: step === '中', ldstep:step === '强'}" v-text="step">强</span></p>
  27. <p class="pwd">密码须为8-20字符的英文、数字混合</p>
  28. </template>
  29. </div>
  30. <div class="page-part" v-if="!speediness">
  31. <mt-field :state="state.confirm"
  32. placeholder="确认密码"
  33. v-model="confirm"
  34. type="password"></mt-field>
  35. </div>
  36. <div class="page-part">
  37. <mt-field :state="state.mobile"
  38. placeholder="手机号码"
  39. v-model="mobile"
  40. type="tel"></mt-field>
  41. </div>
  42. <div class="page-part">
  43. <mt-field placeholder="验证码" v-model="code">
  44. <img :src="imgSrc" height="45px" width="100px" @click="getCode">
  45. </mt-field>
  46. </div>
  47. <div class="page-part">
  48. <mt-field :state="state.token"
  49. placeholder="短信验证码"
  50. v-model="token"
  51. auto-complete="off">
  52. <span class="token" v-text="tokenText" @click="getCheckCode">获取验证码</span>
  53. </mt-field>
  54. </div>
  55. </div>
  56. <div class="form-btn">
  57. <div class="page-part">
  58. <el-checkbox v-model="checked">我已阅读并同意 <a class="rgba" href="/common/agreement">《优软云服务条款》</a></el-checkbox>
  59. </div>
  60. <mt-button type="primary" size="large" @click.native="allSubmit">完成注册</mt-button>
  61. </div>
  62. </div>
  63. </template>
  64. <script>
  65. import md5 from 'js-md5'
  66. export default {
  67. name: 'registerPerson',
  68. data () {
  69. return {
  70. speediness: false,
  71. imgSrc: '',
  72. code: '',
  73. step: 1,
  74. state: {
  75. vipName: 'error',
  76. password: 'error',
  77. confirm: 'error',
  78. mobile: 'error',
  79. token: 'error',
  80. code: 'error'
  81. },
  82. vipName: '',
  83. password: '',
  84. confirm: '',
  85. mobile: '',
  86. token: '',
  87. tokenCode: '',
  88. tokenText: '获取验证码',
  89. tokenTime: '60',
  90. checked: true
  91. }
  92. },
  93. mounted () {
  94. this.$nextTick(() => {
  95. this.getCode()
  96. })
  97. },
  98. watch: {
  99. 'token': {
  100. handler (newVal) {
  101. if (newVal.length === 6) {
  102. this.codeToken()
  103. }
  104. },
  105. immediate: true
  106. }
  107. },
  108. methods: {
  109. // 切换注册方式
  110. clickWay (type) {
  111. if (this.speediness !== type) {
  112. this.speediness = type
  113. this.imgSrc = ''
  114. this.getCode()
  115. }
  116. },
  117. getCode () {
  118. this.imgSrc = '/sso/resetPwd/checkCaptcha?timestamp=' + (new Date()).valueOf()
  119. },
  120. // 注册
  121. goRegister () {
  122. window.location.href = `/register/enterpriseRegistration${this.$store.state.option.fullPath}`
  123. },
  124. // 验证弹窗
  125. downToast (type) {
  126. this.$toast({
  127. message: type,
  128. iconClass: 'el-icon-warning'
  129. })
  130. },
  131. // 验证会员名
  132. codeVipName () {
  133. let count = this.vipName.length
  134. if (count === 0) {
  135. this.downToast('会员名不能为空')
  136. this.state.vipName = 'error'
  137. } else if (count < 2 || count > 20) {
  138. this.downToast('请填写合适的会员名称,2~20个字符')
  139. this.state.vipName = 'warning'
  140. } else {
  141. this.state.vipName = 'success'
  142. }
  143. },
  144. // 验证密码强度
  145. codePwd () {
  146. let reg1 = /^(?=.{8,20})(((?=.*[0-9])(?=.*[a-z])(?=.*[A-Z]))|((?=.*[0-9])((?=.*[a-zA-Z]))(?=.*[^a-zA-Z0-9]))).*$/
  147. let reg2 = /^(?=.{8,20})(((?=.*[0-9])(?=.*[a-z]))|((?=.*[0-9])(?=.*[A-Z]))).*$/
  148. if (reg1.test(this.password)) {
  149. this.step = '强'
  150. } else if (reg2.test(this.password)) {
  151. this.step = '中'
  152. } else {
  153. this.step = '弱'
  154. }
  155. },
  156. // 验证密码格式
  157. codePwdBlur () {
  158. let reg2 = /^(?=.{8,20})(((?=.*[0-9])(?=.*[a-z]))|((?=.*[0-9])(?=.*[A-Z]))).*$/
  159. if (!this.password) {
  160. this.downToast('请输入密码')
  161. this.state.password = 'error'
  162. } else if (!reg2.test(this.password)) {
  163. this.downToast('密码须为8-20字符的英文、数字混合')
  164. this.state.password = 'warning'
  165. } else {
  166. this.state.password = 'success'
  167. if (this.confirm) {
  168. this.codePassword()
  169. }
  170. }
  171. },
  172. // 验证密码的确认信息
  173. codePassword () {
  174. if (!this.confirm) {
  175. this.downToast('请再次输入密码')
  176. this.state.confirm = 'error'
  177. } else if (this.confirm !== this.password) {
  178. this.downToast('两次输入密码不一致!')
  179. this.state.confirm = 'warning'
  180. } else {
  181. this.state.confirm = 'success'
  182. }
  183. },
  184. // 验证手机号
  185. codeMobile () {
  186. let reg = /^1([0-9]{10})$/
  187. if (!this.mobile) {
  188. this.downToast('请输入手机号')
  189. this.state.mobile = 'error'
  190. } else if (!reg.test(this.mobile)) {
  191. this.downToast('请填写正确的手机号码')
  192. this.state.mobile = 'warning'
  193. } else {
  194. this.$http.get(`/api/user/checkMobile`, {params: {mobile: this.mobile, mobileArea: ''}})
  195. .then(response => {
  196. if (response.data.hasRegister) {
  197. this.downToast('该手机号已被注册,可直接登录')
  198. this.state.mobile = 'warning'
  199. } else {
  200. this.state.mobile = 'success'
  201. }
  202. }).catch((err) => {
  203. this.downToast(err.errMsg)
  204. })
  205. }
  206. },
  207. // 验证-验证码信息
  208. codeToken () {
  209. if (!this.token) {
  210. this.downToast('请先填写验证码')
  211. this.state.token = 'error'
  212. } else {
  213. if (!this.mobile) {
  214. this.downToast('请先填写正确的手机号码')
  215. this.state.token = 'warning'
  216. } else {
  217. if (this.tokenCode) {
  218. let param = new FormData()
  219. param.append('mobile', this.mobile)
  220. param.append('token', this.tokenCode)
  221. param.append('code', this.token)
  222. let config = {
  223. headers: {'Content-Type': 'multipart/form-data'}
  224. }
  225. this.$http.post('/sso/personal/register/checkCode', param, config)
  226. .then(response => {
  227. if (response.data.success) {
  228. this.state.token = 'success'
  229. } else {
  230. this.$toast({
  231. message: response.data.errMsg,
  232. iconClass: 'el-icon-error'
  233. })
  234. }
  235. }).catch((err) => {
  236. this.downToast(err.errMsg)
  237. })
  238. } else {
  239. this.downToast('请点击先获取验证码信息')
  240. this.state.token = 'warning'
  241. }
  242. }
  243. }
  244. },
  245. // 获取验证码
  246. loadCheckCode () {
  247. let md5Code = md5(`{mobile=${this.mobile},code=${this.code},salt=sso}`)
  248. if (this.state.mobile !== 'success') {
  249. this.codeMobile()
  250. } else if (this.code === '') {
  251. this.downToast('请输入验证码后获取!')
  252. } else {
  253. this.$indicator.open('获取中...')
  254. let _this = this
  255. this.$http.get('/sso/personal/register/checkCode', {params: {sign: md5Code, code: this.code, mobile: this.mobile, timestamp: new Date().getTime() + ''}})
  256. .then(response => {
  257. this.$indicator.close()
  258. if (response.data.errMsg) {
  259. this.$toast({
  260. message: response.data.errMsg,
  261. iconClass: 'el-icon-error'
  262. })
  263. this.code = ''
  264. this.getCode()
  265. return
  266. }
  267. if (response.data) {
  268. this.tokenCode = response.data.token
  269. this.$toast({
  270. message: '验证码已经发送到您的手机,请注意查收',
  271. iconClass: 'el-icon-success'
  272. })
  273. this.tokenText = '已发送(' + this.tokenTime + 'S)'
  274. let setTime = setInterval(() => {
  275. _this.tokenTime--
  276. this.tokenText = '已发送(' + this.tokenTime + 'S)'
  277. if (this.tokenTime <= 0) {
  278. clearInterval(setTime)
  279. _this.tokenText = '获取验证码'
  280. _this.tokenTime = 60
  281. }
  282. }, 1000)
  283. }
  284. }).catch((err) => {
  285. this.$indicator.close()
  286. this.downToast(err.errMsg)
  287. })
  288. }
  289. },
  290. // 验证码发送请求
  291. getCheckCode () {
  292. if (this.tokenTime > 0 && this.tokenTime < 60) {
  293. this.downToast('请稍后再点击,我在倒计时')
  294. } else {
  295. this.loadCheckCode()
  296. }
  297. },
  298. // 表单提交
  299. submit () {
  300. if (this.state.vipName !== 'success') {
  301. this.codeVipName()
  302. } else if (this.state.password !== 'success') {
  303. this.codePwdBlur()
  304. } else if (this.state.confirm !== 'success') {
  305. this.codePassword()
  306. } else if (this.state.mobile !== 'success') {
  307. this.codeMobile()
  308. } else if (this.state.token !== 'success') {
  309. this.codeToken()
  310. } else if (this.checked === false) {
  311. this.downToast('您对阅读条款未做勾选')
  312. } else {
  313. this.$indicator.open('注册中...')
  314. let param = new FormData()
  315. param.append('vipName', this.vipName)
  316. param.append('password', this.password)
  317. param.append('mobile', this.mobile)
  318. // param.append('mobileArea', '')
  319. param.append('appId', this.$store.state.option.appId)
  320. param.append('code', this.token)
  321. param.append('token', this.tokenCode)
  322. param.append('t', this.$route.query.tk ? this.$route.query.tk : '')
  323. param.append('returnUrl', this.$route.query.returnURL ? this.$route.query.returnURL : '')
  324. let config = {
  325. header: {'Content-Type': 'multipart/form-data'}
  326. }
  327. this.$http.post('/sso/personal/register', param, config)
  328. .then(response => {
  329. this.$indicator.close()
  330. if (response.data.success) {
  331. if (response.data.content.data) {
  332. let param = response.data.content.data
  333. let a = ''
  334. for (let n in param) {
  335. a += (n + '=' + encodeURIComponent(param[n]) + '&')
  336. }
  337. let params = a.substr(0, a.length - 1)
  338. this.isShowLoading = true
  339. if (response.data.content.currentUrl) {
  340. this.$jsonp(`${response.data.content.currentUrl}?${params}`, {
  341. name: 'successCallback',
  342. timeout: 3000
  343. }, (err, data) => {
  344. if (err) {
  345. this.$message.error('注册成功,请点击下方“立即登录”完成登录')
  346. this.isShowLoading = false
  347. throw err
  348. } else {
  349. this.loginOther(response, params)
  350. }
  351. })
  352. } else {
  353. this.loginOther(response, params, 3000)
  354. }
  355. } else {
  356. let userUU = response.data.content.userUU
  357. window.location.href = `/overRegister/${userUU}`
  358. }
  359. } else if (response.data.error) {
  360. this.$toast({
  361. message: response.data.errMsg,
  362. iconClass: 'el-icon-error'
  363. })
  364. }
  365. }).catch((err) => {
  366. this.$indicator.close()
  367. this.downToast(err.errMsg)
  368. })
  369. }
  370. },
  371. // 快速登录
  372. waySubmit () {
  373. if (this.state.mobile !== 'success') {
  374. this.codeMobile()
  375. } else if (this.state.token !== 'success') {
  376. this.codeToken()
  377. } else if (this.checked === false) {
  378. this.downToast('您对阅读条款未做勾选')
  379. } else {
  380. this.$indicator.open('注册中...')
  381. let param = new FormData()
  382. param.append('mobile', this.mobile)
  383. // param.append('mobileArea', '')
  384. param.append('appId', this.$store.state.option.appId)
  385. param.append('code', this.token)
  386. param.append('token', this.tokenCode)
  387. param.append('t', this.$route.query.tk ? this.$route.query.tk : '')
  388. if (this.$route.query.baseUrl) {
  389. param.append('baseUrl', this.$route.query.baseUrl)
  390. }
  391. if (this.$route.query.returnURL) {
  392. param.append('returnUrl', this.$route.query.returnURL)
  393. }
  394. let config = {
  395. header: {'Content-Type': 'multipart/form-data'}
  396. }
  397. this.$http.post('/sso/personal/register/sms', param, config)
  398. .then(response => {
  399. this.$indicator.close()
  400. if (response.data.success) {
  401. if (response.data.content.data) {
  402. let param = response.data.content.data
  403. let a = ''
  404. for (let n in param) {
  405. a += (n + '=' + encodeURIComponent(param[n]) + '&')
  406. }
  407. let params = a.substr(0, a.length - 1)
  408. this.isShowLoading = true
  409. if (response.data.content.currentUrl) {
  410. this.$jsonp(`${response.data.content.currentUrl}?${params}`, {
  411. name: 'successCallback',
  412. timeout: 3000
  413. }, (err, data) => {
  414. if (err) {
  415. this.$message.error('注册成功,请点击下方“立即登录”完成登录')
  416. this.isShowLoading = false
  417. throw err
  418. } else {
  419. this.loginOther(response, params)
  420. }
  421. })
  422. } else {
  423. this.loginOther(response, params, 3000)
  424. }
  425. } else {
  426. let userUU = response.data.content.userUU
  427. window.location.href = `/overRegister/${userUU}`
  428. }
  429. } else if (response.data.error) {
  430. this.$toast({
  431. message: response.data.errMsg,
  432. iconClass: 'el-icon-error'
  433. })
  434. }
  435. }).catch((err) => {
  436. this.$indicator.close()
  437. this.downToast(err.errMsg)
  438. })
  439. }
  440. },
  441. // 提交注册流程
  442. allSubmit () {
  443. if (this.speediness) {
  444. this.waySubmit()
  445. } else {
  446. this.submit()
  447. }
  448. },
  449. getJsonp: function (url, timeout = 500) {
  450. return new Promise((resolve, reject) => {
  451. this.$jsonp(url, {
  452. name: 'successCallback',
  453. timeout: timeout
  454. }, function (err, data) {
  455. if (err) {
  456. reject(err)
  457. throw err
  458. } else {
  459. resolve(data)
  460. }
  461. })
  462. })
  463. },
  464. crossAfter (url) {
  465. try {
  466. window.location.href = url
  467. } catch (err) {
  468. console.log(err)
  469. }
  470. },
  471. loginOther (response, a, timeout) {
  472. const crossAfter = this.crossAfter
  473. let promises = []
  474. for (let i in response.data.content.loginUrls) {
  475. if (response.data.content.currentUrl !== response.data.content.loginUrls[i]) {
  476. promises.push(this.getJsonp(`${response.data.content.loginUrls[i]}?${a}`))
  477. }
  478. }
  479. let returnUrl = decodeURIComponent(this.$route.query.returnURL)
  480. Promise.all(promises).then(() => {
  481. crossAfter(returnUrl || 'http://www.ubtob.com', timeout)
  482. }).catch(() => {
  483. crossAfter(returnUrl || 'http://www.ubtob.com', timeout)
  484. })
  485. }
  486. }
  487. }
  488. </script>
  489. <style type="text/scss" scoped lang="scss">
  490. .content-tab{
  491. width: 70%;
  492. margin: 0 auto;
  493. margin-top:.3rem;
  494. span{
  495. display:inline-block;
  496. width:49%;
  497. vertical-align:top;
  498. text-align: center;
  499. line-height:.6rem;
  500. height:.6rem;
  501. font-size:16px;
  502. border:1px solid #E7E7E7;
  503. background: #E7E7E7;
  504. color:#999;
  505. &.speed{
  506. color:#3F84F6;
  507. border:1px solid #3F84F6;
  508. background: #fff;
  509. }
  510. }
  511. }
  512. </style>