index.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. <script setup>
  2. import { ref, unref } from 'vue';
  3. import { userApi } from '@/api/login';
  4. import { useUserStore } from '@/stores/modules/userStore';
  5. const REMOTE_PATH = {
  6. logo: 'https://static.fuxicarbon.com/bigModel/wechat/login/img-desc.png',
  7. username: 'https://static.fuxicarbon.com/bigModel/wechat/login/icon-username.png',
  8. password: 'https://static.fuxicarbon.com/bigModel/wechat/login/icon-password.png'
  9. }
  10. const userStore = useUserStore();
  11. const showPasswordIcon = ref(false);
  12. const loading = ref(false);
  13. const loginFormData = ref({
  14. username: 'admin',
  15. password: 'admin123'
  16. });
  17. const handleSubmit = async () => {
  18. const { username, password } = unref(loginFormData);
  19. if (!username) {
  20. return uni.showToast({ icon: 'none', title: "请输入账号", duration: 3 * 1000 });
  21. }
  22. if (!password) {
  23. return uni.showToast({ icon: 'none', title: "请输入密码", duration: 3 * 1000 });
  24. }
  25. loading.value = true;
  26. try {
  27. const { token } = await userApi.postLogin({ username, password });
  28. userStore.setUserInfo({ token });
  29. const { user } = await userApi.getUserInfo();
  30. userStore.setUserInfo({ ...user });
  31. await uni.showToast({ icon: 'none', title: "登录成功", duration: 2 * 1000});
  32. setTimeout(() => uni.redirectTo({url: '/pages/home/index'}), 2 * 1000);
  33. } catch (error) {
  34. console.log("打印error", error);
  35. } finally {
  36. loading.value = false;
  37. }
  38. }
  39. </script>
  40. <template>
  41. <view class="login-viewport">
  42. <TheNavBar title-text="登录" class="nav-bar"></TheNavBar>
  43. <view class="login-content">
  44. <view class="logo-inner">
  45. <image :src="REMOTE_PATH.logo" class="img-desc"></image>
  46. </view>
  47. <view class="form-inner">
  48. <view class="login-form-item">
  49. <image :src="REMOTE_PATH.username" class="image"></image>
  50. <input class="inp" v-model.trim="loginFormData.username" placeholder="请输入账号"
  51. placeholder-style="color: #ADB0BD" />
  52. </view>
  53. <view class="login-form-item">
  54. <image :src="REMOTE_PATH.password" class="image"></image>
  55. <input class="inp" v-model.trim="loginFormData.password" placeholder="请输入密码"
  56. placeholder-style="color: #ADB0BD" :password="!showPasswordIcon" />
  57. <uni-icons size="20" color="#ADB0BD" class="icon-eye" :type="showPasswordIcon ? 'eye' : 'eye-slash'"
  58. @click="showPasswordIcon = !showPasswordIcon"></uni-icons>
  59. </view>
  60. <button class="sub-btn" hover-class="sub-btn_hover" :loading="loading" @click="handleSubmit">
  61. <text>登录</text>
  62. </button>
  63. </view>
  64. <view class="text-inner">
  65. <text>人工智能运营体智慧决策助手</text>
  66. </view>
  67. </view>
  68. </view>
  69. </template>
  70. <style scoped lang="scss">
  71. .login-viewport {
  72. display: flex;
  73. flex-flow: column;
  74. height: 100vh;
  75. background: url("https://static.fuxicarbon.com/bigModel/wechat/login/bg-login.png") no-repeat;
  76. background-size: 100% 100%;
  77. .login-content {
  78. flex: 1;
  79. display: flex;
  80. justify-content: space-between;
  81. flex-flow: column;
  82. padding: 132rpx 60rpx 36rpx 60rpx;
  83. .logo-inner {
  84. .img-desc {
  85. width: 500rpx;
  86. height: 96rpx;
  87. }
  88. }
  89. .form-inner {
  90. width: 628rpx;
  91. margin: 0 auto;
  92. .login-form-item {
  93. position: relative;
  94. .inp {
  95. height: 52rpx;
  96. padding: 24rpx 96rpx 24rpx 96rpx;
  97. border-radius: 100rpx;
  98. background: #f6f7f8;
  99. line-height: 100rpx;
  100. font-size: 32rpx;
  101. }
  102. .image {
  103. position: absolute;
  104. top: 50%;
  105. left: 40rpx;
  106. width: 40rpx;
  107. height: 40rpx;
  108. margin-right: 16rpx;
  109. transform: translateY(-50%);
  110. }
  111. &:not(:last-child) {
  112. margin-bottom: 24rpx;
  113. }
  114. &:nth-child(2) {
  115. .icon-eye {
  116. position: absolute;
  117. top: 50%;
  118. right: 40rpx;
  119. transform: translateY(-50%);
  120. }
  121. }
  122. }
  123. .sub-btn {
  124. height: 100rpx;
  125. margin-top: 180rpx;
  126. border-radius: 100rpx;
  127. text-align: center;
  128. line-height: 100rpx;
  129. font-size: 32rpx;
  130. color: #fff;
  131. background: #8ab1ff;
  132. }
  133. .sub-btn_hover {
  134. background: #6495f7;
  135. }
  136. }
  137. .text-inner {
  138. padding-bottom: 50rpx;
  139. font-size: 28rpx;
  140. text-align: center;
  141. color: #727687;
  142. }
  143. }
  144. }
  145. </style>