index.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. // store/index.js
  2. import Vue from 'vue';
  3. import Vuex from 'vuex';
  4. Vue.use(Vuex);
  5. import {
  6. getConfigByKey
  7. } from '@/api/index.js'
  8. export default new Vuex.Store({
  9. state: {
  10. coureLogin: uni.getStorageSync('coureLogin') || 0,
  11. webviewUrl: '',
  12. wsDanmuUrl: 'wss://userapp.cqsft.vip', // 弹幕评论接口地址
  13. //红包领取规则:
  14. answerType: 1, //红包领取规则 0:完课且最后一分钟(第二次无需最后一分钟), 1:按完课百分比答题领红包
  15. isSpare:1, // 0,主要小程序,1:备选
  16. logoname:'孪有百货店H',
  17. appid:'wxdfcdcbf21e915589',
  18. imgpath: 'https://obs.jnmyunl.com',//金牛
  19. },
  20. mutations: {
  21. setCount(state, value) {
  22. state.count = value;
  23. },
  24. setUserInfo(state, info) {
  25. state.userInfo = info;
  26. },
  27. setWebviewUrl(state, value) {
  28. state.webviewUrl = value;
  29. },
  30. setCoureLogin(state, payload) {
  31. uni.setStorageSync('coureLogin', payload);
  32. state.coureLogin = payload;
  33. }
  34. },
  35. getters: {
  36. coureLogin: (state) => state.coureLogin,
  37. },
  38. actions: {
  39. fetchUser({commit}) {
  40. // const res = await uni.request({ url: '/api/user' });
  41. commit('setUserInfo', 'noe');
  42. },
  43. getWebviewUrl({commit}) {
  44. var that = this;
  45. var data = {
  46. key: 'course.config'
  47. }
  48. return new Promise((resolve, reject) => {
  49. getConfigByKey(data).then(res => {
  50. if (res.code == 200) {
  51. console.log("getConfigByKey====", JSON.parse(res.data))
  52. let data = JSON.parse(res.data)
  53. commit('setWebviewUrl', data.userCourseAuthDomain);
  54. resolve()
  55. }
  56. }).catch(error => {
  57. reject(error)
  58. });
  59. })
  60. }
  61. }
  62. });