index.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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. <uni-easyinput :inputBorder="false" class="login_input" type="text" v-model="username" placeholder="请输入账号" />
  10. </view>
  11. <view class="password item">
  12. <text>密码:</text>
  13. <uni-easyinput :inputBorder="false" class="login_input" type="password" v-model="password" placeholder="请输入密码">
  14. </uni-easyinput>
  15. </view>
  16. <button type="primary" @click="loginSubmit" class="submit-BT">登录</button>
  17. </view>
  18. </view>
  19. </template>
  20. <script>
  21. import store from '@/store/index.js'
  22. import { login } from '@/api/system/user.js';
  23. import { setToken } from '@/utils/auth.js';
  24. export default {
  25. data() {
  26. return {
  27. username: "",
  28. password: "",
  29. }
  30. },
  31. onLoad({username,password}) {
  32. if(username){
  33. this.username=username;
  34. this.password=password;
  35. }
  36. },
  37. methods: {
  38. loginSubmit() {
  39. let username = (this.username).trim();
  40. let password = (this.password).trim();
  41. if (username.length < 1) {
  42. uni.showToast({
  43. title: '请填写账号',
  44. icon: "error"
  45. })
  46. return;
  47. }
  48. if (password.length < 1) {
  49. uni.showToast({
  50. title: '请填写密码',
  51. icon: "error"
  52. })
  53. return;
  54. }
  55. login({
  56. username,
  57. password
  58. }).then((res) => {
  59. let token = res.data.accessToken;
  60. let accountInfo = JSON.stringify(res.data.user);
  61. const userId=res.data.user.userId;
  62. setToken(token);
  63. uni.setStorageSync('accountInfo', accountInfo);
  64. store.commit('setToken', token);
  65. uni.reLaunch({
  66. url: '/pages/index/index'
  67. })
  68. }).catch((res)=>{
  69. console.log(res)
  70. })
  71. }
  72. }
  73. }
  74. </script>
  75. <style lang="scss" scoped>
  76. .content {
  77. .head {
  78. font-size: 50upx;
  79. text-align: center;
  80. padding: 40upx 0;
  81. letter-spacing: 2upx;
  82. }
  83. .login-wrap {
  84. width: 90%;
  85. margin: 50upx auto 0;
  86. box-sizing: border-box;
  87. padding: 20upx;
  88. border-radius: 8upx;
  89. .item {
  90. display: flex;
  91. justify-content: flex-start;
  92. align-items: center;
  93. height: 100upx;
  94. font-size: 32upx;
  95. line-height: 100upx;
  96. input {
  97. font-size: 32upx;
  98. height: 100upx;
  99. border: 0;
  100. }
  101. .login_input {
  102. width: 580upx;
  103. border: none;
  104. }
  105. }
  106. .tip {
  107. text-align: right;
  108. padding: 18upx 0;
  109. font-size: 28upx;
  110. }
  111. .submit-BT {
  112. border-radius: 16upx;
  113. margin-top: 50upx;
  114. background-color:#3384FF;
  115. }
  116. }
  117. }
  118. </style>