login.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <template>
  2. <view class="pages">
  3. <view class="wrap">
  4. <view class="title">城市智慧停车场管理<br>PDA登录</view>
  5. <u-form class="login-form" :model="form" ref="uForm">
  6. <u-form-item class="u-p-r-40" label="账号:" :border-bottom="false" label-width="100rpx">
  7. <u-input v-model="form.name" placeholder="请输入您的工号" type="number" maxlength="11" placeholder-style="color:rgba(255,255,255,.5)" />
  8. </u-form-item>
  9. <u-form-item class="u-p-r-40" label="密码:" :border-bottom="false" label-width="100rpx">
  10. <u-input class="password" v-model="form.password" type="password" placeholder="请输入您的密码" placeholder-style="color:rgba(255,255,255,.5)" />
  11. </u-form-item>
  12. </u-form>
  13. <view class="pass-tool">
  14. <u-checkbox v-model="form.passCheck" active-color="transparent">记住密码</u-checkbox>
  15. <!-- <view class="" @click="$refs.uToast.show({title: '请联系管理员修改'})">忘记密码?</view> -->
  16. </view>
  17. <view class="login-btn" @click="handleLogin">立即登录</view>
  18. </view>
  19. <u-toast ref="uToast" />
  20. <u-bottom ></u-bottom>
  21. </view>
  22. </template>
  23. <script>
  24. var device = uni.requireNativePlugin("DeviceInfo")
  25. export default {
  26. data() {
  27. return {
  28. pic:'https://uviewui.com/common/logo.png',
  29. userInfo:[],
  30. form:{
  31. name:'9345',
  32. password:'000000',
  33. passCheck:false,
  34. deviceNo: ''
  35. },
  36. }
  37. },
  38. onLoad() {
  39. uni.getStorage({
  40. key:'loginData',
  41. success: (res) => {
  42. this.form.name = res.data.name;
  43. this.form.password = res.data.password;
  44. console.log('passWord',res.data)
  45. },
  46. fail: (err) => {
  47. console.log('passWord err',err)
  48. }
  49. })
  50. },
  51. methods: {
  52. openPage(path) {
  53. console.log('path',path);
  54. this.$u.route({
  55. url: path
  56. })
  57. },
  58. //登录判断
  59. // login(status){
  60. // if(!status){
  61. // console.log('config',this.config);
  62. // window.location.replace(this.config.loginUrl)
  63. // }
  64. // },
  65. handleLogin(){
  66. // this.form.deviceNo = '1122334455';
  67. this.form.deviceNo = device?.getDeviceInfo()?.deviceId;
  68. this.$u.api.login(this.form)
  69. .then(res=>{
  70. this.$refs.uToast.show({
  71. title: res.msg,
  72. type: 'success',
  73. });
  74. this.$u.vuex('vuex_token', res.data.accessToken);
  75. this.$u.vuex('vuex_user', res.data);
  76. this.$u.vuex('vuex_hasLogin', true);
  77. if(this.form.passCheck){
  78. uni.setStorage({
  79. key:'loginData',
  80. data:{name:this.form.name,password:this.form.password}
  81. });
  82. }else{
  83. uni.removeStorage({
  84. key:'loginData'
  85. })
  86. };
  87. this.$u.route('pages/index/index', {});
  88. console.log('login',res)
  89. }).catch(err=>{
  90. if(err.errMsg){
  91. this.$refs.uToast.show({
  92. title: '请检查网络',
  93. type: 'error',
  94. });
  95. return false;
  96. };
  97. err.msg&&this.$refs.uToast.show({
  98. title: err.msg,
  99. type: 'error',
  100. });
  101. console.log('login ',err)
  102. });
  103. }
  104. }
  105. }
  106. </script>
  107. <style lang="scss" scoped>
  108. @import './login.scss'
  109. </style>