login.vue 6.7 KB

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