App.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <template>
  2. <div id="app">
  3. <cube-button @click="goTo('service')" v-show="isService">进入微信服务台</cube-button>
  4. <cube-button @click="goTo('user')" v-show="isUser">进入微信运维端</cube-button>
  5. <cube-button @click="goTo('req')" v-show="isReq">进入微信报修端</cube-button>
  6. </div>
  7. </template>
  8. <script>
  9. export default {
  10. name: "App",
  11. data() {
  12. return {
  13. baseUrl: document.location.protocol + "//" + document.domain,
  14. isService:false,//服务台
  15. isUser:false,//运维端
  16. isReq:false,//报修端
  17. };
  18. },
  19. methods: {
  20. // 判断角色
  21. roleHandler(user,requester){
  22. let userRoles = user.role.map(v=>({id:v.id,rolecode:v.rolecode}));
  23. if(userRoles.length){
  24. this.isService = userRoles.some(v=>(v.rolecode === 'call center' || v.rolecode === 'call center admin'))
  25. this.isUser = userRoles.some(v=>(v.rolecode === 'first-line support' || v.rolecode === 'second-line support' || v.rolecode === 'incident manager' || v.rolecode === 'inspectman' || v.rolecode === 'incident-category-manager'))
  26. }else{
  27. this.isService = false;
  28. this.isUser = false;
  29. }
  30. this.isReq = requester ? true : false;
  31. },
  32. // 跳转应用
  33. goTo(type) {
  34. switch (type) {
  35. case "service":
  36. location.href = this.baseUrl + "/serviceApp";
  37. break;
  38. case "user":
  39. location.href = this.baseUrl + "/user";
  40. break;
  41. case "req":
  42. location.href = this.baseUrl + "/req";
  43. break;
  44. }
  45. },
  46. // 登陆
  47. login() {
  48. this.$http.post("service/auth/wechatAuth", {}).then((res) => {
  49. if (res.data.url) {
  50. window.location.href = res.data.url;
  51. } else {
  52. if (res.data.user) {
  53. this.roleHandler(res.data.user.user,res.data.user.requester);
  54. }
  55. }
  56. });
  57. },
  58. // 获取code
  59. getCode() {
  60. var url = window.location.href.split("?");
  61. if (!url[1]) {
  62. this.login();
  63. } else {
  64. var code = {
  65. code: url[1],
  66. };
  67. this.$http.post("service/auth/wechatLoginEncrypt", code).then(res => {
  68. if (res.data.state == 200) {
  69. if (res.data.user) {
  70. this.roleHandler(res.data.user.user,res.data.user.requester);
  71. }
  72. } else if (res.data.state == 501) {
  73. this
  74. .$createDialog({
  75. type: "alert",
  76. title: "您的账号被删除,请联系管理员",
  77. icon: "cubeic-alert"
  78. })
  79. .show();
  80. } else {
  81. this
  82. .$createDialog({
  83. type: "alert",
  84. title: res.data.remarks,
  85. icon: "cubeic-alert"
  86. })
  87. .show();
  88. }
  89. });
  90. }
  91. },
  92. },
  93. created() {
  94. this.getCode();
  95. },
  96. };
  97. </script>
  98. <style lang="less">
  99. #app {
  100. height: 100vh;
  101. background: url('./assets/imgs/weChartBackImage.jpg') no-repeat;
  102. background-size: cover;
  103. button{
  104. background-color: #005395;
  105. margin-bottom: 0.2rem;
  106. }
  107. }
  108. </style>