index.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. import Vue from "vue";
  2. import Vuex from "vuex";
  3. import { checkToken, User } from "@/config/api.js";
  4. import audioBg from "./modules/audioBg";
  5. import videoPlay from "./modules/videoPlay";
  6. import audioJoinPlaylist from "./modules/audioPlaylist";
  7. Vue.use(Vuex);
  8. const store = new Vuex.Store({
  9. state: {
  10. isAuth: "", // 默认为
  11. isBind: "",
  12. pageRouterReport: "", //报告详情的路径
  13. pageRouterActivity: "", //活动详情的路径
  14. requestLoading: false, //加载等待是否显示
  15. isSceneNumber: 0, // 入口来源
  16. },
  17. mutations: {
  18. globalData(state, payload) {
  19. state.isAuth = payload.IsAuth;
  20. state.isBind = payload.IsBind;
  21. },
  22. setRouterReport(state, payload) {
  23. state.pageRouterReport = payload;
  24. },
  25. setRouterActivity(state, payload) {
  26. state.pageRouterActivity = payload;
  27. },
  28. //显示请求加载动画
  29. requestShowLoading(state) {
  30. state.requestLoading = true;
  31. },
  32. //隐藏请求加载动画
  33. requestHideLoading(state) {
  34. state.requestLoading = false;
  35. },
  36. // 场景值
  37. getSceneNumber(state, payload) {
  38. state.isSceneNumber = payload;
  39. },
  40. },
  41. actions: {
  42. checkHandle(context, navigateUrl = "") {
  43. return new Promise((resolve, reject) => {
  44. checkToken()
  45. .then((res) => {
  46. if (res.Ret === 200) {
  47. context.commit("globalData", res.Data);
  48. if (navigateUrl != "noGO") {
  49. if (!res.Data.IsAuth && !res.Data.IsBind) {
  50. //已授权已绑定
  51. if (navigateUrl) {
  52. uni.navigateTo({
  53. url: navigateUrl,
  54. });
  55. }
  56. } else if (res.Data.IsAuth) {
  57. //未授权
  58. uni.navigateTo({
  59. url: "/pageMy/authGuide/authGuide",
  60. });
  61. } else if (res.Data.IsBind && !res.Data.IsAuth) {
  62. uni.showModal({
  63. title: "即将前往登录页面,请确认是否继续",
  64. content: "为了给您提供更好的使用体验,请登录后再进行查看或操作",
  65. confirmColor: "#376cbb",
  66. cancelColor: "#606266",
  67. success: function (res) {
  68. if (res.confirm) {
  69. //已授权未绑定
  70. uni.navigateTo({
  71. url: "/pageMy/login/login",
  72. });
  73. }
  74. },
  75. });
  76. }
  77. }
  78. resolve();
  79. }
  80. })
  81. .catch((err) => {
  82. reject(err);
  83. });
  84. });
  85. },
  86. //获取用户的pv/uv
  87. statistics(type, payload) {
  88. return new Promise((resolve, reject) => {
  89. User.pageHistory(payload)
  90. .then((res) => {
  91. if (res.Ret === 200) {
  92. resolve(res.Data);
  93. }
  94. })
  95. .catch((err) => {
  96. reject(err);
  97. });
  98. });
  99. },
  100. // 绑定手机号的弹框
  101. showLoginModal() {
  102. return new Promise((resolve, reject) => {
  103. if (!store.state.isAuth && store.state.isBind) {
  104. uni.showModal({
  105. title: "即将前往登录页面,请确认是否继续",
  106. content: "为了给您提供更好的使用体验,请登录后再进行查看或操作",
  107. confirmColor: "#376cbb",
  108. cancelColor: "#606266",
  109. success: function (res) {
  110. if (res.confirm) {
  111. //已授权未绑定
  112. uni.navigateTo({
  113. url: "/pageMy/login/login",
  114. });
  115. }
  116. },
  117. });
  118. reject();
  119. } else {
  120. resolve(true);
  121. }
  122. });
  123. },
  124. },
  125. getters: {},
  126. modules: { audioBg, videoPlay, audioJoinPlaylist },
  127. });
  128. export default store;