index.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. <template>
  2. <div class="login-container">
  3. <div class="login-weaper">
  4. <div class="login-left">
  5. <img src="@/assets/img/login-page.png" alt="">
  6. </div>
  7. <div class="login-right">
  8. <el-tabs v-model="data.activeName" class="demo-tabs">
  9. <el-tab-pane label="登录" name="password"></el-tab-pane>
  10. <!-- <el-tab-pane label="验证码登录" name="code"></el-tab-pane> -->
  11. </el-tabs>
  12. <el-form ref="loginForm" :model="data.loginForm" :rules="data.loginRules" :hide-required-asterisk="true"
  13. class="login-ruleForm" :size="formSize">
  14. <el-form-item label="账号" prop="phone">
  15. <el-input v-model="data.loginForm.phone" clearable maxlength="11" placeholder="请输入账号"
  16. class="login-input"></el-input>
  17. </el-form-item>
  18. <el-form-item label="密码" prop="password" v-if="data.activeName == 'password'">
  19. <el-input v-model="data.loginForm.password" @keyup.enter.native="login(loginForm)" clearable show-password
  20. type="password" placeholder="请输入密码" class="login-input"></el-input>
  21. </el-form-item>
  22. <el-form-item label="验证码" prop="code" v-if="data.activeName == 'code'">
  23. <el-input v-model="data.loginForm.code" clearable placeholder="请输入验证码" class="login-input">
  24. <template #append>
  25. <el-button @click="setCode" :disabled="data.changeBtn" class="btn-code">{{ data.btnTitle }}</el-button>
  26. </template>
  27. </el-input>
  28. </el-form-item>
  29. <el-form-item>
  30. <el-button type="primary" @click="login(loginForm)" class="login-btn"><span>登录</span></el-button>
  31. </el-form-item>
  32. </el-form>
  33. </div>
  34. </div>
  35. </div>
  36. </template>
  37. <script setup>
  38. import { onMounted, reactive, ref } from "vue";
  39. import { useRouter, useRoute } from 'vue-router'
  40. import { useCounterStore } from '@/stores/counter.js'
  41. import { openLoading, closeLoading } from '@/utils/loading.js'
  42. const $route = useRoute()
  43. const $router = useRouter()
  44. import { $ls } from "@/storage";
  45. import { getAssetsFile } from '@/utils'
  46. import { passwordLogin } from "@/apis/user.js"
  47. import { ElMessage } from 'element-plus'
  48. const store = useCounterStore();
  49. const data = reactive({
  50. socialForm: {},
  51. loginForm: {
  52. phone: '',
  53. password: '',
  54. code: ''
  55. },
  56. loginRules: {
  57. phone: [
  58. { required: true, message: "请输入账号", trigger: "blur" }
  59. ],
  60. password: [
  61. { required: true, message: "请输入密码", trigger: "blur" },
  62. { min: 6, max: 15, message: "长度在6 ~ 15个字节", trigger: "blur" }
  63. ],
  64. code: [
  65. { required: true, message: "请输入验证码", trigger: 'blur' }
  66. ]
  67. },
  68. activeName: 'password',
  69. btnTitle: '发送验证码',
  70. send: true,
  71. time: null,
  72. count: '',
  73. changeBtn: false,
  74. });
  75. const loginForm = ref();
  76. const formSize = ref('default')
  77. const logo = getAssetsFile('logo.png');
  78. $ls.setItem('isToken', true)
  79. const setCode = (() => {
  80. })
  81. const getCode = (() => {
  82. })
  83. const login = async (formEl) => {
  84. formEl.validate((valid) => {
  85. if(valid){
  86. let params = {
  87. password: data.loginForm.password,
  88. username: data.loginForm.phone
  89. }
  90. store.LoginUsername(params);
  91. }
  92. })
  93. // const res = await passwordLogin(params)
  94. // if (res.code === 1) {
  95. // getMenu()
  96. // $ls.setItem('token', res.data)
  97. // $router.push('/home')
  98. // } else {
  99. // ElMessage.error(res.message)
  100. // }
  101. }
  102. // const getMenu = async () =>{
  103. // const res = await userMenu(data.loginForm.phone)
  104. // if(res.code === 1){
  105. // $ls.setItem('menu',res.data)
  106. // }
  107. // }
  108. </script>
  109. <style lang="scss" scoped>
  110. .login-container {
  111. height: 100vh;
  112. background: url('@/assets/img/login.png') no-repeat center;
  113. background-size: 100% 100%;
  114. display: flex;
  115. justify-content: center;
  116. align-items: center;
  117. /* position: relative; */
  118. .login-weaper {
  119. width: 718px;
  120. height: 399px;
  121. background: #FFFFFF;
  122. box-shadow: 0px 0px 11px 0px rgba(117, 154, 193, 0.24);
  123. border-radius: 5px;
  124. display: flex;
  125. align-items: center;
  126. .login-left {
  127. width: 399px;
  128. height: 100%;
  129. img {
  130. width: 100%;
  131. }
  132. }
  133. .login-right {
  134. flex: 1;
  135. align-self: start;
  136. margin-top: 30px;
  137. :deep(.el-tabs) {
  138. .el-tabs__nav {
  139. width: 100%;
  140. display: flex;
  141. justify-content: center;
  142. }
  143. }
  144. :deep(.el-tabs__nav-wrap::after) {
  145. height: 0;
  146. }
  147. :deep(.el-tabs__content) {
  148. display: none;
  149. }
  150. :deep(.el-tabs__item) {
  151. font-weight: 500;
  152. font-size: 16px;
  153. color: #707476;
  154. }
  155. :deep(.el-tabs__active-bar) {
  156. height: 3px;
  157. }
  158. :deep(.el-tabs__item.is-active) {
  159. color: #17163D;
  160. font-weight: bold;
  161. }
  162. h3 {
  163. font-size: 20px;
  164. font-weight: 600;
  165. letter-spacing: 1px;
  166. color: #333333;
  167. }
  168. .login-ruleForm {
  169. /* margin-left: 39px; */
  170. margin-top: 35px;
  171. padding: 0 30px;
  172. /* width: 76%; */
  173. :deep(.el-form-item) {
  174. display: block;
  175. margin-bottom: 19px;
  176. .el-form-item__label {
  177. font-weight: 600;
  178. color: #333333;
  179. letter-spacing: 1px;
  180. }
  181. .el-form-item__content {
  182. .el-input {
  183. height: 37px;
  184. }
  185. }
  186. .login-btn {
  187. width: 100%;
  188. height: 37px;
  189. margin-top: 37px;
  190. font-size: 14px;
  191. }
  192. .btn-code {
  193. color: #0BA0FF;
  194. font-size: 12px;
  195. letter-spacing: 1px;
  196. width: 100px;
  197. }
  198. }
  199. }
  200. }
  201. }
  202. @media screen and (max-width: 700px) {
  203. .login-weaper {
  204. box-sizing: border-box;
  205. width: 319px;
  206. background: #fff;
  207. .login-left {
  208. display: none;
  209. }
  210. .login-right {
  211. width: 100%;
  212. }
  213. }
  214. }
  215. }
  216. </style>