Commit a1c4515b authored by 郭志伟's avatar 郭志伟

feat(index.ts): 购物车功能实现

parent 60b60416
...@@ -4,5 +4,8 @@ import config from '../config'; ...@@ -4,5 +4,8 @@ import config from '../config';
export default { export default {
getPageById(params) { getPageById(params) {
return http.get(`${config.apiHost}/editor/get/${params.pageId}`); return http.get(`${config.apiHost}/editor/get/${params.pageId}`);
},
getShopCartCount() {
return http.get(`${config.kdspApi}/api/kdsp/shop-cart/count`);
} }
}; };
\ No newline at end of file
...@@ -3,6 +3,7 @@ const protocol = EASY_ENV_IS_BROWSER ? window.location.protocol : 'https'; ...@@ -3,6 +3,7 @@ const protocol = EASY_ENV_IS_BROWSER ? window.location.protocol : 'https';
const hostMap = { const hostMap = {
apiHost: `${protocol}//quantum-blocks-vcc2.liangkebang.net`, apiHost: `${protocol}//quantum-blocks-vcc2.liangkebang.net`,
kdspApi: `${protocol}//talos-vcc2.liangkebang.net`,
shenceUrl: `${protocol}//bn.xyqb.com/sa?project=default`, shenceUrl: `${protocol}//bn.xyqb.com/sa?project=default`,
test: true test: true
}; };
......
...@@ -2,6 +2,7 @@ const protocol = EASY_ENV_IS_BROWSER ? window.location.protocol : 'https'; ...@@ -2,6 +2,7 @@ const protocol = EASY_ENV_IS_BROWSER ? window.location.protocol : 'https';
export default { export default {
apiHost: `https://quantum-blocks.q-gp.com`, apiHost: `https://quantum-blocks.q-gp.com`,
kdspApi: `${protocol}//talos.xyqb.com`,
shenceUrl: `${protocol}//bn.xyqb.com/sa?project=production`, shenceUrl: `${protocol}//bn.xyqb.com/sa?project=production`,
// opapiHost: `${protocol}//opapi.q-gp.com`, // opapiHost: `${protocol}//opapi.q-gp.com`,
test: false test: false
......
...@@ -3,6 +3,7 @@ const protocol = EASY_ENV_IS_BROWSER ? window.location.protocol : 'https'; ...@@ -3,6 +3,7 @@ const protocol = EASY_ENV_IS_BROWSER ? window.location.protocol : 'https';
const hostMap = { const hostMap = {
apiHost: `${protocol}//quantum-blocks-vcc2.liangkebang.net`, apiHost: `${protocol}//quantum-blocks-vcc2.liangkebang.net`,
kdspApi: `${protocol}//talos-vcc2.liangkebang.net`,
shenceUrl: `${protocol}//bn.xyqb.com/sa?project=default`, shenceUrl: `${protocol}//bn.xyqb.com/sa?project=default`,
test: true test: true
}; };
......
...@@ -23,7 +23,7 @@ export default class App { ...@@ -23,7 +23,7 @@ export default class App {
sync(store, router); sync(store, router);
if (EASY_ENV_IS_BROWSER) { if (EASY_ENV_IS_BROWSER) {
// const { initSa } = require('@/service/sa.service'); // const { initSa } = require('@/service/sa.service');
// initService.init(router); initService.init(router);
// initSa(router); // initSa(router);
} }
return { return {
......
<template> <template>
<div> <div>
<cr-back-top :show-back-top="showBackTop && pageData.props.showBackTop" :list="backTopList" @click="handleBackTopClick" /> <cr-back-top :show-back-top="showBackTop && pageData.props.showBackTop" :list="backTopList" @click="handleBackTopClick" ref="crBackTop" />
<cr-popover <cr-popover
class="wxmp-tip" class="wxmp-tip"
:value="showMpTip" :value="showMpTip"
...@@ -17,8 +17,10 @@ ...@@ -17,8 +17,10 @@
<script> <script>
import Bridge from '@qg/js-bridge'; import Bridge from '@qg/js-bridge';
import { mapGetters } from 'vuex'; import { mapGetters } from 'vuex';
import { isApp, isWxMp } from '@/service/utils.service'; import { isApp, isWxMp, debounce } from '@/service/utils.service';
import localStorage from '@/service/localStorage.service';
import { registeredEvents } from '@/service/sa.service'; import { registeredEvents } from '@/service/sa.service';
import api from '@/api/editor.api';
export default { export default {
name: 'BackTop', name: 'BackTop',
props: { props: {
...@@ -29,7 +31,9 @@ export default { ...@@ -29,7 +31,9 @@ export default {
...mapGetters(['pageInfo']), ...mapGetters(['pageInfo']),
backTopList() { backTopList() {
const btAttachVal = this.pageData && this.pageData.props.btAttachVal ? this.pageData.props.btAttachVal : []; const btAttachVal = this.pageData && this.pageData.props.btAttachVal ? this.pageData.props.btAttachVal : [];
if (this.cartIndex !== null && btAttachVal.length) {
btAttachVal[this.cartIndex - 1].info = this.cartCount;
}
return isApp ? btAttachVal : isWxMp ? btAttachVal.filter(item => item.persets !== '购物车') : []; return isApp ? btAttachVal : isWxMp ? btAttachVal.filter(item => item.persets !== '购物车') : [];
} }
}, },
...@@ -38,7 +42,10 @@ export default { ...@@ -38,7 +42,10 @@ export default {
showMpTip: false, showMpTip: false,
tipTimer: null, tipTimer: null,
jsBridge: null, jsBridge: null,
wx: null wx: null,
cartIndex: null,
cartCount: 0,
getCartCountDebounce: debounce(this.getCartCount, 2000)
}; };
}, },
created() { created() {
...@@ -47,6 +54,12 @@ export default { ...@@ -47,6 +54,12 @@ export default {
this.wx = require('weixin-js-sdk'); this.wx = require('weixin-js-sdk');
} }
}, },
watch: {
backTopList(val) {
this.cartIndex = (val || []).findIndex(item => item.persets === '购物车') + 1;
this.getCartCountDebounce();
}
},
methods: { methods: {
handleBackTopClick(e) { handleBackTopClick(e) {
registeredEvents('PD_WUXIEC_H5ActivityPageSuspendedBtnClick', { registeredEvents('PD_WUXIEC_H5ActivityPageSuspendedBtnClick', {
...@@ -94,6 +107,15 @@ export default { ...@@ -94,6 +107,15 @@ export default {
this.showMpTip = false; this.showMpTip = false;
}, 10000); }, 10000);
}, },
async getCartCount() {
if (localStorage.get('vccToken') && this.cartIndex && isApp) {
const [res] = await api.getShopCartCount();
this.cartCount = res.count;
this.$nextTick(() => {
this.$refs.crBackTop.$forceUpdate();
});
}
}
}, },
} }
</script> </script>
......
...@@ -82,7 +82,13 @@ export default class Activity extends Mixins(TransformStyleMixin, SaMixin) { ...@@ -82,7 +82,13 @@ export default class Activity extends Mixins(TransformStyleMixin, SaMixin) {
const { pageId } = route.params; const { pageId } = route.params;
return store.dispatch('getPageDate', { pageId }); return store.dispatch('getPageDate', { pageId });
} }
updateShopCartCount() {
if (EASY_ENV_IS_BROWSER) {
this.$nextTick(() => {
this.$refs.backTop.getCartCount();
});
}
}
modifyPoints() { modifyPoints() {
const clientWidth = document.documentElement.clientWidth > 768 ? 375 : document.documentElement.clientWidth; const clientWidth = document.documentElement.clientWidth > 768 ? 375 : document.documentElement.clientWidth;
const elements = this.pageData?.elements?.map(v => { const elements = this.pageData?.elements?.map(v => {
......
...@@ -40,7 +40,7 @@ ...@@ -40,7 +40,7 @@
<page-bottom-tip /> <page-bottom-tip />
</grid-item> </grid-item>
</grid-layout> </grid-layout>
<back-top :show-back-top="showBackTop" /> <back-top :show-back-top="showBackTop" ref="backTop" />
</div> </div>
</template> </template>
<script lang="ts" src="./index.ts"></script> <script lang="ts" src="./index.ts"></script>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment