login.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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('')">用户登录</div><div class="login-tab" :class="{'is-active': type==='camera'}" @click="toOtherLogin('camera')">相机登录</div>
  5. </div>
  6. <div class="account-login" v-if="!type">
  7. <input type="text" class="input" placeholder="请输入手机号码/邮箱" v-model="form.phone">
  8. <input type="password" class="input password" placeholder="请输入密码" v-model="form.password">
  9. <div class="toCodeLogin tips-tap" >
  10. <a @click="$router.push({name: 'login', query: {type: 'codeLogin'}})">验证码登录</a>
  11. </div>
  12. <div class="checkbox"><input type="checkbox" v-model="rememberMe" />记住密码</div>
  13. <div class="login-btn" @click="login" @keyup.enter="login">登录</div>
  14. <div class="others">
  15. <a class="other-actions" @click="$router.push('/login/forget')">忘记密码</a>
  16. <a class="other-actions" @click="$router.push('/login/register')">账号注册</a>
  17. </div>
  18. </div>
  19. <cameraLogin v-if="type === 'camera'" />
  20. <codeLogin v-if="type === 'codeLogin'" />
  21. </div>
  22. </template>
  23. <script>
  24. import cameraLogin from './cameraLogin'
  25. import codeLogin from './codeLogin'
  26. import { encodeStr } from '@/util'
  27. import { Base64 } from 'js-base64'
  28. export default {
  29. data () {
  30. return {
  31. rememberMe: false,
  32. form: {
  33. phone: '',
  34. password: ''
  35. }
  36. }
  37. },
  38. computed: {
  39. type () {
  40. return this.$route.query.type
  41. }
  42. },
  43. components: {
  44. cameraLogin,
  45. codeLogin
  46. },
  47. methods: {
  48. toOtherLogin (type) {
  49. this.$router.push({
  50. url: '/login',
  51. query: {
  52. type: type
  53. }
  54. })
  55. },
  56. async login () {
  57. let check = value => {
  58. for (let i = 0, len = value.length; i < len; i++) {
  59. if (!value[i].val) {
  60. return this.$toast.show('warn', (this.language === 'en' ? value[i].En : value[i].name) + this.langToast['7'])
  61. }
  62. }
  63. return true
  64. }
  65. let checkStr = [
  66. {
  67. name: '手机',
  68. En: 'Phone number',
  69. val: this.form.phone
  70. },
  71. {
  72. name: '密码',
  73. En: 'Password',
  74. val: this.form.password
  75. }
  76. ]
  77. if (!check(checkStr)) {
  78. return
  79. }
  80. localStorage.setItem('remember', this.rememberMe)
  81. if (this.rememberMe) {
  82. localStorage.setItem('username', this.form.phone)
  83. localStorage.setItem('password', this.form.password)
  84. } else {
  85. localStorage.setItem('username', '')
  86. localStorage.setItem('password', '')
  87. }
  88. let params = {
  89. phoneNum: this.form.phone,
  90. password: encodeStr(Base64.encode(this.form.password)),
  91. randomcode: '1234',
  92. rememberMe: Boolean(this.rememberMe)
  93. }
  94. await this.$store.dispatch('login', params)
  95. const from = this.$route.query.from
  96. if (from) {
  97. this.$router.push(from)
  98. } else {
  99. this.$router.push('/')
  100. }
  101. }
  102. }
  103. }
  104. </script>
  105. <style lang="scss" >
  106. .login-box {
  107. width: 398px;
  108. padding: 38px 0;
  109. input[type=text] {
  110. height: 60px;
  111. line-height: 60px;
  112. padding-left: 8px;
  113. border: 1px solid #909090;
  114. border-radius: 3px;
  115. }
  116. }
  117. .login-tabs {
  118. padding: 0 38px;
  119. }
  120. .login-tab {
  121. display: inline-block;
  122. width: 50%;
  123. font-size: 20px;
  124. text-align: center;
  125. padding-bottom: 10px;
  126. border-bottom: 1px solid #707070;
  127. margin-bottom: 38px;
  128. cursor: pointer;
  129. &.is-active {
  130. border-bottom: 2px solid #1FE4DC;
  131. padding-bottom: 9px;
  132. }
  133. }
  134. .account-login {
  135. padding: 0 38px;
  136. }
  137. .password {
  138. margin: 29px 0 13px;
  139. }
  140. .toCodeLogin {
  141. text-align: right;
  142. a {
  143. cursor: pointer;
  144. }
  145. }
  146. .checkbox {
  147. // padding-left: 27px;
  148. position: relative;
  149. font-size: 16px;
  150. color: #202020;
  151. display: inline-block;
  152. input {
  153. margin-right: 7px;
  154. cursor: pointer;
  155. }
  156. * {
  157. vertical-align: middle;
  158. }
  159. }
  160. .login-btn {
  161. margin: 36px 0 18px;
  162. background: #1FE4DC;
  163. width: 100%;
  164. text-align: center;
  165. line-height: 60px;
  166. font-weight: 600;
  167. border-radius: 3px;
  168. cursor: pointer;
  169. }
  170. .others {
  171. text-align: center;
  172. }
  173. .other-actions {
  174. color: #202020;
  175. font-size: 16px;
  176. &:first-child {
  177. margin-right: 34px;
  178. position: relative;
  179. &::after {
  180. content: '';
  181. height: 14px;
  182. width: 1px;
  183. background: #909090;
  184. position: absolute;
  185. right: -18px;
  186. top: 50%;
  187. margin-top: -7px;
  188. }
  189. }
  190. }
  191. </style>