login.vue 6.7 KB

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