login.vue 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. <template>
  2. <div class="conatiner">
  3. <div class="login-wrap">
  4. <div>
  5. <div class="logo">
  6. <span> 营销管理平台</span><br>
  7. <small>SALE-MANAGE-SYSTEM</small>
  8. </div>
  9. <div class="login-form">
  10. <h4 class="title">登录</h4>
  11. <el-tabs v-model="activeName">
  12. <el-tab-pane label="账号登录" name="first">
  13. <el-form :rules="rules2" ref="loginForm" :model="loginForm">
  14. <el-form-item prop="phonenumber">
  15. <el-input v-model="loginForm.phonenumber" placeholder="账号" @keyup.native.enter="loginbyaccount"></el-input>
  16. </el-form-item>
  17. <el-form-item prop="password">
  18. <el-input v-model="loginForm.password" type="password" placeholder="密码" @keyup.native.enter="loginbyaccount">
  19. </el-input>
  20. </el-form-item>
  21. <el-form-item>
  22. <div class="flex-between">
  23. <el-checkbox v-model="checked">记住账号</el-checkbox>
  24. </div>
  25. </el-form-item>
  26. <el-form-item>
  27. <el-button type="primary" style="width:100%" @click="loginbyaccount">登 录</el-button>
  28. </el-form-item>
  29. </el-form>
  30. </el-tab-pane>
  31. <el-tab-pane label="短信登录" name="second">
  32. <el-form :rules="rules" ref="loginForm" :model="loginForm">
  33. <el-form-item prop="phonenumber">
  34. <el-input v-model="loginForm.phonenumber" placeholder="账号"></el-input>
  35. </el-form-item>
  36. <el-form-item prop="password">
  37. <el-input v-model="loginForm.password" placeholder="验证码">
  38. <template slot="append">
  39. <span v-if="count > 0">{{count === 0?'获取验证码':count+ 's'}}</span>
  40. <el-button v-else @click="countDown" type="primary">{{count === 0?'获取验证码':count+ 's'}}</el-button>
  41. </template>
  42. </el-input>
  43. </el-form-item>
  44. <el-form-item>
  45. <div class="flex-between">
  46. <el-checkbox v-model="checked">记住账号</el-checkbox>
  47. </div>
  48. </el-form-item>
  49. <el-form-item>
  50. <el-button type="primary" style="width:100%" @click="login">登 录</el-button>
  51. </el-form-item>
  52. </el-form>
  53. </el-tab-pane>
  54. </el-tabs>
  55. </div>
  56. </div>
  57. </div>
  58. </div>
  59. </template>
  60. <script>
  61. import md5 from 'js-md5'
  62. export default {
  63. data () {
  64. return {
  65. rules: {
  66. phonenumber: [
  67. { required: true, message: '请输入账号', trigger: 'blur' },
  68. ],
  69. password: [
  70. { required: true, message: '请输入验证码', trigger: 'blur' }
  71. ],
  72. },
  73. rules2:{
  74. phonenumber: [
  75. { required: true, message: '请输入账号', trigger: 'blur' },
  76. ],
  77. password: [
  78. { required: true, message: '请输入密码', trigger: 'blur' }
  79. ],
  80. },
  81. loginForm:{
  82. phonenumber:''
  83. },
  84. activeName:'first',
  85. checked:false,
  86. count:0
  87. }
  88. },
  89. created () {
  90. this.$store.dispatch('DrawerShowChange',false)
  91. },
  92. mounted () {
  93. if (localStorage.getItem('phonenumber')) {
  94. this.loginForm.phonenumber = localStorage.getItem('phonenumber')
  95. this.checked = true
  96. }
  97. },
  98. methods:{
  99. //验证码请求
  100. loginCode () {
  101. this.$api.loginCode({
  102. "phonenumber":this.loginForm.phonenumber,
  103. "systemclient": "web"
  104. }).then(res => {
  105. console.log(res)
  106. const h = this.$createElement;
  107. res.code === 1?this.$notify({
  108. title: '获取验证码成功!',
  109. message: h('i', { style: 'color: teal'}, res.msg)
  110. }):this.$notify({
  111. title: '失败',
  112. message: res.msg,
  113. type: 'error'
  114. })
  115. });
  116. },
  117. // 获取验证码计时
  118. async countDown () {
  119. await this.loginCode()
  120. this.count = 5
  121. var down = setInterval(()=>{
  122. this.count --
  123. this.count === 0? clearInterval(down):''
  124. },1000)
  125. },
  126. // 登录请求
  127. async login () {
  128. const res = await this.$api.login({
  129. "phonenumber":this.loginForm.phonenumber,
  130. "password":md5(this.loginForm.password),
  131. "systemclient": "web"
  132. })
  133. let that = this
  134. if (res.code === 1) {
  135. this.checked?localStorage.setItem('phonenumber',this.loginForm.phonenumber):localStorage.clear('phonenumber')
  136. sessionStorage.setItem('account_list',JSON.stringify(res.account_list))
  137. sessionStorage.setItem('active_account',JSON.stringify(res.account_list[0]))
  138. this.basicData.query_userauth().then(()=>{
  139. this.basicData.querySite_Parameter()
  140. this.$router.push({path:'/main'})
  141. this.getAccountInfo()
  142. })
  143. } else {
  144. this.$notify({
  145. title: '失败',
  146. message:res.msg,
  147. type: 'error'
  148. })
  149. }
  150. },
  151. /* 获取账户信息 */
  152. async getAccountInfo () {
  153. let res = await this.$api.requested({
  154. "classname": "common.usercenter.usercenter",
  155. "method": "queryUserMsg",
  156. "content": {
  157. }
  158. })
  159. window.sessionStorage.setItem('accountinfo',JSON.stringify(res.data))
  160. },
  161. // 账号密码登录
  162. async loginbyaccount () {
  163. const res = await this.$api.loginbyaccount({
  164. "accountno": this.loginForm.phonenumber,
  165. "password": md5(this.loginForm.password),
  166. "systemclient":"web"
  167. })
  168. if (res.code === 1) {
  169. this.checked?localStorage.setItem('phonenumber',this.loginForm.phonenumber):localStorage.clear('phonenumber')
  170. sessionStorage.setItem('account_list',JSON.stringify(res.account_list))
  171. sessionStorage.setItem('active_account',JSON.stringify(res.account_list[0]))
  172. this.basicData.query_userauth().then(()=>{
  173. this.basicData.querySite_Parameter()
  174. this.$router.push({path:'/main'})
  175. this.getAccountInfo()
  176. })
  177. } else {
  178. this.$notify({
  179. title: '失败',
  180. message: res.msg,
  181. type: 'error'
  182. })
  183. }
  184. },
  185. }
  186. }
  187. </script>
  188. <style>
  189. .login-form .el-input__inner{
  190. color:#fff;
  191. border: 1px solid #0000004d;
  192. background: rgba(0, 0, 0, 0.1);
  193. box-shadow: 2px 8px 8px 0 rgb(0 0 0 / 10%) inset;
  194. }
  195. .login-form .el-tabs__item{
  196. color: #ffffff7d;
  197. }
  198. .login-form .el-tabs__item.is-active {
  199. color:#fff
  200. }
  201. .login-form .el-tabs__nav-wrap::after {
  202. background-color: #e4e7ed33;
  203. }
  204. .login-form .el-tabs__active-bar{
  205. background-color: #fff;
  206. }
  207. .login-form .el-checkbox__input.is-checked+.el-checkbox__label {
  208. color:#fff
  209. }
  210. </style>
  211. <style scoped>
  212. .logo{
  213. text-align: center;
  214. margin-bottom: 30px;
  215. color:#fff;
  216. }
  217. .logo span{
  218. display: block;
  219. font-size: 24px;
  220. line-height: 15px;
  221. }
  222. .logo small{
  223. color:#999
  224. }
  225. .title{
  226. display: flex;
  227. align-items: center;
  228. justify-content: space-between;
  229. height: 33px;
  230. margin: 0 0 30px;
  231. color: #fff;
  232. font-size: 24px;
  233. font-weight: 600;
  234. }
  235. .login-wrap{
  236. display: flex;
  237. align-items: center;
  238. justify-content: space-around;
  239. width: 100%;
  240. height: 100vh;
  241. /* background: #fff no-repeat 50% url(../../assets/bg.png); */
  242. background: url("../../assets/wallhaven-0pq8gm.jpeg") no-repeat;
  243. background-size: 100% 100%;
  244. }
  245. .login-form{
  246. /* min-height: 500px; */
  247. width: 400px;
  248. padding: 30px;
  249. color:#fff;
  250. background: rgb(255, 255, 255,.2);
  251. backdrop-filter: blur(30px);
  252. border-radius: 10px;
  253. box-shadow: 2px 8px 8px 0 rgb(0 0 0 / 20%);
  254. }
  255. .form-input-group{
  256. margin-bottom: 16px
  257. }
  258. .input-wrap{
  259. width: 100%;
  260. }
  261. .d-input{
  262. height: 40px;
  263. width: 100%;
  264. }
  265. .flex-between{
  266. display: flex;
  267. align-items: center;
  268. justify-content: space-between;
  269. }
  270. </style>