index.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. import Vue from 'vue'
  2. import Vuex from 'vuex'
  3. Vue.use(Vuex)
  4. import {
  5. http
  6. } from "../common/http.js"
  7. export const store = new Vuex.Store({
  8. state: {
  9. showWxLogin: false,
  10. userInfo: uni.getStorageSync('userInfo') || {},
  11. token: uni.getStorageSync('token') || '',
  12. city: uni.getStorageSync('city') || '郑州市',
  13. start: {},
  14. end: {},
  15. hyend: {},
  16. hyaddress: uni.getStorageSync('hyaddress') ||[],
  17. height: 30, //状态栏高度
  18. tabList: [],
  19. address: uni.getStorageSync('address') || [], //默认搜索的地址
  20. city1: '',
  21. city2: '',
  22. },
  23. mutations: {
  24. getCity1(state, city1) {
  25. state.city1 = city1
  26. },
  27. getCity2(state, city2) {
  28. state.city2 = city2
  29. },
  30. getTab(state, tabList) {
  31. state.tabList = tabList
  32. },
  33. setLoginPopupShow(state, showWxLogin) {
  34. state.showWxLogin = showWxLogin
  35. },
  36. getHeight(state, height) {
  37. state.height = height
  38. },
  39. getStart(state, start) {
  40. state.start = start
  41. state.city1 = start.city
  42. let flag = false;
  43. state.address.forEach(item => {
  44. if (item.address == start.address) {
  45. flag = true
  46. }
  47. })
  48. if (!flag) {
  49. if (state.address.length < 5) {
  50. state.address.unshift(start)
  51. } else {
  52. state.address.pop()
  53. state.address.unshift(start)
  54. }
  55. }
  56. uni.setStorageSync('address', state.address)
  57. },
  58. getEnd(state, end) {
  59. state.end = end
  60. state.city2 = end.city
  61. let flag = false;
  62. state.address.forEach(item => {
  63. if (item.address == end.address) {
  64. flag = true
  65. }
  66. })
  67. if (!flag) {
  68. if (state.address.length < 5) {
  69. state.address.unshift(end)
  70. } else {
  71. state.address.pop()
  72. state.address.unshift(end)
  73. }
  74. }
  75. uni.setStorageSync('address', state.address)
  76. },
  77. getHyEnd(state, end) {
  78. state.hyend = end
  79. if (Object.keys(end).length > 0) {
  80. let flag = false;
  81. state.address.forEach(item => {
  82. if (item.address == end.address) {
  83. flag = true
  84. }
  85. })
  86. if (!flag) {
  87. if (state.address.length < 5) {
  88. state.address.unshift(end)
  89. } else {
  90. state.address.pop()
  91. state.address.unshift(end)
  92. }
  93. }
  94. uni.setStorageSync('address', state.address)
  95. }
  96. },
  97. getHyAddress(state, addr) {
  98. state.hyaddress.push(addr)
  99. uni.setStorageSync('hyaddress', state.hyaddress)
  100. },
  101. delHyAddress(state, index) {
  102. state.hyaddress.splice(index,1)
  103. uni.setStorageSync('hyaddress', state.hyaddress)
  104. },
  105. getCity(state, city) {
  106. state.city = city
  107. uni.setStorageSync('city', state.city)
  108. },
  109. getUserInfo(state, info) {
  110. console.log(state);
  111. state.userInfo = info
  112. state.token = state.userInfo.token
  113. uni.setStorageSync('userInfo', state.userInfo)
  114. uni.setStorageSync('token', state.userInfo.token)
  115. },
  116. exitLogin(state) {
  117. state.userInfo = {}
  118. state.token = ''
  119. uni.setStorageSync('userInfo', state.userInfo)
  120. uni.setStorageSync('token', state.userInfo.token)
  121. },
  122. },
  123. getters: {},
  124. // this.$store.dispatch('updateUserInfo')
  125. actions: {
  126. updateUserInfo({
  127. commit
  128. }) {
  129. http('/addons/ddrive/user/userInfo', "POST").then(data => {
  130. commit('getUserInfo', data)
  131. })
  132. }
  133. }
  134. })