index.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <template>
  2. <view class="content">
  3. <u-card :show-head="false" :show-foot="false" padding="40" margin="20rpx 20rpx" borderRadius="20" box-shadow="0 0 4px rgba(0, 0, 0, 0.4)"
  4. class="card-box">
  5. <view slot="body" class="login-form">
  6. <u-image :src="logo" mode="aspectFit" width="321rpx" height="109rpx" class="logo"></u-image>
  7. <u-cell-group :border="false">
  8. <u-cell-item icon="account" icon-size="46" :icon-style="iconStyle" :arrow="false">
  9. <u-input v-model="userAccount" placeholder="请输入账号" />
  10. </u-cell-item>
  11. <u-cell-item icon="lock" icon-size="46" :icon-style="iconStyle" :arrow="false">
  12. <u-input v-model="password" type="password" :password-icon="true" placeholder="请输入密码" />
  13. </u-cell-item>
  14. </u-cell-group>
  15. <view style="text-align: right;">
  16. <text @click="goToChangePassword" :style="{borderBottom: '1px solid '+ mainColor, color: mainColor}">修改密码</text>
  17. </view>
  18. <u-button type="primary" :ripple="true" :custom-style="{...customStyle, margin: '10px 0'}" @click="login()">登录</u-button>
  19. </view>
  20. </u-card>
  21. <u-top-tips ref="uTips"></u-top-tips>
  22. </view>
  23. </template>
  24. <script>
  25. import {
  26. mapGetters
  27. } from 'vuex'
  28. const NET = require('@/utils/request')
  29. const API = require('@/config/api')
  30. export default {
  31. computed: {
  32. ...mapGetters([
  33. 'mainColor',
  34. 'customStyle',
  35. ])
  36. },
  37. data() {
  38. return {
  39. logo: API.getServerImg + '1.png',
  40. userAccount: '',
  41. password: '',
  42. iconStyle: {
  43. color: '#999999',
  44. marginRight: '10px'
  45. }
  46. }
  47. },
  48. methods: {
  49. // 登录
  50. login() {
  51. if (!this.userAccount || !this.password) {
  52. this.$refs.uTips.show({
  53. title: '请输入账号密码',
  54. type: 'warning',
  55. })
  56. return
  57. }
  58. NET.request(API.loginByPassword, {
  59. userAccount: this.userAccount,
  60. pwd: this.password,
  61. }, 'POST').then(res => {
  62. uni.setStorage({
  63. key: 'token',
  64. data: res.data.token
  65. })
  66. uni.setStorage({
  67. key: 'userData',
  68. data: {
  69. userId: res.data.userId,
  70. companyId: res.data.companyId,
  71. userName: res.data.userName,
  72. }
  73. })
  74. uni.reLaunch({
  75. url: '/pages/index/index'
  76. })
  77. }).catch(error => {
  78. this.$refs.uTips.show({
  79. title: '登录失败',
  80. type: 'warning',
  81. })
  82. })
  83. },
  84. // 修改密码
  85. goToChangePassword() {
  86. uni.navigateTo({
  87. url: '/pages/login/passwordForm'
  88. });
  89. }
  90. }
  91. }
  92. </script>
  93. <style lang="scss" scoped>
  94. .content {
  95. width: 100%;
  96. height: 100vh;
  97. padding: 150rpx 0 0 0;
  98. float: left;
  99. background-color: #5976ba;
  100. .card-box {
  101. .login-form {
  102. height: calc(100vh - 280rpx);
  103. padding-top: 120px;
  104. position: relative;
  105. .logo {
  106. width: 321rpx;
  107. margin-bottom: 40rpx;
  108. top: 25px;
  109. left: 50%;
  110. transform: translateX(-50%);
  111. position: absolute;
  112. }
  113. }
  114. /deep/.u-cell {
  115. border: 1px solid #eeeeee;
  116. border-radius: 8px;
  117. padding: 8px 10px;
  118. margin-bottom: 16px;
  119. }
  120. }
  121. }
  122. </style>