loginModal.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. <!--登录弹框 @zjf-2021-01-08-->
  2. <template>
  3. <div class="sld_login_modal">
  4. <el-dialog
  5. title=""
  6. :model-value="modalVisible"
  7. :close-on-click-modal="false"
  8. :show-close="false"
  9. >
  10. <div class="sld_login_content">
  11. <span
  12. class="iconfont icon-shanchutupian close_icon"
  13. @click="closeModal"
  14. />
  15. <div class="login">
  16. <div class="login_box">
  17. <div class="top">
  18. <div class="item1">{{ L["账号登录"] }}</div>
  19. </div>
  20. <div class="center">
  21. <div class="item account">
  22. <span
  23. style="color: #bbb; font-size: 19px; padding-top: 7px"
  24. class="icon iconfont icon-wode"
  25. ></span>
  26. <input
  27. type="text"
  28. v-model="name"
  29. :placeholder="L['请输入账号']"
  30. class="input"
  31. />
  32. <div
  33. data-type="userName"
  34. class="cancel"
  35. @click="clearInputVal('name')"
  36. >
  37. <span style="color: #bbb" class="iconfont icon-cuowu"></span>
  38. </div>
  39. </div>
  40. <div class="item password">
  41. <span
  42. style="color: #bbb; font-size: 21px; padding-top: 7px"
  43. class="icon iconfont icon-mima1"
  44. ></span>
  45. <input
  46. type="password"
  47. v-model="password"
  48. :placeholder="L['请输入密码']"
  49. class="input"
  50. autocomplete="new-password"
  51. />
  52. <div
  53. data-type="password"
  54. class="cancel"
  55. @click="clearInputVal('password')"
  56. >
  57. <span style="color: #bbb" class="iconfont icon-cuowu"></span>
  58. </div>
  59. </div>
  60. <div class="error">
  61. <span
  62. v-if="errorMsg"
  63. style="color: #e1251b; font-size: 14px"
  64. class="iconfont icon-jubao"
  65. ></span>
  66. {{ errorMsg }}
  67. </div>
  68. <a href="javascript:void(0)" @click="login" class="login_btn">{{
  69. L["登录"]
  70. }}</a>
  71. </div>
  72. <div :class="{ bottom: true, flex_row_between_center: true }">
  73. <router-link tag="a" :to="`/register`">
  74. {{ L["立即注册"] }}
  75. </router-link>
  76. <router-link tag="a" :to="`/pwd/forget`">
  77. {{ L["忘记密码"] }}
  78. </router-link>
  79. </div>
  80. </div>
  81. </div>
  82. </div>
  83. </el-dialog>
  84. </div>
  85. </template>
  86. <script setup>
  87. // import { lang_zn } from "@/assets/language/zh";
  88. import { getCurLanguage } from '@/composables/common.js';
  89. // const L = lang_zn;
  90. const L = getCurLanguage();
  91. const props = defineProps(["visibleFlag"]);
  92. const modalVisible = ref(props.visibleFlag);
  93. const { proxy } = getCurrentInstance();
  94. const route = useRoute();
  95. const name = ref(""); //用户名
  96. const errorMsg = ref(); //错误提示
  97. const password = ref(""); //密码
  98. const loginType = ref(1); //登陆类型:1-账号密码登陆,2-手机验证码登陆
  99. const fromurl = ref("");
  100. const login = () => {
  101. let param = {};
  102. param.username = name.value;
  103. param.password = password.value;
  104. param.loginType = loginType.value;
  105. //账号验证
  106. if (!param.username) {
  107. errorMsg.value = L["请输入账号"];
  108. return false;
  109. }
  110. //密码校验
  111. if (!param.password) {
  112. errorMsg.value = L["请输入密码"];
  113. return false;
  114. } else {
  115. let checkPwdVal = checkPwd(param.password);
  116. if (checkPwdVal !== true) {
  117. errorMsg.value = checkPwdVal;
  118. return false;
  119. }
  120. }
  121. //如果未登录vuex中有购物车数据,需同步到该用户
  122. let cartInfo = [];
  123. let cartListData = store.state.cartListData;
  124. if (JSON.stringify(cartListData) != "{}") {
  125. cartListData.storeCartGroupList.map((cartListItem) => {
  126. cartListItem.promotionCartGroupList.map((promotItem) => {
  127. promotItem.cartList.map((cartItem) => {
  128. cartInfo.push({
  129. productId: cartItem.productId,
  130. buyNum: cartItem.buyNum,
  131. });
  132. });
  133. });
  134. });
  135. }
  136. param.cartInfo = JSON.stringify(cartInfo);
  137. post("v3/frontLogin/oauth/token", param).then((res) => {
  138. if (res.state == 200) {
  139. //将用户信息存缓存,并跳转到首页
  140. localStorage.setItem("access_token", res.data.access_token);
  141. localStorage.setItem("refresh_token", res.data.refresh_token);
  142. localStorage.setItem("time", new Date().getTime().toString()); //存储refresh_token更新时间
  143. //获取用户信息,并同步信息到vuex
  144. get("v3/member/front/member/getInfo").then((res) => {
  145. if (res.state == 200) {
  146. emit("refreshInfo");
  147. store.commit("updateMemberInfo", res.data);
  148. // proxy.$getLoginCartListData(); //更新购物车数据
  149. closeModal();
  150. }
  151. });
  152. } else {
  153. //提示错误
  154. errorMsg.value = res.msg;
  155. }
  156. });
  157. };
  158. //清空输入框内容
  159. const clearInputVal = (type) => {
  160. if (type == "name") {
  161. name.value = "";
  162. } else if (type == "password") {
  163. password.value = "";
  164. }
  165. };
  166. watchEffect(() => {
  167. modalVisible.value = props.visibleFlag;
  168. if (modalVisible.value == false) {
  169. document.body.style.overflow = "";
  170. } else {
  171. fromurl.value = window.location.origin + route.fullPath;
  172. }
  173. });
  174. //关闭登录modal
  175. const closeModal = () => {
  176. emit("closeLoingModal");
  177. };
  178. </script>
  179. <style lang="scss">
  180. @use "@/assets/style/loginModal.scss" as *;
  181. .sld_login_modal {
  182. .el-dialog {
  183. width: 376px !important;
  184. }
  185. .el-dialog__body {
  186. padding: 0;
  187. }
  188. .el-dialog__headerbtn {
  189. z-index: 999;
  190. }
  191. }
  192. .sld_login_modal {
  193. .sld_login_content {
  194. .login {
  195. .login_box {
  196. .top {
  197. .item1 {
  198. flex: 1;
  199. text-align: center;
  200. font-size: 18px;
  201. color: #666;
  202. position: relative;
  203. cursor: default;
  204. }
  205. }
  206. }
  207. }
  208. }
  209. }
  210. </style>