login.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374
  1. <template>
  2. <div class="page">
  3. <img src="@/assets/images/agent/logo3.png" class="logo">
  4. <div class="login">
  5. <div class="l_tabs adfac">
  6. <div class="t_pre" :class="{'active':tidx===1}" @click="handleChangeTab(1)">账号密码登录</div>
  7. <div class="t_pre" :class="{'active':tidx===2}" @click="handleChangeTab(2)">验证码登录</div>
  8. </div>
  9. <div class="l_form">
  10. <template v-if="tidx===1">
  11. <el-form ref="accountRef" :model="accountForm" :rules="accountRules" label-width="0px">
  12. <el-form-item label="" prop="username">
  13. <el-input v-model="accountForm.username" placeholder="请输入账号" />
  14. </el-form-item>
  15. <el-form-item label="" prop="password">
  16. <el-input show-password v-model="accountForm.password" placeholder="请输入密码" />
  17. </el-form-item>
  18. </el-form>
  19. </template>
  20. <template v-else-if="tidx===2">
  21. <el-form ref="codeRef" :model="codeForm" :rules="codeRules" label-width="0px">
  22. <el-form-item label="" prop="phone">
  23. <el-input type="number" v-model="codeForm.phone" placeholder="请输入手机号码" />
  24. </el-form-item>
  25. <el-form-item label="" prop="code">
  26. <div class="c_pre">
  27. <div class="left">
  28. <el-input v-model="codeForm.code" placeholder="请输入验证码"></el-input>
  29. </div>
  30. <div class="cp_right" @click="handleCode">
  31. <span>{{ codeBtnText }}</span>
  32. </div>
  33. </div>
  34. </el-form-item>
  35. </el-form>
  36. </template>
  37. </div>
  38. <div class="l_check">
  39. <el-checkbox v-model="checked">记住密码</el-checkbox>
  40. </div>
  41. <div class="l_btn" :class="{'active':((tidx===1&&accountForm.username&&accountForm.password)||(tidx===2&&codeForm.phone&&codeForm.code))}" @click="handleLogin">立即登录</div>
  42. <div class="l_check">
  43. <el-checkbox v-model="agree">已阅读并同意 <span class="lcs">隐私协议</span> 和 <span class="lcs">服务条款</span></el-checkbox>
  44. </div>
  45. </div>
  46. </div>
  47. </template>
  48. <script setup name="">
  49. var timer = null;
  50. import Cookies from "js-cookie";
  51. import { getUUID } from "@/utils";
  52. import { ref, getCurrentInstance } from 'vue'
  53. const { proxy } = getCurrentInstance();
  54. const time = ref(60);
  55. const codeBtn = ref(true);
  56. const codeBtnText = ref('获取验证码');
  57. const tidx = ref(1);
  58. const accountRef = ref(null);
  59. const codeRef = ref(null);
  60. const accountForm = ref({
  61. username: '',
  62. password: '',
  63. uuid: getUUID()
  64. });
  65. const accountRules = ref({
  66. username: [
  67. { required: true, message: '请输入账号', trigger: 'blur' }
  68. ],
  69. password: [
  70. { required: true, message: '请输入密码', trigger: 'blur' }
  71. ]
  72. });
  73. const codeForm = ref({
  74. phone: '',
  75. code: ''
  76. });
  77. const codeRules = ref({
  78. phone: [
  79. { required: true, message: '请输入手机号码', trigger: 'blur' },
  80. { pattern: /^1[3456789]\d{9}$/, message: '请输入正确的手机号码', trigger: 'blur' }
  81. ],
  82. code: [
  83. { required: true, message: '请输入验证码', trigger: 'blur' }
  84. ]
  85. })
  86. const checked = ref(false);
  87. const agree = ref(false);
  88. const handleChangeTab = (idx) => {
  89. tidx.value = idx;
  90. }
  91. const handleCode = () => {
  92. if(!codeBtn.value) return;
  93. codeBtn.value = false;
  94. codeBtnText.value = '重新发送('+time.value+'s)';
  95. timer = setInterval(()=>{
  96. time.value--;
  97. if(time.value<=0){
  98. clearInterval(timer);
  99. codeBtnText.value = '获取验证码';
  100. codeBtn.value = true;
  101. time.value = 60;
  102. }else{
  103. codeBtnText.value = '重新发送('+time.value+'s)';
  104. }
  105. },1000)
  106. }
  107. const handleLogin = () => {
  108. if(tidx.value===1){
  109. proxy.$refs.accountRef.validate((valid) => {
  110. if (valid) {
  111. if(!agree.value) return proxy.$message({type: 'warning', message: '请阅读并同意隐私协议和服务条款'})
  112. toLogin();
  113. } else {
  114. return false;
  115. }
  116. });
  117. }else if(tidx.value===2){
  118. proxy.$refs.codeRef.validate((valid) => {
  119. if (valid) {
  120. if(!agree.value) return proxy.$message({type: 'warning', message: '请阅读并同意隐私协议和服务条款'})
  121. console.log("验证码登录");
  122. } else {
  123. return false;
  124. }
  125. });
  126. }
  127. }
  128. const toLogin = () => {
  129. proxy.$http.post("/login", accountForm.value).then(({ data: res }) => {
  130. if (res.code !== 0) return proxy.$message.error(res.msg);
  131. sessionStorage.removeItem("tags");
  132. Cookies.set("token", res.data.token);
  133. if (checked.value) {
  134. setCookie(accountForm.value.username, accountForm.value.password, 7);
  135. } else {
  136. setCookie("", "", -1);
  137. }
  138. // 获取菜单列表, 添加并全局变量保存
  139. proxy.$http.get("/sys/menu/nav", {
  140. params: {
  141. menuClassify: 1
  142. }
  143. }).then(({ data: res }) => {
  144. if (res.code !== 0) proxy.$message.error(res.msg);
  145. var menuList = res.data;
  146. for (var i = 0; i < menuList.length; i++) {
  147. var menu = {};
  148. if (menuList[i].url != "") {
  149. menu = menuList[i];
  150. } else if (menuList[i].children.length > 0) {
  151. menu = menuList[i].children[0];
  152. }
  153. // 组装路由
  154. var route = {
  155. path: "",
  156. component: null,
  157. name: "index",
  158. meta: {
  159. ...window.SITE_CONFIG["contentTabDefault"],
  160. menuId: menu.id,
  161. title: menu.name,
  162. },
  163. };
  164. let URL = (menu.url || "").replace(/{{([^}}]+)?}}/g,(s1, s2) => eval(s2));
  165. URL = URL.replace(/^\//, "").replace(/_/g, "-");
  166. route["path"] = route["name"] = URL.replace(/\//g, "-");
  167. route["component"] = () => import(`@/views/modules/${URL}`);
  168. // proxy.$router.push(route);
  169. proxy.$router.push('home');
  170. proxy.$store.state.sidebarMenuActiveName = [];
  171. var proute = menuList.filter(
  172. (item) =>
  173. item.children.filter((child) => child.id == menu.id).length > 0
  174. );
  175. proxy.$store.state.sidebarMenuActiveName.push(
  176. proute.length > 0 ? proute[0].name : ""
  177. );
  178. proxy.$store.state.sidebarMenuActiveName.push(
  179. route.meta.title
  180. );
  181. break;
  182. }
  183. localStorage.setItem("currentMenuIndex", 0);
  184. proxy.$store.state.currentMenuIndex = 0;
  185. });
  186. })
  187. }
  188. const setCookie = (name, pwd, exdays) => {
  189. var exdate = new Date();
  190. exdate.setTime(exdate.getTime() + 24 * 60 * 60 * 1000 * exdays);
  191. window.document.cookie =
  192. "userName" + "=" + name + ";path=/;expires=" + exdate.toGMTString();
  193. window.document.cookie =
  194. "userPwd" + "=" + pwd + ";path=/;expires=" + exdate.toGMTString();
  195. }
  196. const getCookie = () => {
  197. if (document.cookie.length > 0) {
  198. var arr = document.cookie.split("; ");
  199. for (var i = 0; i < arr.length; i++) {
  200. var arr2 = arr[i].split("=");
  201. if (arr2[0] === "userName") {
  202. accountForm.value.username = arr2[1];
  203. } else if (arr2[0] === "userPwd") {
  204. accountForm.value.password = arr2[1];
  205. }
  206. }
  207. checked.value = true;
  208. }
  209. }
  210. getCookie();
  211. </script>
  212. <style scoped lang="scss">
  213. .page{
  214. width: 100%;
  215. height: 100vh;
  216. background: url(@/assets/images/agent/login_bg.png) no-repeat;
  217. background-size: 100% 100%;
  218. position: relative;
  219. .logo{
  220. width: 167px;
  221. height: 48px;
  222. position: absolute;
  223. top: 40px;
  224. left: 48px;
  225. z-index: 2;
  226. }
  227. .login{
  228. width: 514px;
  229. height: 614px;
  230. background: #FFFFFF;
  231. border-radius: 16px;
  232. padding: 64px 48px;
  233. box-sizing: border-box;
  234. position: absolute;
  235. top: 50%;
  236. margin-top: -307px;
  237. right: 262px;
  238. .l_tabs{
  239. .t_pre{
  240. font-family: PingFangSC, PingFang SC;
  241. font-weight: 400;
  242. font-size: 20px;
  243. color: #646464;
  244. line-height: 28px;
  245. padding-bottom: 4px;
  246. cursor: pointer;
  247. &.active{
  248. font-weight: bold;
  249. color: #761E6A;
  250. position: relative;
  251. &::after{
  252. content:'';
  253. width: 100%;
  254. height: 2px;
  255. background: #761E6A;
  256. position: absolute;
  257. left: 0;
  258. bottom: 0;
  259. }
  260. }
  261. &:last-child{
  262. margin-left: 64px;
  263. }
  264. }
  265. }
  266. .l_check{
  267. margin-top: 48px;
  268. .lcs{
  269. font-family: PingFangSC, PingFang SC;
  270. font-weight: 400;
  271. font-size: 16px;
  272. color: #761E6A;
  273. line-height: 22px;
  274. }
  275. }
  276. .l_btn{
  277. margin-top: 48px;
  278. height: 60px;
  279. background: rgba(131, 52, 120, .4);
  280. border-radius: 6px;
  281. font-family: PingFang-SC, PingFang-SC;
  282. font-weight: bold;
  283. font-size: 20px;
  284. color: #FFFFFF;
  285. line-height: 60px;
  286. text-align: center;
  287. cursor: pointer;
  288. letter-spacing: 1px;
  289. cursor: not-allowed;
  290. &.active{
  291. background: rgba(131, 52, 120, 1);
  292. cursor: pointer;
  293. }
  294. }
  295. .c_pre{
  296. height: 54px;
  297. background: #FFFFFF;
  298. border-radius: 6px;
  299. border: 1px solid #ECEEF5;
  300. display: flex;
  301. align-items: center;
  302. .left{
  303. width: 304px;
  304. }
  305. .cp_right{
  306. width: calc(100% - 304px);
  307. display: flex;
  308. align-items: center;
  309. justify-content: center;
  310. position: relative;
  311. cursor: pointer;
  312. &::before{
  313. content: '';
  314. width: 1px;
  315. height: 21px;
  316. background: #ECEEF5;
  317. position: absolute;
  318. top: 50%;
  319. margin-top: -10.5px;
  320. left: 0;
  321. }
  322. &>span{
  323. font-family: PingFangSC, PingFang SC;
  324. font-weight: 400;
  325. font-size: 14px;
  326. color: #761E6A;
  327. line-height: 20px;
  328. }
  329. }
  330. }
  331. }
  332. }
  333. ::v-deep .el-form-item{
  334. margin-bottom: 0 !important;
  335. margin-top: 48px;
  336. }
  337. ::v-deep .el-input__inner{
  338. height: 54px !important;
  339. line-height: 54px !important;
  340. }
  341. ::v-deep .el-checkbox__label{
  342. font-size: 16px !important;
  343. color: #393939;
  344. }
  345. ::v-deep .c_pre .el-input__inner{
  346. border: none !important;
  347. height: 48px !important;
  348. line-height: 48px !important;
  349. width: calc(100% - 2px);
  350. margin-left: 2px;
  351. }
  352. </style>