login.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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:'9345',
  34. password:'000000',
  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. console.log('passWord',res.data)
  47. },
  48. fail: (err) => {
  49. console.log('passWord err',err)
  50. }
  51. })
  52. },
  53. onBackPress(options) {
  54. if (options.from === 'backbutton') {
  55. uni.showModal({
  56. title: '温馨提示',
  57. content: '已经到头了',
  58. showCancel: false,
  59. success: (res) => { }
  60. })
  61. // 禁止默认返回
  62. return true
  63. }
  64. },
  65. methods: {
  66. handleLogin(){
  67. //#ifdef APP-PLUS
  68. this.form.deviceNo = device?.getDeviceInfo()?.deviceId;
  69. //#endif
  70. //#ifdef H5
  71. this.form.deviceNo = '123456789';
  72. //#endif
  73. this.$u.api.login(this.form)
  74. .then(res=>{
  75. this.$refs.uToast.show({
  76. title: res.msg,
  77. type: 'success',
  78. });
  79. this.$u.vuex('vuex_token', res.data.accessToken);
  80. this.$u.vuex('vuex_user', res.data);
  81. this.$u.vuex('vuex_hasLogin', true);
  82. if(this.form.passCheck){
  83. uni.setStorage({
  84. key:'loginData',
  85. data:{name:this.form.name,password:this.form.password}
  86. });
  87. }else{
  88. uni.removeStorage({
  89. key:'loginData'
  90. })
  91. };
  92. // this.$u.route('pages/index/index', {});
  93. uni.redirectTo({
  94. url:'../index/index'
  95. });
  96. }).catch(err=>{
  97. if(err.errMsg){
  98. this.$refs.uToast.show({
  99. title: '请检查网络',
  100. type: 'error',
  101. });
  102. return false;
  103. };
  104. err.msg&&this.$refs.uToast.show({
  105. title: err.msg,
  106. type: 'error',
  107. });
  108. console.log('login ',err)
  109. });
  110. }
  111. }
  112. }
  113. </script>
  114. <style lang="scss" scoped>
  115. @import './login.scss'
  116. </style>