百富门答题小程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

158 lines
3.4 KiB

1 year ago
1 year ago
11 months ago
1 year ago
11 months ago
10 months ago
8 months ago
1 year ago
11 months ago
8 months ago
11 months ago
1 year ago
11 months ago
1 year ago
1 year ago
8 months ago
11 months ago
1 year ago
8 months ago
1 year ago
8 months ago
11 months ago
8 months ago
8 months ago
11 months ago
8 months ago
1 year ago
  1. import Vue from 'vue'
  2. import Vuex from 'vuex'
  3. Vue.use(Vuex); //vue的插件机制
  4. import api from '@/api/api.js'
  5. const accountInfo = wx.getAccountInfoSync();
  6. let envVersion = accountInfo.miniProgram.envVersion;
  7. //Vuex.Store 构造器选项
  8. const store = new Vuex.Store({
  9. state: {
  10. configList: {}, //配置列表
  11. userInfo : {}, //用户信息
  12. bannerList : [],//轮播图
  13. articleList : [],//文章列表
  14. problemList : [],//问题列表
  15. queryMyLog : [],//我的答题记录
  16. reviewAnswerList : [],//评论题目列表
  17. titleBy : {},//称号
  18. },
  19. getters: {
  20. },
  21. mutations: {
  22. // 初始化配置
  23. initConfig(state){
  24. api('getConfig', res => {
  25. if(res.code == 200){
  26. // state.configList = res.result
  27. res.result.forEach(n => {
  28. state.configList[n.keyName] = n.keyContent
  29. })
  30. uni.$emit('initConfig', state.configList)
  31. }
  32. })
  33. // let config = ['getPrivacyPolicy', 'getUserAgreement']
  34. // config.forEach(k => {
  35. // api(k, res => {
  36. // if (res.code == 200) {
  37. // state.configList[k] = res.result
  38. // }
  39. // })
  40. // })
  41. },
  42. login(state){
  43. uni.showLoading({
  44. title: '登录中...'
  45. })
  46. uni.login({
  47. success(res) {
  48. if(res.errMsg != "login:ok"){
  49. return
  50. }
  51. api('wxLogin', {
  52. code : res.code
  53. }, res => {
  54. uni.hideLoading()
  55. if(res.code != 200){
  56. return
  57. }
  58. state.userInfo = res.result.userInfo
  59. uni.setStorageSync('token', res.result.token)
  60. // if(!['release'].includes(envVersion)){
  61. // return
  62. // }
  63. // if(!state.userInfo.nickName || !state.userInfo.headImage){
  64. // uni.navigateTo({
  65. // url: '/pages_order/auth/wxUserInfo'
  66. // })
  67. // }else{
  68. // uni.navigateTo({
  69. // url: '/pages/index/index'
  70. // })
  71. uni.navigateBack(-1)
  72. // }
  73. })
  74. }
  75. })
  76. },
  77. getUserInfo(state, fn){
  78. api('getInfo', res => {
  79. if(res.code == 200){
  80. state.userInfo = res.result
  81. fn && fn(state.userInfo)
  82. }
  83. })
  84. },
  85. // 获得的称号接口
  86. getTitleByIds(state, ids){
  87. api('getTitleByIds', {ids}, res => {
  88. if(res.code == 200){
  89. state.titleBy = res.result
  90. state.articleList = res.result.answerObjectRuleNewsList
  91. setTimeout(uni.navigateTo, 0, {
  92. url: '/pages/index/title'
  93. })
  94. }
  95. })
  96. },
  97. // // 获取轮播图
  98. // getBanner(state){
  99. // api('bannerList', res => {
  100. // if(res.code == 200){
  101. // state.bannerList = res.result
  102. // }
  103. // })
  104. // },
  105. // // 获取文章列表
  106. // getArticleList(state){
  107. // api('articleList', res => {
  108. // if(res.code == 200){
  109. // state.articleList = res.result
  110. // }
  111. // })
  112. // },
  113. // // 获取问题列表
  114. // getProblemList(state){
  115. // api('problemList', res => {
  116. // if(res.code == 200){
  117. // state.problemList = res.result
  118. // }
  119. // })
  120. // },
  121. // // 评论题目列表接口
  122. // getAnswerList(state, id){
  123. // api('queryAnswerList', res => {
  124. // if(res.code == 200){
  125. // state.reviewAnswerList = res.result
  126. // uni.navigateTo({
  127. // url: '/pages/index/review?oid=' + id
  128. // })
  129. // }
  130. // })
  131. // },
  132. // // 查询我的答题记录
  133. // getQueryMyLog(state){
  134. // api('queryMyLog', res => {
  135. // if(res.code == 200){
  136. // state.queryMyLog = res.result
  137. // uni.navigateTo({
  138. // url: '/pages/index/home'
  139. // })
  140. // }
  141. // })
  142. // },
  143. },
  144. actions: {},
  145. })
  146. export default store