123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171 |
- <script setup>
- import { ref, unref } from 'vue';
- import { userApi } from '@/api/login';
- import { useUserStore } from '@/stores/modules/userStore';
- const REMOTE_PATH = {
- logo: 'https://static.fuxicarbon.com/bigModel/wechat/login/img-desc.png',
- username: 'https://static.fuxicarbon.com/bigModel/wechat/login/icon-username.png',
- password: 'https://static.fuxicarbon.com/bigModel/wechat/login/icon-password.png'
- }
- const userStore = useUserStore();
- const showPasswordIcon = ref(false);
- const loading = ref(false);
- const loginFormData = ref({
- username: 'admin',
- password: 'admin123'
- });
- const handleSubmit = async () => {
- const { username, password } = unref(loginFormData);
-
- if (!username) {
- return uni.showToast({ icon: 'none', title: "请输入账号", duration: 3 * 1000 });
- }
- if (!password) {
- return uni.showToast({ icon: 'none', title: "请输入密码", duration: 3 * 1000 });
- }
- loading.value = true;
- try {
- const { token } = await userApi.postLogin({ username, password });
- userStore.setUserInfo({ token });
- const { user } = await userApi.getUserInfo();
- userStore.setUserInfo({ ...user });
- await uni.showToast({ icon: 'none', title: "登录成功", duration: 2 * 1000});
- setTimeout(() => uni.redirectTo({url: '/pages/home/index'}), 2 * 1000);
- } catch (error) {
- console.log("打印error", error);
- } finally {
- loading.value = false;
- }
- }
- </script>
- <template>
- <view class="login-viewport">
- <TheNavBar title-text="登录" class="nav-bar"></TheNavBar>
- <view class="login-content">
- <view class="logo-inner">
- <image :src="REMOTE_PATH.logo" class="img-desc"></image>
- </view>
- <view class="form-inner">
- <view class="login-form-item">
- <image :src="REMOTE_PATH.username" class="image"></image>
- <input class="inp" v-model.trim="loginFormData.username" placeholder="请输入账号"
- placeholder-style="color: #ADB0BD" />
- </view>
- <view class="login-form-item">
- <image :src="REMOTE_PATH.password" class="image"></image>
- <input class="inp" v-model.trim="loginFormData.password" placeholder="请输入密码"
- placeholder-style="color: #ADB0BD" :password="!showPasswordIcon" />
- <uni-icons size="20" color="#ADB0BD" class="icon-eye" :type="showPasswordIcon ? 'eye' : 'eye-slash'"
- @click="showPasswordIcon = !showPasswordIcon"></uni-icons>
- </view>
- <button class="sub-btn" hover-class="sub-btn_hover" :loading="loading" @click="handleSubmit">
- <text>登录</text>
- </button>
- </view>
- <view class="text-inner">
- <text>人工智能运营体智慧决策助手</text>
- </view>
- </view>
- </view>
- </template>
- <style scoped lang="scss">
- .login-viewport {
- display: flex;
- flex-flow: column;
- height: 100vh;
- background: url("https://static.fuxicarbon.com/bigModel/wechat/login/bg-login.png") no-repeat;
- background-size: 100% 100%;
- .login-content {
- flex: 1;
- display: flex;
- justify-content: space-between;
- flex-flow: column;
- padding: 132rpx 60rpx 36rpx 60rpx;
- .logo-inner {
- .img-desc {
- width: 500rpx;
- height: 96rpx;
- }
- }
- .form-inner {
- width: 628rpx;
- margin: 0 auto;
- .login-form-item {
- position: relative;
- .inp {
- height: 52rpx;
- padding: 24rpx 96rpx 24rpx 96rpx;
- border-radius: 100rpx;
- background: #f6f7f8;
- line-height: 100rpx;
- font-size: 32rpx;
- }
- .image {
- position: absolute;
- top: 50%;
- left: 40rpx;
- width: 40rpx;
- height: 40rpx;
- margin-right: 16rpx;
- transform: translateY(-50%);
- }
- &:not(:last-child) {
- margin-bottom: 24rpx;
- }
- &:nth-child(2) {
- .icon-eye {
- position: absolute;
- top: 50%;
- right: 40rpx;
- transform: translateY(-50%);
- }
- }
- }
- .sub-btn {
- height: 100rpx;
- margin-top: 180rpx;
- border-radius: 100rpx;
- text-align: center;
- line-height: 100rpx;
- font-size: 32rpx;
- color: #fff;
- background: #8ab1ff;
- }
- .sub-btn_hover {
- background: #6495f7;
- }
- }
- .text-inner {
- padding-bottom: 50rpx;
- font-size: 28rpx;
- text-align: center;
- color: #727687;
- }
- }
- }
- </style>
|