top-nav-client-select.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <template>
  2. <ul class="nav navbar-nav navbar-right">
  3. <li class="dropdown">
  4. <a
  5. v-if="loginInfo"
  6. class="dropdown-toggle"
  7. data-toggle="dropdown"
  8. role="button"
  9. aria-haspopup="true"
  10. aria-expanded="false"
  11. >
  12. {{ loginClientName }}
  13. <span class="caret" />
  14. </a>
  15. <ul
  16. v-if="clientCanAccessList != null && clientCanAccessList.length > 0"
  17. class="dropdown-menu"
  18. >
  19. <li
  20. v-for="clientCanAccess in clientCanAccessList"
  21. :key="clientCanAccess.id"
  22. >
  23. <a @click="changeTokenClient(clientCanAccess.id)">{{ clientCanAccess.name }}</a>
  24. </li>
  25. </ul>
  26. </li>
  27. </ul>
  28. <a-modal v-model:open="visible" title="新用户未设置所属部门或岗位">
  29. <p>
  30. 尊敬的用户,
  31. </p>
  32. <p>
  33. 您好,
  34. 您的账号还未设置所属部门或岗位,因此您可能看不到任何数据。请联系您公司的管理员为您分配权限。
  35. </p>
  36. <template #footer>
  37. <a-button @click="visible = false">确定</a-button>
  38. <a-button @click="goHome">退出</a-button>
  39. </template>
  40. </a-modal>
  41. </template>
  42. <script>
  43. import Common from '../common/Common.js';
  44. import ClientResourceV2 from '../api/base/ClientResourceV2.js';
  45. import TokenClientResource from '../api/base/TokenClientResource.js';
  46. import { Notify, Uuid } from 'pc-component-v3';
  47. export default {
  48. props: {
  49. loginInfo: {
  50. type: Object,
  51. default: function(){
  52. return null;
  53. },
  54. },
  55. },
  56. data: function () {
  57. return {
  58. clientCanAccessList: [],
  59. loginClientName:'',
  60. visible: false,
  61. };
  62. },
  63. mounted: function () {
  64. this.listClientCanAccess();
  65. this.queryTokenClient();
  66. },
  67. methods: {
  68. /**
  69. * 获取可以访问的公司
  70. */
  71. listClientCanAccess: function () {
  72. var _self = this;
  73. ClientResourceV2.listClientCanAccess().then(baseListResponse => {
  74. if (baseListResponse.errorCode == 0) {
  75. _self.clientCanAccessList = baseListResponse.datas;
  76. } else if(baseListResponse.errorCode == -1){
  77. _self.visible = true;
  78. } else {
  79. Notify.error(_self.$t('lang.Notify.error'), baseListResponse.errorMessage, false);
  80. }
  81. }, errorData => {
  82. Common.processException(errorData);
  83. });
  84. },
  85. /**
  86. * 切换公司
  87. */
  88. changeTokenClient: function (clientId) {
  89. var _self = this;
  90. console.log(_self.loginInfo);
  91. const tokenClientChangeRequest = {
  92. userId: _self.loginInfo.userId,
  93. clientId: clientId,
  94. token: _self.loginInfo.token,
  95. };
  96. TokenClientResource.changeTokenClient(tokenClientChangeRequest).then(baseObjectResponse => {
  97. if (baseObjectResponse.errorCode == 0) {
  98. // Notify.success('正确','公司切换成功',true);
  99. _self.queryTokenClient();
  100. window.location.reload();
  101. }else{
  102. Notify.error(_self.$t('lang.Notify.companySwitchFailed'), baseObjectResponse.errorMessage, false);
  103. }
  104. }, errorData => {
  105. Common.processException(errorData);
  106. });
  107. },
  108. /**
  109. * 查询设置的公司
  110. */
  111. queryTokenClient: function () {
  112. var _self = this;
  113. TokenClientResource.queryTokenClient().then(baseObjectResponse => {
  114. if (baseObjectResponse.errorCode == 0) {
  115. _self.loginClientName = baseObjectResponse.data.clientName;
  116. }else if (baseObjectResponse.errorCode == -1){
  117. // add by jack 2024-04-09
  118. // see http://wuzhixin.vip:8080/#/knowledge/1/markdown/viewer/1239
  119. _self.visible = true;
  120. }else{
  121. Notify.error(_self.$t('lang.Notify.error'), baseObjectResponse.errorMessage, false);
  122. }
  123. }, errorData => {
  124. Common.processException(errorData);
  125. });
  126. },
  127. goHome: function(){
  128. window.location.href = Common.getRootPath() + '/';
  129. },
  130. },
  131. };
  132. </script>