123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319 |
- <template>
- <div class="container">
- <div class="title">
- Log in
- <div></div>
- <span @click="close()" class="iconfont icon-shanchu1"></span>
- </div>
- <n-form ref="formRef" label-placement="left" :label-width="100" :model="form" :rules="rules" size="large" require-mark-placement="left">
- <n-form-item path="loginCode">
- <n-input v-model:value="form.loginCode" :placeholder="t('common.login.usernameTip')">
- <template #prefix>
- <div class="icon">
- <img src="@/assets/images/img18.png" alt="">
- </div>
- </template>
- </n-input>
- </n-form-item>
- <n-form-item path="password">
- <n-input v-model:value="form.password" type="password" show-password-on="click" :placeholder="t('common.login.passwordTip')">
- <template #prefix>
- <div class="icon1">
- <img src="@/assets/images/img19.png" alt="">
- </div>
- </template></n-input>
- <div class="forgotBox">
- <a href="#" class="forgot" @click="handleForgot"> {{t('common.login.forgetPassword')}}</a>
- </div>
- </n-form-item>
- <n-form-item path="validCode">
- <n-input v-model:value="form.validCode" :placeholder="t('common.login.validCodeTip')">
- <template #prefix>
- <div class="icon1">
- <img src="@/assets/images/img20.png" alt="">
- </div>
- </template>
- <template #suffix>
- <img :src="getValidCodeImg" @click="refreshValidCodeImg" class="cursor-pointer" width="100" />
- </template>
- </n-input>
- </n-form-item>
- </n-form>
- <n-button class="login-btn" attr-type="button" type="info" color="#18A058" :disabled="submitLoading" @click="handleLogin">
- {{ submitLoading ? t('common.login.submitting') : t('common.login.title') }}
- </n-button>
- <p class="register-btn">
- No account yet? Click to
- <span @click="handleRegister">Register</span>
- </p>
- </div>
- </template>
- <script lang="ts" setup>
- import { useI18n } from "#imports";
- import { ref, reactive, onMounted } from "vue";
- import { createDiscreteApi } from "naive-ui";
- import { useUserStore } from "@/store/user";
- const config = useRuntimeConfig();
- const baseUrl = ref(config.public.apiBase);
- const emit = defineEmits(["closeSginDialog"]);
- const userStore = useUserStore();
- const { t, locale, setLocale } = useI18n();
- const temptime = ref();
- const formRef = ref();
- const submitLoading = ref(false);
- const form: Login = reactive({
- loginCode: "",
- password: "",
- });
- const rules: FormRules = {
- loginCode: [
- {
- required: true,
- message: t("common.login.usernameTip"),
- trigger: ["input", "blur"],
- },
- ],
- password: [
- {
- required: true,
- message: t("common.login.passwordTip"),
- trigger: ["input", "blur"],
- },
- ],
- validCode: [
- {
- required: true,
- message: t("common.login.validCodeTip"),
- trigger: ["input", "blur"],
- },
- ],
- };
- const getValidCodeImg = ref<string>("");
- const refreshValidCodeImg = () => {
- temptime.value = +new Date().getTime();
- getValidCodeImg.value =
- baseUrl.value + `/report/websiteUser/getValidCode?unTime=${temptime.value}`;
- };
- refreshValidCodeImg();
- const message = createDiscreteApi(["message"]);
- const handleLogin = () => {
- formRef.value?.validate(async (errors: any) => {
- if (!errors) {
- submitLoading.value = true;
- const params = JSON.parse(JSON.stringify(form));
- params.loginCode = encryptByBase64(params.loginCode);
- params.password = encryptByBase64(params.password);
- params.unTime = temptime.value;
- try {
- const { code, data } = await login_Api(params);
- if (code === 200) {
- userStore.setToken(data?.token);
- userStore.setUserInfo(data?.user);
- emit("closeSginDialog", "success");
- message.message.success(t("common.login.success"));
- } else {
- refreshValidCodeImg();
- form.validCode = "";
- }
- submitLoading.value = false;
- } catch (error) {
- submitLoading.value = false;
- }
- }
- });
- };
- const handleForgot = () => {
- emit("closeSginDialog", "forgot");
- };
- const handleRegister = () => {
- emit("closeSginDialog", "register");
- };
- const close = () => {
- emit("closeSginDialog", "success");
- };
- </script>
- <style lang="scss" scoped>
- @import "~/assets/css/tool.scss";
- .container {
- padding: 20px 58px;
- background: #ffffff;
- border-radius: 20px;
- position: relative;
- .title {
- font-size: 38px;
- font-family: Arial, Arial-Bold;
- font-weight: 700;
- text-align: center;
- color: #1a1a1a;
- > div {
- width: 71px;
- height: 6px;
- background: linear-gradient(90deg, #719d59 2%, #479f82 98%);
- border-radius: 3px;
- margin: auto;
- }
- > span {
- position: absolute;
- right: 20px;
- top: 15px;
- cursor: pointer;
- }
- }
- .login-btn {
- width: 100%;
- height: 58px;
- background: linear-gradient(90deg, #60ab91, #84a86c);
- border-radius: 8px;
- font-size: 18px;
- margin-top: 10px;
- }
- .register-btn {
- font-size: 18px;
- color: #808080;
- text-align: center;
- font-family: Arial, Arial-Regular;
- span {
- color: #61ab90;
- cursor: pointer;
- }
- }
- .forgotBox {
- margin-left: 10px;
- flex-shrink: 0;
- }
- .forgot {
- font-size: 14px;
- color: #00c2ff;
- // text-decoration: underline;
- border-bottom: 1px solid #00c2ff;
- }
- .cursor-pointer {
- cursor: pointer;
- }
- :deep(input::-ms-reveal) {
- display: none;
- }
- }
- .icon {
- height: 26px;
- padding-right: 18px;
- margin-right: 18px;
- border-right: 1px solid #cccccc;
- img {
- width: 26px;
- height: 26px;
- }
- }
- .icon1 {
- height: 26px;
- padding-right: 22px;
- margin-right: 18px;
- border-right: 1px solid #cccccc;
- img {
- width: 22px;
- height: 26px;
- }
- }
- .icon2 {
- height: 26px;
- padding-right: 21px;
- margin-right: 18px;
- border-right: 1px solid #cccccc;
- img {
- width: 23px;
- height: 26px;
- }
- }
- .n-form {
- margin-top: 30px;
- }
- :deep(.n-form-item-blank) {
- border-bottom: 1px solid #e6e6e6;
- }
- :deep(.n-form-item-label) {
- color: #666666;
- font-family: Microsoft YaHei, Microsoft YaHei-Regular;
- line-height: var(--size-20);
- padding: 0px 10px 10px 0;
- }
- :deep(.n-input-wrapper) {
- font-size: var(--size-14);
- font-family: Microsoft YaHei, Microsoft YaHei-Regular;
- line-height: var(--size-20);
- padding: 0px 0 10px;
- }
- :deep(.n-form-item-blank--error .n-input) {
- --n-border-error: var(--size-1) solid transparent !important;
- --n-border-focus-error: var(--size-1) solid transparent !important;
- --n-border-hover-error: var(--size-1) solid transparent !important;
- --n-box-shadow-focus-error: var(--size-1) solid transparent !important;
- }
- .area {
- width: 100%;
- :deep(.n-form-item-label),
- :deep(.n-input-wrapper) {
- border-bottom: none;
- }
- :deep(.n-input--textarea) {
- background: #fafafa;
- border-radius: var(--size-10);
- padding: 0 var(--size-5);
- }
- :deep(.n-input.n-input--textarea.n-input--resizable .n-input-wrapper) {
- min-height: var(--size-260);
- }
- }
- @include responseTo("phone") {
- .container {
- padding: 10px 20px;
- .title {
- font-size: 20px;
- > div {
- width: 30px;
- height: 4px;
- border-radius: 3px;
- }
- }
- .n-form {
- margin-top: 15px;
- .icon {
- height: 26px;
- padding-right: 10px;
- margin-right: 10px;
- border-right: 1px solid #cccccc;
- }
- .icon1 {
- height: 26px;
- padding-right: 14px;
- margin-right: 10px;
- border-right: 1px solid #cccccc;
- }
- .icon2 {
- height: 26px;
- padding-right: 13px;
- margin-right: 10px;
- border-right: 1px solid #cccccc;
- }
- }
- .login-btn {
- height: 45px;
- }
- }
- }
- </style>
|