login.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  1. <template>
  2. <div class="login-container">
  3. <!-- 跳转页面登录 -->
  4. <div class="login-page">
  5. <div class="l-header">
  6. <div class="content">
  7. <nuxt-link to="/" class="logo">
  8. <!--<span class="img"></span>-->
  9. <img class="img" v-if="webConfigData.pcLogoImgText" :src="webConfigData.pcLogoImgText"/>
  10. <!--<span class="text">蓝海创新科技</span>-->
  11. </nuxt-link>
  12. <div class="go-register">
  13. {{$t('login.notRegisteredYet')}}
  14. <nuxt-link to="/register" class="register-btn">{{$t('login.registeredUsername')}}</nuxt-link>
  15. </div>
  16. </div>
  17. </div>
  18. <div class="l-content" :style="webConfigData.pcLoginBgImg ? {background:'url('+webConfigData.pcLoginBgImg+') no-repeat'} : ''">
  19. <div class="login">
  20. <div class="login-box">
  21. <div class="login-header">
  22. <div
  23. :class="['item',loginType==1?'active':'']"
  24. @click="changeLoginType($event)"
  25. data-logintype="1"
  26. >{{$t('login.mobileLogin')}}</div>
  27. <div
  28. :class="['item',loginType==0?'active':'']"
  29. @click="changeLoginType($event)"
  30. data-logintype="0"
  31. >{{$t('login.accountLogin')}}</div>
  32. </div>
  33. <!-- 账号登录 -->
  34. <div class="login-con" v-if="loginType==0">
  35. <div :class="['item','account',errorTips==3?'msg-error':'']">
  36. <div class="icon"></div>
  37. <input
  38. type="text"
  39. @keyup.enter="login"
  40. class="input"
  41. v-model="userName"
  42. :placeholder="$t('login.enterUsername')"
  43. />
  44. <div class="cancel" @click="clearInput($event)" data-type="userName"></div>
  45. </div>
  46. <div class="error" v-show="errorTips == 3">{{$t('login.accountRestrictions')}}</div>
  47. <div :class="['item','password',errorTips==4?'msg-error':'']">
  48. <div class="icon"></div>
  49. <input
  50. type="password"
  51. class="input"
  52. v-model="password"
  53. @keyup.enter="login"
  54. :placeholder="$t('login.enterPassword')"
  55. />
  56. <div class="cancel" @click="clearInput($event)" data-type="password"></div>
  57. </div>
  58. <!-- <div class="error" v-show="errorTips" >{{['','请输入正确的手机号','请输入验证码','账号为4~16位字母、数字或下划线','请输入密码','验证码有误','请同意下方条款'][errorTips]}}</div> -->
  59. <div class="error" v-show="errorTips == 4">{{$t('login.enterPassword')}}</div>
  60. <div class="error" v-show="errorTips == 6">{{$t('login.pleaseAgreefollowingTerms')}} </div>
  61. <a href="javascript:void(0)" class="login-button" @click="login" @keyup="login">{{$t('login.login')}}</a>
  62. <div :class="['agree-box',this.$t('language') == 'en'?'agree-box-en':'']">
  63. <!-- <input
  64. type="checkbox"
  65. @click="checkAgree"
  66. :class="['checkbox',isAgree?'checked': 'default']"
  67. class="checkbox default"
  68. /> -->
  69. <span class="text" v-if="serviceTermsSwitch || privacyPolicySwitch">
  70. {{$t('login.consentOfLoginRepresentative')}}
  71. <a href="javaScript:void(0)" class="agreement" @click="toTermsPage(0)" v-if="serviceTermsSwitch">{{$t('login.termsOfService')}}</a>
  72. <span v-if="privacyPolicySwitch && serviceTermsSwitch">{{$t('login.and')}}</span>
  73. <a href="javaScript:void(0)" class="agreement" @click="toTermsPage(1)" v-if="privacyPolicySwitch">{{$t('login.privacyPolicy')}}</a>
  74. </span>
  75. </div>
  76. </div>
  77. <!-- /账号登录 -->
  78. <!-- 手机登录 -->
  79. <div class="login-con" v-if="loginType==1">
  80. <div :class="['item','phone',errorTips==1?'msg-error':'']">
  81. <div class="icon"></div>
  82. <input
  83. type="text"
  84. @keyup.enter="login"
  85. class="input"
  86. v-model="mobile"
  87. :placeholder="$t('login.enterUserNumber')"
  88. />
  89. <div class="cancel" @click="clearInput($event)" data-type="mobile"></div>
  90. </div>
  91. <div class="error" v-show="errorTips == 1">{{$t('register.enterValidPhone')}}</div>
  92. <div :class="['item','code',errorTips==2?'msg-error':'']">
  93. <div class="icon"></div>
  94. <input
  95. type="text"
  96. class="input"
  97. v-model="validCode"
  98. @keyup.enter="login"
  99. :placeholder="$t('login.enterCode')"
  100. :style="{width:$t('language')=='en'?'100px':'150px'}"
  101. />
  102. <a href="javascript:void(0);" class="send-code" v-show="show" @click="getCode" :style="{width:$t('language')=='en'?'139px':'89px'}">{{$t('login.getCode')}}</a>
  103. <span v-show="!show" class="send-code" :style="{width:$t('language')=='en'?'139px':'89px'}" style="cursor: not-allowed;">{{count}} s</span>
  104. </div>
  105. <!-- <div class="error" v-show="errorTips" >{{['','请输入正确的手机号','请输入验证码','账号为4~16位字母、数字或下划线','请输入密码','验证码有误','请同意下方条款'][errorTips]}}</div> -->
  106. <div class="error" v-show="errorTips == 2">{{$t('login.enterCode')}}</div>
  107. <div class="error" v-show="errorTips == 6">{{$t('login.pleaseAgreefollowingTerms')}}</div>
  108. <a href="javascript:void(0)" @click="login" class="login-button" @keyup="login">{{$t('login.login')}}</a>
  109. <div :class="['agree-box',this.$t('language') == 'en'?'agree-box-en':'']" >
  110. <!-- <input
  111. type="checkbox"
  112. @keyup.enter="login"
  113. @click="checkAgree"
  114. :class="['checkbox',isAgree?'checked': 'default']"
  115. class="checkbox default"
  116. /> -->
  117. <span class="text" v-if="serviceTermsSwitch || privacyPolicySwitch">
  118. {{$t('login.consentOfLoginRepresentative')}}
  119. <a href="javaScript:void(0)" class="agreement" @click="toTermsPage(0)" v-if="serviceTermsSwitch">{{$t('login.termsOfService')}}</a>
  120. <span v-if="privacyPolicySwitch && serviceTermsSwitch">{{$t('login.and')}}</span>
  121. <a href="javaScript:void(0)" class="agreement" @click="toTermsPage(1)" v-if="privacyPolicySwitch">{{$t('login.privacyPolicy')}}</a>
  122. </span>
  123. </div>
  124. </div>
  125. <!-- /手机登录 -->
  126. <div class="login-footer">
  127. <!-- <div class="other-login">
  128. <a href=""
  129. class="item qq-login">QQ</a>
  130. <a href=""
  131. class="item weixin-login">微信</a>
  132. </div>-->
  133. <nuxt-link to="/register" class="footer-a">{{$t('register.registerNow')}}</nuxt-link>
  134. <nuxt-link to="/forget-password" class="footer-a">{{$t('login.forgotYourPassword')}}</nuxt-link>
  135. </div>
  136. </div>
  137. </div>
  138. </div>
  139. <div class="l-footer content">
  140. <!-- <div class="links">
  141. <nuxt-link to="/" class="item">{{$t('ucPassword.mallHome')}}</nuxt-link>
  142. <nuxt-link to="/user-center" class="item" v-show="!this.$route.name==='login'">{{$t('commonHead.personalCenter')}}</nuxt-link>
  143. <a href='https://www.gz-yami.com/' target="_blank" class="item">{{$t('commonFoot.officialWebsite')}}</a>
  144. <a href="https://www.mall4j.com/" target="_blank" class="item">{{$t('commonFoot.openSourceWebsite')}}</a> -->
  145. <!-- </div> -->
  146. <div class="copyright">{{$t('language')=='zh'?webConfigData.pcCopyrightCn:webConfigData.pcCopyrightEn}}</div>
  147. <!--<div class="copyright">©Copyright 2018 广州市蓝海创新科技有限公司 版权所有 | 粤ICP备18115813号-1</div>-->
  148. </div>
  149. </div>
  150. <!-- /跳转页面登录 -->
  151. </div>
  152. </template>
  153. <script>
  154. import Cookie from 'js-cookie'
  155. import util from '~/plugins/util'
  156. import { encrypt } from '~/plugins/crypto.js'
  157. export default {
  158. layout: 'empty',
  159. data () {
  160. return {
  161. loginType: 0, // 1手机登录 0账号登录
  162. mobile: '',
  163. validCode: '',
  164. userName: '',
  165. password: '',
  166. imgValid: '',
  167. errorTips: 0, // 输入错误提示: 1手机号输入错误 2验证码输入错误 3账号输入错误 4密码输入错误 5图形验证码错误 6未同意条款
  168. // 验证码相关
  169. show: true,
  170. count: '',
  171. timer: null,
  172. hadGotCode: false,
  173. isAgree: true, // 是否同意条款
  174. isLogging: false, //是否正在登录
  175. webConfigData: {}, // 网站配置信息
  176. serviceTermsSwitch: true,
  177. privacyPolicySwitch: true
  178. }
  179. },
  180. methods: {
  181. /**
  182. * 切换登录方式
  183. */
  184. changeLoginType (e) {
  185. this.loginType = e.target.dataset.logintype
  186. this.errorTips = 0
  187. this.mobile = ''
  188. this.validCode = ''
  189. this.userName = ''
  190. this.password = ''
  191. this.imgValid = ''
  192. },
  193. /**
  194. * 获取登录验证码
  195. */
  196. getCode () {
  197. if (!util.checkPhoneNumber(this.mobile)) {
  198. this.errorTips = 1
  199. return
  200. }
  201. // if (this.hadGotCode) {
  202. // return
  203. // }
  204. this.errorTips = 0
  205. let sendSmsParam = {
  206. mobile: this.mobile,
  207. }
  208. this.$axios.post('/sms/sendLoginCode', sendSmsParam)
  209. .then(({ data }) => {
  210. this.hadGotCode = true
  211. const timeCount = 60;
  212. if (!this.timer) {
  213. this.count = timeCount;
  214. this.show = false;
  215. this.timer = setInterval(() => {
  216. if (this.count > 0 && this.count <= timeCount) {
  217. this.count--;
  218. } else {
  219. this.show = true;
  220. clearInterval(this.timer);
  221. this.timer = null;
  222. this.hadGotCode = false
  223. }
  224. }, 1000)
  225. }
  226. })
  227. },
  228. /**
  229. * 登录
  230. */
  231. login () {
  232. if (this.loginType == 1) {
  233. // 手机验证码登录
  234. if (!util.checkPhoneNumber(this.mobile)) {
  235. this.errorTips = 1
  236. return
  237. } else if (!this.validCode.trim()) {
  238. this.errorTips = 2
  239. return
  240. } else if (!this.isAgree) {
  241. this.errorTips = 6
  242. return
  243. }
  244. } else {
  245. // 用户名密码
  246. if (!util.checkUserName(this.userName)) {
  247. this.errorTips = 3
  248. return
  249. } else if (!this.password.trim()) {
  250. this.errorTips = 4
  251. return
  252. } else if (!this.isAgree) {
  253. this.errorTips = 6
  254. return
  255. }
  256. }
  257. this.errorTips = 0
  258. const data = {
  259. userName: this.mobile ? this.mobile : this.userName,
  260. passWord: this.loginType == 0 ? encrypt(this.password) : this.validCode,
  261. }
  262. if (this.isLogging) {
  263. return
  264. } else {
  265. this.$axios.post(this.loginType == 0 ? '/login' : '/smsLogin', data)
  266. .then(({ data }) => {
  267. this.isLogging = true
  268. // var expire = new Date(new Date().getTime() + 1 * 60 * 1000) // token 过期时间
  269. // Cookie.set('token', data.access_token,{ expires: expire })
  270. Cookie.set('token', data.accessToken)
  271. const user = {
  272. nickName: data.nickName==null?'用户名':data.nickName,
  273. userAvatar: data.pic
  274. }
  275. this.$store.commit('SET_USER', user)
  276. this.$router.push({ path: '/' })
  277. })
  278. this.$axios.onError(error => {
  279. const code = parseInt(error.response.status)
  280. if (code == 500) {
  281. Message.error(error.response.message)
  282. this.mobile = '',
  283. this.validCode = ''
  284. }
  285. })
  286. }
  287. },
  288. /**
  289. * 清除输入框内容
  290. */
  291. clearInput (e) {
  292. const type = e.target.dataset.type
  293. switch (type) {
  294. case 'mobile':
  295. this.mobile = ''
  296. break;
  297. case 'userName':
  298. this.userName = ''
  299. break;
  300. case 'password':
  301. this.password = ''
  302. break;
  303. default:
  304. break;
  305. }
  306. },
  307. /**
  308. * 跳转到《服务条款》或《隐私协议》
  309. */
  310. toTermsPage (sts) {
  311. this.$router.push({ path: '/termsPage?sts=' + sts })
  312. },
  313. /**
  314. * 同意条款
  315. */
  316. // checkAgree () {
  317. // this.isAgree = !this.isAgree
  318. // if (this.errorTips == 6) {
  319. // this.errorTips = 0
  320. // }
  321. // }
  322. },
  323. mounted () {
  324. this.$axios.get('/webConfig/getPcWebConfig').then(({ data }) => {
  325. this.webConfigData = data
  326. localStorage.setItem('webConfig', JSON.stringify(data))
  327. })
  328. document.title = this.$t('login.login')
  329. this.$axios.get('/sys/config/info/getSysServiceSwitch').then(({ data }) => {
  330. this.serviceTermsSwitch = data.serviceTermsSwitch
  331. this.privacyPolicySwitch = data.privacyPolicySwitch
  332. })
  333. }
  334. }
  335. </script>
  336. <style scoped src='~/assets/css/login.css'>
  337. </style>