index.vue 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552
  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. <template v-if="step === 1">
  8. <div class="f-form">
  9. <div class="page-part">
  10. <mt-field placeholder="手机号码"
  11. v-model="step1.mobile"
  12. :state="state.mobile"
  13. type="tel"
  14. ></mt-field>
  15. </div>
  16. <div class="page-part">
  17. <mt-field auto-complete="off"
  18. placeholder="短信验证码"
  19. v-model="step1.token"
  20. :state="state.token">
  21. <span class="token" @click="getCheckCode" v-text="tokenText">获取验证码</span>
  22. </mt-field>
  23. </div>
  24. </div>
  25. <div class="form-btn">
  26. <div class="page-part">
  27. <el-checkbox v-model="checked">我已阅读并同意 <a href="/common/agreement" class="rgba">《优软云服务条款》</a></el-checkbox>
  28. </div>
  29. <mt-button type="primary" size="large" @click.native="checkPhone">验证手机</mt-button>
  30. </div>
  31. </template>
  32. <template v-if="step === 2">
  33. <div class="f-form">
  34. <div class="page-part">
  35. <mt-field placeholder="企业名称"
  36. :attr="{ maxlength: 20 }"
  37. v-model="step2.spaceName"
  38. :state="state.spaceName"></mt-field>
  39. </div>
  40. <div class="page-part">
  41. <mt-field placeholder="营业执照号"
  42. v-model="step2.businessCode"
  43. :state="state.businessCode"></mt-field>
  44. </div>
  45. <div class="page-part" v-if="!hasRegister">
  46. <mt-field placeholder="管理员姓名"
  47. v-model="step2.vipName"
  48. :state="state.vipName"></mt-field>
  49. </div>
  50. <div class="page-part" v-if="!hasRegister">
  51. <mt-field placeholder="登录密码"
  52. :attr="{ maxlength: 20 }"
  53. v-model="step2.password"
  54. :state="state.password"
  55. type="password"
  56. auto-complete="new-password"
  57. @input.native="validatePassword"></mt-field>
  58. <template v-if="step2.password">
  59. <p class="pwd">密码强度 <em :class="{sm:progress === '弱', md: progress === '中', ld:progress === '强'}"></em> <em :class="{md: progress === '中', ld:progress === '强'}"></em> <em :class="{ld:progress === '强'}"></em> <span :class="{smstep:progress === '弱', mdstep: progress === '中', ldstep:progress === '强'}" v-text="progress">强</span></p>
  60. <p class="pwd">密码须为8-20字符的英文、数字混合</p>
  61. </template>
  62. </div>
  63. <div class="page-part" v-if="hasRegister">
  64. <mt-field placeholder="登录密码"
  65. v-model="step2.password"
  66. :state="state.password"
  67. type="password"
  68. auto-complete="new-password"></mt-field>
  69. <template v-if="!step2.password">
  70. <p class="pwd" style="text-align:right;"><a href="/reset/forgetPasswordValidationAccount">忘记密码?</a></p>
  71. </template>
  72. <template v-if="step2.password">
  73. <p class="pwd">手机号已注册,请输入原密码</p>
  74. </template>
  75. </div>
  76. <div class="page-part" v-if="!hasRegister">
  77. <mt-field placeholder="密码确认"
  78. v-model="step2.confirm"
  79. :state="state.confirm"
  80. type="password"
  81. auto-complete="new-password"></mt-field>
  82. </div>
  83. <div class="page-part" v-if="!hasEmail">
  84. <mt-field placeholder="联系邮箱"
  85. v-model="step2.email"
  86. :state="state.email"
  87. type="email"></mt-field>
  88. </div>
  89. </div>
  90. <div class="form-btn">
  91. <mt-button type="primary" size="large" @click.native="sureRegister">完成注册</mt-button>
  92. </div>
  93. </template>
  94. </div>
  95. </template>
  96. <script>
  97. export default {
  98. name: 'registerEnterprise',
  99. data () {
  100. return {
  101. step: 1,
  102. state: {
  103. mobile: 'error',
  104. token: 'error',
  105. spaceName: 'error',
  106. businessCode: 'error',
  107. vipName: 'error',
  108. password: 'error',
  109. confirm: 'error',
  110. email: 'success'
  111. },
  112. step1: {
  113. mobile: '',
  114. token: ''
  115. },
  116. step2: {
  117. spaceName: '',
  118. businessCode: '',
  119. vipName: '',
  120. password: '',
  121. confirm: '',
  122. email: ''
  123. },
  124. checked: true,
  125. tokenCode: '',
  126. tokenTime: 60,
  127. tokenText: '获取验证码',
  128. hasRegister: false,
  129. hasEmail: false,
  130. progress: '弱'
  131. }
  132. },
  133. watch: {
  134. 'step1.token': {
  135. handler (newVal) {
  136. if (newVal.length === 6) {
  137. this.validateCode()
  138. }
  139. },
  140. immediate: true
  141. }
  142. },
  143. methods: {
  144. // 注册
  145. goRegister () {
  146. window.location.href = `/register/personalRegistration${this.$store.state.option.fullPath}`
  147. },
  148. // 弹窗处理
  149. downToast (type) {
  150. this.$toast({
  151. message: type,
  152. iconClass: 'el-icon-warning'
  153. })
  154. },
  155. // 验证手机号
  156. validateMobile () {
  157. let reg = /^1[0-9]{10}$/
  158. if (!this.step1.mobile) {
  159. this.downToast('请先填写手机号')
  160. this.state.mobile = 'error'
  161. } else {
  162. if (!reg.test(this.step1.mobile)) {
  163. this.downToast('请填写正确的手机号')
  164. this.state.mobile = 'warning'
  165. } else {
  166. this.state.mobile = 'success'
  167. }
  168. }
  169. },
  170. // 验证正确的验证码
  171. validateCode () {
  172. if (!this.step1.token) {
  173. this.downToast('请先填写验证码')
  174. this.state.token = 'error'
  175. } else {
  176. if (!this.step1.mobile) {
  177. this.downToast('请先填写正确的手机号码')
  178. this.state.token = 'warning'
  179. } else {
  180. if (this.tokenCode) {
  181. let param = new FormData()
  182. param.append('mobile', this.step1.mobile)
  183. param.append('token', this.tokenCode)
  184. param.append('code', this.step1.token)
  185. let config = {
  186. headers: {'Content-Type': 'multipart/form-data'}
  187. }
  188. this.$http.post('/sso/personal/register/checkCode', param, config)
  189. .then(response => {
  190. if (response.data.success) {
  191. this.state.token = 'success'
  192. } else {
  193. this.$toast({
  194. message: response.data.errMsg,
  195. iconClass: 'el-icon-error'
  196. })
  197. }
  198. }).catch((err) => {
  199. this.downToast(err.errMsg)
  200. })
  201. } else {
  202. this.downToast('请点击先获取验证码信息')
  203. this.state.token = 'warning'
  204. }
  205. }
  206. }
  207. },
  208. // 获取验证码
  209. getCheckCode () {
  210. if (this.tokenTime > 0 && this.tokenTime < 60) {
  211. this.downToast('请稍后再点击,我在倒计时')
  212. } else {
  213. this.validateMobile()
  214. if (this.state.mobile === 'success') {
  215. this.$indicator.open('获取中...')
  216. let _this = this
  217. this.$http.get('/sso/personal/register/checkCode', {params: {mobile: this.step1.mobile}})
  218. .then(response => {
  219. this.$indicator.close()
  220. if (response.data) {
  221. this.tokenCode = response.data.token
  222. this.$toast({
  223. message: '验证码已经发送到您的手机,请注意查收',
  224. iconClass: 'el-icon-success'
  225. })
  226. this.tokenText = '已发送(' + this.tokenTime + 'S)'
  227. let setTime = setInterval(() => {
  228. _this.tokenTime--
  229. this.tokenText = '已发送(' + this.tokenTime + 'S)'
  230. if (this.tokenTime <= 0) {
  231. clearInterval(setTime)
  232. _this.tokenText = '获取验证码'
  233. _this.tokenTime = 60
  234. }
  235. }, 1000)
  236. }
  237. }).catch(() => {
  238. this.$indicator.close()
  239. this.downToast('获取失败,请检查网络')
  240. })
  241. }
  242. }
  243. },
  244. // 验证手机
  245. checkPhone () {
  246. this.validateMobile()
  247. this.validateCode()
  248. if (this.state.mobile !== 'success' || this.state.token !== 'success') {
  249. this.downToast('请确认填写部分是否有误')
  250. } else if (this.checked === false) {
  251. this.downToast('您对阅读条款未做勾选')
  252. } else {
  253. this.$indicator.open('验证手机中...')
  254. let param = new FormData()
  255. param.append('mobile', this.step1.mobile)
  256. param.append('code', this.step1.token)
  257. param.append('appId', this.$store.state.option.appId)
  258. param.append('token', this.tokenCode)
  259. let config = {
  260. headers: {'Content-Type': 'multipart/form-data'}
  261. }
  262. this.$http.post('/sso/userspace/register/checkAdminTel', param, config)
  263. .then(response => {
  264. this.$indicator.close()
  265. if (response.data.success) {
  266. response.data.content.hasEmail ? this.hasEmail = true : this.hasEmail = false
  267. response.data.content.hasRegister ? this.hasRegister = true : this.hasRegister = false
  268. this.step = 2
  269. }
  270. }).catch((err) => {
  271. this.$indicator.close()
  272. this.downToast(err.errMsg)
  273. })
  274. }
  275. },
  276. // 验证企业名
  277. validateSpaceName () {
  278. if (!this.step2.spaceName) {
  279. this.downToast('请填写企业名称')
  280. this.state.spaceName = 'error'
  281. } else {
  282. if (this.step2.spaceName.length > 20) {
  283. this.downToast('输入长度过长,限定20个字符以内')
  284. this.state.spaceName = 'warning'
  285. } else {
  286. this.$http.get(`/api/userspace/checkSpaceName`, {params: {spaceName: this.step2.spaceName}})
  287. .then(response => {
  288. if (response.data.success) {
  289. this.state.spaceName = 'success'
  290. } else {
  291. this.state.spaceName = 'warning'
  292. this.downToast(response.data.errMsg)
  293. }
  294. })
  295. }
  296. }
  297. },
  298. // 验证营业号
  299. validateBusinessCode () {
  300. let reg = /^[A-Za-z0-9]+$/
  301. if (!this.step2.businessCode) {
  302. this.downToast('请填写营业执照号')
  303. this.state.businessCode = 'error'
  304. } else {
  305. if (!reg.test(this.step2.businessCode)) {
  306. this.downToast('请填写正确的营业执照号')
  307. this.state.businessCode = 'warning'
  308. } else {
  309. this.$http.get(`/api/userspace/checkBusinessCode`, {params: {businessCode: this.step2.businessCode}})
  310. .then(response => {
  311. if (response.data.success) {
  312. this.state.businessCode = 'success'
  313. } else {
  314. this.state.businessCode = 'warning'
  315. this.downToast(response.data.errMsg)
  316. }
  317. })
  318. }
  319. }
  320. },
  321. // 验证管理员名
  322. validateVipName () {
  323. if (!this.step2.vipName) {
  324. this.downToast('请填写管理员姓名')
  325. this.state.vipName = 'error'
  326. } else {
  327. if (this.step2.vipName.length > 20) {
  328. this.downToast('输入长度请限制在20个字符以内')
  329. this.state.vipName = 'warning'
  330. } else {
  331. this.state.vipName = 'success'
  332. }
  333. }
  334. },
  335. // 验证密码强度
  336. validatePassword () {
  337. let reg1 = /^(?=.{8,20})(((?=.*[0-9])(?=.*[a-z])(?=.*[A-Z]))|((?=.*[0-9])((?=.*[a-zA-Z]))(?=.*[^a-zA-Z0-9]))).*$/
  338. let reg2 = /^(?=.{8,20})(((?=.*[0-9])(?=.*[a-z]))|((?=.*[0-9])(?=.*[A-Z]))).*$/
  339. if (reg1.test(this.step2.password)) {
  340. this.progress = '强'
  341. } else if (reg2.test(this.step2.password)) {
  342. this.progress = '中'
  343. } else {
  344. this.progress = '弱'
  345. }
  346. },
  347. // 验证密码
  348. validatePasswordTip () {
  349. let reg2 = /^(?=.{8,20})(((?=.*[0-9])(?=.*[a-z]))|((?=.*[0-9])(?=.*[A-Z]))).*$/
  350. if (!this.step2.password) {
  351. this.downToast('请输入密码')
  352. this.state.password = 'error'
  353. } else {
  354. if (!reg2.test(this.step2.password)) {
  355. this.downToast('密码须为8-20字符的英文、数字混合')
  356. this.state.password = 'warning'
  357. } else {
  358. this.state.password = 'success'
  359. if (this.step2.confirm) {
  360. this.validateConfirm()
  361. }
  362. }
  363. }
  364. },
  365. // 验证密码
  366. validatePasswordTipHas () {
  367. if (!this.step2.password) {
  368. this.downToast('请输入密码')
  369. this.state.password = 'error'
  370. } else {
  371. this.state.password = 'success'
  372. }
  373. },
  374. // 验证二次密码
  375. validateConfirm () {
  376. if (!this.step2.confirm) {
  377. this.downToast('请再次输入密码')
  378. this.state.confirm = 'error'
  379. } else {
  380. if (this.step2.confirm === this.step2.password) {
  381. this.state.confirm = 'success'
  382. } else {
  383. this.state.confirm = 'warning'
  384. this.downToast('两次输入密码不一致,请重新输入')
  385. }
  386. }
  387. },
  388. // 验证邮箱
  389. validateEmail () {
  390. let reg = /^([\w-])+(\.\w+)*@([\w-])+((\.\w{2,3}){1,3})$/
  391. if (this.step2.email) {
  392. if (!reg.test(this.step2.email)) {
  393. this.downToast('请输入正确的邮箱地址格式')
  394. this.state.email = 'warning'
  395. } else {
  396. this.$http.get('/api/user/checkEmail', {params: {email: this.step2.email}})
  397. .then(response => {
  398. if (response.data.hasRegister) {
  399. this.state.email = 'warning'
  400. this.downToast('该邮箱已被注册')
  401. } else {
  402. this.state.email = 'success'
  403. }
  404. }).catch((err) => {
  405. this.downToast(err.errMsg)
  406. })
  407. }
  408. } else {
  409. // this.downToast('请填写联系邮箱信息')
  410. this.state.email = 'success'
  411. }
  412. },
  413. // 注册请求方法
  414. sbmitRegister () {
  415. this.$indicator.open('注册中...')
  416. let param = new FormData()
  417. param.append('spaceName', this.step2.spaceName)
  418. param.append('businessCode', this.step2.businessCode)
  419. param.append('vipName', this.step2.vipName || '')
  420. param.append('password', this.step2.password)
  421. param.append('email', this.step2.email || '')
  422. param.append('appId', this.$store.state.option.appId)
  423. param.append('inviteSpaceUU', this.$store.state.option.inviteSpaceUU)
  424. param.append('inviteUserUU', this.$store.state.option.inviteUserUU)
  425. param.append('invitationTime', this.$store.state.option.invitationTime)
  426. let config = {
  427. headers: {'Content-Type': 'multipart/form-data'}
  428. }
  429. this.$http.post('/sso/userspace/register', param, config)
  430. .then(response => {
  431. this.$indicator.close()
  432. if (response.data.success) {
  433. if (response.data.content) {
  434. let param = response.data.content.data
  435. let a = ''
  436. for (let n in param) {
  437. a += (n + '=' + encodeURIComponent(param[n]) + '&')
  438. }
  439. let params = a.substr(0, a.length - 1)
  440. this.isShowLoading = true
  441. if (response.data.content.currentUrl) {
  442. this.$jsonp(`${response.data.content.currentUrl}?${params}`, {
  443. name: 'successCallback',
  444. timeout: 3000
  445. }, (err, data) => {
  446. if (err) {
  447. this.$message.error('注册成功,请点击下方“立即登录”完成登录')
  448. this.isShowLoading = false
  449. throw err
  450. } else {
  451. this.loginOther(response, params)
  452. }
  453. })
  454. } else {
  455. this.loginOther(response, params, 3000)
  456. }
  457. } else {
  458. window.location.href = '/overRegister/overEnterprise'
  459. }
  460. } else {
  461. this.downToast(response.data.errMsg)
  462. }
  463. }).catch((err) => {
  464. this.$indicator.close()
  465. this.downToast(err.errMsg)
  466. })
  467. },
  468. // 企业注册
  469. sureRegister () {
  470. this.validateSpaceName()
  471. this.validateBusinessCode()
  472. if (!this.hasRegister) {
  473. this.validateVipName()
  474. this.validatePasswordTip()
  475. this.validateConfirm()
  476. } else {
  477. this.validatePasswordTipHas()
  478. }
  479. if (!this.hasEmail) {
  480. this.validateEmail()
  481. }
  482. if (!this.hasRegister) {
  483. if (this.state.spaceName !== 'success' ||
  484. this.state.businessCode !== 'success' ||
  485. this.state.vipName !== 'success' ||
  486. this.state.password !== 'success' ||
  487. this.state.confirm !== 'success' ||
  488. this.state.email !== 'success') {
  489. this.downToast('请确认填写部分是否有误')
  490. } else {
  491. this.sbmitRegister()
  492. }
  493. } else {
  494. if (!this.hasEmail) {
  495. if (this.state.spaceName !== 'success' ||
  496. this.state.businessCode !== 'success' ||
  497. this.state.password !== 'success' ||
  498. this.state.email !== 'success') {
  499. this.downToast('请确认填写部分是否有误')
  500. } else {
  501. this.sbmitRegister()
  502. }
  503. } else {
  504. if (this.state.spaceName !== 'success' ||
  505. this.state.businessCode !== 'success' ||
  506. this.state.password !== 'success') {
  507. this.downToast('请确认填写部分是否有误')
  508. } else {
  509. this.sbmitRegister()
  510. }
  511. }
  512. }
  513. },
  514. getJsonp: function (url, timeout = 500) {
  515. return new Promise((resolve, reject) => {
  516. this.$jsonp(url, {
  517. name: 'successCallback',
  518. timeout: timeout
  519. }, function (err, data) {
  520. if (err) {
  521. reject(err)
  522. throw err
  523. } else {
  524. resolve(data)
  525. }
  526. })
  527. })
  528. },
  529. crossAfter (url) {
  530. try {
  531. window.location.href = url
  532. } catch (err) {
  533. console.log(err)
  534. }
  535. },
  536. loginOther (response, a, timeout) {
  537. const crossAfter = this.crossAfter
  538. let promises = []
  539. for (let i in response.data.content.loginUrls) {
  540. promises.push(this.getJsonp(`${response.data.content.loginUrls[i]}?${a}`))
  541. }
  542. let returnUrl = decodeURIComponent(this.$route.query.returnURL)
  543. Promise.all(promises).then(() => {
  544. crossAfter(returnUrl || 'http://www.ubtob.com', timeout)
  545. }).catch(() => {
  546. crossAfter(returnUrl || 'http://www.ubtob.com', timeout)
  547. })
  548. }
  549. }
  550. }
  551. </script>