index.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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/${encodeURIComponent(
  53. location.hostname
  54. // 'kkburwoodvicg.promocatalogue.com.au'
  55. )}`
  56. )
  57. .then(res => {
  58. ctx.commit('setShopInfo', res.result)
  59. resolve(res.result)
  60. })
  61. .catch(e => {
  62. console.log(e)
  63. reject(e)
  64. })
  65. } else {
  66. resolve(ctx.state.shopInfo)
  67. }
  68. })
  69. },
  70. login({ commit, dispatch }, data) {
  71. return new Promise((resolve, reject) => {
  72. if (data) {
  73. this.$axios({
  74. url: '/au/login',
  75. method: 'POST',
  76. data,
  77. }).then(res => {
  78. commit('setToken', res.result.token)
  79. dispatch('getUserInfo')
  80. resolve(res)
  81. })
  82. }
  83. }).catch(() => {
  84. // reject(error);
  85. })
  86. },
  87. getUserInfo({ commit, dispatch }) {
  88. return new Promise((resolve, reject) => {
  89. this.$axios({
  90. url: 'au/member/detail',
  91. method: 'GET',
  92. }).then(res => {
  93. commit('setUserInfo', res.result)
  94. resolve(res)
  95. if (location.pathname.includes('contact')) {
  96. location.href = location.origin
  97. }
  98. })
  99. }).catch(() => {
  100. // reject(error);
  101. })
  102. },
  103. getCompareList({ commit, dispatch }) {
  104. return new Promise((resolve, reject) => {
  105. this.$axios
  106. .post('home/compare_list', { compare_keys: 'keys' })
  107. .then(res => {
  108. commit('setCompareList', res.result)
  109. resolve(res)
  110. })
  111. }).catch(() => {
  112. // reject(error);
  113. })
  114. },
  115. logout({ commit, dispatch }) {
  116. return new Promise((resolve, reject) => {
  117. // 未有退出登录接口
  118. commit('clearUserInfo')
  119. resolve()
  120. }).catch(() => {
  121. // reject(error);
  122. })
  123. },
  124. }