123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151 |
- import { getUserInfo } from "@/api/user.js";
- import { diyProductApi } from "@/api/store.js"
- import {
- LOGIN_STATUS,
- NON_WIFI_AUTOPLAY,
- UID,
- USER_INFO,
- STORE_NUM
- } from '@/config/cache';
- import Cache from '@/utils/cache';
- const state = {
- token: Cache.get(LOGIN_STATUS) || false,
- backgroundColor: "#fff",
- userInfo: Cache.get(USER_INFO) || {},
- uid: Cache.get(UID) || 0,
- homeActive: false,
- phoneStatus: true,
- pageFooter: uni.getStorageSync('pageFoot') || {},
- autoplay: Cache.get(NON_WIFI_AUTOPLAY) || false,
-
- diyProduct: {
- navList: [0, 1, 2, 3, 4],
- openShare: 1,
- pictureConfig: 0,
- swiperDot: 1,
- showPrice: [0, 1],
- isOpen: [0, 1, 2],
- showSvip: 1,
- showRank: 1,
- showService: [0, 1, 2, 3],
- showReply: 1,
- replyNum: 3,
- showMatch: 1,
- matchNum: 3,
- showRecommend: 1,
- recommendNum: 12,
- menuList: [0, 1, 2],
- showCart: 1
- },
-
- diyCategory: {
- level: 2,
- index: 0
- },
- productVideoStatus: true,
- nearbyStore: 0,
- storeNum: Cache.get(STORE_NUM) || 0 ,
- };
- const mutations = {
- SETPHONESTATUS(state, val) {
- state.phoneStatus = val;
- },
- LOGIN(state, opt) {
- state.token = opt.token;
- Cache.set(LOGIN_STATUS, opt.token, opt.time);
- },
- SETUID(state, val) {
- state.uid = val;
- Cache.set(UID, val);
- },
- UPDATE_LOGIN(state, token) {
- state.token = token;
- },
- LOGOUT(state) {
- Cache.clear(LOGIN_STATUS);
- Cache.clear(UID);
- Cache.clear(USER_INFO);
- Cache.clear('newcomerGift');
- state.token = undefined;
- state.uid = undefined
- state.userInfo = {}
- },
- BACKGROUND_COLOR(state, color) {
- state.color = color;
- document.body.style.backgroundColor = color;
- },
- UPDATE_USERINFO(state, userInfo) {
- state.userInfo = userInfo;
- Cache.set(USER_INFO, userInfo);
- },
- OPEN_HOME(state) {
- state.homeActive = true;
- },
- CLOSE_HOME(state) {
- state.homeActive = false;
- },
- FOOT_UPLOAD(state, data) {
- state.pageFooter = data
- },
- SET_AUTOPLAY(state, data) {
- state.autoplay = data
- Cache.set(NON_WIFI_AUTOPLAY, data)
- },
- SET_PRODUCT_DIY(state, data){
- state.diyProduct = data.product_detail;
- state.diyCategory = data.product_category;
- state.productVideoStatus = data.product_video_status;
- },
- SET_NEARBY(state,data){
- state.nearbyStore = data
- },
- SET_STORE(state,data){
- Cache.set(STORE_NUM, data);
- state.storeNum = data
- }
- };
- const actions = {
- USERINFO({
- state,
- commit
- }, force) {
- if (state.userInfo !== null && !force)
- return Promise.resolve(state.userInfo);
- else
- return new Promise(reslove => {
- getUserInfo().then(res => {
- commit("UPDATE_USERINFO", res.data);
- Cache.set(USER_INFO, res.data);
- reslove(res.data);
- });
- }).catch(() => {
- });
- },
-
- async getDiyProduct({commit}) {
- let result = await diyProductApi();
- if(result.status == 200){
- commit("SET_PRODUCT_DIY",result.data);
- }
- },
- };
- export default {
- state,
- mutations,
- actions
- };
|