index.vue 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. <!-- <getPhone showByPlatform /> -->
  17. <button type="primary" @click="loginSubmit" class="submit-BT">登录</button>
  18. </view>
  19. </view>
  20. </template>
  21. <script>
  22. import { login} from '@/api/user';
  23. import { setToken } from '@/libs/auth';
  24. import getPhone from '@/components/getPhone.vue'
  25. export default {
  26. data() {
  27. return {
  28. username: "",
  29. password: "888888",
  30. }
  31. },
  32. onLoad({username,password}) {
  33. if(username){
  34. this.username=username;
  35. this.password=password;
  36. }
  37. },
  38. methods: {
  39. loginSubmit() {
  40. let username = (this.username).trim();
  41. let password = (this.password).trim();
  42. if (username.length < 1) {
  43. uni.showToast({
  44. title: '请填写账号',
  45. icon: "error"
  46. })
  47. return;
  48. }
  49. login({
  50. accountName:username,
  51. password
  52. }).then((res) => {
  53. let token = res.data.token;
  54. uni.setStorageSync('phone',username)
  55. setToken(token);
  56. uni.switchTab({
  57. url: '/pages/index/index'
  58. })
  59. }).catch((res)=>{
  60. console.log(res)
  61. })
  62. }
  63. }
  64. }
  65. </script>
  66. <style lang="scss" scoped>
  67. .content {
  68. .head {
  69. font-size: 50upx;
  70. text-align: center;
  71. padding: 40upx 0;
  72. letter-spacing: 2upx;
  73. }
  74. .login-wrap {
  75. width: 90%;
  76. margin: 50upx auto 0;
  77. box-sizing: border-box;
  78. padding: 20upx;
  79. border-radius: 8upx;
  80. .item {
  81. display: flex;
  82. justify-content: flex-start;
  83. align-items: center;
  84. height: 100upx;
  85. font-size: 32upx;
  86. line-height: 100upx;
  87. input {
  88. font-size: 32upx;
  89. height: 100upx;
  90. border: 0;
  91. }
  92. }
  93. .tip {
  94. text-align: right;
  95. padding: 18upx 0;
  96. font-size: 28upx;
  97. }
  98. .submit-BT {
  99. border-radius: 16upx;
  100. margin-top: 50upx;
  101. background-color: #409eff;
  102. border-color: #409eff;
  103. }
  104. }
  105. }
  106. </style>