login.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. <template>
  2. <view class="login-container">
  3. <view class="login-box">
  4. <view class="logo">
  5. <image src="/static/logo.png" mode="aspectFit"></image>
  6. </view>
  7. <view class="title">用户登录</view>
  8. <u-form :model="loginForm" ref="uForm" :border-bottom="false">
  9. <u-form-item :border-bottom="false">
  10. <u-input
  11. v-model="loginForm.username"
  12. placeholder="请输入用户名"
  13. prefixIcon="account"
  14. :border="borderText"
  15. clearable
  16. :prefix-icon-style="{
  17. fontSize: '36rpx',
  18. color: '#909399'
  19. }"
  20. :custom-style="{
  21. backgroundColor: '#f5f5f5',
  22. padding: '0 24rpx',
  23. borderRadius: '40rpx'
  24. }"
  25. :input-style="{
  26. height: '88rpx',
  27. lineHeight: '88rpx'
  28. }"
  29. ></u-input>
  30. </u-form-item>
  31. <u-form-item :border-bottom="false">
  32. <u-input
  33. v-model="loginForm.password"
  34. placeholder="请输入密码"
  35. prefixIcon="lock"
  36. :type="showPassword ? 'text' : 'password'"
  37. :border="borderText"
  38. clearable
  39. :prefix-icon-style="{
  40. fontSize: '36rpx',
  41. color: '#909399'
  42. }"
  43. :custom-style="{
  44. backgroundColor: '#f5f5f5',
  45. padding: '0 24rpx',
  46. borderRadius: '40rpx'
  47. }"
  48. :input-style="{
  49. height: '88rpx',
  50. lineHeight: '88rpx'
  51. }"
  52. >
  53. <template slot="suffix">
  54. <u-icon
  55. :name="showPassword ? 'eye' : 'eye-off'"
  56. size="36"
  57. :style="{
  58. height: '88rpx',
  59. lineHeight: '88rpx'
  60. }"
  61. @click="togglePasswordVisibility"
  62. ></u-icon>
  63. </template>
  64. </u-input>
  65. </u-form-item>
  66. </u-form>
  67. <u-button
  68. type="primary"
  69. @click="handleLogin"
  70. :custom-style="{
  71. marginTop: '80rpx',
  72. width: '100%',
  73. height: '88rpx',
  74. lineHeight: '88rpx',
  75. borderRadius: '44rpx',
  76. fontSize: '32rpx'
  77. }"
  78. >
  79. 登 录
  80. </u-button>
  81. </view>
  82. </view>
  83. </template>
  84. <script>
  85. import Base_url from "@/api/request.js";
  86. export default {
  87. data() {
  88. return {
  89. borderText: 'none',
  90. loginForm: {
  91. username: '',
  92. password: ''
  93. },
  94. showPassword: false,
  95. rules: {
  96. username: [{
  97. required: true,
  98. message: '请输入用户名',
  99. trigger: ['blur', 'change']
  100. }],
  101. password: [{
  102. required: true,
  103. message: '请输入密码',
  104. trigger: ['blur', 'change']
  105. }]
  106. }
  107. }
  108. },
  109. methods: {
  110. togglePasswordVisibility() {
  111. this.showPassword = !this.showPassword
  112. },
  113. handleLogin() {
  114. console.log('loginForm', this.loginForm)
  115. let obj = {
  116. "username": this.loginForm.username,
  117. "password": this.loginForm.password
  118. }
  119. uni.request({
  120. url: Base_url + 'landed3.action',
  121. method: 'POST',
  122. data:obj,
  123. // data: obj,
  124. header: {
  125. 'content-type': 'application/x-www-form-urlencoded' // 设置请求头,根据你的数据格式进行设置
  126. },
  127. success: (res) => {
  128. console.log('登录响应:', res)
  129. if (res.data.code === 'success') {
  130. wx.setStorageSync('userName', this.loginForm.username);
  131. wx.setStorageSync('password', this.loginForm.password);
  132. wx.setStorageSync('accountId', res.data.data.accountId);
  133. wx.setStorageSync('userId', res.data.data.userId);
  134. if (res.data.data.customerVOS.length > 0) {
  135. wx.setStorageSync('customerVOS', res.data.data.customerVOS);
  136. }
  137. uni.showToast({
  138. title: '登录成功',
  139. icon: 'success',
  140. duration: 1500
  141. })
  142. setTimeout(() => {
  143. uni.reLaunch({
  144. url: '/pages/index/index',
  145. success: () => {
  146. console.log('跳转成功')
  147. },
  148. fail: (err) => {
  149. console.error('跳转失败:', err)
  150. uni.navigateTo({
  151. url: '/pages/index/index'
  152. })
  153. }
  154. })
  155. }, 1500)
  156. } else {
  157. uni.showToast({
  158. title: res.data.message || '登录失败',
  159. icon: 'none'
  160. })
  161. }
  162. },
  163. fail: (err) => {
  164. console.error('登录请求失败:', err)
  165. console.log(err)
  166. uni.showToast({
  167. title: '网络错误',
  168. icon: 'none'
  169. })
  170. }
  171. })
  172. }
  173. }
  174. }
  175. </script>
  176. <style lang="scss" scoped>
  177. .login-container {
  178. display: flex;
  179. justify-content: center;
  180. align-items: center;
  181. min-height: 100vh;
  182. background-color: #ffffff;
  183. padding: 40rpx;
  184. .login-box {
  185. width: 100%;
  186. padding: 40rpx;
  187. .logo {
  188. text-align: center;
  189. margin-bottom: 60rpx;
  190. image {
  191. width: 180rpx;
  192. height: 180rpx;
  193. }
  194. }
  195. .title {
  196. font-size: 48rpx;
  197. text-align: center;
  198. margin-bottom: 80rpx;
  199. color: #303133;
  200. font-weight: bold;
  201. }
  202. /deep/ .u-form-item {
  203. margin-bottom: 40rpx;
  204. .u-input {
  205. &__content {
  206. display: flex;
  207. align-items: center;
  208. height: 88rpx;
  209. &__field-wrapper {
  210. display: flex;
  211. align-items: center;
  212. height: 88rpx;
  213. &__field {
  214. height: 88rpx;
  215. line-height: 88rpx;
  216. }
  217. }
  218. &__prefix-icon {
  219. height: 88rpx;
  220. line-height: 88rpx;
  221. margin-right: 12rpx;
  222. }
  223. &__suffix-icon {
  224. height: 88rpx;
  225. line-height: 88rpx;
  226. display: flex;
  227. align-items: center;
  228. }
  229. }
  230. }
  231. .u-icon {
  232. color: #909399;
  233. display: flex;
  234. align-items: center;
  235. height: 88rpx;
  236. }
  237. }
  238. }
  239. }
  240. // 适配不同屏幕尺寸
  241. @media screen and (min-width: 768px) {
  242. .login-box {
  243. max-width: 600rpx;
  244. margin: 0 auto;
  245. }
  246. }
  247. // 适配iPhone X 等刘海屏
  248. @supports (padding-bottom: constant(safe-area-inset-bottom)) {
  249. .login-container {
  250. padding-bottom: constant(safe-area-inset-bottom);
  251. }
  252. }
  253. @supports (padding-bottom: env(safe-area-inset-bottom)) {
  254. .login-container {
  255. padding-bottom: env(safe-area-inset-bottom);
  256. }
  257. }
  258. </style>