index.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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. import { wxLogin} from '@/api/openApi.js'
  25. export default {
  26. data() {
  27. return {
  28. username: "",
  29. password: "",
  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. if (password.length < 1) {
  50. uni.showToast({
  51. title: '请填写密码',
  52. icon: "error"
  53. })
  54. return;
  55. }
  56. uni.login({
  57. provider: 'weixin',
  58. success: function (loginRes) {
  59. let code=loginRes.code;
  60. wxLogin(code).then((resp)=>{
  61. const { code, data, msg } = resp
  62. login({
  63. username,
  64. password
  65. }).then((res) => {
  66. let token = res.data.accessToken;
  67. setToken(token);
  68. uni.setStorageSync('unionid',data.unionid)
  69. uni.setStorageSync('accountInfo', res.data.user);
  70. uni.setStorageSync('isLogin', true);
  71. store.commit('setToken', token);
  72. uni.reLaunch({
  73. url: '/pages/index/index'
  74. })
  75. })
  76. })
  77. }
  78. })
  79. }
  80. }
  81. }
  82. </script>
  83. <style lang="scss" scoped>
  84. .content {
  85. .head {
  86. font-size: 50upx;
  87. text-align: center;
  88. padding: 40upx 0;
  89. letter-spacing: 2upx;
  90. }
  91. .login-wrap {
  92. width: 90%;
  93. margin: 50upx auto 0;
  94. box-sizing: border-box;
  95. padding: 20upx;
  96. border-radius: 8upx;
  97. .item {
  98. display: flex;
  99. justify-content: flex-start;
  100. align-items: center;
  101. height: 100upx;
  102. font-size: 32upx;
  103. line-height: 100upx;
  104. input {
  105. font-size: 32upx;
  106. height: 100upx;
  107. border: 0;
  108. }
  109. .login_input {
  110. width: 580upx;
  111. border: none;
  112. }
  113. }
  114. .tip {
  115. text-align: right;
  116. padding: 18upx 0;
  117. font-size: 28upx;
  118. }
  119. .submit-BT {
  120. border-radius: 16upx;
  121. margin-top: 50upx;
  122. background-color:#3384FF;
  123. }
  124. }
  125. }
  126. </style>