login.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  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. export default {
  86. data() {
  87. return {
  88. borderText: 'none',
  89. loginForm: {
  90. username: '',
  91. password: ''
  92. },
  93. showPassword: false,
  94. rules: {
  95. username: [{
  96. required: true,
  97. message: '请输入用户名',
  98. trigger: ['blur', 'change']
  99. }],
  100. password: [{
  101. required: true,
  102. message: '请输入密码',
  103. trigger: ['blur', 'change']
  104. }]
  105. }
  106. }
  107. },
  108. methods: {
  109. togglePasswordVisibility() {
  110. this.showPassword = !this.showPassword
  111. },
  112. handleLogin() {
  113. console.log('loginForm', this.loginForm)
  114. let obj = {
  115. "username": this.loginForm.username,
  116. "password": this.loginForm.password
  117. }
  118. uni.request({
  119. url: 'http://localhost:8012/BH_CLIS/landed3.action',
  120. method: 'POST',
  121. data:obj,
  122. // data: obj,
  123. header: {
  124. 'content-type': 'application/x-www-form-urlencoded' // 设置请求头,根据你的数据格式进行设置
  125. },
  126. success: (res) => {
  127. console.log('登录响应:', res)
  128. if (res.data.code === 'success') {
  129. wx.setStorageSync('userName', this.loginForm.username);
  130. wx.setStorageSync('password', this.loginForm.password);
  131. wx.setStorageSync('accountId', res.data.data.accountId);
  132. if (res.data.data.customerVOS.length > 0) {
  133. wx.setStorageSync('customerVOS', res.data.data.customerVOS);
  134. }
  135. uni.showToast({
  136. title: '登录成功',
  137. icon: 'success',
  138. duration: 1500
  139. })
  140. setTimeout(() => {
  141. uni.reLaunch({
  142. url: '/pages/index/index',
  143. success: () => {
  144. console.log('跳转成功')
  145. },
  146. fail: (err) => {
  147. console.error('跳转失败:', err)
  148. uni.navigateTo({
  149. url: '/pages/index/index'
  150. })
  151. }
  152. })
  153. }, 1500)
  154. } else {
  155. uni.showToast({
  156. title: res.data.message || '登录失败',
  157. icon: 'none'
  158. })
  159. }
  160. },
  161. fail: (err) => {
  162. console.error('登录请求失败:', err)
  163. uni.showToast({
  164. title: '网络错误',
  165. icon: 'none'
  166. })
  167. }
  168. })
  169. }
  170. }
  171. }
  172. </script>
  173. <style lang="scss" scoped>
  174. .login-container {
  175. display: flex;
  176. justify-content: center;
  177. align-items: center;
  178. min-height: 100vh;
  179. background-color: #ffffff;
  180. padding: 40rpx;
  181. .login-box {
  182. width: 100%;
  183. padding: 40rpx;
  184. .logo {
  185. text-align: center;
  186. margin-bottom: 60rpx;
  187. image {
  188. width: 180rpx;
  189. height: 180rpx;
  190. }
  191. }
  192. .title {
  193. font-size: 48rpx;
  194. text-align: center;
  195. margin-bottom: 80rpx;
  196. color: #303133;
  197. font-weight: bold;
  198. }
  199. /deep/ .u-form-item {
  200. margin-bottom: 40rpx;
  201. .u-input {
  202. &__content {
  203. display: flex;
  204. align-items: center;
  205. height: 88rpx;
  206. &__field-wrapper {
  207. display: flex;
  208. align-items: center;
  209. height: 88rpx;
  210. &__field {
  211. height: 88rpx;
  212. line-height: 88rpx;
  213. }
  214. }
  215. &__prefix-icon {
  216. height: 88rpx;
  217. line-height: 88rpx;
  218. margin-right: 12rpx;
  219. }
  220. &__suffix-icon {
  221. height: 88rpx;
  222. line-height: 88rpx;
  223. display: flex;
  224. align-items: center;
  225. }
  226. }
  227. }
  228. .u-icon {
  229. color: #909399;
  230. display: flex;
  231. align-items: center;
  232. height: 88rpx;
  233. }
  234. }
  235. }
  236. }
  237. // 适配不同屏幕尺寸
  238. @media screen and (min-width: 768px) {
  239. .login-box {
  240. max-width: 600rpx;
  241. margin: 0 auto;
  242. }
  243. }
  244. // 适配iPhone X 等刘海屏
  245. @supports (padding-bottom: constant(safe-area-inset-bottom)) {
  246. .login-container {
  247. padding-bottom: constant(safe-area-inset-bottom);
  248. }
  249. }
  250. @supports (padding-bottom: env(safe-area-inset-bottom)) {
  251. .login-container {
  252. padding-bottom: env(safe-area-inset-bottom);
  253. }
  254. }
  255. </style>