123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146 |
- import http from '@/shopro/request/index'
- import share from '@/shopro/share';
- const state = {
- shop: {},
- wechat: {},
- share: {},
- payment: {},
- addons: [],
- chat: uni.getStorageSync("chat") || {},
- store: {},
- tabbarData: [],
- recharge: uni.getStorageSync("recharge") || {},
- homeTemplate: [],
- userTemplate: [],
- floatData: {},
- popupData: {},
- hasTemplate: true,
- shareInfo: {}
- }
- const getters = {
- initShop: state => state.shop,
- initStore: state => state.store,
- initShare: state => state.share,
- initPayment: state => state.payment,
- initAddons: state => state.addons,
- initChat: state => state.chat,
- initWechat: state => state.wechat,
- initRecharge: state => state.recharge,
- hasTemplate: state => state.hasTemplate,
- homeTemplate: state => state.homeTemplate,
- userTemplate: state => state.userTemplate,
- floatData: state => state.floatData,
- popupData: state => state.popupData,
- tabbarData: state => state.tabbarData,
- shareInfo: state => state.shareInfo
- }
- const actions = {
-
- async appInit({
- commit,
- dispatch
- }, options) {
- const result = await http('common.init');
- if (result.code === 1) {
- commit('CONFIG', result.data);
- if (!options?.query?.token) {
- dispatch('autoLogin');
- }
- return result.data;
- }
- return false;
- },
-
- async getTemplate({
- commit
- }, options) {
- let shop_id = 0;
-
- if (options?.query.shop_id) {
- shop_id = options.query.shop_id;
- }
-
-
- if (options?.query.scene) {
- let scene = decodeURIComponent(options?.query.scene);
- let sceneObj = scene.split('=');
- if (sceneObj[0] === 'shop_id') {
- shop_id = sceneObj[1]
- }
- }
-
- const result = await http('common.template', shop_id ? {
- shop_id
- } : {});
- if (result.code === 1) {
- commit("hasTemplate", true);
- commit('TEMPLATE', result.data);
- return result.data;
- } else {
- commit("hasTemplate", false);
- return false;
- }
- },
-
- syncPages({
- commit
- }) {
- http('common.syncPages', {
- data: ROUTES,
- })
- },
- }
- const mutations = {
- CONFIG(state, payload) {
- Object.keys(payload).forEach(k => {
- state[k] = payload[k];
- if (k === 'chat') {
- uni.setStorageSync("chat", payload[k]);
- }
- if (k === 'recharge') {
- uni.setStorageSync("recharge", payload[k])
- }
- })
- },
- TEMPLATE(state, data) {
- state.template = data;
- state.homeTemplate = data.home
- state.userTemplate = data.user
- state.floatData = data['float-button']?. [0]?.content
- state.popupData = {}
- state.tabbarData = data?.tabbar?. [0]?.content
- },
- hasTemplate(state, data) {
- state.hasTemplate = data
- },
-
- delPopup(state, index) {
- let popupData = state.popupData;
- popupData.list.splice(index, 1)
- state.template = popupData;
- },
- shareInfo(state, shareInfo) {
- state.shareInfo = shareInfo;
- }
- }
- export default {
- state,
- mutations,
- actions,
- getters
- }
|