123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131 |
- import Vue from "vue";
- import Vuex from "vuex";
- import { checkToken, User } from "@/config/api.js";
- import audioBg from "./modules/audioBg";
- import videoPlay from "./modules/videoPlay";
- import audioJoinPlaylist from "./modules/audioPlaylist";
- Vue.use(Vuex);
- const store = new Vuex.Store({
- state: {
- isAuth: "", // 默认为
- isBind: "",
- pageRouterReport: "", //报告详情的路径
- pageRouterActivity: "", //活动详情的路径
- requestLoading: false, //加载等待是否显示
- isSceneNumber: 0, // 入口来源
- },
- mutations: {
- globalData(state, payload) {
- state.isAuth = payload.IsAuth;
- state.isBind = payload.IsBind;
- },
- setRouterReport(state, payload) {
- state.pageRouterReport = payload;
- },
- setRouterActivity(state, payload) {
- state.pageRouterActivity = payload;
- },
- //显示请求加载动画
- requestShowLoading(state) {
- state.requestLoading = true;
- },
- //隐藏请求加载动画
- requestHideLoading(state) {
- state.requestLoading = false;
- },
- // 场景值
- getSceneNumber(state, payload) {
- state.isSceneNumber = payload;
- },
- },
- actions: {
- checkHandle(context, navigateUrl = "") {
- return new Promise((resolve, reject) => {
- checkToken()
- .then((res) => {
- if (res.Ret === 200) {
- context.commit("globalData", res.Data);
- if (navigateUrl != "noGO") {
- if (!res.Data.IsAuth && !res.Data.IsBind) {
- //已授权已绑定
- if (navigateUrl) {
- uni.navigateTo({
- url: navigateUrl,
- });
- }
- } else if (res.Data.IsAuth) {
- //未授权
- uni.navigateTo({
- url: "/pageMy/authGuide/authGuide",
- });
- } else if (res.Data.IsBind && !res.Data.IsAuth) {
- uni.showModal({
- title: "即将前往登录页面,请确认是否继续",
- content: "为了给您提供更好的使用体验,请登录后再进行查看或操作",
- confirmColor: "#376cbb",
- cancelColor: "#606266",
- success: function (res) {
- if (res.confirm) {
- //已授权未绑定
- uni.navigateTo({
- url: "/pageMy/login/login",
- });
- }
- },
- });
- }
- }
- resolve();
- }
- })
- .catch((err) => {
- reject(err);
- });
- });
- },
- //获取用户的pv/uv
- statistics(type, payload) {
- return new Promise((resolve, reject) => {
- User.pageHistory(payload)
- .then((res) => {
- if (res.Ret === 200) {
- resolve(res.Data);
- }
- })
- .catch((err) => {
- reject(err);
- });
- });
- },
- // 绑定手机号的弹框
- showLoginModal() {
- return new Promise((resolve, reject) => {
- if (!store.state.isAuth && store.state.isBind) {
- uni.showModal({
- title: "即将前往登录页面,请确认是否继续",
- content: "为了给您提供更好的使用体验,请登录后再进行查看或操作",
- confirmColor: "#376cbb",
- cancelColor: "#606266",
- success: function (res) {
- if (res.confirm) {
- //已授权未绑定
- uni.navigateTo({
- url: "/pageMy/login/login",
- });
- }
- },
- });
- reject();
- } else {
- resolve(true);
- }
- });
- },
- },
- getters: {},
- modules: { audioBg, videoPlay, audioJoinPlaylist },
- });
- export default store;
|