loginoa.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <template>
  2. <view>
  3. </view>
  4. </template>
  5. <script>
  6. import {
  7. sysloginoa
  8. } from "@/common/api/loginApi.js";
  9. export default {
  10. data() {
  11. return {
  12. usercode:this.$util.getQuery("userid")
  13. }
  14. },
  15. created:function(){
  16. this.syslogin();
  17. },
  18. methods: {
  19. syslogin: function(e) {
  20. let usercode=this.$util.getQuery("userid");
  21. console.info('syslogin',usercode);
  22. if (usercode) {
  23. //uni.showToast({title:"验证通过!", icon:"none"});
  24. this.loading = true;
  25. //this.$store.dispatch('user/login', this.formData)
  26. sysloginoa(usercode)
  27. .then((res) => {
  28. console.info('sysloginoa',res);
  29. if (!res.isSuccess) //失败,显示错误
  30. {
  31. uni.showModal({
  32. title:'提示',
  33. content:res.errorMsg,
  34. showCancel:false
  35. })
  36. return;
  37. }
  38. //设置状态中的各种值
  39. this.$store.commit('setIsLogin',true);
  40. this.$store.commit('setToken',res.tnToken);
  41. this.$store.commit('setAvatar',res.data.avatar);
  42. this.$store.commit('setName',res.data.name);
  43. this.$store.commit('setIntroduction',res.data.introduction);
  44. this.$store.commit('setRoles',res.data.roles);
  45. this.$store.commit('setUser',res.data.user);
  46. this.$store.commit('setStationName',res.data.stationName);
  47. this.$store.commit('setStationCode',res.data.stationCode);
  48. this.$store.commit('setDepartmentName',res.data.departmentName);
  49. this.$store.commit('setDepartmentCode',res.data.departmentCode);
  50. if(res.data.projectCode){
  51. this.$store.commit('setProjectCode',res.projectCode);
  52. }
  53. console.info("登录页面state:",this.$store.state);
  54. uni.setStorage({
  55. key:'storage_state',
  56. data:this.$store.state,
  57. success:function(){
  58. console.info("setStorage状态缓存成功");
  59. console.info('storage_state',uni.getStorageSync('storage_state'));
  60. },
  61. fail: () => {
  62. console.error("setStorage状态缓存失败");
  63. }
  64. });
  65. this.loading = false;
  66. if(this.$store.state.projectCode==="")
  67. {
  68. uni.navigateTo({
  69. url: "/pages/SelectProject/SelectProject"
  70. });
  71. return;
  72. }
  73. //导向到首页
  74. uni.navigateTo({
  75. url: "/pages/index/index"
  76. });
  77. })
  78. .catch((error) => {
  79. console.log(error);
  80. this.loading = false;
  81. })
  82. } else {
  83. uni.showModal({
  84. title:'提示',
  85. content:'用户名不能为空',
  86. showCancel:false
  87. })
  88. }
  89. }
  90. }
  91. }
  92. </script>
  93. <style>
  94. </style>