login.vue 3.0 KB

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