index.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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:1, // 0,主要小程序,1:备选
  21. uploadFile: 'https://userapp.cqsft.vip',
  22. imgpath: 'https://kntobs.jnmyunl.com',//惠选商城图片请求地址
  23. // https://kntobs.jnmyunl.com/shop 惠选商城图片链接
  24. logoname:'荣健堂优选',
  25. // appid:'wxdc473753fd42a1d2',//荣健堂优选
  26. //appid:'wx6c20263c87c4dfae',//德信嘉选
  27. //appid:'wx93e9cafa0f306254',//康年嘉选
  28. // appid:'wx1de020b57c05a990',//臻选
  29. //appid:'wxd2edd379beb6581b',//惠选
  30. appid:'wx7f32e725d9935c32',//其他
  31. },
  32. mutations: {
  33. setCount(state, value) {
  34. state.count = value;
  35. },
  36. setUserInfo(state, info) {
  37. state.userInfo = info;
  38. },
  39. setWebviewUrl(state, value) {
  40. state.webviewUrl = value;
  41. },
  42. setlogoimg(state, value) {
  43. state.logoimg = value;
  44. },
  45. setCoureLogin(state, payload) {
  46. uni.setStorageSync('coureLogin', payload);
  47. state.coureLogin = payload;
  48. }
  49. },
  50. getters: {
  51. coureLogin: (state) => state.coureLogin,
  52. logoimg:(state) => state.logoimg,
  53. },
  54. actions: {
  55. fetchUser({ commit }) {
  56. // const res = await uni.request({ url: '/api/user' });
  57. commit('setUserInfo', 'noe');
  58. },
  59. getAppInfos({commit}){
  60. const data={
  61. appId:wx.getAccountInfoSync().miniProgram.appId
  62. }
  63. return new Promise((resolve, reject) => {
  64. getAppInfo(data).then(res => {
  65. if (res.code == 200) {
  66. console.log('=====',res)
  67. commit('setlogoimg', res.data.img);
  68. resolve()
  69. }
  70. }).catch(error => {
  71. reject(error)
  72. });
  73. })
  74. // getAppInfo(data).then(res=>{
  75. // if(res.code==200){
  76. // commit('logoimg', res.data.img);
  77. // resolve()
  78. // }else{
  79. // uni.showToast({
  80. // title: res.msg,
  81. // icon: 'none'
  82. // });
  83. // }
  84. // })
  85. },
  86. getWebviewUrl({commit}) {
  87. var that = this;
  88. var data = {
  89. key: 'course.config'
  90. }
  91. return new Promise((resolve, reject) => {
  92. getConfigByKey(data).then(res => {
  93. if (res.code == 200) {
  94. console.log("getConfigByKey====", JSON.parse(res.data))
  95. let data = JSON.parse(res.data)
  96. commit('setWebviewUrl', data.userCourseAuthDomain);
  97. resolve()
  98. }
  99. }).catch(error => {
  100. reject(error)
  101. });
  102. })
  103. }
  104. }
  105. });