index.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. export const state = () => ({
  2. token: '',
  3. // email: "",
  4. userInfo: {},
  5. dialogVisible: false,
  6. compareList: [],
  7. jumpList: 'contact',
  8. shopInfo: {},
  9. })
  10. export const mutations = {
  11. setToken(state, token) {
  12. state.token = token
  13. this.$cookies.set('shop-token', token, { maxAge: 2592000, path: '/' })
  14. },
  15. getToken(state) {
  16. state.token = this.$cookies.get('shop-token')
  17. },
  18. setUserInfo(state, data) {
  19. state.userInfo = data
  20. // state.email = data.email;
  21. this.$cookies.set('shop-user-info', data, { maxAge: 2592000, path: '/' })
  22. },
  23. clearUserInfo(state) {
  24. state.userInfo = {}
  25. // state.email = "";
  26. state.token = ''
  27. this.$cookies.remove('shop-token')
  28. this.$cookies.remove('shop-user-info')
  29. },
  30. openDialog(state) {
  31. state.dialogVisible = true
  32. },
  33. closeDialog(state) {
  34. state.dialogVisible = false
  35. },
  36. setCompareList(state, data) {
  37. state.compareList = data
  38. },
  39. clearCompareList(state) {
  40. state.compareList = []
  41. },
  42. setShopInfo(state, data) {
  43. state.shopInfo = data
  44. },
  45. }
  46. export const actions = {
  47. getShopInfo(ctx, data) {
  48. return new Promise((resolve, reject) => {
  49. if (ctx.state.shopInfo && !ctx.state.shopInfo.id) {
  50. this.$axios
  51. .post(
  52. `/c-api/logo/info/${
  53. !/promocatalogue/.test(location.hostname)
  54. ? 'kkburwoodvicl.promocatalogue.com.au'
  55. : encodeURIComponent(location.hostname)
  56. }`
  57. )
  58. .then(res => {
  59. ctx.commit('setShopInfo', res.result)
  60. resolve(res.result)
  61. })
  62. .catch(e => {
  63. console.log(e)
  64. reject(e)
  65. })
  66. } else {
  67. resolve(ctx.state.shopInfo)
  68. }
  69. })
  70. },
  71. login({ commit, dispatch }, data) {
  72. return new Promise((resolve, reject) => {
  73. if (data) {
  74. this.$axios({
  75. url: '/au/login',
  76. method: 'POST',
  77. data,
  78. }).then(res => {
  79. commit('setToken', res.result.token)
  80. dispatch('getUserInfo')
  81. resolve(res)
  82. })
  83. }
  84. }).catch(() => {
  85. // reject(error);
  86. })
  87. },
  88. getUserInfo({ commit, dispatch }) {
  89. return new Promise((resolve, reject) => {
  90. this.$axios({
  91. url: 'au/member/detail',
  92. method: 'GET',
  93. }).then(res => {
  94. commit('setUserInfo', res.result)
  95. resolve(res)
  96. if (location.pathname.includes('contact')) {
  97. location.href = location.origin
  98. }
  99. })
  100. }).catch(() => {
  101. // reject(error);
  102. })
  103. },
  104. getCompareList({ commit, dispatch }) {
  105. return new Promise((resolve, reject) => {
  106. this.$axios
  107. .post('home/compare_list', { compare_keys: 'keys' })
  108. .then(res => {
  109. commit('setCompareList', res.result)
  110. resolve(res)
  111. })
  112. }).catch(() => {
  113. // reject(error);
  114. })
  115. },
  116. logout({ commit, dispatch }) {
  117. return new Promise((resolve, reject) => {
  118. // 未有退出登录接口
  119. commit('clearUserInfo')
  120. resolve()
  121. }).catch(() => {
  122. // reject(error);
  123. })
  124. },
  125. }