index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355
  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="f-form">
  8. <div class="page-part">
  9. <mt-field :state="state.vipName"
  10. placeholder="会员名"
  11. v-model="vipName"
  12. @blur.native.capture="codeVipName" ></mt-field>
  13. </div>
  14. <div class="page-part">
  15. <mt-field :state="state.password"
  16. placeholder="密码"
  17. :attr="{ maxlength: 20 }"
  18. v-model="password"
  19. @input.native="codePwd"
  20. type="password"
  21. @blur.native.capture="codePwdBlur"></mt-field>
  22. <template v-if="password">
  23. <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>
  24. <p class="pwd">密码须为8-20字符的英文、数字混合</p>
  25. </template>
  26. </div>
  27. <div class="page-part">
  28. <mt-field :state="state.confirm"
  29. placeholder="确认密码"
  30. v-model="confirm"
  31. type="password"
  32. @blur.native.capture="codePassword"></mt-field>
  33. </div>
  34. <div class="page-part">
  35. <mt-field :state="state.mobile"
  36. placeholder="手机号码"
  37. v-model="mobile"
  38. @blur.native.capture="codeMobile"
  39. type="tel"></mt-field>
  40. </div>
  41. <div class="page-part">
  42. <mt-field :state="state.token"
  43. placeholder="短信验证码"
  44. v-model="token"
  45. @blur.native.capture="codeToken"
  46. auto-complete="off">
  47. <span class="token" v-text="tokenText" @click="getCheckCode" v-if="state.mobile === 'success'">获取验证码</span>
  48. <span class="token-no" v-text="tokenText" v-if="state.mobile !== 'success'">获取验证码</span>
  49. </mt-field>
  50. </div>
  51. </div>
  52. <div class="form-btn">
  53. <div class="page-part">
  54. <el-checkbox v-model="checked">我已阅读并同意 <a class="rgba" href="/common/agreement">《优软云服务条款》</a></el-checkbox>
  55. </div>
  56. <mt-button type="primary" size="large" @click.native="submit">完成注册</mt-button>
  57. </div>
  58. </div>
  59. </template>
  60. <script>
  61. export default {
  62. name: 'registerPerson',
  63. data () {
  64. return {
  65. step: 1,
  66. state: {
  67. vipName: 'error',
  68. password: 'error',
  69. confirm: 'error',
  70. mobile: 'error',
  71. token: 'error'
  72. },
  73. vipName: '',
  74. password: '',
  75. confirm: '',
  76. mobile: '',
  77. token: '',
  78. tokenCode: '',
  79. tokenText: '获取验证码',
  80. tokenTime: '60',
  81. checked: true
  82. }
  83. },
  84. methods: {
  85. // 注册
  86. goRegister () {
  87. window.location.href = `/register/enterpriseRegistration${this.$store.state.option.fullPath}`
  88. },
  89. // 验证弹窗
  90. downToast (type) {
  91. this.$toast({
  92. message: type,
  93. iconClass: 'el-icon-warning'
  94. })
  95. },
  96. // 验证会员名
  97. codeVipName () {
  98. let count = this.vipName.length
  99. if (count === 0) {
  100. this.downToast('会员名不能为空')
  101. this.state.vipName = 'error'
  102. } else if (count < 2 || count > 20) {
  103. this.downToast('请填写合适的会员名称,2~20个字符')
  104. this.state.vipName = 'warning'
  105. } else {
  106. this.state.vipName = 'success'
  107. }
  108. },
  109. // 验证密码强度
  110. codePwd () {
  111. let reg1 = /^(?=.{8,20})(((?=.*[0-9])(?=.*[a-z])(?=.*[A-Z]))|((?=.*[0-9])((?=.*[a-zA-Z]))(?=.*[^a-zA-Z0-9]))).*$/
  112. let reg2 = /^(?=.{8,20})(((?=.*[0-9])(?=.*[a-z]))|((?=.*[0-9])(?=.*[A-Z]))).*$/
  113. if (reg1.test(this.password)) {
  114. this.step = '强'
  115. } else if (reg2.test(this.password)) {
  116. this.step = '中'
  117. } else {
  118. this.step = '弱'
  119. }
  120. },
  121. // 验证密码格式
  122. codePwdBlur () {
  123. let reg2 = /^(?=.{8,20})(((?=.*[0-9])(?=.*[a-z]))|((?=.*[0-9])(?=.*[A-Z]))).*$/
  124. if (!this.password) {
  125. this.downToast('请输入密码')
  126. this.state.password = 'error'
  127. } else if (!reg2.test(this.password)) {
  128. this.downToast('密码须为8-20字符的英文、数字混合')
  129. this.state.password = 'warning'
  130. } else {
  131. this.state.password = 'success'
  132. if (this.confirm) {
  133. this.codePassword()
  134. }
  135. }
  136. },
  137. // 验证密码的确认信息
  138. codePassword () {
  139. if (!this.confirm) {
  140. this.downToast('请再次输入密码')
  141. this.state.confirm = 'error'
  142. } else if (this.confirm !== this.password) {
  143. this.downToast('两次输入密码不一致!')
  144. this.state.confirm = 'warning'
  145. } else {
  146. this.state.confirm = 'success'
  147. }
  148. },
  149. // 验证手机号
  150. codeMobile () {
  151. let reg = /^1([0-9]{10})$/
  152. if (!this.mobile) {
  153. this.downToast('请输入手机号')
  154. this.state.mobile = 'error'
  155. } else if (!reg.test(this.mobile)) {
  156. this.downToast('请填写正确的手机号码')
  157. this.state.mobile = 'warning'
  158. } else {
  159. this.$http.get(`/api/user/checkMobile`, {params: {mobile: this.mobile, mobileArea: ''}})
  160. .then(response => {
  161. if (response.data.hasRegister) {
  162. this.downToast('该手机号已被注册,可直接登录')
  163. this.state.mobile = 'warning'
  164. } else {
  165. this.state.mobile = 'success'
  166. }
  167. }).catch((err) => {
  168. this.downToast(err.errMsg)
  169. })
  170. }
  171. },
  172. // 验证-验证码信息
  173. codeToken () {
  174. if (!this.token) {
  175. this.downToast('请先填写验证码')
  176. this.state.token = 'error'
  177. } else {
  178. if (!this.mobile) {
  179. this.downToast('请先填写正确的手机号码')
  180. this.state.token = 'warning'
  181. } else {
  182. if (this.tokenCode) {
  183. let param = new FormData()
  184. param.append('mobile', this.mobile)
  185. param.append('token', this.tokenCode)
  186. param.append('code', this.token)
  187. let config = {
  188. headers: {'Content-Type': 'multipart/form-data'}
  189. }
  190. this.$http.post('/sso/personal/register/checkCode', param, config)
  191. .then(response => {
  192. if (response.data.success) {
  193. this.state.token = 'success'
  194. } else {
  195. this.$toast({
  196. message: response.data.errMsg,
  197. iconClass: 'el-icon-error'
  198. })
  199. }
  200. }).catch((err) => {
  201. this.downToast(err.errMsg)
  202. })
  203. } else {
  204. this.downToast('请点击先获取验证码信息')
  205. this.state.token = 'warning'
  206. }
  207. }
  208. }
  209. },
  210. // 获取验证码
  211. loadCheckCode () {
  212. if (this.state.mobile === 'success') {
  213. this.$indicator.open('获取中...')
  214. let _this = this
  215. this.$http.get('/sso/personal/register/checkCode', {params: {mobile: this.mobile}})
  216. .then(response => {
  217. this.$indicator.close()
  218. if (response.data) {
  219. this.tokenCode = response.data.token
  220. this.$toast({
  221. message: '验证码已经发送到您的手机,请注意查收',
  222. iconClass: 'el-icon-success'
  223. })
  224. this.tokenText = '已发送(' + this.tokenTime + 'S)'
  225. let setTime = setInterval(() => {
  226. _this.tokenTime--
  227. this.tokenText = '已发送(' + this.tokenTime + 'S)'
  228. if (this.tokenTime <= 0) {
  229. clearInterval(setTime)
  230. _this.tokenText = '获取验证码'
  231. _this.tokenTime = 60
  232. }
  233. }, 1000)
  234. }
  235. }).catch((err) => {
  236. this.$indicator.close()
  237. this.downToast(err.errMsg)
  238. })
  239. }
  240. },
  241. // 验证码发送请求
  242. getCheckCode () {
  243. if (this.tokenTime > 0 && this.tokenTime < 60) {
  244. this.downToast('请稍后再点击,我在倒计时')
  245. } else {
  246. this.loadCheckCode()
  247. }
  248. },
  249. // 表单提交
  250. submit () {
  251. if (this.state.vipName !== 'success' ||
  252. this.state.password !== 'success' ||
  253. this.state.confirm !== 'success' ||
  254. this.state.mobile !== 'success' ||
  255. this.state.token !== 'success') {
  256. this.downToast('请确认填写部分是否有误')
  257. } else if (this.checked === false) {
  258. this.downToast('您对阅读条款未做勾选')
  259. } else {
  260. this.$indicator.open('注册中...')
  261. let param = new FormData()
  262. param.append('vipName', this.vipName)
  263. param.append('password', this.password)
  264. param.append('mobile', this.mobile)
  265. // param.append('mobileArea', '')
  266. param.append('appId', this.$store.state.option.appId)
  267. param.append('code', this.token)
  268. param.append('token', this.tokenCode)
  269. let config = {
  270. header: {'Content-Type': 'multipart/form-data'}
  271. }
  272. this.$http.post('/sso/personal/register', param, config)
  273. .then(response => {
  274. this.$indicator.close()
  275. if (response.data.success) {
  276. if (response.data.content.data) {
  277. let param = response.data.content.data
  278. let a = ''
  279. for (let n in param) {
  280. a += (n + '=' + encodeURIComponent(param[n]) + '&')
  281. }
  282. let params = a.substr(0, a.length - 1)
  283. this.isShowLoading = true
  284. if (response.data.content.currentUrl) {
  285. this.$jsonp(`${response.data.content.currentUrl}?${params}`, {
  286. name: 'successCallback',
  287. timeout: 3000
  288. }, (err, data) => {
  289. if (err) {
  290. this.$message.error('注册成功,请点击下方“立即登录”完成登录')
  291. this.isShowLoading = false
  292. throw err
  293. } else {
  294. this.loginOther(response, params)
  295. }
  296. })
  297. } else {
  298. this.loginOther(response, params, 3000)
  299. }
  300. } else {
  301. let userUU = response.data.content.userUU
  302. window.location.href = `/overRegister/${userUU}`
  303. }
  304. } else if (response.data.error) {
  305. this.$toast({
  306. message: response.data.errMsg,
  307. iconClass: 'el-icon-error'
  308. })
  309. }
  310. }).catch((err) => {
  311. this.$indicator.close()
  312. this.downToast(err.errMsg)
  313. })
  314. }
  315. },
  316. getJsonp: function (url, timeout = 500) {
  317. return new Promise((resolve, reject) => {
  318. this.$jsonp(url, {
  319. name: 'successCallback',
  320. timeout: timeout
  321. }, function (err, data) {
  322. if (err) {
  323. reject(err)
  324. throw err
  325. } else {
  326. resolve(data)
  327. }
  328. })
  329. })
  330. },
  331. crossAfter (url) {
  332. try {
  333. window.location.href = url
  334. } catch (err) {
  335. console.log(err)
  336. }
  337. },
  338. loginOther (response, a, timeout) {
  339. const crossAfter = this.crossAfter
  340. let promises = []
  341. for (let i in response.data.content.loginUrls) {
  342. promises.push(this.getJsonp(`${response.data.content.loginUrls[i]}?${a}`))
  343. }
  344. let returnUrl = decodeURIComponent(this.$route.query.returnURL)
  345. Promise.all(promises).then(() => {
  346. crossAfter(returnUrl || 'http://www.ubtob.com', timeout)
  347. }).catch(() => {
  348. crossAfter(returnUrl || 'http://www.ubtob.com', timeout)
  349. })
  350. }
  351. }
  352. }
  353. </script>