青蛙卖大米小程序2024-11-24
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

6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 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. riceInfo : {},//用户相关信息
  11. category : [],//分类信息
  12. payOrderProduct : [],//支付订单中的商品
  13. },
  14. getters: {
  15. },
  16. mutations: {
  17. // 初始化配置
  18. initConfig(state){
  19. api('getConfig', res => {
  20. if(res.code == 200){
  21. res.result.forEach(n => {
  22. state.configList[n.keyName] = n.keyContent
  23. })
  24. }
  25. })
  26. // let config = ['getPrivacyPolicy', 'getUserAgreement']
  27. // config.forEach(k => {
  28. // api(k, res => {
  29. // if (res.code == 200) {
  30. // state.configList[k] = res.result
  31. // }
  32. // })
  33. // })
  34. },
  35. login(state){
  36. uni.showLoading({
  37. title: '登录中...'
  38. })
  39. uni.login({
  40. success(res) {
  41. if(res.errMsg != "login:ok"){
  42. return
  43. }
  44. api('wxLogin', {
  45. code : res.code
  46. }, res => {
  47. uni.hideLoading()
  48. if(res.code != 200){
  49. return
  50. }
  51. state.userInfo = res.result.userInfo
  52. uni.setStorageSync('token', res.result.token)
  53. if(!state.userInfo.nickName || !state.userInfo.headImage){
  54. uni.navigateTo({
  55. url: '/pages_order/auth/wxUserInfo'
  56. })
  57. }else{
  58. uni.navigateBack(-1)
  59. }
  60. })
  61. }
  62. })
  63. },
  64. getUserInfo(state){
  65. api('getInfo', res => {
  66. if(res.code == 200){
  67. state.userInfo = res.result
  68. }
  69. })
  70. },
  71. getRiceInfo(state){
  72. api('getRiceInfo', {
  73. token : uni.getStorageSync('token') || ''
  74. },res => {
  75. if(res.code == 200){
  76. state.riceInfo = res.result
  77. }
  78. })
  79. },
  80. // 退出登录
  81. logout(state){
  82. uni.showModal({
  83. title: '确认退出登录吗',
  84. success(r) {
  85. if(r.confirm){
  86. state.userInfo = {}
  87. state.role = false
  88. uni.removeStorageSync('token')
  89. uni.reLaunch({
  90. url: '/pages/index/index'
  91. })
  92. }
  93. }
  94. })
  95. },
  96. // 查询分类接口
  97. getCategoryList(state){
  98. api('getCategoryList', res => {
  99. if(res.code == 200){
  100. state.category = res.result
  101. }
  102. })
  103. },
  104. // 设置支付订单中的商品
  105. setPayOrderProduct(state, data){
  106. state.payOrderProduct = data
  107. },
  108. },
  109. actions: {},
  110. })
  111. export default store