SldLoginModal.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  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="`/member/login/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 { ref, getCurrentInstance, watchEffect } from "vue";
  88. // import { lang_zn } from "@/assets/language/zh";
  89. import { getCurLanguage } from '@/composables/common.js';
  90. import { useFiltersStore } from "@/store/filter.js";
  91. import { ElMessage, ElButton, ElInput,ElDialog,ElCheckbox } from "element-plus";
  92. const filtersStore = useFiltersStore();
  93. // const L = lang_zn;
  94. const L = getCurLanguage();
  95. const modalVisible = ref(true);
  96. const route = useRoute();
  97. const name = ref(""); //用户名
  98. const errorMsg = ref(); //错误提示
  99. const password = ref(""); //密码
  100. const loginType = ref(1); //登陆类型:1-账号密码登陆,2-手机验证码登陆
  101. const fromurl = ref("");
  102. const emit = defineEmits(['refreshInfo','closeLoingModal'])
  103. const login = () => {
  104. let param = {};
  105. param.username = name.value;
  106. param.password = password.value;
  107. param.loginType = loginType.value;
  108. //账号验证
  109. if (!param.username) {
  110. errorMsg.value = L["请输入账号"];
  111. return false;
  112. }
  113. //密码校验
  114. if (!param.password) {
  115. errorMsg.value = L["请输入密码"];
  116. return false;
  117. } else {
  118. let checkPwdVal = checkPwd(param.password);
  119. if (checkPwdVal !== true) {
  120. errorMsg.value = checkPwdVal;
  121. return false;
  122. }
  123. }
  124. post("v3/frontLogin/oauth/token", param).then((res) => {
  125. if (res.state == 200) {
  126. //将用户信息存缓存,并跳转到首页
  127. filtersStore.setLoginStatus(true);
  128. filtersStore.setToken(res.data.access_token);
  129. filtersStore.setRefreshToken(res.data.refresh_token)
  130. filtersStore.setTime(new Date().getTime().toString())//存储refresh_token更新时间
  131. //获取用户信息,并同步信息到vuex
  132. get("v3/member/front/member/getInfo").then((res) => {
  133. if (res.state == 200) {
  134. emit("refreshInfo");
  135. filtersStore.setMemberInfo(res.data)
  136. closeModal();
  137. if(process.client){
  138. if (window.history.state.back) {
  139. if(window.history.state.back == '/register' || window.history.state.back == '/member/login/forget'){
  140. window.location.href = '/'
  141. }else{
  142. window.location.href = window.history.state.back;
  143. }
  144. }else{
  145. window.location.reload()
  146. }
  147. }
  148. }
  149. });
  150. } else {
  151. //提示错误
  152. errorMsg.value = res.msg;
  153. }
  154. });
  155. };
  156. //清空输入框内容
  157. const clearInputVal = (type) => {
  158. if (type == "name") {
  159. name.value = "";
  160. } else if (type == "password") {
  161. password.value = "";
  162. }
  163. };
  164. watchEffect(() => {
  165. if(process.client){
  166. if (modalVisible.value == false) {
  167. document.body.style.overflow = "";
  168. } else {
  169. fromurl.value = window.location.origin + route.fullPath;
  170. }
  171. }
  172. });
  173. //关闭登录modal
  174. const closeModal = () => {
  175. emit("closeLoingModal");
  176. };
  177. </script>
  178. <style lang="scss">
  179. @use "@/assets/style/loginModal.scss" as *;
  180. .sld_login_modal {
  181. .el-dialog {
  182. width: 376px !important;
  183. }
  184. .el-dialog__body {
  185. padding: 0;
  186. }
  187. .el-dialog__headerbtn {
  188. z-index: 999;
  189. }
  190. }
  191. .sld_login_modal {
  192. .sld_login_content {
  193. .login {
  194. .login_box {
  195. .top {
  196. .item1 {
  197. flex: 1;
  198. text-align: center;
  199. font-size: 18px;
  200. color: #666;
  201. position: relative;
  202. cursor: default;
  203. }
  204. }
  205. }
  206. }
  207. }
  208. }
  209. </style>