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

120 lines
2.3 KiB

8 months ago
6 months ago
8 months ago
6 months ago
8 months ago
6 months ago
8 months ago
6 months ago
8 months ago
6 months ago
8 months ago
6 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. },
  15. getters: {
  16. },
  17. mutations: {
  18. // 初始化配置
  19. initConfig(state){
  20. api('getConfig', res => {
  21. if(res.code == 200){
  22. // state.configList = res.result
  23. res.result.forEach(n => {
  24. state.configList[n.keyName] = n.keyContent
  25. })
  26. }
  27. })
  28. // let config = ['getPrivacyPolicy', 'getUserAgreement']
  29. // config.forEach(k => {
  30. // api(k, res => {
  31. // if (res.code == 200) {
  32. // state.configList[k] = res.result
  33. // }
  34. // })
  35. // })
  36. },
  37. login(state){
  38. uni.showLoading({
  39. title: '登录中...'
  40. })
  41. uni.login({
  42. success(res) {
  43. if(res.errMsg != "login:ok"){
  44. return
  45. }
  46. api('wxLogin', {
  47. code : res.code
  48. }, res => {
  49. uni.hideLoading()
  50. if(res.code != 200){
  51. return
  52. }
  53. state.userInfo = res.result.userInfo
  54. uni.setStorageSync('token', res.result.token)
  55. if(!state.userInfo.nickName || !state.userInfo.headImage){
  56. uni.navigateTo({
  57. url: '/pages_order/auth/wxUserInfo'
  58. })
  59. }else{
  60. uni.navigateBack(-1)
  61. }
  62. })
  63. }
  64. })
  65. },
  66. getUserInfo(state){
  67. api('getInfo', res => {
  68. if(res.code == 200){
  69. state.userInfo = res.result
  70. }
  71. })
  72. },
  73. // 获取轮播图
  74. getBanner(state){
  75. api('bannerList', res => {
  76. if(res.code == 200){
  77. state.bannerList = res.result
  78. }
  79. })
  80. },
  81. // 获取文章列表
  82. getArticleList(state){
  83. api('articleList', res => {
  84. if(res.code == 200){
  85. state.articleList = res.result
  86. }
  87. })
  88. },
  89. // 获取问题列表
  90. getProblemList(state){
  91. api('problemList', res => {
  92. if(res.code == 200){
  93. state.problemList = res.result
  94. }
  95. })
  96. },
  97. // 查询我的答题记录
  98. getQueryMyLog(state){
  99. api('queryMyLog', res => {
  100. if(res.code == 200){
  101. state.queryMyLog = res.result
  102. uni.navigateTo({
  103. url: '/pages/index/home'
  104. })
  105. }
  106. })
  107. },
  108. },
  109. actions: {},
  110. })
  111. export default store