index.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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. <view class="tip">
  17. <label>
  18. <checkbox style="transform:scale(0.7)" class="check" value="cb" checked="true" />
  19. <text>我已阅读并同意《数字管家用户协议》和《数字管家隐私政策》,且已明确知晓平台仅限企业内部用户使用。 </text>
  20. </label>
  21. </view>
  22. <button type="primary" @click="loginSubmit" class="submit-BT">登录</button>
  23. </view>
  24. </view>
  25. </template>
  26. <script>
  27. import store from '@/store/index.js'
  28. import { login } from '@/api/system/user.js';
  29. import { setToken } from '@/libs/auth.js';
  30. export default {
  31. data() {
  32. return {
  33. username: "",
  34. password: "",
  35. }
  36. },
  37. onLoad({username,password}) {
  38. if(username){
  39. this.username=username;
  40. this.password=password;
  41. }
  42. },
  43. methods: {
  44. loginSubmit() {
  45. let username = (this.username).trim();
  46. let password = (this.password).trim();
  47. if (username.length < 1) {
  48. uni.showToast({
  49. title: '请填写账号',
  50. icon: "error"
  51. })
  52. return;
  53. }
  54. if (password.length < 1) {
  55. uni.showToast({
  56. title: '请填写密码',
  57. icon: "error"
  58. })
  59. return;
  60. }
  61. login({
  62. username,
  63. password
  64. }).then((res) => {
  65. let token = res.data.accessToken;
  66. let accountInfo = JSON.stringify(res.data.user);
  67. const userId=res.data.user.userId;
  68. setToken(token);
  69. uni.setStorageSync('accountInfo', accountInfo);
  70. store.commit('setToken', token);
  71. uni.reLaunch({
  72. url: '/pages/index/index'
  73. })
  74. }).catch((res)=>{
  75. console.log(res)
  76. })
  77. }
  78. }
  79. }
  80. </script>
  81. <style lang="scss" scoped>
  82. .content {
  83. height: 100vh;
  84. background-color: #F5F6F8;
  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. background-color: #fff;
  105. border-radius: 60rpx;
  106. margin-top: 40rpx;
  107. padding-left: 30rpx;
  108. box-sizing: border-box;
  109. input {
  110. font-size: 32upx;
  111. height: 100upx;
  112. border: 0;
  113. }
  114. .login_input {
  115. width: 580upx;
  116. border: none;
  117. }
  118. }
  119. .tip {
  120. padding: 48rpx 0 0 56rpx;
  121. font-size: 28upx;
  122. color: #323233;
  123. position: relative;
  124. .check{
  125. position: absolute;
  126. left: 8rpx;
  127. top: 44rpx;
  128. }
  129. }
  130. .submit-BT {
  131. height: 88rpx;
  132. line-height: 88rpx;
  133. border-radius: 50rpx;
  134. margin-top: 50upx;
  135. background-color:#2A5BEE;
  136. padding: 0;
  137. }
  138. }
  139. }
  140. </style>