login-popup.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. <template>
  2. <div class="login">
  3. <div class="popup-mask"></div>
  4. <div class="login-box">
  5. <div class="close" @click="$emit('hideLoginPop')"></div>
  6. <div class="login-header">
  7. <div
  8. :class="['item',loginType==0?'active':'']"
  9. @click="changeLoginType($event)"
  10. data-logintype="0"
  11. :style="{padding:$t('language')=='en'?'0 30px 0 0':'18px'}"
  12. >{{$t('login.accountLogin')}}</div>
  13. <div
  14. :class="['item',loginType==1?'active':'']"
  15. @click="changeLoginType($event)"
  16. data-logintype="1"
  17. :style="{padding:$t('language')=='en'?'0 0 0 30px':'18px'}"
  18. >{{$t('login.mobileLogin')}}</div>
  19. </div>
  20. <!-- 账号登录 -->
  21. <div class="login-con" v-if="loginType==0">
  22. <div :class="['item','account',errorTips==3?'msg-error':'']">
  23. <div class="icon"></div>
  24. <input
  25. type="text"
  26. class="input"
  27. v-model="userName"
  28. @keyup.enter="login"
  29. :placeholder="$t('login.enterUsername')"
  30. />
  31. <div class="cancel" @click="clearInput($event)" data-type="userName"></div>
  32. </div>
  33. <div class="error" v-show="errorTips == 3">{{$t('login.accountRestrictions')}}</div>
  34. <div :class="['item','password',errorTips==4?'msg-error':'']">
  35. <div class="icon"></div>
  36. <input
  37. type="password"
  38. class="input"
  39. v-model="password"
  40. @keyup.enter="login"
  41. :placeholder="$t('login.enterPassword')"
  42. />
  43. <div class="cancel" @click="clearInput($event)" data-type="password"></div>
  44. </div>
  45. <!-- <div class="error"
  46. v-show="errorTips">{{['','请输入正确的手机号','请输入验证码','账号为4~16位字母、数字或下划线','请输入密码','验证码有误','请同意下方条款'][errorTips]}}</div>-->
  47. <div class="error" v-show="errorTips == 4">{{$t('login.enterPassword')}}</div>
  48. <div class="error" v-show="errorTips == 6">{{$t('login.pleaseAgreefollowingTerms')}}</div>
  49. <a href="javascript:void(0)" class="login-button" @click="login">{{$t('login.login')}}</a>
  50. <div :class="['agree-box',this.$t('language') == 'en'?'agree-box-en':'']">
  51. <!-- <input
  52. type="checkbox"
  53. @click="checkAgree"
  54. :class="['checkbox',isAgree?'checked': 'default']"
  55. class="checkbox default"
  56. /> -->
  57. <span class="text" v-if="serviceTermsSwitch || privacyPolicySwitch">
  58. {{$t('login.consentOfLoginRepresentative')}}
  59. <a href="javaScript:void(0)" class="agreement" @click="toTermsPage(0)" v-if="serviceTermsSwitch">{{$t('login.termsOfService')}}</a>
  60. <span v-if="privacyPolicySwitch && serviceTermsSwitch">{{$t('login.and')}}</span>
  61. <a href="javaScript:void(0)" class="agreement" @click="toTermsPage(1)" v-if="privacyPolicySwitch">{{$t('login.privacyPolicy')}}</a>
  62. </span>
  63. </div>
  64. </div>
  65. <!-- /账号登录 -->
  66. <!-- 手机登录 -->
  67. <div class="login-con" v-if="loginType==1">
  68. <div :class="['item','phone',errorTips==1?'msg-error':'']">
  69. <div class="icon"></div>
  70. <input
  71. type="text"
  72. class="input"
  73. v-model="mobile"
  74. @keyup.enter="login"
  75. :placeholder="$t('login.enterPhone')"
  76. />
  77. <div class="cancel" @click="clearInput($event)" data-type="mobile"></div>
  78. </div>
  79. <div class="error" v-show="errorTips == 1">{{$t('register.enterValidPhone')}}</div>
  80. <div :class="['item','code',errorTips==2?'msg-error':'']">
  81. <div class="icon"></div>
  82. <input
  83. type="text"
  84. class="input"
  85. v-model="validCode"
  86. @keyup.enter="login"
  87. :placeholder="$t('login.enterCode')"
  88. :style="{width:$t('language')=='en'?'100px':'150px'}"
  89. />
  90. <a href="javascript:void(0);" class="send-code" v-show="show" @click="getCode" :style="{width:$t('language')=='en'?'139px':'89px'}">{{$t('login.getCode')}}</a>
  91. <span v-show="!show" class="send-code" :style="{width:$t('language')=='en'?'139px':'89px'}" style="cursor: not-allowed;">{{count}} s</span>
  92. </div>
  93. <!-- <div class="item img-code">
  94. <input type="text"
  95. class="input"
  96. v-model="imgValid"
  97. placeholder="请输入验证码">
  98. <a href=""
  99. class="code-img"><img src="~/assets/img/adv1.jpg"
  100. alt=""></a>
  101. </div>-->
  102. <!-- <div class="error"
  103. v-show="errorTips">{{['','请输入正确的手机号','请输入验证码','账号为4~16位字母、数字或下划线','请输入密码','验证码有误','请同意下方条款'][errorTips]}}</div>-->
  104. <div class="error" v-show="errorTips == 2">{{$t('login.enterCode')}}</div>
  105. <!-- <div class="error" v-show="errorTips == 5">验证码有误</div> -->
  106. <div class="error" v-show="errorTips == 6">{{$t('login.pleaseAgreefollowingTerms')}}</div>
  107. <a href="javascript:void(0)" @click="login" class="login-button" >{{$t('login.login')}}</a>
  108. <div :class="['agree-box',this.$t('language') == 'en'?'agree-box-en':'']"
  109. >
  110. <!-- <input
  111. type="checkbox"
  112. @click="checkAgree"
  113. :class="['checkbox',isAgree?'checked': 'default']"
  114. class="checkbox default"
  115. /> -->
  116. <span class="text" v-if="serviceTermsSwitch || privacyPolicySwitch">
  117. {{$t('login.consentOfLoginRepresentative')}}
  118. <a href="javaScript:void(0)" class="agreement" @click="toTermsPage(0)" v-if="serviceTermsSwitch">{{$t('login.termsOfService')}}</a>
  119. <span v-if="privacyPolicySwitch && serviceTermsSwitch">{{$t('login.and')}}</span>
  120. <a href="javaScript:void(0)" class="agreement" @click="toTermsPage(1)" v-if="privacyPolicySwitch">{{$t('login.privacyPolicy')}}</a>
  121. </span>
  122. </div>
  123. </div>
  124. <!-- /手机登录 -->
  125. <div class="login-footer">
  126. <!-- <div class="other-login">
  127. <a href=""
  128. class="item qq-login">QQ</a>
  129. <a href=""
  130. class="item weixin-login">微信</a>
  131. </div>-->
  132. <nuxt-link class="footer-a" to="/register">{{$t('register.registerNow')}}</nuxt-link>
  133. <nuxt-link to="/forget-password" class="footer-a">{{$t('login.forgotYourPassword')}}</nuxt-link>
  134. </div>
  135. </div>
  136. </div>
  137. </template>
  138. <script>
  139. import Cookie from 'js-cookie'
  140. import util from '../plugins/util'
  141. import { encrypt } from '~/plugins/crypto.js'
  142. export default {
  143. data () {
  144. return {
  145. loginType: 0, // 1手机登录 0账号登录
  146. mobile: '',
  147. validCode: '',
  148. userName: '',
  149. password: '',
  150. imgValid: '',
  151. errorTips: 0, // 输入错误提示: 1手机号输入错误 2验证码输入错误 3账号输入错误 4密码输入错误 5图形验证码错误 6未同意条款
  152. // 验证码相关
  153. show: true,
  154. count: '',
  155. timer: null,
  156. hadGotCode: false,
  157. isAgree: true, // 是否同意条款
  158. isLogging: false,
  159. serviceTermsSwitch: true,
  160. privacyPolicySwitch: true
  161. }
  162. },
  163. watch: {
  164. },
  165. mounted () {
  166. this.$axios.get('/sys/config/info/getSysServiceSwitch').then(({ data }) => {
  167. this.serviceTermsSwitch = data.serviceTermsSwitch
  168. this.privacyPolicySwitch = data.privacyPolicySwitch
  169. })
  170. },
  171. methods: {
  172. /**
  173. * 切换登录方式
  174. */
  175. changeLoginType (e) {
  176. this.loginType = e.target.dataset.logintype
  177. this.errorTips = 0
  178. this.mobile = ''
  179. this.validCode = ''
  180. this.userName = ''
  181. this.password = ''
  182. this.imgValid = ''
  183. },
  184. /**
  185. * 获取登录验证码
  186. */
  187. getCode () {
  188. if (!util.checkPhoneNumber(this.mobile)) {
  189. this.errorTips = 1
  190. return
  191. }
  192. // if (this.hadGotCode) {
  193. // return
  194. // }
  195. this.hadGotCode = true
  196. this.errorTips = 0
  197. let sendSmsParam = {
  198. mobile: this.mobile,
  199. }
  200. this.$axios.post('/sms/sendLoginCode', sendSmsParam).then(({ data }) => {
  201. const timeCount = 60;
  202. if (!this.timer) {
  203. this.count = timeCount;
  204. this.show = false;
  205. this.timer = setInterval(() => {
  206. if (this.count > 0 && this.count <= timeCount) {
  207. this.count--;
  208. } else {
  209. this.show = true;
  210. clearInterval(this.timer);
  211. this.timer = null;
  212. this.hadGotCode = false
  213. }
  214. }, 1000)
  215. }
  216. })
  217. },
  218. /**
  219. * 登录
  220. */
  221. login () {
  222. if (this.loginType == 1) {
  223. // 手机验证码登录
  224. if (!util.checkPhoneNumber(this.mobile)) {
  225. this.errorTips = 1
  226. return
  227. } else if (!this.validCode.trim()) {
  228. this.errorTips = 2
  229. return
  230. } else if (!this.isAgree) {
  231. this.errorTips = 6
  232. return
  233. }
  234. } else {
  235. // console.log(this.userName)
  236. // console.log(this.password)
  237. // 用户名密码
  238. if (!util.checkUserName(this.userName)) {
  239. this.errorTips = 3
  240. return
  241. } else if (!this.password.trim()) {
  242. this.errorTips = 4
  243. return
  244. } else if (!this.isAgree) {
  245. this.errorTips = 6
  246. return
  247. }
  248. }
  249. this.errorTips = 0
  250. const data = {
  251. userName: this.mobile ? this.mobile : this.userName,
  252. passWord: this.loginType == 0 ? encrypt(this.password) : this.validCode,
  253. }
  254. if (this.isLogging) {
  255. return
  256. } else {
  257. this.$axios.post( this.loginType == 0 ? '/login' : '/smsLogin', data)
  258. .then(({ data }) => {
  259. Cookie.set('token', data.accessToken)
  260. this.isLogging = true
  261. this.$emit('hideLoginPop')
  262. window.location.pathname == '/register' ? this.$router.push({ path: '/' }) : window.location.reload();
  263. })
  264. }
  265. },
  266. /**
  267. * 清除输入框内容
  268. */
  269. clearInput (e) {
  270. const type = e.target.dataset.type
  271. switch (type) {
  272. case 'mobile':
  273. this.mobile = ''
  274. break;
  275. case 'userName':
  276. this.userName = ''
  277. break;
  278. case 'password':
  279. this.password = ''
  280. break;
  281. default:
  282. break;
  283. }
  284. },
  285. /**
  286. * 同意条款
  287. */
  288. // checkAgree () {
  289. // this.isAgree = !this.isAgree
  290. // if (this.errorTips == 6) {
  291. // this.errorTips = 0
  292. // }
  293. // },
  294. /**
  295. * 跳转到《服务条款》或《隐私协议》
  296. */
  297. toTermsPage (sts) {
  298. this.$router.push({ path: '/termsPage?sts=' + sts })
  299. },
  300. },
  301. }
  302. </script>
  303. <style scoped src='~/assets/css/login.css'></style>