login.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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. //#ifdef APP-PLUS
  25. var device = uni.requireNativePlugin("DeviceInfo")
  26. //#endif
  27. export default {
  28. data() {
  29. return {
  30. pic:'https://uviewui.com/common/logo.png',
  31. userInfo:[],
  32. form:{
  33. name:'',
  34. password:'',
  35. passCheck:false,
  36. deviceNo: ''
  37. },
  38. }
  39. },
  40. onLoad() {
  41. uni.getStorage({
  42. key:'loginData',
  43. success: (res) => {
  44. this.form.name = res.data.name;
  45. this.form.password = res.data.password;
  46. this.form.passCheck = res.data.passCheck?res.data.passCheck:false
  47. // console.log('passWord',res.data)
  48. },
  49. fail: (err) => {
  50. // console.log('passWord err',err)
  51. }
  52. })
  53. },
  54. onBackPress(options) {
  55. if (options.from === 'backbutton') {
  56. // uni.showModal({
  57. // title: '温馨提示',
  58. // content: '已经到头了',
  59. // showCancel: false,
  60. // success: (res) => { }
  61. // })
  62. // 禁止默认返回
  63. return true
  64. }
  65. },
  66. methods: {
  67. handleLogin(){
  68. //#ifdef APP-PLUS
  69. this.form.deviceNo = device?.getDeviceInfo()?.deviceId;
  70. //#endif
  71. //#ifdef H5
  72. this.form.deviceNo = '123456789';
  73. //#endif
  74. this.$u.api.login(this.form)
  75. .then(res=>{
  76. this.$refs.uToast.show({
  77. title: res.msg,
  78. type: 'success',
  79. });
  80. this.$u.vuex('vuex_token', res.data.accessToken);
  81. this.$u.vuex('vuex_user', res.data);
  82. this.$u.vuex('vuex_hasLogin', true);
  83. if(this.form.passCheck){
  84. uni.setStorage({
  85. key:'loginData',
  86. data:{name:this.form.name,password:this.form.password,passCheck:this.form.passCheck }
  87. });
  88. }else{
  89. uni.setStorage({
  90. key:'loginData',
  91. data:{name:this.form.name}
  92. });
  93. };
  94. uni.removeStorageSync('pushreg_switch');//删除推送开关,登录成功后允许处理推送
  95. // this.$u.route('pages/index/index', {});
  96. uni.redirectTo({
  97. url:'../index/index'
  98. });
  99. }).catch(err=>{
  100. if(err.errMsg){
  101. this.$refs.uToast.show({
  102. title: '请检查网络',
  103. type: 'error',
  104. });
  105. return false;
  106. };
  107. err.msg&&this.$refs.uToast.show({
  108. title: err.msg,
  109. type: 'error',
  110. });
  111. console.log('login ',err)
  112. });
  113. }
  114. }
  115. }
  116. </script>
  117. <style lang="scss" scoped>
  118. @import './login.scss'
  119. </style>