index.vue 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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. setToken(token);
  61. uni.setStorageSync('accountInfo', res.data.user);
  62. uni.setStorageSync('isLogin', true);
  63. store.commit('setToken', token);
  64. uni.reLaunch({
  65. url: '/pages/index/index'
  66. })
  67. })
  68. }
  69. }
  70. }
  71. </script>
  72. <style lang="scss" scoped>
  73. .content {
  74. .head {
  75. font-size: 50upx;
  76. text-align: center;
  77. padding: 40upx 0;
  78. letter-spacing: 2upx;
  79. }
  80. .login-wrap {
  81. width: 90%;
  82. margin: 50upx auto 0;
  83. box-sizing: border-box;
  84. padding: 20upx;
  85. border-radius: 8upx;
  86. .item {
  87. display: flex;
  88. justify-content: flex-start;
  89. align-items: center;
  90. height: 100upx;
  91. font-size: 32upx;
  92. line-height: 100upx;
  93. input {
  94. font-size: 32upx;
  95. height: 100upx;
  96. border: 0;
  97. }
  98. .login_input {
  99. width: 580upx;
  100. border: none;
  101. }
  102. }
  103. .tip {
  104. text-align: right;
  105. padding: 18upx 0;
  106. font-size: 28upx;
  107. }
  108. .submit-BT {
  109. border-radius: 16upx;
  110. margin-top: 50upx;
  111. background-color:#3384FF;
  112. }
  113. }
  114. }
  115. </style>