index.ts 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. import { createStore } from "vuex";
  2. const taskList = [
  3. {
  4. id: 1,
  5. label: "发送一条消息",
  6. status: false,
  7. },
  8. {
  9. id: 2,
  10. label: "撤回一条消息",
  11. status: false,
  12. },
  13. {
  14. id: 3,
  15. label: "修改一次我的昵称",
  16. status: false,
  17. },
  18. {
  19. id: 4,
  20. label: "发起一个群聊",
  21. status: false,
  22. },
  23. {
  24. id: 5,
  25. label: "开启一次群禁言",
  26. status: false,
  27. },
  28. {
  29. id: 6,
  30. label: "解散一个群聊",
  31. status: false,
  32. },
  33. {
  34. id: 7,
  35. label: "发起一次通话",
  36. status: false,
  37. },
  38. ];
  39. const state: any = {
  40. taskList,
  41. userInfo: {},
  42. platform: "classroom", // 平台
  43. imConnent: true, // IM是否连接
  44. token: "", //
  45. isMsgNeedReadReceipt: true,
  46. displayOnlineStatus: true,
  47. allowNotification: true,
  48. _isTIMCallKit: true,
  49. };
  50. if (localStorage.getItem("TUIKit-userInfo")) {
  51. const localUserInfoStorage: any = localStorage.getItem("TUIKit-userInfo") || {};
  52. try {
  53. state.userInfo = JSON.parse(localUserInfoStorage);
  54. } catch (error) {
  55. state.userInfo = {};
  56. }
  57. }
  58. if (sessionStorage.getItem("isMsgNeedReadReceipt")) {
  59. const localNeedReadReceipt: string = sessionStorage.getItem("isMsgNeedReadReceipt") || "";
  60. try {
  61. state.isMsgNeedReadReceipt = JSON.parse(localNeedReadReceipt);
  62. } catch (error) {
  63. state.isMsgNeedReadReceipt = false;
  64. }
  65. }
  66. if (sessionStorage.getItem("displayOnlineStatus")) {
  67. const localDisplayOnlineStatus: string = sessionStorage.getItem("displayOnlineStatus") || "";
  68. try {
  69. state.displayOnlineStatus = JSON.parse(localDisplayOnlineStatus);
  70. } catch (error) {
  71. state.displayOnlineStatus = false;
  72. }
  73. }
  74. if (sessionStorage.getItem("allowNotification")) {
  75. const localAllowNotification: string = sessionStorage.getItem("allowNotification") || "";
  76. try {
  77. state.allowNotification = JSON.parse(localAllowNotification);
  78. } catch (error) {
  79. state.allowNotification = false;
  80. }
  81. }
  82. // 平台
  83. if (sessionStorage.getItem("platform")) {
  84. const platform: string = sessionStorage.getItem("platform") || "";
  85. try {
  86. state.platform = JSON.parse(platform);
  87. } catch (error) {
  88. state.platform = false;
  89. }
  90. }
  91. // 平台
  92. if (sessionStorage.getItem("token")) {
  93. const token: string = sessionStorage.getItem("token") || "";
  94. try {
  95. state.token = JSON.parse(token);
  96. } catch (error) {
  97. state.token = false;
  98. }
  99. }
  100. export default createStore({
  101. state,
  102. mutations: {
  103. handleTask(state: any, index: number) {
  104. state.taskList[index].status = true;
  105. },
  106. setUserInfo(state: any, userInfo: any) {
  107. state.userInfo = userInfo;
  108. localStorage.setItem("TUIKit-userInfo", JSON.stringify(userInfo));
  109. },
  110. setNeedReadReceipt(state: any, isMsgNeedReadReceipt: boolean) {
  111. state.isMsgNeedReadReceipt = isMsgNeedReadReceipt;
  112. sessionStorage.setItem("isMsgNeedReadReceipt", JSON.stringify(isMsgNeedReadReceipt));
  113. },
  114. setDisplayOnlineStatus(state: any, displayOnlineStatus: boolean) {
  115. state.displayOnlineStatus = displayOnlineStatus;
  116. sessionStorage.setItem("displayOnlineStatus", JSON.stringify(displayOnlineStatus));
  117. },
  118. setNotification(state: any, allowNotification: boolean) {
  119. state.allowNotification = allowNotification;
  120. sessionStorage.setItem("allowNotification", JSON.stringify(allowNotification));
  121. },
  122. setPlatform(state: any, platform: string) {
  123. state.platform = platform;
  124. sessionStorage.setItem("platform", platform);
  125. },
  126. setImConnent(state: any, connent: boolean) {
  127. state.imConnent = connent;
  128. },
  129. },
  130. actions: {},
  131. modules: {},
  132. });