Skip to content

Commit

Permalink
v0.2版本更新: 1. fix bug 2. 【增强】 增加组件 form-page 表单页 3. 【增强】 增加组件 actionsh…
Browse files Browse the repository at this point in the history
…eet 模拟原生actionsheet 4. 【优化】 优化 slideview 右滑操作UI
  • Loading branch information
cunjinli6 committed Oct 24, 2019
1 parent 6c40363 commit 94e7353
Show file tree
Hide file tree
Showing 64 changed files with 1,603 additions and 264 deletions.
4 changes: 4 additions & 0 deletions src/actionsheet/actionsheet.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"component": true,
"usingComponents": {}
}
13 changes: 13 additions & 0 deletions src/actionsheet/actionsheet.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
@import "../weui-wxss/src/style/widget/weui-tips/weui-mask.wxss";
@import "../weui-wxss/src/style/widget/weui-tips/weui-actionsheet.wxss";

.weui-mask.weui-mask_hidden {
opacity: 0;
transform: scale3d(1, 1, 0)
}
.weui-mask{
opacity: 1;
transform: scale3d(1, 1, 1);
transition: all 0.3s;
}

71 changes: 71 additions & 0 deletions src/actionsheet/actionsheet.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
Component({
options: {
multipleSlots: true, // 在组件定义时的选项中启用多slot支持
addGlobalClass: true
},
properties: {
title: { // 标题
type: String,
value: ''
},
showCancel: { // 是否显示取消按钮
type: Boolean,
value: true
},
cancelText: { // 取消按钮文案
type: String,
value: '取消'
},
maskClass: { // 遮罩层class
type: String,
value: ''
},
extClass: { // 弹出窗 class
type: String,
value: ''
},
maskClosable: { // 点击遮罩 关闭 actionsheet
type: Boolean,
value: true,
},
mask: { // 是否需要 遮罩层
type: Boolean,
value: true
},
show: { // 是否开启 actionsheet
type: Boolean,
value: false
},
actions: { // actions 列表
type: Array,
value: [], // {text, extClass}
observer: '_groupChange'
}
},

methods: {
_groupChange(e) {
// 支持 一维数组 写法
if(e.length > 0 && typeof e[0] !== 'string' && !(e[0] instanceof Array)) {
this.setData({
actions: [this.data.actions]
})
}
},
buttonTap(e) {
const { value, groupindex, index } = e.currentTarget.dataset
this.triggerEvent('actiontap', { value, groupindex, index })
},
closeActionSheet(e) {
const { type } = e.currentTarget.dataset
if(this.data.maskClosable || type) {
// 点击 action 里面的 取消
this.setData({
show: false
})
// 关闭回调事件
this.triggerEvent('close')
}
}
}
})
50 changes: 50 additions & 0 deletions src/actionsheet/actionsheet.wxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<wxs module="utils">
var join = function(a,b) {
return a+b
};
var isNotSlot = function(v) {
return typeof v !== 'string'
}
module.exports = {
join: join,
isNotSlot: isNotSlot
}
</wxs>

<view wx:if="{{mask}}" class="weui-mask {{show ? '' : 'weui-mask_hidden'}} {{maskClass}}" bindtap="closeActionSheet"></view>
<view class="weui-actionsheet {{show ? 'weui-actionsheet_toggle' : ''}} {{extClass}}">
<!-- 标题 -->
<block wx:if="{{title}}">
<view class="weui-actionsheet__title">
<view class="weui-actionsheet__title-text">{{title}}</view>
</view>
</block>
<slot name="title" wx:else></slot>
<view
class="{{ !showCancel && index === actions.length-1 ? 'weui-actionsheet__action' : 'weui-actionsheet__menu' }}"
wx:key="{{index}}"
wx:for-item="actionItem"
wx:for-index="index"
wx:for="{{actions}}"
>
<block wx:if="{{utils.isNotSlot(actionItem)}}">
<view
class="weui-actionsheet__cell {{item.type === 'warn' ? 'weui-actionsheet__cell_warn' : '' }}"
wx:key="{{item.text}}"
wx:for="{{actionItem}}"
wx:for-index="actionIndex"
data-groupindex="{{index}}"
data-index="{{actionIndex}}"
data-value="{{item.value}}"
bindtap="buttonTap"
>
{{item.text}}
</view>
</block>
<slot name="{{actionItem}}" wx:else></slot>
</view>
<!-- 取消按钮 -->
<view class="weui-actionsheet__action" wx:if="{{showCancel}}">
<view class="weui-actionsheet__cell" data-type="close" id="iosActionsheetCancel" bindtap="closeActionSheet">{{cancelText}}</view>
</view>
</view>
1 change: 1 addition & 0 deletions src/badge/badge.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"component": true,
"usingComponents": {}
}
16 changes: 16 additions & 0 deletions src/cell/cell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ Component({
type: String,
value: ''
},
bodyClass: {
type: String,
value: ''
},
icon: {
type: String,
value: '',
Expand Down Expand Up @@ -55,6 +59,18 @@ Component({
inline: { // 左右布局样式还是上下布局
type: Boolean,
value: true
},
hasHeader: {
type: Boolean,
value: true
},
hasFooter: {
type: Boolean,
value: true
},
hasBody: {
type: Boolean,
value: true
}
},
relations: {
Expand Down
12 changes: 6 additions & 6 deletions src/cell/cell.wxml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<block wx:if="{{link}}">
<view bindtap="navigateTo" class="weui-cell weui-cell_access {{extClass}} {{outerClass}}{{inForm ? ' weui-cell-inform' : ''}}{{inline ? '' : ' .weui-cell_label-block'}}" hover-class="{{hover ? 'weui-cell_active' : ''}}">
<view class="weui-cell__hd {{iconClass}}">
<view wx:if="{{hasHeader}}" class="weui-cell__hd {{iconClass}}">
<block wx:if="{{icon}}">
<image src="{{icon}}" class="weui-cell__icon" mode="aspectFit"></image>
</block>
Expand All @@ -20,13 +20,13 @@
</block>
</block>
</view>
<view class="weui-cell__bd">
<view wx:if="{{hasBody}}" class="weui-cell__bd">
<block wx:if="{{value}}">{{value}}</block>
<block wx:else>
<slot></slot>
</block>
</view>
<view class="weui-cell__ft weui-cell__ft_in-access {{footerClass}}">
<view wx:if="{{hasFooter}}" class="weui-cell__ft weui-cell__ft_in-access {{footerClass}}">
<block wx:if="{{footer}}">{{footer}}</block>
<block wx:else>
<slot name="footer"></slot>
Expand All @@ -36,7 +36,7 @@
</block>
<block wx:else>
<view bindtap="navigateTo" class="weui-cell {{showError && error ? 'weui-cell_warn' : ''}} {{inForm ? 'weui-cell-inform' : ''}} {{extClass}} {{outerClass}}" hover-class="{{hover ? 'weui-cell_active' : ''}}">
<view class="weui-cell__hd {{iconClass}}">
<view wx:if="{{hasHeader}}" class="weui-cell__hd {{iconClass}}">
<block wx:if="{{icon}}">
<image src="{{icon}}" class="weui-cell__icon" mode="aspectFit"></image>
</block>
Expand All @@ -56,13 +56,13 @@
</block>
</block>
</view>
<view class="weui-cell__bd">
<view wx:if="{{hasBody}}" class="weui-cell__bd {{bodyClass}}">
<block wx:if="{{value}}">{{value}}</block>
<block wx:else>
<slot></slot>
</block>
</view>
<view class="weui-cell__ft {{footerClass}}">
<view wx:if="{{hasFooter}}" class="weui-cell__ft {{footerClass}}">
<block wx:if="{{footer}}">{{footer}}</block>
<block wx:else>
<slot name="footer"></slot>
Expand Down
19 changes: 17 additions & 2 deletions src/cells/cells.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ Component({
data: {
firstItem: null,
checkboxCount: 0,
checkboxIsMulti: false
checkboxIsMulti: false,
outerClass: '',
childClass: '',
},
relations: {
'../cell/cell': {
Expand All @@ -34,6 +36,9 @@ Component({
}
},
},
'../form-page/form-page': {
type: 'ancestor',
},
'../checkbox-group/checkbox-group': {
type: 'descendant',
linked(target) {
Expand All @@ -55,6 +60,16 @@ Component({
this.setData({
checkboxIsMulti: multi
})
}
},
setCellsClass(className) {
this.setData({
childClass: className
})
},
setOuterClass(className) {
this.setData({
outerClass: className
})
},
}
})
8 changes: 4 additions & 4 deletions src/cells/cells.wxml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<view class="{{extClass}}">
<view class="{{extClass}} weui-cells__group {{outerClass}} {{childClass}}">
<view wx:if="{{title}}" class="weui-cells__title">{{title}}</view>
<view class="weui-cells weui-cells_after-title {{checkboxCount > 0 && checkboxIsMulti ? 'weui-cells_checkbox' : ''}}">
<view class="weui-cells weui-cells_after-title weui-cells_form {{checkboxCount > 0 && checkboxIsMulti ? 'weui-cells_checkbox' : ''}}">
<slot></slot>
</view>
<view v-if="{{footer}}" class="weui-cells__tips">{{footer}}</view>
<template v-else><slot name="footer"></slot></template>
<view wx:if="{{footer}}" class="weui-cells__tips">{{footer}}</view>
<slot name="footer" wx:else></slot>
</view>
7 changes: 7 additions & 0 deletions src/checkbox-group/checkbox-group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ Component({
if (!this.data.parentCell) {
this.data.parentCell = target
}
this.setParentCellsClass()
},
unlinked(target) {
this.data.parentCell = null; // 方便内存回收
Expand Down Expand Up @@ -85,6 +86,12 @@ Component({
this.triggerEvent('change', {value: val}, {})
}
},
setParentCellsClass() {
const className = this.data.multi ? 'weui-cells_checkbox' : ''
if (this.data.parentCell) {
this.data.parentCell.setCellsClass(className)
}
},
_multiChange(multi) {
this.data.targetList.forEach(target => {
target.setMulti(multi)
Expand Down
2 changes: 1 addition & 1 deletion src/checkbox/checkbox.wxml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<mp-cell bindtap="checkedChange" footer-class="{{!multi ? 'weui-check__ft_in-radio' : ''}}" icon-class="{{multi ? 'weui-check__hd_in-checkbox' : ''}}" ext-class="weui-check__label {{outerClass}} {{extClass}}">
<mp-cell has-footer="{{!multi}}" has-header="{{multi}}" bindtap="checkedChange" footer-class="{{!multi ? 'weui-check__ft_in-radio' : ''}}" icon-class="{{multi ? 'weui-check__hd_in-checkbox' : ''}}" ext-class="weui-check__label {{outerClass}} {{extClass}} {{!multi ? 'weui-cell_radio' : 'weui-cell_checkbox'}}">

<view slot="icon" wx:if="{{multi}}">
<checkbox value="{{value}}" checked="{{checked}}" disabled="{{disabled}}" color="{{color}}" class="weui-check"></checkbox>
Expand Down
4 changes: 4 additions & 0 deletions src/form-page/form-page.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"component": true,
"usingComponents": {}
}
3 changes: 3 additions & 0 deletions src/form-page/form-page.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@import "../weui-wxss/src/style/widget/weui-page/weui-form.wxss";


32 changes: 32 additions & 0 deletions src/form-page/form-page.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
Component({
options: {
addGlobalClass: true,
multipleSlots: true,
},
properties: {
title: { // Msg 标题
type: String,
value: '',
},
subtitle: { // icon 的 type
type: String,
value: ''
},
},
relations: {
'../cells/cells': {
type: 'descendant',
linked(target) {
if (!this.data.firstItem) {
this.data.firstItem = target
}
if (target !== this.data.firstItem) {
target.setOuterClass('weui-cells__group_wxss')
}
},
},
},
data: {
firstItem: null
},
})
33 changes: 33 additions & 0 deletions src/form-page/form-page.wxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<view class="weui-form">
<block wx:if="{{title || subtitle}}">
<view class="weui-form__text-area">
<view class="weui-form__title">{{title}}</view>
<view class="weui-form__desc">{{subtitle}}</view>
</view>
</block>
<block wx:else>
<view class="weui-form__text-area">
<slot name="title"></slot>
</view>
</block>
<view class="weui-form__control-area">
<view class="weui-cells__group weui-cells__group_form">
<slot></slot>
</view>
</view>
<view class="weui-form__tips-area">
<slot name="tips"></slot>
</view>
<view class="weui-form__opr-area">
<slot name="button"></slot>
</view>
<view class="weui-form__tips-area">
<slot name="suffixtips"></slot>
</view>
<view class="weui-form__extra-area">
<view class="weui-footer">
<slot name="footer"></slot>
</view>
</view>
</view>

2 changes: 1 addition & 1 deletion src/form/form-validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const toString = Object.prototype.toString
const validateSingleRule = (rule: any, value:any, param:any = null, models = null) => {
let message = ''
for (const ruleKey in rule) {
if (ruleKey === 'validator' || ruleKey === 'name' || ruleKey === 'message') continue
if (ruleKey === 'name' || ruleKey === 'message') continue
const validateMethod = typeof rule.validator !== 'undefined' ? rule.validator : Validator[ruleKey]
if (typeof validateMethod === 'function') {
message = validateMethod(rule, value, param, models)
Expand Down
Loading

0 comments on commit 94e7353

Please sign in to comment.