loginoa.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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.token);
  41. this.$store.commit('setAvatar',res.avatar);
  42. this.$store.commit('setName',res.name);
  43. this.$store.commit('setIntroduction',res.introduction);
  44. this.$store.commit('setRoles',res.roles);
  45. this.$store.commit('setUser',res.user);
  46. this.$store.commit('setStationName',res.stationName);
  47. this.$store.commit('setStationCode',res.stationCode);
  48. this.$store.commit('setDepartmentName',res.departmentName);
  49. this.$store.commit('setDepartmentCode',res.departmentCode);
  50. if(res.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. },
  60. fail: () => {
  61. console.error("setStorage状态缓存失败");
  62. }
  63. });
  64. this.loading = false;
  65. if(this.$store.state.projectCode==="")
  66. {
  67. uni.navigateTo({
  68. url: "/pages/SelectProject/SelectProject"
  69. });
  70. return;
  71. }
  72. //导向到首页
  73. uni.navigateTo({
  74. url: "/pages/index/index"
  75. });
  76. })
  77. .catch((error) => {
  78. console.log(error);
  79. this.loading = false;
  80. })
  81. } else {
  82. uni.showModal({
  83. title:'提示',
  84. content:'用户名不能为空',
  85. showCancel:false
  86. })
  87. }
  88. }
  89. }
  90. }
  91. </script>
  92. <style>
  93. </style>