login.vue 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  1. <template>
  2. <div class="sld_login">
  3. <NavTopBar />
  4. <div class="sld_login_header">
  5. <div class="content">
  6. <nuxt-link tag="a" class="l_logo" :to="'/'">
  7. <img
  8. class="img"
  9. :src="
  10. filtersStore.getSiteLogo ? filtersStore.getSiteLogo : defaultImg
  11. "
  12. :onerror="defaultImg"
  13. alt
  14. />
  15. </nuxt-link>
  16. <div class="r_register_wrap">
  17. {{ L["还没注册?"] }}
  18. <a
  19. class="go_register_btn"
  20. href="javascript:void(0)"
  21. @click="goToPage('/register')"
  22. >{{ L["去注册"] }}</a
  23. >
  24. </div>
  25. </div>
  26. </div>
  27. <div class="sld_login_content">
  28. <img class="bg" :src="ImgBG" :onerror="defaultBgImg" alt />
  29. <div class="login">
  30. <div class="login_box">
  31. <div class="top">
  32. <div class="item1">{{ L["账号登录"] }}</div>
  33. </div>
  34. <LoginEmail
  35. ref="loginEmail"
  36. v-if="appType === 'user'"
  37. :loginLoding="loginLoding"
  38. @login="login"
  39. />
  40. <LoginPhone
  41. ref="loginPhone"
  42. v-if="appType === 'distributor'"
  43. :loginLoding="loginLoding"
  44. @login="login"
  45. />
  46. <div
  47. :class="{
  48. bottom: true,
  49. flex_row_between_center: wxEnable == 0,
  50. flex_row_end_center: wxEnable != 0,
  51. }"
  52. style="padding: 0 30px"
  53. >
  54. <a
  55. class="a_link"
  56. href="javascript:void(0)"
  57. @click="goToPage('/register')"
  58. >{{ L["立即注册"] }}</a
  59. >
  60. <router-link
  61. class="a_link"
  62. tag="a"
  63. :to="`/member/login/forget`"
  64. style="margin-right: 0px"
  65. >{{ L["忘记密码"] }}</router-link
  66. >
  67. </div>
  68. </div>
  69. </div>
  70. </div>
  71. </div>
  72. </template>
  73. <script setup>
  74. import { ElMessage } from "element-plus";
  75. // import { lang_zn } from "@/assets/language/zh";
  76. import { getCurLanguage } from "@/composables/common.js";
  77. import { useUserInfo } from "@/store/user.js";
  78. import { useFiltersStore } from "@/store/filter.js";
  79. const configInfo = useUserInfo();
  80. const filtersStore = useFiltersStore();
  81. const loginEmail = ref();
  82. const loginPhone = ref();
  83. const config = useRuntimeConfig();
  84. const appType = config.public.appType;
  85. const L = getCurLanguage();
  86. const router = useRouter();
  87. const route = useRoute();
  88. const { proxy } = getCurrentInstance();
  89. // const keyEnter = ref(true);
  90. const loginLoding = ref(false);
  91. const defaultImg = ref("/common_top_logo.png");
  92. const defaultBgImg = ref("/login_bg.png");
  93. const fromurl = ref("");
  94. const wxEnable = ref("");
  95. const ImgBG = ref("");
  96. useHead({
  97. title: "Login",
  98. meta: [
  99. {
  100. name: "description",
  101. content: "Login",
  102. },
  103. {
  104. name: "keywords",
  105. content: "Login",
  106. },
  107. ],
  108. });
  109. // //由于这里的回车键触发事件和商品搜索框的回车键触发事件冲突,引入keyEnter变量判断
  110. // if (process.client) {
  111. // document.onkeydown = function () {
  112. // var key = window.event.keyCode;
  113. // if (key == 13 && keyEnter.value) {
  114. // // login();
  115. // }
  116. // };
  117. // }
  118. //获取背景图
  119. const getBg = () => {
  120. get("v3/system/front/setting/getSettings?names=main_user_logon_bg").then(
  121. (res) => {
  122. ImgBG.value = res.data[0];
  123. }
  124. );
  125. };
  126. getBg();
  127. const login = (param) => {
  128. loginLoding.value = true;
  129. post("v3/frontLogin/oauth/token", param)
  130. .then((res) => {
  131. if (res.state == 200) {
  132. //将用户信息存缓存,并跳转到首页
  133. filtersStore.setLoginStatus(true);
  134. filtersStore.setToken(res.data.access_token);
  135. filtersStore.setRefreshToken(res.data.refresh_token);
  136. filtersStore.setTime(new Date().getTime().toString()); //存储refresh_token更新时间
  137. //获取用户信息,并同步信息到pinia
  138. get("v3/member/front/member/getInfo").then((res) => {
  139. if (res.state == 200) {
  140. filtersStore.setMemberInfo(res.data);
  141. router.replace({
  142. path: "/",
  143. });
  144. localStorage.setItem("isLoggedIn", "true");
  145. setTimeout(() => {
  146. localStorage.removeItem("isLoggedIn");
  147. }, 200);
  148. }
  149. });
  150. } else {
  151. //提示错误
  152. const instance =
  153. appType === "user" ? loginEmail.value : loginPhone.value;
  154. instance.updateErrorMsg(res.msg);
  155. }
  156. })
  157. .finally(() => {
  158. loginLoding.value = false;
  159. });
  160. };
  161. //通过replace方式跳转页面
  162. const goToPage = (type) => {
  163. router.replace({
  164. path: type,
  165. });
  166. };
  167. onMounted(() => {
  168. if (route.query.redirectUrl) {
  169. fromurl.value =
  170. window.location.origin + decodeURIComponent(route.query.redirectUrl);
  171. } else {
  172. fromurl.value = window.location.origin;
  173. }
  174. if (route.query.error) {
  175. ElMessage.error(decodeURIComponent(route.query.error));
  176. }
  177. });
  178. </script>
  179. <style lang="scss" scoped>
  180. @import "@/assets/style/register.scss";
  181. :deep(.center) {
  182. flex: 1;
  183. height: 100%;
  184. position: relative;
  185. padding: 0 28px;
  186. margin-top: 60px;
  187. // padding: 30px 30px 40px;
  188. .item {
  189. position: relative;
  190. margin-top: 15px;
  191. border-radius: 2px;
  192. &:first-child {
  193. margin-top: 0;
  194. }
  195. .icon {
  196. display: flex;
  197. align-items: center;
  198. justify-content: flex-end;
  199. position: absolute;
  200. left: 1px;
  201. top: 1px;
  202. width: 50px;
  203. height: 46px;
  204. img {
  205. width: 22px;
  206. height: 22px;
  207. position: relative;
  208. right: 5px;
  209. }
  210. // background: #f8f8f8;
  211. }
  212. .input {
  213. border: 1px solid #e8e8e8;
  214. height: 48px;
  215. padding: 0 44px 0 60px;
  216. width: 431px;
  217. font-size: 14px;
  218. }
  219. input::placeholder {
  220. font-weight: 400;
  221. font-size: $fontE;
  222. color: rgba(40, 46, 48, 0.6);
  223. }
  224. ::-webkit-input-placeholder {
  225. font-weight: 400;
  226. font-size: $fontE;
  227. color: rgba(40, 46, 48, 0.6);
  228. }
  229. /* 使用webkit内核的浏览器 */
  230. :-moz-placeholder {
  231. font-weight: 400;
  232. font-size: $fontE;
  233. color: rgba(40, 46, 48, 0.6);
  234. }
  235. /* Firefox版本19+ */
  236. :-ms-input-placeholder {
  237. font-weight: 400;
  238. font-size: $fontE;
  239. color: rgba(40, 46, 48, 0.6);
  240. }
  241. }
  242. .cancel {
  243. position: absolute;
  244. right: 0;
  245. top: 1px;
  246. width: 44px;
  247. line-height: 46px;
  248. height: 46px;
  249. text-align: center;
  250. cursor: pointer;
  251. :before {
  252. // position: absolute;
  253. // top: 9px;
  254. // left: 14px;
  255. }
  256. }
  257. .error {
  258. margin-top: 10px;
  259. position: relative;
  260. color: #e2231a;
  261. height: 16px;
  262. line-height: 16px;
  263. .iconfont {
  264. font-size: 14px;
  265. }
  266. }
  267. .submit {
  268. margin-top: 180px;
  269. background: $colorMain;
  270. font-weight: bold;
  271. font-size: 20px;
  272. color: #ffffff;
  273. text-align: center;
  274. border-radius: 2px;
  275. width: 100%;
  276. height: 45px;
  277. letter-spacing: 0px;
  278. &:hover {
  279. opacity: 0.9;
  280. }
  281. &.disabled {
  282. background-color: #909399;
  283. }
  284. }
  285. }
  286. </style>