index.js 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. export const state = () => ({
  2. token: "",
  3. // email: "",
  4. userInfo: {},
  5. dialogVisible: false,
  6. compareList:[],
  7. jumpList:'contact'
  8. });
  9. export const mutations = {
  10. setToken(state, token) {
  11. state.token = token;
  12. if (this.$cookies.get('can-use-cookie')) this.$cookies.set("token", token, { maxAge: 2592000, path: '/' });
  13. },
  14. getToken(state) {
  15. if (this.$cookies.get('can-use-cookie')) state.token = this.$cookies.get("token");
  16. },
  17. setUserInfo(state, data) {
  18. state.userInfo = data;
  19. // state.email = data.email;
  20. if (this.$cookies.get('can-use-cookie')) this.$cookies.set("user-info", data, { maxAge: 2592000, path: '/' });
  21. },
  22. clearUserInfo(state) {
  23. state.userInfo = {};
  24. // state.email = "";
  25. state.token = "";
  26. this.$cookies.remove("token");
  27. this.$cookies.remove("user-info");
  28. },
  29. openDialog(state) {
  30. state.dialogVisible = true;
  31. },
  32. closeDialog(state) {
  33. state.dialogVisible = false;
  34. },
  35. setCompareList(state,data) {
  36. state.compareList = data;
  37. },
  38. clearCompareList(state) {
  39. state.compareList = [];
  40. },
  41. };
  42. export const actions = {
  43. login({ commit, dispatch }, data) {
  44. return new Promise((resolve, reject) => {
  45. if (data) {
  46. this.$axios({
  47. url: "/au/login",
  48. method: "POST",
  49. data,
  50. }).then((res) => {
  51. commit("setToken", res.result.token);
  52. dispatch("getUserInfo");
  53. resolve(res);
  54. });
  55. }
  56. }).catch(() => {
  57. // reject(error);
  58. });
  59. },
  60. getUserInfo({ commit, dispatch }) {
  61. return new Promise((resolve, reject) => {
  62. this.$axios({
  63. url: "au/member/detail",
  64. method: "GET",
  65. }).then((res) => {
  66. commit("setUserInfo", res.result);
  67. resolve(res);
  68. if(location.pathname.indexOf('contact')>-1){
  69. location.href = location.origin
  70. }
  71. });
  72. }).catch(() => {
  73. // reject(error);
  74. });
  75. },
  76. getCompareList({ commit, dispatch }) {
  77. return new Promise((resolve, reject) => {
  78. this.$axios
  79. .post("home/compare_list", { compare_keys: "keys" })
  80. .then((res) => {
  81. commit("setCompareList", res.result);
  82. resolve(res);
  83. });
  84. }).catch(() => {
  85. // reject(error);
  86. });
  87. },
  88. logout({ commit, dispatch }) {
  89. return new Promise((resolve, reject) => {
  90. //未有退出登录接口
  91. commit("clearUserInfo");
  92. resolve();
  93. }).catch(() => {
  94. // reject(error);
  95. });
  96. },
  97. };