index.vue 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <template>
  2. <div class="body">
  3. <uni-forms ref="form" label-position="top" :rules="rules" :model="form">
  4. <uni-forms-item label="账号" name="username" clearable>
  5. <uni-easyinput v-model="form.username" placeholder="请输入账号" trim></uni-easyinput>
  6. </uni-forms-item>
  7. <uni-forms-item label="密码" name="password">
  8. <uni-easyinput v-model="form.password" type="password" placeholder="请输入密码" trim></uni-easyinput>
  9. </uni-forms-item>
  10. </uni-forms>
  11. <button class="login-BT" type="default" @click="submit">登录</button>
  12. </div>
  13. </template>
  14. <script>
  15. import { login } from '@/api/system';
  16. import { setToken } from '@/libs/auth';
  17. export default {
  18. data() {
  19. return {
  20. rules:{
  21. username:{
  22. rules:[
  23. {
  24. required: true,
  25. errorMessage: '请填写账号'
  26. }
  27. ],
  28. validateTrigger:'submit'
  29. },
  30. password:{
  31. rules:[
  32. {
  33. required: true,
  34. errorMessage: '请填写密码',
  35. }
  36. ],
  37. validateTrigger:'submit'
  38. }
  39. },
  40. form:{
  41. username:"",
  42. password:""
  43. }
  44. }
  45. },
  46. methods: {
  47. submit(){
  48. this.$refs.form.validate().then(res=>{
  49. login(this.form).then((res) => {
  50. let token = res.data.accessToken;
  51. setToken(token);
  52. uni.setStorageSync('accountInfo', res.data.user);
  53. uni.reLaunch({
  54. url: '/pages/index/index'
  55. })
  56. })
  57. }).catch(err =>{
  58. uni.showToast({
  59. icon:"none",
  60. title:"请检查填写信息!"
  61. })
  62. })
  63. }
  64. }
  65. }
  66. </script>
  67. <style lang="scss" scoped>
  68. .body{
  69. padding:224upx 90upx 0;
  70. .login-BT{
  71. margin-top:110upx;
  72. // background: #8DA6FF;
  73. background-color: #409eff;
  74. border-radius: 6px;
  75. color: #fff;
  76. }
  77. }
  78. </style>