1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- export const state = () => ({
- token: "",
- // email: "",
- userInfo: {},
- dialogVisible: false,
- compareList:[],
- jumpList:'contact'
- });
- export const mutations = {
- setToken(state, token) {
- state.token = token;
- if (this.$cookies.get('can-use-cookie')) this.$cookies.set("token", token, { maxAge: 2592000, path: '/' });
- },
- getToken(state) {
- if (this.$cookies.get('can-use-cookie')) state.token = this.$cookies.get("token");
- },
- setUserInfo(state, data) {
- state.userInfo = data;
- // state.email = data.email;
- if (this.$cookies.get('can-use-cookie')) this.$cookies.set("user-info", data, { maxAge: 2592000, path: '/' });
- },
- clearUserInfo(state) {
- state.userInfo = {};
- // state.email = "";
- state.token = "";
- this.$cookies.remove("token");
- this.$cookies.remove("user-info");
- },
- openDialog(state) {
- state.dialogVisible = true;
- },
- closeDialog(state) {
- state.dialogVisible = false;
- },
- setCompareList(state,data) {
- state.compareList = data;
- },
- clearCompareList(state) {
- state.compareList = [];
- },
- };
- export const actions = {
- login({ commit, dispatch }, data) {
- return new Promise((resolve, reject) => {
- if (data) {
- this.$axios({
- url: "/au/login",
- method: "POST",
- data,
- }).then((res) => {
- commit("setToken", res.result.token);
- dispatch("getUserInfo");
- resolve(res);
- });
- }
- }).catch(() => {
- // reject(error);
- });
- },
- getUserInfo({ commit, dispatch }) {
- return new Promise((resolve, reject) => {
- this.$axios({
- url: "au/member/detail",
- method: "GET",
- }).then((res) => {
- commit("setUserInfo", res.result);
- resolve(res);
-
- if(location.pathname.indexOf('contact')>-1){
- location.href = location.origin
- }
- });
- }).catch(() => {
- // reject(error);
- });
- },
- getCompareList({ commit, dispatch }) {
- return new Promise((resolve, reject) => {
- this.$axios
- .post("home/compare_list", { compare_keys: "keys" })
- .then((res) => {
- commit("setCompareList", res.result);
- resolve(res);
- });
- }).catch(() => {
- // reject(error);
- });
- },
- logout({ commit, dispatch }) {
- return new Promise((resolve, reject) => {
- //未有退出登录接口
- commit("clearUserInfo");
- resolve();
- }).catch(() => {
- // reject(error);
- });
- },
- };
|