Skip to content

Commit

Permalink
feat: 优化piui转场动画
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangzhenfei committed Sep 19, 2020
1 parent 226216d commit 447a076
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 224 deletions.
7 changes: 7 additions & 0 deletions components/pi-list/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ export default {
return list.title
}
},
// 列表面板描述
desc: {
type: String,
default() {
return list.desc
}
},
// 标题自定义样式,对象形式(默认值:{})
titleStyle: {
type: Object,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,41 +3,40 @@ uni-page {
opacity: 0;
}

uni-page.animation-show {
opacity: 1;
}

uni-page.animation-enter,
uni-page.animation-leave {
transition: all 0.3s ease-in-out;
}

/* 前进 */
uni-page.animation-forward {
/* 在页面上使用 transform 会导致页面内的 fixed 定位渲染为 absolute,需要在动画完成后移除 */
transform: translateX(-100px);
transform: translateX(-100%);
}

/* 返回 */
uni-page.animation-back {
transform: translateX(100px);
transform: translateX(100%);
}

uni-page.animation-leave {
transition: all 0.3s ease;
}

uni-page.animation-enter {
transition: all 0.3s ease;
}

uni-page.animation-show {
opacity: 1;
}

/* 前进 */
uni-page.animation-afterstart-forward {
transform: translateX(100px);
transform: translateX(100%);
}

/* 返回 */
uni-page.animation-afterstart-back {
transform: translateX(-100px);
transform: translateX(-100%);
}
uni-page.animation-after {
/* 在页面上使用 transform 会导致页面内的 fixed 定位渲染为 absolute,需要在动画完成后移除 */
transform: translateX(0);
transition: inherit;
transform: inherit;
}

/* #endif */
85 changes: 85 additions & 0 deletions mixin/page-transitions/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import './index.css'

export function create(setting) {
return {
// #ifdef H5
data() {
return {
pageBefore: '',
pageAfterStart: '',
isPageBack: false
}
},
onLaunch: function() {
// 监听浏览器返回按钮
window.addEventListener(
'popstate',
e => {
this.isPageBack = true
},
false
)
// 如果有页面自定义权重配置
setting && this.init()
// 页面默认是隐藏的,一开始先执行一次显示的逻辑
this.handlePageShow()
// 页面进入前
this.$router.beforeEach((toPage, fromPage, next) => {
let toDepth = toPage.path.split('/').filter(v => !!v).length
let fromDepth = fromPage.path.split('/').filter(v => !!v).length
let type = toDepth > fromDepth ? 'forward' : 'back'
// 如果配置tab的优先级,使用设置判断是前进还是后退
if (toPage.meta.pageIndex && fromPage.meta.pageIndex) {
type = toPage.meta.pageIndex >= fromPage.meta.pageIndex ? 'forward' : 'back'
}
this.pageBefore = `animation-${type}`
this.pageAfterStart = `animation-afterstart-${type}`
setTimeout(this.handlePageHide(next))
})
// 页面进入完毕
this.$router.afterEach(() => {
// 标记当前页面为返回模式
this.isPageBack = false
setTimeout(this.handlePageShow, 50)
})
},
methods: {
init() {
this.$router.options.routes.forEach(item => {
const indexSetting = setting[item.meta.pagePath]
item.meta.pageIndex = indexSetting
})
},
handlePageHide(callback) {
setTimeout(() => {
this.pageBefore = this.isPageBack ? 'animation-back' : this.pageBefore
this.pageAfterStart = this.isPageBack ? 'animation-afterstart-back' : this.pageAfterStart

const classList = document.querySelector('uni-page').classList
classList.add(this.pageBefore, 'animation-leave')
classList.remove('animation-show')
setTimeout(() => {
classList.remove(this.pageBefore, 'animation-leave')
callback && callback()
}, 300)
}, 20)
},
handlePageShow() {
const classList = document.querySelector('uni-page').classList
classList.add(this.pageAfterStart, 'animation-before')
setTimeout(() => {
classList.add('animation-enter', 'animation-after', 'animation-show')
setTimeout(() => {
classList.remove(
'animation-before',
'animation-after',
'animation-enter',
this.pageAfterStart
)
}, 300)
}, 20)
}
}
// #endif
}
}
80 changes: 0 additions & 80 deletions mixin/pi-page-transitions/index.vue

This file was deleted.

5 changes: 0 additions & 5 deletions mixin/pi-page-transitions/setting.js

This file was deleted.

123 changes: 0 additions & 123 deletions scss/common.scss
Original file line number Diff line number Diff line change
Expand Up @@ -509,129 +509,6 @@
@extend .pi-align-center;
}

/* 表单 form
---------------------- */
.pi-form {
display: block;
width: 100%;

.item {
@extend .pi-rela;
@extend .pi-flex-nowrap;
@extend .pi-justify-between;
@extend .pi-align-center;
@extend .pi-bg-white;

transition: all $pi-animation-duration ease-in-out;
// 表单label(如果需要固定宽度对齐,请使用pi-w 配合text-align)
.label {
flex-shrink: 0; // 默认不收缩
height: $pi-form-item-height;
font-size: $pi-form-font-size;
font-weight: $pi-form-font-weight;
line-height: $pi-form-item-height;
color: $pi-form-label-color;
}
&.required .label {
// 必选红点
position: relative;
padding-left: 24rpx;
&::after {
position: absolute;
top: 50%;
left: 0;
color: $pi-form-required-color;
content: '*';
transform: translateY(-50%);
}
}
.input {
flex: 1;
margin-left: 40rpx;
font-size: $pi-form-font-size;
color: $pi-form-input-color;
text-align: right;
background: none;
border: 0;
}

.other {
display: flex;
flex: 1;
align-items: center;
justify-content: flex-end;
margin-left: 40rpx;
overflow: hidden;
font-size: $pi-form-font-size;
.input {
margin-left: 0;
}
}
&.display-model {
// 显示模式
.pi-form-label {
color: #999999;
}
.input {
color: #000000;
text-align: left;
}
}
// 显示边框(如果需要定制边框,自行使用pi-solid-x实现)
&.border {
@include pi-border;
&::after {
border-bottom: 1px solid $pi-line-color;
}
}
&.wrap {
// 换行模式显示
flex-direction: column;
align-items: flex-start;
.label,
.other,
textarea {
width: 100%;
}
.input,
.other {
justify-content: flex-start;
margin-left: 0;
text-align: left;
}
.other {
padding-bottom: 32rpx;
}
}
// item里面放置picker显示效果
picker {
@extend .other;

height: $pi-form-item-height;
line-height: $pi-form-item-height;
text-align: right;
}
picker text {
font-size: 28upx;
color: #333333;
}
}
}

/**
* 列表
* -------------------------------------------------------------------------------------------------
*/
.pi-list {
@extend .pi-bg-white;
.item {
@extend .pi-rela;
@extend .pi-align-center;

transition: all $pi-animation-duration ease-in-out;
}
}

/**
* 初始化全局样式
* -------------------------------------------------------------------------------------------------
Expand Down

0 comments on commit 447a076

Please sign in to comment.