加油站付款小程序,打印小票
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.

67 lines
1.2 KiB

11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 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. mutations: {
  13. // 初始化配置
  14. initConfig(state) {
  15. let config = ['preferential', 'wx']
  16. config.forEach(k => {
  17. api('getConfig', {
  18. keyValue : k
  19. }, res => {
  20. if (res.code == 200) {
  21. state.configList[k] = res.result
  22. }
  23. })
  24. })
  25. },
  26. login(state) {
  27. uni.login({
  28. success(res) {
  29. if (res.errMsg != "login:ok") {
  30. return
  31. }
  32. api('loginLogin', {
  33. code: res.code
  34. }, res => {
  35. if (res.code != 200) {
  36. return
  37. }
  38. state.userInfo = res.result.userInfo
  39. uni.setStorageSync('token', res.result.token)
  40. if (!state.userInfo.nickName || !state.userInfo.headImage) {
  41. uni.navigateTo({
  42. url: '/pages/login/wxUserInfo'
  43. })
  44. }
  45. })
  46. },
  47. fail(err) {
  48. console.error(err)
  49. }
  50. })
  51. },
  52. getUserInfo(state) {
  53. api('infoGetInfo', res => {
  54. if(res.code == 200){
  55. state.userInfo = res.result
  56. }
  57. })
  58. },
  59. },
  60. actions: {},
  61. })
  62. export default store