index.vue 1.9 KB

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