index.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. import {
  9. getAppInfo
  10. } from '@/api/common.js'
  11. export default new Vuex.Store({
  12. state: {
  13. coureLogin: uni.getStorageSync('coureLogin') || 0,
  14. webviewUrl: '',
  15. logoimg:'',
  16. wsDanmuUrl: 'wss://userapp.cqsft.vip', // 弹幕评论接口地址
  17. //红包领取规则:
  18. //获取惠选的图片,logo加s
  19. answerType: 1, //红包领取规则 0:完课且最后一分钟(第二次无需最后一分钟), 1:按完课百分比答题领红包
  20. isSpare:0, // 0,主要小程序,1:备选
  21. uploadFile: 'https://userapp.cqsft.vip',
  22. imgpath: 'https://kntobs.jnmyunl.com',//惠选商城图片请求地址
  23. // https://kntobs.jnmyunl.com/shop 惠选商城图片链接
  24. logoname:'德信小站',
  25. // appid:'wx1de020b57c05a990',//康年臻选
  26. appid:'wxd2edd379beb6581b',//康年惠选
  27. //appid:'wxd2892bb660356ecf',//其他
  28. },
  29. mutations: {
  30. setCount(state, value) {
  31. state.count = value;
  32. },
  33. setUserInfo(state, info) {
  34. state.userInfo = info;
  35. },
  36. setWebviewUrl(state, value) {
  37. state.webviewUrl = value;
  38. },
  39. setlogoimg(state, value) {
  40. state.logoimg = value;
  41. },
  42. setCoureLogin(state, payload) {
  43. uni.setStorageSync('coureLogin', payload);
  44. state.coureLogin = payload;
  45. }
  46. },
  47. getters: {
  48. coureLogin: (state) => state.coureLogin,
  49. logoimg:(state) => state.logoimg,
  50. },
  51. actions: {
  52. fetchUser({ commit }) {
  53. // const res = await uni.request({ url: '/api/user' });
  54. commit('setUserInfo', 'noe');
  55. },
  56. getAppInfos({commit}){
  57. const data={
  58. appId:wx.getAccountInfoSync().miniProgram.appId
  59. }
  60. return new Promise((resolve, reject) => {
  61. getAppInfo(data).then(res => {
  62. if (res.code == 200) {
  63. console.log('=====',res)
  64. commit('setlogoimg', res.data.img);
  65. resolve()
  66. }
  67. }).catch(error => {
  68. reject(error)
  69. });
  70. })
  71. // getAppInfo(data).then(res=>{
  72. // if(res.code==200){
  73. // commit('logoimg', res.data.img);
  74. // resolve()
  75. // }else{
  76. // uni.showToast({
  77. // title: res.msg,
  78. // icon: 'none'
  79. // });
  80. // }
  81. // })
  82. },
  83. getWebviewUrl({commit}) {
  84. var that = this;
  85. var data = {
  86. key: 'course.config'
  87. }
  88. return new Promise((resolve, reject) => {
  89. getConfigByKey(data).then(res => {
  90. if (res.code == 200) {
  91. console.log("getConfigByKey====", JSON.parse(res.data))
  92. let data = JSON.parse(res.data)
  93. commit('setWebviewUrl', data.userCourseAuthDomain);
  94. resolve()
  95. }
  96. }).catch(error => {
  97. reject(error)
  98. });
  99. })
  100. }
  101. }
  102. });