login.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. <template>
  2. <div class="login-box">
  3. <div class="login-tabs">
  4. <div class="login-tab" :class="{'is-active': !type || type === 'codeLogin'}" @click="toOtherLogin('')">{{$t('login.userLogin')}}</div><div class="login-tab" :class="{'is-active': type==='camera'}" @click="toOtherLogin('camera')">{{$t('login.cameraLogin')}}</div>
  5. </div>
  6. <div class="account-login" v-if="!type">
  7. <input type="text" v-if="!isInternational" oninput="value=value.replace(/[^\d]/g,'')" maxlength="11" class="input" :placeholder="isInternational? $t('login.emailPlaceholder') : $t('login.phonePlaceholder')" v-model="form.phone">
  8. <input type="text" v-else class="input" :placeholder="isInternational? $t('login.emailPlaceholder') : $t('login.phonePlaceholder')" v-model="form.phone">
  9. <div class="password-w">
  10. <input maxLength="16" :type="showPassword ? 'test' : 'password'" class="input password" :placeholder="$t('login.passwordPlaceholder')" v-model="form.password" @keyup.enter="login">
  11. <h-icon :type="showPassword ? 'mimakejian' : 'mimabukejian'" class="password-visible" @click="showPassword=!showPassword" />
  12. </div>
  13. <div class="toCodeLogin tips-tap" >
  14. <!-- <a @click="$router.push({name: 'login', query: {type: 'codeLogin'}})">{{$t('login.codeLogin')}}</a> -->
  15. </div>
  16. <div class="checkbox"><input type="checkbox" v-model="rememberMe" id="rember" /><label for="rember">{{$t('login.rememberPassword')}}</label></div>
  17. <div class="login-btn" @click="login" >{{$t('login.login')}}</div>
  18. <div class="others">
  19. <a class="other-actions" @click="$router.push('/login/forget')">{{ $t('login.forgetPassword') }}</a>
  20. <a class="other-actions" @click="$router.push(isInternational ? '/login/register?type=email' : '/login/register')">{{ $t('login.registerAccount') }}</a>
  21. </div>
  22. </div>
  23. <cameraLogin v-if="type === 'camera'" />
  24. <codeLogin v-if="type === 'codeLogin'" />
  25. </div>
  26. </template>
  27. <script>
  28. import cameraLogin from './cameraLogin'
  29. import codeLogin from './codeLogin'
  30. import { encodeStr } from '@/util'
  31. import { Base64 } from 'js-base64'
  32. import { mapState } from 'vuex'
  33. export default {
  34. data () {
  35. let remember = localStorage.getItem('remember') || false
  36. let username = localStorage.getItem('username')
  37. let password = localStorage.getItem('password')
  38. return {
  39. showPassword: false,
  40. rememberMe: remember,
  41. form: {
  42. phone: username,
  43. password: password
  44. }
  45. }
  46. },
  47. computed: {
  48. ...mapState({
  49. language: state => state.language.current,
  50. langToast: state => state.language.home.toast,
  51. isInternational: state => state.isInternational
  52. }),
  53. type () {
  54. return this.$route.query.type
  55. }
  56. },
  57. components: {
  58. cameraLogin,
  59. codeLogin
  60. },
  61. mounted () {
  62. this.rememberMe = eval(localStorage.getItem('remember')) || ''
  63. },
  64. methods: {
  65. toOtherLogin (type) {
  66. this.$router.push({
  67. url: '/login',
  68. query: {
  69. type: type
  70. }
  71. })
  72. },
  73. async login () {
  74. let check = value => {
  75. for (let i = 0, len = value.length; i < len; i++) {
  76. if (!value[i].val) {
  77. this.$toast.show('warn', (this.language === 'en' ? value[i].En : value[i].name) + this.langToast['7'])
  78. return
  79. }
  80. }
  81. return true
  82. }
  83. let checkStr = [
  84. {
  85. name: this.isInternational ? '邮箱' : '手机',
  86. En: this.isInternational ? 'E-mail' :'Phone number',
  87. val: this.form.phone
  88. },
  89. {
  90. name: '密码',
  91. En: 'Password',
  92. val: this.form.password
  93. }
  94. ]
  95. if (!check(checkStr)) {
  96. return
  97. }
  98. localStorage.setItem('remember', this.rememberMe)
  99. if (this.rememberMe) {
  100. localStorage.setItem('username', this.form.phone)
  101. localStorage.setItem('password', this.form.password)
  102. } else {
  103. localStorage.setItem('username', '')
  104. localStorage.setItem('password', '')
  105. }
  106. let params = {
  107. phoneNum: this.form.phone,
  108. password: encodeStr(Base64.encode(this.form.password)),
  109. randomcode: '1234',
  110. rememberMe: Boolean(this.rememberMe)
  111. }
  112. try {
  113. let res = await this.$store.dispatch('login', params)
  114. if (!res) {
  115. return
  116. }
  117. const from = this.$route.query.from
  118. // if (from) {
  119. // this.$router.push(from)
  120. // } else {
  121. // this.$router.push('/information')
  122. // }
  123. this.$router.push('/information')
  124. } catch (err) {
  125. }
  126. }
  127. }
  128. }
  129. </script>
  130. <style lang="scss" >
  131. .login-box {
  132. width: 398px;
  133. padding: 38px 0;
  134. input[type=text] {
  135. height: 60px;
  136. line-height: 60px;
  137. padding-left: 8px;
  138. border: 1px solid #909090;
  139. border-radius: 3px;
  140. }
  141. }
  142. .login-tabs {
  143. padding: 0 38px;
  144. }
  145. .login-tab {
  146. display: inline-block;
  147. width: 50%;
  148. font-size: 20px;
  149. text-align: center;
  150. padding-bottom: 10px;
  151. border-bottom: 1px solid #707070;
  152. margin-bottom: 38px;
  153. cursor: pointer;
  154. &.is-active {
  155. border-bottom: 2px solid #1FE4DC;
  156. padding-bottom: 9px;
  157. }
  158. }
  159. .account-login {
  160. padding: 0 38px;
  161. }
  162. .password-w {
  163. position: relative;
  164. margin: 29px 0 13px;
  165. .password-visible {
  166. position: absolute;
  167. right: 20px;
  168. font-size: 30px;
  169. line-height: 60px;
  170. cursor: pointer;
  171. top: 0;
  172. }
  173. }
  174. .password {
  175. }
  176. .toCodeLogin {
  177. text-align: right;
  178. a {
  179. cursor: pointer;
  180. }
  181. }
  182. .checkbox {
  183. // padding-left: 27px;
  184. position: relative;
  185. font-size: 16px;
  186. color: #202020;
  187. display: flex;
  188. align-items: center;
  189. line-height: 18px;
  190. input {
  191. margin-right: 7px;
  192. cursor: pointer;
  193. }
  194. }
  195. .login-btn {
  196. margin: 36px 0 18px;
  197. background: #1FE4DC;
  198. width: 100%;
  199. text-align: center;
  200. line-height: 60px;
  201. font-weight: 600;
  202. border-radius: 3px;
  203. cursor: pointer;
  204. }
  205. .others {
  206. text-align: center;
  207. }
  208. .other-actions {
  209. color: #202020;
  210. font-size: 16px;
  211. &:first-child {
  212. margin-right: 34px;
  213. position: relative;
  214. &::after {
  215. content: '';
  216. height: 14px;
  217. width: 1px;
  218. background: #909090;
  219. position: absolute;
  220. right: -18px;
  221. top: 50%;
  222. margin-top: -7px;
  223. }
  224. }
  225. }
  226. </style>