index.js 781 B

12345678910111213141516171819202122232425262728293031323334353637
  1. import Vue from 'vue'
  2. import Vuex from 'vuex'
  3. Vue.use(Vuex)
  4. import {getConfigByKey} from '@/api/course.js'
  5. const store = new Vuex.Store({
  6. state: {
  7. coureLogin: uni.getStorageSync('coureLogin') || 0,
  8. webviewUrl: ""
  9. },
  10. mutations: {
  11. setCoureLogin(state, payload) {
  12. uni.setStorageSync('coureLogin', payload);
  13. state.coureLogin = payload;
  14. },
  15. SET_WEBVIEWURL(state, payload) {
  16. state.webviewUrl = payload;
  17. },
  18. },
  19. getters: {
  20. coureLogin: (state) => state.coureLogin,
  21. webviewUrl: (state) => state.webviewUrl,
  22. },
  23. actions: {
  24. async getWebviewUrl({commit}) {
  25. const res = await getConfigByKey({
  26. key: 'course.config'
  27. })
  28. if (res.code === 200) {
  29. commit('SET_WEBVIEWURL', JSON.parse(res.data).userCourseAuthDomain)
  30. }
  31. }
  32. }
  33. })
  34. export default store