index.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. <template>
  2. <view class="content">
  3. <view class="head">
  4. <text>登录</text>
  5. </view>
  6. <view class="login-wrap">
  7. <view class="username item">
  8. <!-- <text>账号:</text> -->
  9. <image class="icon" src="/static/login/phone.png" mode="widthFix"></image>
  10. <uni-easyinput :inputBorder="false" class="login_input" type="text" v-model="username" placeholder="请输入账号" />
  11. </view>
  12. <view class="password item">
  13. <image class="icon" src="/static/login/pwd.png" mode="widthFix"></image>
  14. <!-- <text>密码:</text> -->
  15. <uni-easyinput :inputBorder="false" class="login_input" type="password" v-model="password" placeholder="请输入密码">
  16. </uni-easyinput>
  17. </view>
  18. <view class="tip">
  19. <label>
  20. <checkbox style="transform:scale(0.7)" class="check" value="cb" checked="true" />
  21. <text>我已阅读并同意《用户协议》和《隐私政策》,且已明确知晓平台仅限企业内部用户使用。 </text>
  22. </label>
  23. </view>
  24. <button type="primary" @click="loginSubmit" class="submit-BT">登录</button>
  25. </view>
  26. </view>
  27. </template>
  28. <script>
  29. import store from '@/store/index.js'
  30. import { login } from '@/api/system/user.js';
  31. import { setToken ,getToken} from '@/libs/auth.js';
  32. export default {
  33. data() {
  34. return {
  35. username: "",
  36. password: "",
  37. }
  38. },
  39. onLoad({username,password}) {
  40. if(username){
  41. this.username=username;
  42. this.password=password;
  43. }
  44. if(getToken()){
  45. uni.reLaunch({
  46. url: '/pages/index/index'
  47. })
  48. }
  49. },
  50. methods: {
  51. loginSubmit() {
  52. let username = (this.username).trim();
  53. let password = (this.password).trim();
  54. if (username.length < 1) {
  55. uni.showToast({
  56. title: '请填写账号',
  57. icon: "error"
  58. })
  59. return;
  60. }
  61. if (password.length < 1) {
  62. uni.showToast({
  63. title: '请填写密码',
  64. icon: "error"
  65. })
  66. return;
  67. }
  68. login({
  69. username,
  70. password
  71. }).then((res) => {
  72. let token = res.data.accessToken;
  73. setToken(token);
  74. uni.setStorageSync('accountInfo', res.data.user);
  75. uni.setStorageSync('isLogin', true);
  76. store.commit('setToken', token);
  77. uni.reLaunch({
  78. url: '/pages/index/index'
  79. })
  80. }).catch((res)=>{
  81. uni.showToast({
  82. icon:'none',
  83. title:res.msg||"登录失败!"
  84. })
  85. })
  86. }
  87. }
  88. }
  89. </script>
  90. <style lang="scss" scoped>
  91. .content {
  92. height: 100vh;
  93. background-color: #F5F6F8;
  94. .head {
  95. font-size: 50upx;
  96. text-align: center;
  97. padding: 40upx 0;
  98. letter-spacing: 2upx;
  99. }
  100. .login-wrap {
  101. width: 90%;
  102. margin: 50upx auto 0;
  103. box-sizing: border-box;
  104. padding: 20upx;
  105. border-radius: 8upx;
  106. .item {
  107. display: flex;
  108. justify-content: flex-start;
  109. align-items: center;
  110. height: 100upx;
  111. font-size: 32upx;
  112. line-height: 100upx;
  113. background-color: #fff;
  114. border-radius: 60rpx;
  115. margin-top: 40rpx;
  116. padding-left: 30rpx;
  117. box-sizing: border-box;
  118. .icon{
  119. width: 48rpx;
  120. }
  121. input {
  122. font-size: 32upx;
  123. height: 100upx;
  124. border: 0;
  125. }
  126. .login_input {
  127. width: 580upx;
  128. border: none;
  129. }
  130. }
  131. .tip {
  132. padding: 48rpx 0 0 56rpx;
  133. font-size: 28upx;
  134. color: #323233;
  135. position: relative;
  136. .check{
  137. position: absolute;
  138. left: 8rpx;
  139. top: 44rpx;
  140. }
  141. }
  142. .submit-BT {
  143. height: 88rpx;
  144. line-height: 88rpx;
  145. border-radius: 50rpx;
  146. margin-top: 50upx;
  147. background-color:#2A5BEE;
  148. padding: 0;
  149. }
  150. }
  151. }
  152. </style>