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

90 lines
1.8 KiB

9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 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. getConfig(state){
  13. return state.configList
  14. }
  15. },
  16. mutations: {
  17. // 初始化配置
  18. initConfig(state) {
  19. let config = ['preferential', 'wx']
  20. config.forEach(k => {
  21. api('getConfig', {
  22. keyValue : k
  23. }, res => {
  24. if (res.code == 200) {
  25. state.configList[k] = res.result
  26. }
  27. })
  28. })
  29. let apiConfig = [ 'getPrivacyPolicy' , 'getUserAgreement' ] //需要访问不同接口才能得到的配置数据
  30. let key = ['privacyAgreement','userAgreement']
  31. apiConfig.forEach((item,index) => {
  32. api(item,res => {
  33. state.configList[key[index]] = res.result
  34. })
  35. })
  36. },
  37. login(state) {
  38. uni.showLoading({
  39. title:"登录中..."
  40. })
  41. uni.login({
  42. success(res) {
  43. console.log(res);
  44. if (res.errMsg != "login:ok") {
  45. return
  46. }
  47. api('loginLogin', {
  48. code: res.code
  49. }, res => {
  50. uni.hideLoading()
  51. if (res.code != 200) {
  52. return
  53. }
  54. state.userInfo = res.result.userInfo
  55. uni.setStorageSync('token', res.result.token)
  56. if (!state.userInfo.nickName || !state.userInfo.headImage) {
  57. uni.navigateTo({
  58. url: '/pages/login/wxUserInfo'
  59. })
  60. }else{
  61. uni.switchTab({
  62. url: '/pages/payment/payment'
  63. })
  64. }
  65. })
  66. },
  67. fail(err) {
  68. console.error(err)
  69. uni.hideLoading()
  70. }
  71. })
  72. },
  73. getUserInfo(state) {
  74. api('infoGetInfo', res => {
  75. if(res.code == 200){
  76. state.userInfo = res.result
  77. }
  78. })
  79. },
  80. },
  81. actions: {},
  82. })
  83. export default store