login.vue 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  1. <template>
  2. <div class="sld_login">
  3. <div class="sld_login_header">
  4. <div class="content">
  5. <nuxt-link tag="a" class="l_logo" :to="'/'">
  6. <img
  7. class="img"
  8. :src="
  9. filtersStore.getSiteLogo ? filtersStore.getSiteLogo : defaultImg
  10. "
  11. :onerror="defaultImg"
  12. alt
  13. />
  14. </nuxt-link>
  15. <div class="r_register_wrap">
  16. {{ L["还没注册?"] }}
  17. <a
  18. class="go_register_btn"
  19. href="javascript:void(0)"
  20. @click="goToPage('/register')"
  21. >{{ L["去注册"] }}</a
  22. >
  23. </div>
  24. </div>
  25. </div>
  26. <div class="sld_login_content">
  27. <img
  28. class="bg"
  29. :src="ImgBG ? ImgBG : configInfo.main_user_logon_bg + ''"
  30. :onerror="defaultBgImg"
  31. alt
  32. />
  33. <div class="login">
  34. <div class="login_box">
  35. <div class="top">
  36. <div class="item1">{{ L["账号登录"] }}</div>
  37. </div>
  38. <div class="center">
  39. <div class="item account">
  40. <span
  41. style="color: #bbb; font-size: 19px; padding-top: 7px"
  42. class="icon iconfont icon-wode"
  43. ></span>
  44. <input
  45. type="text"
  46. v-model="name"
  47. :placeholder="L['请输入邮箱']"
  48. class="input"
  49. autocomplete="off"
  50. />
  51. <div
  52. data-type="userName"
  53. class="cancel"
  54. @click="clearInputVal('name')"
  55. >
  56. <span style="color: #bbb" class="iconfont icon-cuowu"></span>
  57. </div>
  58. </div>
  59. <div class="item password">
  60. <span
  61. style="color: #bbb; font-size: 21px; padding-top: 7px"
  62. class="icon iconfont icon-mima1"
  63. ></span>
  64. <input
  65. type="password"
  66. v-model="password"
  67. :placeholder="L['请输入密码']"
  68. class="input"
  69. autocomplete="new-password"
  70. />
  71. <div
  72. data-type="password"
  73. class="cancel"
  74. @click="clearInputVal('password')"
  75. >
  76. <span style="color: #bbb" class="iconfont icon-cuowu"></span>
  77. </div>
  78. </div>
  79. <div class="error">
  80. <span
  81. v-if="errorMsg"
  82. style="color: #e1251b; font-size: 14px"
  83. class="iconfont icon-jubao"
  84. ></span>
  85. {{ errorMsg }}
  86. </div>
  87. <el-button
  88. @click="login"
  89. :class="{ submit: true, disabled: loginDisabled }"
  90. :disabled="loginDisabled"
  91. :loading="loginLoding"
  92. >{{ L["登录"] }}</el-button
  93. >
  94. </div>
  95. <div
  96. :class="{
  97. bottom: true,
  98. flex_row_between_center: wxEnable == 0,
  99. flex_row_end_center: wxEnable != 0,
  100. }"
  101. >
  102. <a href="javascript:void(0)" @click="goToPage('/register')">{{
  103. L["立即注册"]
  104. }}</a>
  105. <router-link tag="a" :to="`/member/login/forget`">{{
  106. L["忘记密码"]
  107. }}</router-link>
  108. </div>
  109. </div>
  110. </div>
  111. </div>
  112. </div>
  113. </template>
  114. <script setup>
  115. import { ElMessage } from "element-plus";
  116. // import { lang_zn } from "@/assets/language/zh";
  117. import { getCurLanguage } from "@/composables/common.js";
  118. import { useUserInfo } from "@/store/user.js";
  119. import { useFiltersStore } from "@/store/filter.js";
  120. const configInfo = useUserInfo();
  121. const filtersStore = useFiltersStore();
  122. const isLoading = ref(false);
  123. // const L = lang_zn;
  124. const L = getCurLanguage();
  125. const router = useRouter();
  126. const route = useRoute();
  127. const { proxy } = getCurrentInstance();
  128. const keyEnter = ref(true);
  129. const errorMsg = ref(); //错误提示
  130. const name = ref(""); //账户
  131. const password = ref(""); //密码
  132. const loginType = ref(1); //登陆类型:1-账号密码登陆,2-手机验证码登陆
  133. const defaultImg = ref("/common_top_logo.png");
  134. const defaultBgImg = ref("/login_bg.png");
  135. const fromurl = ref("");
  136. const wxEnable = ref("");
  137. const pwdCalc = ref();
  138. const ImgBG = ref("");
  139. const loginLoding = ref(false);
  140. const loginDisabled = computed(() => !name.value || !password.value);
  141. useHead({
  142. title: "Login",
  143. meta: [
  144. {
  145. name: "description",
  146. content: "Login",
  147. },
  148. {
  149. name: "keywords",
  150. content: "Login",
  151. },
  152. ],
  153. });
  154. //由于这里的回车键触发事件和商品搜索框的回车键触发事件冲突,引入keyEnter变量判断
  155. if (process.client) {
  156. document.onkeydown = function () {
  157. var key = window.event.keyCode;
  158. if (key == 13 && keyEnter.value) {
  159. login();
  160. }
  161. };
  162. }
  163. //获取背景图
  164. const getBg = () => {
  165. get("v3/system/front/setting/getSettings?names=main_user_logon_bg").then(
  166. (res) => {
  167. ImgBG.value = res.data[0];
  168. }
  169. );
  170. };
  171. getBg();
  172. const login = () => {
  173. let param = {};
  174. param.username = name.value;
  175. param.password = password.value;
  176. param.loginType = loginType.value;
  177. //账号验证
  178. if (!param.username) {
  179. errorMsg.value = L["请输入账号"];
  180. return false;
  181. }
  182. //密码校验
  183. if (!param.password) {
  184. errorMsg.value = L["请输入密码"];
  185. return false;
  186. } else {
  187. pwdCalc.value = checkPwd(param.password);
  188. if (pwdCalc.value !== true) {
  189. errorMsg.value = pwdCalc.value;
  190. return false;
  191. }
  192. }
  193. loginLoding.value = true;
  194. post("v3/frontLogin/oauth/token", param).then((res) => {
  195. if (res.state == 200) {
  196. //将用户信息存缓存,并跳转到首页
  197. filtersStore.setLoginStatus(true);
  198. filtersStore.setToken(res.data.access_token);
  199. filtersStore.setRefreshToken(res.data.refresh_token);
  200. filtersStore.setTime(new Date().getTime().toString()); //存储refresh_token更新时间
  201. //获取用户信息,并同步信息到pinia
  202. get("v3/member/front/member/getInfo")
  203. .then((res) => {
  204. if (res.state == 200) {
  205. filtersStore.setMemberInfo(res.data);
  206. if (window.history.state.back) {
  207. // if(window.history.state.back == '/register' || window.history.state.back == '/member/login/forget' || window.history.state.back == '/member/login/forget' || window.history.state.back == '/member/login/forget'){
  208. window.location.href = "/";
  209. // }else{
  210. // window.location.href = window.history.state.back;
  211. // }
  212. } else {
  213. router.replace({ path: "/member/home" });
  214. }
  215. }
  216. }).catch(err => {
  217. loginLoding.value = false;
  218. })
  219. } else {
  220. //提示错误
  221. errorMsg.value = res.msg;
  222. }
  223. });
  224. };
  225. //清空输入框内容
  226. const clearInputVal = (type) => {
  227. if (type == "name") {
  228. name.value = "";
  229. } else if (type == "password") {
  230. password.value = "";
  231. }
  232. };
  233. //登录方式切换
  234. const changeLoginType = (type) => {
  235. loginType.value = type;
  236. name.value = "";
  237. password.value = "";
  238. errorMsg.value = "";
  239. };
  240. //通过replace方式跳转页面
  241. const goToPage = (type) => {
  242. router.replace({
  243. path: type,
  244. });
  245. };
  246. watch([name, password], () => {
  247. if (loginType.value == 1) {
  248. password.value = password.value.substring(0, 20);
  249. // name.value = memberEmail.value.substring(0, 20)
  250. } else {
  251. password.value = password.value.substring(0, 6);
  252. // name.value = memberEmail.value.substring(0, .gitignore)
  253. }
  254. if (password.value || name.value) {
  255. errorMsg.value = "";
  256. }
  257. });
  258. onMounted(() => {
  259. if (route.query.redirectUrl) {
  260. fromurl.value =
  261. window.location.origin + decodeURIComponent(route.query.redirectUrl);
  262. } else {
  263. fromurl.value = window.location.origin;
  264. }
  265. if (route.query.error) {
  266. ElMessage.error(decodeURIComponent(route.query.error));
  267. }
  268. });
  269. // onBeforeRouteLeave(() => {
  270. // keyEnter.value = false;
  271. // });
  272. </script>
  273. <style lang="scss" scoped>
  274. @import "@/assets/style/register.scss";
  275. .center {
  276. padding: 30px 30px 40px;
  277. .item {
  278. position: relative;
  279. margin-top: 15px;
  280. border-radius: 2px;
  281. &:first-child {
  282. margin-top: 0;
  283. }
  284. .icon {
  285. position: absolute;
  286. left: 1px;
  287. top: 1px;
  288. width: 50px;
  289. text-align: center;
  290. height: 38px;
  291. background: #f8f8f8;
  292. .input {
  293. border: 1px solid #e8e8e8;
  294. height: 40px;
  295. padding: 0 44px 0 60px;
  296. width: 326px;
  297. }
  298. }
  299. .input {
  300. border: 1px solid #e8e8e8;
  301. height: 40px;
  302. padding: 0 44px 0 60px;
  303. width: 326px;
  304. }
  305. }
  306. .cancel {
  307. position: absolute;
  308. right: 0;
  309. top: 1px;
  310. width: 44px;
  311. height: 38px;
  312. cursor: pointer;
  313. :before {
  314. position: absolute;
  315. top: 9px;
  316. left: 14px;
  317. }
  318. }
  319. .error {
  320. margin-top: 10px;
  321. position: relative;
  322. color: $colorMain;
  323. height: 16px;
  324. line-height: 16px;
  325. }
  326. .submit {
  327. margin-top: 35px;
  328. background: $colorMain;
  329. color: #fff;
  330. text-align: center;
  331. border-radius: 2px;
  332. width: 100%;
  333. height: 45px;
  334. font-size: 18px;
  335. letter-spacing: 0px;
  336. &:hover {
  337. opacity: 0.9;
  338. }
  339. &.disabled {
  340. background-color: #909399;
  341. }
  342. }
  343. }
  344. </style>