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

fix: 问题修复

parent 734125c5
const TXT_SIZE = 17;
const TXT_MIN_SIZE = 12;
export default {
inserted(el) {
let txtSize = TXT_SIZE;
console.dir(el.clientWidth);
const containerWidth = el.offsetWidth;
const txtLength = el.innerText.length * TXT_SIZE;
const overTxtWidth = txtLength - containerWidth;
if (overTxtWidth > 0) {
const overSize = Math.ceil(overTxtWidth / TXT_SIZE);
txtSize = txtSize - overSize;
}
txtSize = txtSize < TXT_MIN_SIZE ? TXT_MIN_SIZE : txtSize;
el.style.fontSize = txtSize + 'px';
}
};
...@@ -11,6 +11,7 @@ import Bridge from '@qg/js-bridge'; ...@@ -11,6 +11,7 @@ import Bridge from '@qg/js-bridge';
import Raven from 'raven-js'; import Raven from 'raven-js';
import RavenVue from 'raven-js/plugins/vue'; import RavenVue from 'raven-js/plugins/vue';
import { release } from '../.sentryclirc'; import { release } from '../.sentryclirc';
import fontResize from './directives/fontResize';
if (process.env.SENTRY_ENV !== 'test' && process.env.NODE_ENV === 'production') { if (process.env.SENTRY_ENV !== 'test' && process.env.NODE_ENV === 'production') {
Raven.config('//21779c2dcb594299bdc803c5560cfecd@sentry.q-gp.com/60', { Raven.config('//21779c2dcb594299bdc803c5560cfecd@sentry.q-gp.com/60', {
release, release,
...@@ -24,6 +25,7 @@ window.Bridge = Bridge; ...@@ -24,6 +25,7 @@ window.Bridge = Bridge;
saService.init(router); saService.init(router);
Vue.directive('fontResize', fontResize);
Vue.config.productionTip = false; Vue.config.productionTip = false;
window.addEventListener( window.addEventListener(
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
}" }"
@click="item.hasStock && parent.handleSkuSelected(item, index)" @click="item.hasStock && parent.handleSkuSelected(item, index)"
> >
<div class="Vl__sku-name"> <div v-font-resize class="Vl__sku-name">
{{ props.threeCol ? item.salePrice : item.skuName }}{{ props.showUnit ? '' : '' }} {{ props.threeCol ? item.salePrice : item.skuName }}{{ props.showUnit ? '' : '' }}
</div> </div>
<div class="Vl__sku-price">售价{{ item.price }}</div> <div class="Vl__sku-price">售价{{ item.price }}</div>
......
...@@ -23,7 +23,8 @@ ...@@ -23,7 +23,8 @@
</template> </template>
<script> <script>
import BScroll from '@better-scroll/core'; import BScroll from '@better-scroll/core';
const SCROLL_ITEM_WIDTH = 108; import { SCROLL_ITEM_WIDTH } from './constant';
const EVENT_SCROLL = 'scroll';
export default { export default {
name: 'SpuList', name: 'SpuList',
props: { props: {
...@@ -88,12 +89,25 @@ export default { ...@@ -88,12 +89,25 @@ export default {
click: true, click: true,
scrollX: true, scrollX: true,
scrollY: false, scrollY: false,
probeType: 1 probeType: 2
}); });
this.listWrapper.on('scroll', this.handleScroll); this.listWrapper.on('scroll', this.handleScroll);
}, },
handleScroll(e) { handleScroll(e) {
console.log(e); const currentX = Math.abs(e.x);
for (let i = 0; i < this.list.length; i++) {
const curItem = this.list[i];
let nextItemX = 0;
if (this.list[i + 1]) {
nextItemX = this.list[i + 1].posX;
} else {
nextItemX = this.contentWidth;
}
if (nextItemX >= currentX && curItem.posX <= currentX) {
this.$emit(EVENT_SCROLL, curItem, e.x);
break;
}
}
}, },
numAddUnit(num) { numAddUnit(num) {
return num / 37.5 + 'rem'; return num / 37.5 + 'rem';
......
export const SCROLL_ITEM_WIDTH = 108;
export const ITEM_WIDTH = 97;
@bottom-height: 60px; @bottom-height: 60px;
.Vl { @{deep} .Vl {
&__panel { &__panel {
background-color: @white; background-color: @white;
border-radius: @border-radius-lx @border-radius-lx 0 0; border-radius: @border-radius-lx @border-radius-lx 0 0;
......
<template> <template>
<div class="page page__nopad"> <div class="page page__nopad">
<cr-tabs v-model="currentTab" @change="handleTabChange"> <cr-tabs v-model="currentTab" @click="handleTabChange">
<cr-tab v-for="(item, index) in spuData" :key="index" :title="item.name" :name="+item.type" /> <cr-tab v-for="(item, index) in spuData" :key="index" :title="item.name" :name="+item.type" />
</cr-tabs> </cr-tabs>
<spu-list ref="spuList" :list="spuList" :info="spuInfo" /> <spu-list ref="spuList" :list="spuList" :info="spuInfo" @scroll="handleSpuScroll" />
<div class="Vl__panel"> <div class="Vl__panel">
<template> <template>
<account-input v-if="spuInfo.rechargeAccountType !== 2" v-model="account" :info="spuInfo" /> <account-input v-if="spuInfo.rechargeAccountType !== 2" v-model="account" :info="spuInfo" />
...@@ -40,6 +40,7 @@ import SpuList from './components/SpuList.vue'; ...@@ -40,6 +40,7 @@ import SpuList from './components/SpuList.vue';
import SkuList from './components/SkuList.vue'; import SkuList from './components/SkuList.vue';
import AccountInput from './components/AccountInput.vue'; import AccountInput from './components/AccountInput.vue';
import { throttle } from '@/service/utils.service'; import { throttle } from '@/service/utils.service';
import { ITEM_WIDTH } from './components/constant';
export default { export default {
name: 'VipLife', name: 'VipLife',
components: { components: {
...@@ -66,10 +67,13 @@ export default { ...@@ -66,10 +67,13 @@ export default {
}, },
spuList() { spuList() {
let spuList = []; let spuList = [];
let spuNum = 0;
this.spuData.forEach((item, index) => { this.spuData.forEach((item, index) => {
item.itemList.forEach(it => { item.itemList.forEach(it => {
it.parentIndex = index; it.parentIndex = index;
it.posX = spuNum * ITEM_WIDTH;
spuList.push(it); spuList.push(it);
spuNum++;
}); });
}); });
return spuList; return spuList;
...@@ -99,6 +103,9 @@ export default { ...@@ -99,6 +103,9 @@ export default {
this.updateSpuInfo(this.spuData[this.currentTab - 1].itemList[0]); this.updateSpuInfo(this.spuData[this.currentTab - 1].itemList[0]);
this.getSkuListDebounce(); this.getSkuListDebounce();
}, },
handleSpuScroll(item) {
this.currentTab = item.parentIndex + 1;
},
handleSpuSelected(item) { handleSpuSelected(item) {
this.updateSpuInfo(item); this.updateSpuInfo(item);
this.getSkuListDebounce(); this.getSkuListDebounce();
...@@ -132,10 +139,10 @@ export default { ...@@ -132,10 +139,10 @@ export default {
const [res] = await rechargeApi.getSkuList(spuNos, type); const [res] = await rechargeApi.getSkuList(spuNos, type);
if (res) { if (res) {
this.skuList = res.rechargeList; this.skuList = res.rechargeList;
// const defaultItem = res.rechargeList.find(item => item.hasStock); const defaultItem = res.rechargeList.find(item => item.hasStock);
// const defaultIndex = res.rechargeList.findIndex(item => item.hasStock); const defaultIndex = res.rechargeList.findIndex(item => item.hasStock);
const defaultItem = res.rechargeList[0]; // const defaultItem = res.rechargeList[0];
const defaultIndex = 0; // const defaultIndex = 0;
defaultItem && this.handleSkuSelected(defaultItem, defaultIndex); defaultItem && this.handleSkuSelected(defaultItem, defaultIndex);
} }
this.showLoading = false; this.showLoading = false;
......
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