index.vue 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  1. <template>
  2. <div class="container">
  3. <div class="title">
  4. Log in
  5. <div></div>
  6. <span @click="close()" class="iconfont icon-shanchu1"></span>
  7. </div>
  8. <n-form ref="formRef" label-placement="left" :label-width="100" :model="form" :rules="rules" size="large" require-mark-placement="left">
  9. <n-form-item path="loginCode">
  10. <n-input v-model:value="form.loginCode" :placeholder="t('common.login.usernameTip')">
  11. <template #prefix>
  12. <div class="icon">
  13. <img src="@/assets/images/img18.png" alt="">
  14. </div>
  15. </template>
  16. </n-input>
  17. </n-form-item>
  18. <n-form-item path="password">
  19. <n-input v-model:value="form.password" type="password" show-password-on="click" :placeholder="t('common.login.passwordTip')">
  20. <template #prefix>
  21. <div class="icon1">
  22. <img src="@/assets/images/img19.png" alt="">
  23. </div>
  24. </template></n-input>
  25. <div class="forgotBox">
  26. <a href="#" class="forgot" @click="handleForgot"> {{t('common.login.forgetPassword')}}</a>
  27. </div>
  28. </n-form-item>
  29. <n-form-item path="validCode">
  30. <n-input v-model:value="form.validCode" :placeholder="t('common.login.validCodeTip')">
  31. <template #prefix>
  32. <div class="icon1">
  33. <img src="@/assets/images/img20.png" alt="">
  34. </div>
  35. </template>
  36. <template #suffix>
  37. <img :src="getValidCodeImg" @click="refreshValidCodeImg" class="cursor-pointer" width="100" />
  38. </template>
  39. </n-input>
  40. </n-form-item>
  41. </n-form>
  42. <n-button class="login-btn" attr-type="button" type="info" color="#18A058" :disabled="submitLoading" @click="handleLogin">
  43. {{ submitLoading ? t('common.login.submitting') : t('common.login.title') }}
  44. </n-button>
  45. <p class="register-btn">
  46. No account yet? Click to
  47. <span @click="handleRegister">Register</span>
  48. </p>
  49. </div>
  50. </template>
  51. <script lang="ts" setup>
  52. import { useI18n } from "#imports";
  53. import { ref, reactive, onMounted } from "vue";
  54. import { createDiscreteApi } from "naive-ui";
  55. import { useUserStore } from "@/store/user";
  56. const config = useRuntimeConfig();
  57. const baseUrl = ref(config.public.apiBase);
  58. const emit = defineEmits(["closeSginDialog"]);
  59. const userStore = useUserStore();
  60. const { t, locale, setLocale } = useI18n();
  61. const temptime = ref();
  62. const formRef = ref();
  63. const submitLoading = ref(false);
  64. const form: Login = reactive({
  65. loginCode: "",
  66. password: "",
  67. });
  68. const rules: FormRules = {
  69. loginCode: [
  70. {
  71. required: true,
  72. message: t("common.login.usernameTip"),
  73. trigger: ["input", "blur"],
  74. },
  75. ],
  76. password: [
  77. {
  78. required: true,
  79. message: t("common.login.passwordTip"),
  80. trigger: ["input", "blur"],
  81. },
  82. ],
  83. validCode: [
  84. {
  85. required: true,
  86. message: t("common.login.validCodeTip"),
  87. trigger: ["input", "blur"],
  88. },
  89. ],
  90. };
  91. const getValidCodeImg = ref<string>("");
  92. const refreshValidCodeImg = () => {
  93. temptime.value = +new Date().getTime();
  94. getValidCodeImg.value =
  95. baseUrl.value + `/report/websiteUser/getValidCode?unTime=${temptime.value}`;
  96. };
  97. refreshValidCodeImg();
  98. const message = createDiscreteApi(["message"]);
  99. const handleLogin = () => {
  100. formRef.value?.validate(async (errors: any) => {
  101. if (!errors) {
  102. submitLoading.value = true;
  103. const params = JSON.parse(JSON.stringify(form));
  104. params.loginCode = encryptByBase64(params.loginCode);
  105. params.password = encryptByBase64(params.password);
  106. params.unTime = temptime.value;
  107. try {
  108. const { code, data } = await login_Api(params);
  109. if (code === 200) {
  110. userStore.setToken(data?.token);
  111. userStore.setUserInfo(data?.user);
  112. emit("closeSginDialog", "success");
  113. message.message.success(t("common.login.success"));
  114. } else {
  115. refreshValidCodeImg();
  116. form.validCode = "";
  117. }
  118. submitLoading.value = false;
  119. } catch (error) {
  120. submitLoading.value = false;
  121. }
  122. }
  123. });
  124. };
  125. const handleForgot = () => {
  126. emit("closeSginDialog", "forgot");
  127. };
  128. const handleRegister = () => {
  129. emit("closeSginDialog", "register");
  130. };
  131. const close = () => {
  132. emit("closeSginDialog", "success");
  133. };
  134. </script>
  135. <style lang="scss" scoped>
  136. @import "~/assets/css/tool.scss";
  137. .container {
  138. padding: 20px 58px;
  139. background: #ffffff;
  140. border-radius: 20px;
  141. position: relative;
  142. .title {
  143. font-size: 38px;
  144. font-family: Arial, Arial-Bold;
  145. font-weight: 700;
  146. text-align: center;
  147. color: #1a1a1a;
  148. > div {
  149. width: 71px;
  150. height: 6px;
  151. background: linear-gradient(90deg, #719d59 2%, #479f82 98%);
  152. border-radius: 3px;
  153. margin: auto;
  154. }
  155. > span {
  156. position: absolute;
  157. right: 20px;
  158. top: 15px;
  159. cursor: pointer;
  160. }
  161. }
  162. .login-btn {
  163. width: 100%;
  164. height: 58px;
  165. background: linear-gradient(90deg, #60ab91, #84a86c);
  166. border-radius: 8px;
  167. font-size: 18px;
  168. margin-top: 10px;
  169. }
  170. .register-btn {
  171. font-size: 18px;
  172. color: #808080;
  173. text-align: center;
  174. font-family: Arial, Arial-Regular;
  175. span {
  176. color: #61ab90;
  177. cursor: pointer;
  178. }
  179. }
  180. .forgotBox {
  181. margin-left: 10px;
  182. flex-shrink: 0;
  183. }
  184. .forgot {
  185. font-size: 14px;
  186. color: #00c2ff;
  187. // text-decoration: underline;
  188. border-bottom: 1px solid #00c2ff;
  189. }
  190. .cursor-pointer {
  191. cursor: pointer;
  192. }
  193. :deep(input::-ms-reveal) {
  194. display: none;
  195. }
  196. }
  197. .icon {
  198. height: 26px;
  199. padding-right: 18px;
  200. margin-right: 18px;
  201. border-right: 1px solid #cccccc;
  202. img {
  203. width: 26px;
  204. height: 26px;
  205. }
  206. }
  207. .icon1 {
  208. height: 26px;
  209. padding-right: 22px;
  210. margin-right: 18px;
  211. border-right: 1px solid #cccccc;
  212. img {
  213. width: 22px;
  214. height: 26px;
  215. }
  216. }
  217. .icon2 {
  218. height: 26px;
  219. padding-right: 21px;
  220. margin-right: 18px;
  221. border-right: 1px solid #cccccc;
  222. img {
  223. width: 23px;
  224. height: 26px;
  225. }
  226. }
  227. .n-form {
  228. margin-top: 30px;
  229. }
  230. :deep(.n-form-item-blank) {
  231. border-bottom: 1px solid #e6e6e6;
  232. }
  233. :deep(.n-form-item-label) {
  234. color: #666666;
  235. font-family: Microsoft YaHei, Microsoft YaHei-Regular;
  236. line-height: var(--size-20);
  237. padding: 0px 10px 10px 0;
  238. }
  239. :deep(.n-input-wrapper) {
  240. font-size: var(--size-14);
  241. font-family: Microsoft YaHei, Microsoft YaHei-Regular;
  242. line-height: var(--size-20);
  243. padding: 0px 0 10px;
  244. }
  245. :deep(.n-form-item-blank--error .n-input) {
  246. --n-border-error: var(--size-1) solid transparent !important;
  247. --n-border-focus-error: var(--size-1) solid transparent !important;
  248. --n-border-hover-error: var(--size-1) solid transparent !important;
  249. --n-box-shadow-focus-error: var(--size-1) solid transparent !important;
  250. }
  251. .area {
  252. width: 100%;
  253. :deep(.n-form-item-label),
  254. :deep(.n-input-wrapper) {
  255. border-bottom: none;
  256. }
  257. :deep(.n-input--textarea) {
  258. background: #fafafa;
  259. border-radius: var(--size-10);
  260. padding: 0 var(--size-5);
  261. }
  262. :deep(.n-input.n-input--textarea.n-input--resizable .n-input-wrapper) {
  263. min-height: var(--size-260);
  264. }
  265. }
  266. @include responseTo("phone") {
  267. .container {
  268. padding: 10px 20px;
  269. .title {
  270. font-size: 20px;
  271. > div {
  272. width: 30px;
  273. height: 4px;
  274. border-radius: 3px;
  275. }
  276. }
  277. .n-form {
  278. margin-top: 15px;
  279. .icon {
  280. height: 26px;
  281. padding-right: 10px;
  282. margin-right: 10px;
  283. border-right: 1px solid #cccccc;
  284. }
  285. .icon1 {
  286. height: 26px;
  287. padding-right: 14px;
  288. margin-right: 10px;
  289. border-right: 1px solid #cccccc;
  290. }
  291. .icon2 {
  292. height: 26px;
  293. padding-right: 13px;
  294. margin-right: 10px;
  295. border-right: 1px solid #cccccc;
  296. }
  297. }
  298. .login-btn {
  299. height: 45px;
  300. }
  301. }
  302. }
  303. </style>