百富门答题小程序
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.

149 lines
3.2 KiB

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