-
Notifications
You must be signed in to change notification settings - Fork 879
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
142 changed files
with
596 additions
and
191 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
(The MIT License) | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining | ||
a copy of this software and associated documentation files (the | ||
'Software'), to deal in the Software without restriction, including | ||
without limitation the rights to use, copy, modify, merge, publish, | ||
distribute, sublicense, and/or sell copies of the Software, and to | ||
permit persons to whom the Software is furnished to do so, subject to | ||
the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be | ||
included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | ||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY | ||
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, | ||
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE | ||
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file was deleted.
Oops, something went wrong.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes
File renamed without changes
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,159 @@ | ||
import tools from '../tools/tools' | ||
|
||
/** | ||
* wux组件 | ||
* @param {Object} $scope 作用域对象 | ||
*/ | ||
class wux { | ||
constructor($scope) { | ||
Object.assign(this, { | ||
$scope, | ||
}) | ||
this.__init() | ||
} | ||
|
||
/** | ||
* 初始化类方法 | ||
*/ | ||
__init() { | ||
this.__initDefaults() | ||
this.__initTools() | ||
this.__initComponents() | ||
} | ||
|
||
/** | ||
* 默认参数 | ||
*/ | ||
__initDefaults() { | ||
const actionSheet = {} | ||
|
||
this.$scope.setData({ | ||
[`$wux.actionSheet`]: actionSheet, | ||
}) | ||
} | ||
|
||
/** | ||
* 工具方法 | ||
*/ | ||
__initTools() { | ||
this.tools = new tools | ||
} | ||
|
||
/** | ||
* 初始化所有组件 | ||
*/ | ||
__initComponents() { | ||
this.__initActionSheet() | ||
} | ||
|
||
/** | ||
* 上拉菜单组件 | ||
*/ | ||
__initActionSheet() { | ||
const that = this | ||
const extend = that.tools.extend | ||
const clone = that.tools.clone | ||
const $scope = that.$scope | ||
|
||
that.$wuxActionSheet = { | ||
defaults: { | ||
className: undefined, | ||
titleText: undefined, | ||
buttons: [], | ||
buttonClicked: function() {}, | ||
cancelText: '取消', | ||
cancel: function() {}, | ||
// destructiveText: '删除', | ||
// destructiveButtonClicked: function() {}, | ||
}, | ||
/** | ||
* 显示上拉菜单组件 | ||
* @param {Object} opts 参数对象 | ||
* @param {String} opts.className 添加自定义类 | ||
* @param {String} opts.titleText 标题 | ||
* @param {Array} opts.buttons 按钮 | ||
* @param {Function} opts.buttonClicked 按钮点击事件 | ||
* @param {String} opts.cancelText 取消按钮的文本 | ||
* @param {Function} opts.cancel 取消按钮点击事件 | ||
* @param {String} opts.destructiveText 删除按钮的文本 | ||
* @param {Function} opts.destructiveButtonClicked 删除按钮点击事件 | ||
*/ | ||
show(opts = {}) { | ||
const options = extend(clone(this.defaults), opts) | ||
|
||
// 显示 | ||
const showSheet = () => { | ||
that.setVisible('actionSheet', ['weui-animate-slide-up', 'weui-animate-fade-in']) | ||
} | ||
|
||
// 隐藏 | ||
const removeSheet = (callnack) => { | ||
that.setHidden('actionSheet', ['weui-animate-slide-down', 'weui-animate-fade-out']) | ||
typeof callback === 'function' && callback(opts.buttons) | ||
} | ||
|
||
// 按钮点击事件 | ||
const buttonClicked = (e) => { | ||
const index = e.currentTarget.dataset.index | ||
if (options.buttonClicked(index, options.buttons[index]) === true) { | ||
removeSheet() | ||
} | ||
} | ||
|
||
// 删除按钮点击事件 | ||
const destructiveButtonClicked = () => { | ||
if (options.destructiveButtonClicked() === true) { | ||
removeSheet() | ||
} | ||
} | ||
|
||
// 取消按钮点击事件 | ||
const cancel = () => removeSheet(options.cancel) | ||
|
||
// 渲染组件 | ||
$scope.setData({ | ||
[`$wux.actionSheet`]: options, | ||
[`$wux.actionSheet.onButtonClicked`]: `actionSheetButtonClicked`, | ||
[`$wux.actionSheet.onDestructiveButtonClicked`]: `actionSheetDestructiveButtonClicked`, | ||
[`$wux.actionSheet.onCancel`]: `actionSheetCancel`, | ||
}) | ||
|
||
// 绑定tap事件 | ||
$scope[`actionSheetButtonClicked`] = buttonClicked | ||
$scope[`actionSheetDestructiveButtonClicked`] = destructiveButtonClicked | ||
$scope[`actionSheetCancel`] = cancel | ||
|
||
showSheet() | ||
|
||
return cancel | ||
}, | ||
} | ||
} | ||
|
||
/** | ||
* 设置元素显示 | ||
*/ | ||
setVisible(key, className = 'weui-animate-fade-in') { | ||
this.$scope.setData({ | ||
[`$wux.${key}.visible`]: !0, | ||
[`$wux.${key}.animateCss`]: className, | ||
}) | ||
} | ||
|
||
/** | ||
* 设置元素隐藏 | ||
*/ | ||
setHidden(key, className = 'weui-animate-fade-out', timer = 300) { | ||
this.$scope.setData({ | ||
[`$wux.${key}.animateCss`]: className, | ||
}) | ||
|
||
setTimeout(() => { | ||
this.$scope.setData({ | ||
[`$wux.${key}.visible`]: !1, | ||
}) | ||
}, timer) | ||
} | ||
} | ||
|
||
export default wux |
Oops, something went wrong.