Skip to content
This repository has been archived by the owner on Jun 3, 2021. It is now read-only.

Commit

Permalink
[+] support for full-page
Browse files Browse the repository at this point in the history
  • Loading branch information
tw93 committed Apr 10, 2018
1 parent bb8d741 commit 85ac86a
Show file tree
Hide file tree
Showing 8 changed files with 201 additions and 32 deletions.
40 changes: 40 additions & 0 deletions example/tab-page/full-page-demo/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/**
* Created by 侑夕 on 2016/11/4.
*/
module.exports = {
tabTitles: [
{
title: '热门跟团'
},
{
title: '云南跟团'
},
{
title: '四川跟团'
},
{
title: '海南跟团'
},
{
title: '北京跟团'
},
{
title: '出境跟团'
}
],
tabStyles: {
titleColor: '#BBBBBB',
activeTitleColor: '#FDFDFD',
isActiveTitleBold: true,
width: 160,
height: 60,
top: 50,
fontSize: 28,
hasActiveBottom: false,
activeBottomColor: '#FFC900',
activeBottomHeight: 6,
activeBottomWidth: 120,
textPaddingLeft: 10,
textPaddingRight: 10
}
}
118 changes: 118 additions & 0 deletions example/tab-page/full-page-demo/index.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
<template>
<WxcFullPage ref="wxc-tab-page"
:tab-titles="tabTitles"
:tab-styles="tabStyles"
title-type="text"
:tab-page-height="tabPageHeight"
v-on:wxcTabPageCurrentTabSelected="wxcTabPageCurrentTabSelected">
<div class="page-content"
:style="{ height: (tabPageHeight) + 'px' }"
v-for="(v,index) in tabList"
:key="index">
<div class="content-top" :style="{backgroundColor:bgColors[index]}"></div>
<list class="item-container"
:style="{ height: (tabPageHeight-160) + 'px' }">
<cell v-for="(num,key) in v"
class="cell"
:key="key">
<wxc-pan-item url="https://h5.m.taobao.com/trip/ticket/detail/index.html?scenicId=2675"
@wxcPanItemPan="wxcPanItemPan">
<wxc-item image="https://gw.alicdn.com/i1/2935198750/TB26GMgeOC9MuFjSZFoXXbUzFXa_!!2935198750.jpg"
:image-text="tabTitles[index].title"
title="卡片测试|四川成都出发到九寨沟牟尼沟 温泉3天2晚纯玩跟团旅游"
:desc="desc"
:tags="tags"
price="666"
price-desc="月售58笔|999+条评论"/>
</wxc-pan-item>
</cell>
</list>
</div>
</WxcFullPage>
</template>

<style scoped>
.item-container {
width: 750px;
align-items: center;
justify-content: center;
height: 1334px;
background-color: #f2f3f4;
}
.cell {
background-color: #ffffff;
}
.content-top {
width: 750px;
height: 160px;
background-color: #FFB706;
}
.page-content {
width: 750px;
}
</style>
<script>
const dom = weex.requireModule('dom');
import { WxcFullPage, Utils,WxcPanItem, BindEnv } from '../../../index';
import WxcItem from '../wxc-item.vue';
const config = require('./config');
import { setTitle } from '../../_mods/set-nav';
module.exports = {
components: { WxcFullPage,WxcPanItem, WxcItem },
data: () => ({
tabTitles: config.tabTitles,
tabStyles: config.tabStyles,
tabList: [],
bgColors:['#263238','#635147','#FF7703','#9B7B56','#3B4950','#635147'],
demoList: [1, 2, 3, 4, 5, 6, 7, 8, 9],
tabPageHeight: 1334,
ref: 'viewport',
desc: [{
type: 'text',
value: '特价机票|班期:清明 3/27-4/2等',
theme: 'gray'
}],
tags: [{
type: 'tag',
value: '满100减20测试',
theme: 'yellow'
}]
}),
created () {
setTitle('TabPage')
this.tabPageHeight = Utils.env.getPageHeight();
this.tabList = [...Array(this.tabTitles.length).keys()].map(i => []);
Vue.set(this.tabList, 0, this.demoList);
},
mounted () {
// 适配plus高度问题
dom.getComponentRect && dom.getComponentRect(this.ref, option => {
if (option && option.result && option.size && option.size.height) {
this.tabPageHeight = option.size.height;
}
});
},
methods: {
wxcTabPageCurrentTabSelected (e) {
const self = this;
const index = e.page;
/* 未加载tab模拟数据请求 */
if (!Utils.isNonEmptyArray(self.tabList[index])) {
setTimeout(() => {
Vue.set(self.tabList, index, self.demoList);
}, 100);
}
},
wxcItemGoodPan (e) {
if (BindEnv.supportsEBForAndroid()) {
this.$refs['wxc-tab-page'].bindExp(e.element);
}
}
}
};
</script>
4 changes: 2 additions & 2 deletions example/tab-page/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import entry from './index.vue'
// import entry from './full-page-demo/index.vue'
// import entry from './index.vue'
import entry from './full-page-demo/index.vue'
entry.el = '#root'
export default new Vue(entry)
2 changes: 2 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import WxcSlideNav from './packages/wxc-slide-nav';
import WxcSliderBar from './packages/wxc-slider-bar';
import WxcStepper from './packages/wxc-stepper';
import WxcTabPage from './packages/wxc-tab-page';
import WxcFullPage from './packages/wxc-full-page';
import WxcTabBar from './packages/wxc-tab-bar';
import WxcTag from './packages/wxc-tag';

Expand Down Expand Up @@ -81,6 +82,7 @@ export {
WxcSliderBar,
WxcStepper,
WxcTabPage,
WxcFullPage,
WxcTabBar,
WxcTag
};
3 changes: 1 addition & 2 deletions packages/bind-env/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// hack for babel-plugin-component

import bindEnv from '../utils/bind-env';
export default bindEnv;
export { default } from '../utils/bind-env';
3 changes: 3 additions & 0 deletions packages/wxc-full-page/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// hack for babel-plugin-component

export { default } from '../wxc-tab-page/full-page.vue';
61 changes: 34 additions & 27 deletions packages/wxc-tab-page/full-page.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<!-- CopyRight (C) 2017-2022 Alibaba Group Holding Limited. -->
<!-- Created by Tw93 on 17/07/28. -->
<!-- Updated by Tw93 on 18/04/10. -->

<template>
<div class="wxc-tab-page"
Expand All @@ -25,7 +26,6 @@
:key="index"
:ref="'wxc-tab-title-'+index"
@click="setPage(index,v.url)"
:data-spm-click="`gostr=/tbtrip;locaid=d${v.dataSpm!==undefined ? v.dataSpm : '996' + index}`"
:style="{ width: tabStyles.width +'px', height: tabStyles.height +'px', backgroundColor: currentPage == index ? tabStyles.activeBgColor : tabStyles.bgColor }"
:accessible="true"
:aria-label="`${v.title?v.title:'标签'+index}`">
Expand Down Expand Up @@ -95,8 +95,8 @@

import Utils from '../utils';
import BindEnv from '../utils/bind-env';
import Binding from 'weex-bindingx/lib/index.weex.js';

const supportsEBForIos = BindEnv.supportsEBForIos();
const isIos = Utils.env.isIOS();

export default {
Expand Down Expand Up @@ -157,11 +157,12 @@
if (swipeBack && swipeBack.forbidSwipeBack) {
swipeBack.forbidSwipeBack(true);
}
if (supportsEBForIos && this.needSlider) {
setTimeout(() => {
const tabPageEl = this.$refs['tab-page-wrap'];
tabPageEl && tabPageEl.ref && this.bindExp(tabPageEl);
}, 20);
if (BindEnv.supportsEBForIos() && this.needSlider) {
const tabPageEl = this.$refs['tab-page-wrap'];
Binding.prepare && Binding.prepare({
anchor: tabPageEl.ref,
eventType: 'pan'
});
}
},
methods: {
Expand All @@ -180,26 +181,39 @@
this.setPage(page);
},
startHandler (e) {
if (supportsEBForIos && e.state === 'start' && this.needSlider) {
// list下拉和到最下面问题修复
setTimeout(() => {
this.bindExp(this.$refs['tab-page-wrap']);
}, 0)
if (BindEnv.supportsEBForIos() && this.isTabView && this.needSlider) {
this.bindExp(this.$refs['tab-page-wrap']);
}
},
bindExp (element) {
if (!this.isMoving && element && element.ref) {
if (element && element.ref) {

if (this.isMoving && this.gesToken !== 0) {
Binding.unbind({
eventType: 'pan',
token: this.gesToken
})
this.gesToken = 0;
return;
}

const tabElement = this.$refs['tab-container'];
const { currentPage, panDist, tabTitles } = this;
const { currentPage, panDist } = this;
const dist = currentPage * 750;

// x-dist
const args = [{

const props = [{
element: tabElement.ref,
property: 'transform.translateX',
expression: `{\"type\":\"CallExpression\",\"children\":[{\"type\":\"Identifier\",\"value\":\"min\"},{\"type\":\"Arguments\",\"children\":[{\"type\":\"NumericLiteral\",\"value\":0},{\"type\":\"CallExpression\",\"children\":[{\"type\":\"Identifier\",\"value\":\"max\"},{\"type\":\"Arguments\",\"children\":[{\"type\":\"NumericLiteral\",\"value\":${-(tabTitles.length - 1) * 750}},{\"type\":\"-\",\"children\":[{\"type\":\"Identifier\",\"value\":\"x\"},{\"type\":\"NumericLiteral\",\"value\":${dist}}]}]}]}]}]}`
expression: `{\"type\":\"CallExpression\",\"children\":[{\"type\":\"Identifier\",\"value\":\"min\"},{\"type\":\"Arguments\",\"children\":[{\"type\":\"NumericLiteral\",\"value\":0},{\"type\":\"CallExpression\",\"children\":[{\"type\":\"Identifier\",\"value\":\"max\"},{\"type\":\"Arguments\",\"children\":[{\"type\":\"NumericLiteral\",\"value\":${-(tabTitles.length - 1) * 750}},{\"type\":\"-\",\"children\":[{\"type\":\"Identifier\",\"value\":\"x\"},{\"type\":\"NumericLiteral\",\"value\":${dist}}]}]}]}]}]}`
}];
expressionBinding.enableBinding(element.ref, 'pan');
expressionBinding.createBinding(element.ref, 'pan', '', args, e => {

const gesTokenObj = Binding.bind({
anchor: element.ref,
eventType: 'pan',
props
}, (e) => {
const { deltaX, state } = e;
if (state === 'end') {
if (deltaX < -panDist) {
Expand All @@ -211,6 +225,7 @@
}
}
});
this.gesToken = gesTokenObj.token;
}
},
setPage (page) {
Expand All @@ -233,15 +248,7 @@
page <= 1 && previousPage > page && dom.scrollToElement(currentTabEl, {
offset: -width * page
});

if (isIos) {
// 高版本ios 手淘上面会有不固定情况,hack一下
setTimeout(() => {
this._animateTransformX(page);
}, 10);
} else {
this._animateTransformX(page);
}
this._animateTransformX(page);
this.isMoving = false;
this.currentPage = page;
this.$emit('wxcTabPageCurrentTabSelected', { page });
Expand Down
2 changes: 1 addition & 1 deletion webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const getEntry = dir => {
};

const getCopyConfig = () => {
const foundScripts = glob.sync('example/slider-bar/', {});
const foundScripts = glob.sync('example/tab-page/', {});
const ret = [];
foundScripts.forEach(scriptPath => {
if (!/(_mods|_public)/.test(scriptPath)) {
Expand Down

0 comments on commit 85ac86a

Please sign in to comment.