index.vue 20 KB

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