login.vue 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  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. res.account_list = res.account_list.map(e=>{
  137. if (e.status === 'ACTIVE') {
  138. return e
  139. }
  140. })
  141. sessionStorage.setItem('account_list',JSON.stringify(res.account_list))
  142. sessionStorage.setItem('active_account',JSON.stringify(res.account_list[0]))
  143. this.basicData.query_userauth().then(()=>{
  144. this.basicData.querySite_Parameter()
  145. this.$router.push({path:'/main'})
  146. this.getAccountInfo()
  147. })
  148. } else {
  149. this.$notify({
  150. title: '失败',
  151. message:res.msg,
  152. type: 'error'
  153. })
  154. }
  155. },
  156. /* 获取账户信息 */
  157. async getAccountInfo () {
  158. let res = await this.$api.requested({
  159. "classname": "common.usercenter.usercenter",
  160. "method": "queryUserMsg",
  161. "content": {
  162. }
  163. })
  164. window.sessionStorage.setItem('accountinfo',JSON.stringify(res.data))
  165. },
  166. // 账号密码登录
  167. async loginbyaccount () {
  168. const res = await this.$api.loginbyaccount({
  169. "accountno": this.loginForm.phonenumber,
  170. "password": md5(this.loginForm.password),
  171. "systemclient":"web"
  172. })
  173. if (res.code === 1) {
  174. this.checked?localStorage.setItem('phonenumber',this.loginForm.phonenumber):localStorage.clear('phonenumber')
  175. res.account_list = res.account_list.map(e=>{
  176. if (e.status === 'ACTIVE') {
  177. return e
  178. }
  179. })
  180. sessionStorage.setItem('account_list',JSON.stringify(res.account_list))
  181. sessionStorage.setItem('active_account',JSON.stringify(res.account_list[0]))
  182. this.basicData.query_userauth().then(()=>{
  183. this.basicData.querySite_Parameter()
  184. this.$router.push({path:'/main'})
  185. this.getAccountInfo()
  186. })
  187. } else {
  188. this.$notify({
  189. title: '失败',
  190. message: res.msg,
  191. type: 'error'
  192. })
  193. }
  194. },
  195. }
  196. }
  197. </script>
  198. <style>
  199. .login-form .el-input__inner{
  200. color:#fff;
  201. border: 1px solid #0000004d;
  202. background: rgba(0, 0, 0, 0.1);
  203. box-shadow: 2px 8px 8px 0 rgb(0 0 0 / 10%) inset;
  204. }
  205. .login-form .el-tabs__item{
  206. color: #ffffff7d;
  207. }
  208. .login-form .el-tabs__item.is-active {
  209. color:#fff
  210. }
  211. .login-form .el-tabs__nav-wrap::after {
  212. background-color: #e4e7ed33;
  213. }
  214. .login-form .el-tabs__active-bar{
  215. background-color: #fff;
  216. }
  217. .login-form .el-checkbox__input.is-checked+.el-checkbox__label {
  218. color:#fff
  219. }
  220. </style>
  221. <style scoped>
  222. .logo{
  223. text-align: center;
  224. margin-bottom: 30px;
  225. color:#fff;
  226. }
  227. .logo span{
  228. display: block;
  229. font-size: 24px;
  230. line-height: 15px;
  231. }
  232. .logo small{
  233. color:#999
  234. }
  235. .title{
  236. display: flex;
  237. align-items: center;
  238. justify-content: space-between;
  239. height: 33px;
  240. margin: 0 0 30px;
  241. color: #fff;
  242. font-size: 24px;
  243. font-weight: 600;
  244. }
  245. .login-wrap{
  246. display: flex;
  247. align-items: center;
  248. justify-content: space-around;
  249. width: 100%;
  250. height: 100vh;
  251. /* background: #fff no-repeat 50% url(../../assets/bg.png); */
  252. background: url("../../assets/wallhaven-0pq8gm.jpeg") no-repeat;
  253. background-size: 100% 100%;
  254. }
  255. .login-form{
  256. /* min-height: 500px; */
  257. width: 400px;
  258. padding: 30px;
  259. color:#fff;
  260. background: rgb(255, 255, 255,.2);
  261. backdrop-filter: blur(30px);
  262. border-radius: 10px;
  263. box-shadow: 2px 8px 8px 0 rgb(0 0 0 / 20%);
  264. }
  265. .form-input-group{
  266. margin-bottom: 16px
  267. }
  268. .input-wrap{
  269. width: 100%;
  270. }
  271. .d-input{
  272. height: 40px;
  273. width: 100%;
  274. }
  275. .flex-between{
  276. display: flex;
  277. align-items: center;
  278. justify-content: space-between;
  279. }
  280. </style>