index.js 3.0 KB

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