index.vue 13 KB

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