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

80 lines
1.5 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
  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. },
  11. getters: {
  12. },
  13. mutations: {
  14. // 初始化配置
  15. initConfig(state){
  16. api('getConfig', res => {
  17. if(res.code == 200){
  18. res.result.forEach(n => {
  19. state.configList[n.keyName] = n.keyContent
  20. })
  21. }
  22. })
  23. // let config = ['getPrivacyPolicy', 'getUserAgreement']
  24. // config.forEach(k => {
  25. // api(k, res => {
  26. // if (res.code == 200) {
  27. // state.configList[k] = res.result
  28. // }
  29. // })
  30. // })
  31. },
  32. login(state){
  33. uni.showLoading({
  34. title: '登录中...'
  35. })
  36. uni.login({
  37. success(res) {
  38. if(res.errMsg != "login:ok"){
  39. return
  40. }
  41. api('wxLogin', {
  42. code : res.code
  43. }, res => {
  44. uni.hideLoading()
  45. if(res.code != 200){
  46. return
  47. }
  48. state.userInfo = res.result.userInfo
  49. uni.setStorageSync('token', res.result.token)
  50. if(!state.userInfo.nickName || !state.userInfo.headImage){
  51. uni.navigateTo({
  52. url: '/pages_order/auth/wxUserInfo'
  53. })
  54. }else{
  55. uni.navigateBack(-1)
  56. }
  57. })
  58. }
  59. })
  60. },
  61. getUserInfo(state){
  62. api('getInfo', res => {
  63. if(res.code == 200){
  64. state.userInfo = res.result
  65. }
  66. })
  67. },
  68. },
  69. actions: {},
  70. })
  71. export default store