login.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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. // this.form.deviceNo = '123456789';
  71. //#endif
  72. //#ifdef H5
  73. this.form.deviceNo = '123456789';
  74. //#endif
  75. this.$u.api.login(this.form)
  76. .then(res=>{
  77. this.$refs.uToast.show({
  78. title: res.msg,
  79. type: 'success',
  80. });
  81. this.$u.vuex('vuex_token', res.data.accessToken);
  82. this.$u.vuex('vuex_user', res.data);
  83. this.$u.vuex('vuex_hasLogin', true);
  84. uni.setStorageSync('payee_roadinfo', JSON.stringify(res.data?.roadList?.[0] || []));
  85. if(this.form.passCheck){
  86. uni.setStorage({
  87. key:'loginData',
  88. data:{name:this.form.name,password:this.form.password,passCheck:this.form.passCheck }
  89. });
  90. }else{
  91. uni.setStorage({
  92. key:'loginData',
  93. data:{name:this.form.name}
  94. });
  95. };
  96. uni.removeStorageSync('pushreg_switch');//删除推送开关,登录成功后允许处理推送
  97. // this.$u.route('pages/index/index', {});
  98. uni.redirectTo({
  99. url:'../index/index'
  100. });
  101. }).catch(err=>{
  102. if(err.errMsg){
  103. this.$refs.uToast.show({
  104. title: '请检查网络',
  105. type: 'error',
  106. });
  107. return false;
  108. };
  109. err.msg&&this.$refs.uToast.show({
  110. title: err.msg,
  111. type: 'error',
  112. });
  113. console.log('login ',err)
  114. });
  115. }
  116. }
  117. }
  118. </script>
  119. <style lang="scss" scoped>
  120. @import './login.scss'
  121. </style>