login.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. <template>
  2. <view class="login-container">
  3. <image class="bg-image" src="../../static/login/login-bj.png"></image>
  4. <view class="login-title">
  5. <view class="welcome-text">您好,欢迎使用</view>
  6. <view class="system-name">交收库管理系统</view>
  7. </view>
  8. <view class="login-form">
  9. <view class="input-group">
  10. <view class="input-label">
  11. <uni-icons custom-prefix="iconfont" type="icon-yonghu_yonghuming" color="#000000" size="18"></uni-icons>
  12. 用户名称
  13. </view>
  14. <view class="uni-input-wrapper">
  15. <input v-model="username" class="input-field" placeholder="请输入用户名" />
  16. </view>
  17. </view>
  18. <view class="input-group">
  19. <view class="input-label">
  20. <uni-icons custom-prefix="iconfont" type="icon-mima" color="#000000" size="18"></uni-icons>
  21. 登录密码
  22. </view>
  23. <view class="uni-input-wrapper">
  24. <input v-model="password" class="input-field" placeholder="请输入密码" :password="showPassword" />
  25. <uni-icons @click="changePassword" :type="!showPassword ? 'eye' : 'eye-slash'" color="#000000" size="32"></uni-icons>
  26. </view>
  27. </view>
  28. <button class="login-button" @click="handleLogin">登录</button>
  29. </view>
  30. </view>
  31. </template>
  32. <script setup>
  33. import { ref } from 'vue';
  34. const username = ref('');
  35. const password = ref('');
  36. const showPassword = ref(true)
  37. const changePassword = () => {
  38. showPassword.value = !showPassword.value;
  39. }
  40. const handleLogin = async () => {
  41. if (!username.value || !password.value) {
  42. uni.showToast({
  43. title: '请输入用户名和密码',
  44. icon: 'none'
  45. });
  46. return;
  47. }
  48. uni.request({
  49. url: 'http://172.16.6.128:8011/admin-api/system/auth/login',
  50. method: 'POST',
  51. data: {
  52. username: username.value,
  53. password: password.value
  54. },
  55. success: (res) => {
  56. if (res.data.code === 0) {
  57. uni.showToast({
  58. title: '登录成功',
  59. icon: 'success'
  60. });
  61. // 跳转到首页或其他页面
  62. uni.switchTab({
  63. url: '/pages/home/home' // 注意路径前的斜杠
  64. });
  65. } else {
  66. uni.showToast({
  67. title: res.data.msg,
  68. icon: 'none'
  69. });
  70. }
  71. },
  72. fail: (err) => {
  73. console.error(err); // 失败回调
  74. }
  75. });
  76. };
  77. </script>
  78. <style lang="scss" scoped>
  79. .login-container {
  80. height: 100vh;
  81. display: flex;
  82. flex-direction: column;
  83. position: relative;
  84. overflow: hidden;
  85. .bg-image {
  86. position: absolute;
  87. width: 100%;
  88. height: 100vh;
  89. top: 0;
  90. left: 0;
  91. object-fit: cover;
  92. z-index: -1;
  93. }
  94. .login-title{
  95. margin: 100rpx 30rpx 0;
  96. .welcome-text {
  97. font-size: 58rpx;
  98. margin-bottom: 15rpx;
  99. letter-spacing: 5rpx;
  100. }
  101. .system-name {
  102. font-size: 68rpx;
  103. font-weight: bold;
  104. letter-spacing: 10rpx;
  105. }
  106. }
  107. }
  108. .login-form {
  109. margin: 60rpx 30rpx 0;
  110. padding: 70rpx;
  111. background: linear-gradient(to bottom, rgba(255, 255, 255, 1), rgba(255, 255, 255, 0));
  112. border-radius: 25px 25px 0 0;
  113. box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
  114. height: 100vh;
  115. }
  116. .input-group {
  117. margin-bottom: 55rpx;
  118. }
  119. .input-label {
  120. font-size: 30rpx;
  121. margin-bottom: 10rpx;
  122. display: block;
  123. }
  124. .uni-input-wrapper {
  125. display: flex;
  126. margin: 10rpx 0;
  127. flex-direction: row;
  128. flex-wrap: nowrap;
  129. border: 1px solid #B2C7E6;
  130. background-color: #ffffff;
  131. padding: 0px 10px 0 20px;
  132. border-radius: 4px;
  133. align-items: center;
  134. }
  135. .input-field {
  136. width: 100%;
  137. padding: 10px 0;
  138. }
  139. .login-button {
  140. width: 100%;
  141. height: 70rpx;
  142. line-height: 70rpx;
  143. border-radius: 10rpx;
  144. background-color: #1E5FDF;
  145. color: #fff;
  146. font-size: 28rpx;
  147. text-align: center;
  148. }
  149. .login-button:hover {
  150. background-color: #005bb5;
  151. }
  152. </style>