This repository has been archived on 2023-08-30. You can view files and clone it, but cannot push or open issues/pull-requests.
bytedo
/
wcui
Archived
1
0
Fork 0

修正time过滤器的变量定义;修正触摸模块的适配;修正路由组件的适配

old
宇天 2018-03-13 14:55:46 +08:00
parent 4684ffa4b8
commit c0f5d3395c
5 changed files with 839 additions and 821 deletions

View File

@ -5725,7 +5725,9 @@
time: function(str) { time: function(str) {
str = str >> 0 str = str >> 0
var s = str % 60 var s = str % 60
;(m = Math.floor(str / 60)), (h = Math.floor(m / 60)), (m = m % 60) var m = Math.floor(str / 60)
var h = Math.floor(m / 60)
m = m % 60
m = m < 10 ? '0' + m : m m = m < 10 ? '0' + m : m
s = s < 10 ? '0' + s : s s = s < 10 ? '0' + s : s

View File

@ -61,7 +61,7 @@ const close = function(id) {
} }
} }
const reapeat = function(str, num) { const repeat = function(str, num) {
var idx = 0, var idx = 0,
result = '' result = ''
while (idx < num) { while (idx < num) {
@ -77,15 +77,15 @@ const fixOffset = function(val) {
return val return val
} }
} }
const __layer__ = function(conf) { const __layer__ = function(opt) {
if (conf) { if (opt) {
let { yes, no, success } = conf let { yes, no, success } = opt
delete conf.yes delete opt.yes
delete conf.no delete opt.no
delete conf.success delete opt.success
this.construct({ this.construct({
state: { ...conf }, state: { ...opt },
props: { yes, no, success } props: { yes, no, success }
}) })
.append() .append()
@ -130,27 +130,35 @@ const _layer = {
} }
return _layer.open(opt) return _layer.open(opt)
}, },
msg: function(msg, conf) { toast: function(content, type, timeout, cb) {
if (typeof conf !== 'object') { // if (typeof opt !== 'object') {
var tmp = conf // var tmp = opt
conf = { timeout: 2500 } // opt = { timeout: 2500 }
if (typeof tmp === 'number') { // if (typeof tmp === 'number') {
conf.icon = tmp // opt.icon = tmp
} // }
// }
if (typeof type === 'number') {
timeout = type
type = 'info'
} }
if (!conf.hasOwnProperty('timeout')) { // if (!opt.hasOwnProperty('timeout')) {
conf.timeout = 2500 // opt.timeout = 2500
// }
let opt = {
content: `<mark class="toast-box">${content}</mark>`,
menubar: false,
mask: false,
type: 7,
fixed: true
} }
conf.specialMode = true //特殊模式 opt.toast = true // toast模式
conf.content = '<p class="msg-box">' + msg + '</p>'
conf.type = 7 return _layer.open(opt)
conf.fixed = true
conf.shade = false
conf.menubar = false
conf.radius = '5px'
return _layer.open(conf)
}, },
loading: function(style, time, cb) { loading: function(style, time, cb) {
style = style >>> 0 style = style >>> 0
@ -174,34 +182,34 @@ const _layer = {
fixed: true fixed: true
}) })
}, },
tips: function(content, container, conf) { tips: function(content, container, opt) {
if (!(container instanceof HTMLElement)) { if (!(container instanceof HTMLElement)) {
return Anot.error('tips类型必须指定一个目标容器') return Anot.error('tips类型必须指定一个目标容器')
} }
if (typeof conf !== 'object') { if (typeof opt !== 'object') {
var tmp = conf var tmp = opt
conf = { timeout: 2500 } opt = { timeout: 2500 }
if (typeof tmp === 'number') { if (typeof tmp === 'number') {
conf.icon = tmp opt.icon = tmp
} }
} }
if (!conf.hasOwnProperty('timeout')) { if (!opt.hasOwnProperty('timeout')) {
conf.timeout = 2500 opt.timeout = 2500
} }
if (!conf.background) { if (!opt.background) {
conf.background = 'rgba(0,0,0,.5)' opt.background = 'rgba(0,0,0,.5)'
} }
if (!conf.color) { if (!opt.color) {
conf.color = '#fff' opt.color = '#fff'
} }
conf.container = container opt.container = container
conf.content = content opt.content = content
conf.type = 5 opt.type = 5
conf.icon = 0 opt.icon = 0
conf.fixed = true opt.fixed = true
conf.shade = false opt.shade = false
conf.menubar = false opt.menubar = false
return _layer.open(conf) return _layer.open(opt)
}, },
prompt: function(title, yescb) { prompt: function(title, yescb) {
if (typeof yescb !== 'function') { if (typeof yescb !== 'function') {
@ -226,33 +234,33 @@ const _layer = {
require(['css!./skin/' + skin], callback) require(['css!./skin/' + skin], callback)
}, },
close: close, close: close,
open: function(conf) { open: function(opt) {
if (typeof conf === 'string') { if (typeof opt === 'string') {
/*conf = '$wrap-' + conf /*opt = '$wrap-' + opt
if (!layerObj[conf]) { if (!layerObj[opt]) {
throw new Error('layer实例不存在') throw new Error('layer实例不存在')
} else { } else {
//只能显示一个实例 //只能显示一个实例
if (layerObj[conf].show) { if (layerObj[opt].show) {
return conf return opt
} }
layerObj[conf].show = true layerObj[opt].show = true
if (!Anot.vmodels[conf]) { if (!Anot.vmodels[opt]) {
Anot(layerObj[conf].obj.init) Anot(layerObj[opt].obj.init)
} }
layerObj[conf].parentElem.appendChild(layerDom[conf][1]) layerObj[opt].parentElem.appendChild(layerDom[opt][1])
layerDom[conf][1] layerDom[opt][1]
.querySelector('.detail') .querySelector('.detail')
.appendChild(layerObj[conf].wrap) .appendChild(layerObj[opt].wrap)
layerObj[conf].wrap.style.display = '' layerObj[opt].wrap.style.display = ''
// Anot.scan(layerDom[conf][1]) // Anot.scan(layerDom[opt][1])
layerObj[conf].obj.show() layerObj[opt].obj.show()
return conf return opt
}*/ }*/
} else { } else {
return new __layer__(conf).init.$id return new __layer__(opt).init.$id
} }
}, },
version: Anot.ui.layer version: Anot.ui.layer
@ -277,16 +285,24 @@ __layer__.prototype = {
5: 9 5: 9
}, },
timeout: null, timeout: null,
construct: function(conf) { construct: function(opt) {
let _id = conf.$id || uuid() let _id = opt.$id || uuid()
this.init = { this.init = {
$id: _id, $id: _id,
state: { state: {
...defconf, ...defconf,
...conf.state ...opt.state
}, },
props: conf.props, props: opt.props,
skip: ['area', 'shift', 'skin', 'mask', 'maskClose', 'container'], skip: [
'area',
'shift',
'skin',
'mask',
'maskClose',
'container',
'follow'
],
methods: { methods: {
onMaskClick: function() { onMaskClick: function() {
if (this.type < 4 && !this.maskClose) { if (this.type < 4 && !this.maskClose) {
@ -358,8 +374,8 @@ __layer__.prototype = {
if (state.type === 5) { if (state.type === 5) {
layBox.classList.add('active') layBox.classList.add('active')
} }
if (state.specialMode && state.type === 7) { if (state.toast) {
layBox.classList.add('type-unspecial') layBox.classList.add('type-toast')
} else { } else {
layBox.classList.add('type-' + state.type) layBox.classList.add('type-' + state.type)
} }
@ -396,9 +412,10 @@ __layer__.prototype = {
${this.getMenubar()} ${this.getMenubar()}
<div <div
class="layer-content do-fn-cl ${state.icon < 0 ? 'none-icon' : ''}" class="layer-content do-fn-cl ${state.icon < 0 ? 'none-icon' : ''}"
style="${boxcss}"> style="${boxcss}"
${!state.wrap && state.type !== 6 ? ':html="content"' : ''}>
${this.getCont()} ${state.type === 6 ? this.getLoading(state.load) : ''}
</div> </div>
${this.getCtrl()} ${this.getCtrl()}
${arrow} ${arrow}
@ -407,17 +424,14 @@ __layer__.prototype = {
outerBox.appendChild(layBox) outerBox.appendChild(layBox)
return [outerBox, layBox] return [outerBox, layBox]
}, },
getCont: function() { // getCont: function() {
let { state, $id } = this.init // let { state, $id } = this.init
if (state.type === 6) { // if (state.type === 6) {
return this.getLoading(state.load) // return this.getLoading(state.load)
} else { // } else {
return ` // return !state.wrap ? '{{content | html}}' : ''
${this.getIcon()} // }
<div class="detail" ${!state.wrap ? ':html="content"' : ''}></div> // },
`
}
},
getLoading: function(style) { getLoading: function(style) {
return ` return `
<div class="loading style-${style}"> <div class="loading style-${style}">
@ -481,7 +495,7 @@ __layer__.prototype = {
} }
}, },
append: function() { append: function() {
let { state, $id } = this.init let { state, $id, container } = this.init
//如果有已经打开的弹窗,则关闭 //如果有已经打开的弹窗,则关闭
if (unique) { if (unique) {
_layer.close(unique) _layer.close(unique)
@ -491,14 +505,17 @@ __layer__.prototype = {
} }
layerDom[$id] = this.create() layerDom[$id] = this.create()
delete state.specialMode delete state.toast
if (!container) {
container = document.body
}
document.body.appendChild(layerDom[$id][0]) container.appendChild(layerDom[$id][0])
this.vm = Anot(this.init) this.vm = Anot(this.init)
return this return this
}, },
show: function() { show: function() {
let { state, $id, container } = this.init let { state, $id, follow } = this.init
setTimeout(function() { setTimeout(function() {
var style = { visibility: '', background: state.background } var style = { visibility: '', background: state.background }
@ -509,10 +526,10 @@ __layer__.prototype = {
// only type[tips] can define `color` // only type[tips] can define `color`
style.color = state.color style.color = state.color
let $container = Anot(container) let $follow = Anot(follow)
let ew = $container.innerWidth() let ew = $follow.innerWidth()
let ol = $container.offset().left - document.body.scrollLeft let ol = $follow.offset().left - document.body.scrollLeft
let ot = $container.offset().top - document.body.scrollTop let ot = $follow.offset().top - document.body.scrollTop
style.left = ol + ew * 0.7 style.left = ol + ew * 0.7
style.top = ot - parseInt(css.height) - 8 style.top = ot - parseInt(css.height) - 8
@ -557,7 +574,7 @@ __layer__.prototype = {
_this.vm.yes($id) _this.vm.yes($id)
} }
}, state.timeout) }, state.timeout)
} else if (statetype === 6) { } else if (state.type === 6) {
// loading类型, 非自动关闭时, 主动触发回调 // loading类型, 非自动关闭时, 主动触发回调
this.vm.yes($id) this.vm.yes($id)
} }

View File

@ -13,15 +13,9 @@
.layer-box {position:absolute;} .layer-box {position:absolute;}
&.mask {position:fixed;z-index:65534;left:0;top:0;width:100%;height:100%;background:rgba(0,0,0,.3);
.layer-box {position:absolute;}
}
a {text-decoration:none;} a {text-decoration:none;}
.layer-box {left:50%;top:50%;z-index:65535; .layer-box {left:50%;top:50%;z-index:65535;
&.shift {transition: all .3s ease-in-out;} &.shift {transition: all .3s ease-in-out;}
@ -47,20 +41,19 @@
.layer-title {width:100%;height:43px;padding:0 10px;line-height:43px;font-size:16px;color:nth($cgr, 1);} .layer-title {width:100%;height:43px;padding:0 10px;line-height:43px;font-size:16px;color:nth($cgr, 1);}
/* 弹层主体内容 */ /* 弹层主体内容 */
.layer-content {position:relative;width:100%;height:auto;min-height:50px;padding:10px; .layer-content {position:relative;width:100%;height:auto;min-height:50px;padding:10px;word-break:break-all;word-wrap: break-word;
.msg-icon {position:absolute;left:10px;top:10px;width:50px;height:auto;line-height:40px;font-size:35px;text-align:center;} // .msg-icon {position:absolute;left:10px;top:10px;width:50px;height:auto;line-height:40px;font-size:35px;text-align:center;}
.detail {width:auto;height:100%;margin:auto auto auto 50px;padding:5px 15px;word-break:break-all;word-wrap: break-word;
.prompt-value {width: 230px;height: 30px;padding: 0 8px;border: 1px solid #ddd;border-radius: 3px; .prompt-value {width: 100%;height: 30px;padding: 0 8px;border: 1px solid #ddd;border-radius: 3px;
&.alert {border-color:nth($cr, 1)} &.alert {border-color:nth($cr, 1)}
&:focus {border-color:nth($ct, 1)} &:focus {border-color:nth($ct, 1)}
} }
.msg-box {line-height:30px;} .msg-box {line-height:30px;}
}
&.none-icon .detail {margin:0 auto;}
&.none-icon .detail {margin:0 auto;}
} }
@ -92,7 +85,7 @@
&.active {visibility:visible;opacity:1;} &.active {visibility:visible;opacity:1;}
i.arrow {position:absolute;left:5px;bottom:-14px;width:0;height:0;border:6px solid transparent;border-top:8px solid rgba(0,0,0,.5);content: ""} i.arrow {position:absolute;left:5px;bottom:-14px;width:0;height:0;border:6px solid transparent;border-top:8px solid rgba(0,0,0,.5);content: ""}
.layer-content .detail {margin:0;padding:0} .layer-content {margin:0;padding:0}
} }
@ -100,11 +93,15 @@
&.type-6 {box-shadow:none;background:transparent;} &.type-6 {box-shadow:none;background:transparent;}
/* 特殊类弹层(msg弹层) */ /* 特殊类弹层(toast弹层) */
&.type-unspecial {min-width:10px;background:transparent; &.type-toast {min-width:10px;padding:0;background:transparent;
.layer-content {min-height:60px;padding:0} .layer-content {min-height:40px;height:40px;padding:0}
.layer-content .detail {margin:0;padding:0}
.toast-box {display:inline-block;position:relative;min-height:40px;padding:5px 8px 5px 50px;line-height:28px;border:1px solid nth($co, 1);border-radius:3px;background:#fffbed;color:nth($co, 3);word-break: break-all;
&::before {position:absolute;left:15px;top:5px;font:20px/28px "ui font";color:nth($cr, 1);content:"\e6f6";}
}
} }
@ -182,6 +179,11 @@
} }
} }
&.mask {position:fixed;z-index:65534;left:0;top:0;width:100%;height:100%;background:rgba(0,0,0,.3);
.layer-box {position:absolute;}
}
&:active {z-index:65536;} &:active {z-index:65536;}
} }

View File

@ -1,172 +1,180 @@
define(['yua'], function(){ /**
*
* @authors yutent (yutent@doui.cc)
* @date 2017-04-14 21:04:50
*
*/
function Router(){ 'use strict'
this.table = {get: []}; //储存版本信息
this.errorFn = null; Anot.ui.router = '0.0.1'
this.history = null;
this.hash = '';
this.started = false;
this.init = {};
}
var defaultOptions = { function Router() {
prefix: /^(#!|#)[\/]?/, //hash前缀正则 this.table = { get: [] }
historyOpen: true, //是否开启hash历史 this.errorFn = null
allowReload: true //连续点击同一个链接是否重新加载 this.history = null
}; this.hash = ''
var isMouseUp = true; this.started = false
this.init = {}
}
var ruleRegExp = /(:id)|(\{id\})|(\{id:([A-z\d\,\[\]\{\}\-\+\*\?\!:\^\$]*)\})/g; var defaultOptions = {
prefix: /^(#!|#)[\/]?/, //hash前缀正则
historyOpen: true, //是否开启hash历史
allowReload: true //连续点击同一个链接是否重新加载
}
var isMouseUp = true
Router.prototype = { var ruleRegExp = /(:id)|(\{id\})|(\{id:([A-z\d\,\[\]\{\}\-\+\*\?\!:\^\$]*)\})/g
error: function(callback){
this.errorFn = callback;
},
config: function(opts){
if(this.started)
return console.error('Router config has been set');
this.started = true; Router.prototype = {
if(!opts.allowReload) error: function(callback) {
opts.historyOpen = true; this.errorFn = callback
this.init = yua.mix({}, defaultOptions, opts); },
}, config: function(opts) {
_getRegExp: function(rule, opts){ if (this.started) return console.error('Router config has been set')
var re = rule.replace(ruleRegExp, function(m, p1, p2, p3, p4){
var w = '([\\w.-]';
if(p1 || p2){
return w + '+)';
}else{
if(!/^\{[\d\,]+\}$/.test(p4)){
w = '(';
}
return w + p4 + ')';
}
})
re = re.replace(/(([^\\])([\/]+))/g, '$2\\/').replace(/(([^\\])([\.]+))/g, '$2\\.').replace(/(([^\\])([\-]+))/g, '$2\\-').replace(/(\(.*)(\\[\-]+)(.*\))/g, '$1-$3');
re = '^' + re + '$';
opts.regexp = new RegExp(re)
return opts;
},
_add: function(method, rule, callback){
if(!this.started)
this.config({});
var table = this.table[method.toLowerCase()]; this.started = true
if (rule.charAt(0) !== "/") { if (!opts.allowReload) opts.historyOpen = true
console.error('char "/" must be in front of router rule'); this.init = Anot.mix({}, defaultOptions, opts)
return; },
} _getRegExp: function(rule, opts) {
rule = rule.replace(/^[\/]+|[\/]+$|\s+/g, ''); var re = rule.replace(ruleRegExp, function(m, p1, p2, p3, p4) {
var opts = {}; var w = '([\\w.-]'
opts.rule = rule; if (p1 || p2) {
opts.callback = callback; return w + '+)'
yua.Array.ensure(table, this._getRegExp(rule, opts)); } else {
}, if (!/^\{[\d\,]+\}$/.test(p4)) {
_route: function(method, hash){ w = '('
var hash = hash.trim();
var table = this.table[method];
var init = this.init;
if(!init.allowReload && hash === this.history)
return;
if(init.historyOpen){
this.history = hash;
if(yua.ls)
yua.ls('lastHash', hash);
}
for(var i = 0, obj; obj = table[i++];){
var args = hash.match(obj.regexp);
if(args){
args.shift();
return obj.callback.apply(obj, args)
}
}
this.errorFn && this.errorFn(hash);
},
on: function(rule, callback){
var _this = this
if(Array.isArray(rule)){
rule.forEach(function(it){
_this._add('get', it, callback);
})
}else{
this._add('get', rule, callback);
}
}
}
yua.bind(window, 'load', function(){
if(!yua.router.started)
return;
var prefix = yua.router.init.prefix;
var hash = location.hash;
hash = hash.replace(prefix, "").trim();
yua.router._route('get', hash);
});
if('onhashchange' in window){
window.addEventListener('hashchange', function(event){
if(!isMouseUp)
return;
var prefix = yua.router.init.prefix;
var hash = location.hash.replace(prefix, "").trim();
yua.router._route('get', hash)
})
}
//劫持页面上所有点击事件,如果事件源来自链接或其内部,
//并且它不会跳出本页,并且以"#/"或"#!/"开头那么触发updateLocation方法
yua.bind(document, "mousedown", function(event){
var defaultPrevented = "defaultPrevented" in event ? event['defaultPrevented'] : event.returnValue === false
if (defaultPrevented || event.ctrlKey || event.metaKey || event.which === 2)
return
var target = event.target
while (target.nodeName !== "A") {
target = target.parentNode
if (!target || target.tagName === "BODY") {
return
}
}
if (targetIsThisWindow(target.target)){
if(!yua.router.started)
return;
var href = target.getAttribute("href") || target.getAttribute("xlink:href"),
prefix = yua.router.init.prefix;
if (href === null || !prefix.test(href))
return
yua.router.hash = href.replace(prefix, "").trim();
event.preventDefault();
location.hash = href;
isMouseUp = false;
} }
return w + p4 + ')'
}
}) })
re = re
.replace(/(([^\\])([\/]+))/g, '$2\\/')
.replace(/(([^\\])([\.]+))/g, '$2\\.')
.replace(/(([^\\])([\-]+))/g, '$2\\-')
.replace(/(\(.*)(\\[\-]+)(.*\))/g, '$1-$3')
re = '^' + re + '$'
opts.regexp = new RegExp(re)
return opts
},
_add: function(method, rule, callback) {
if (!this.started) this.config({})
yua.bind(document, "mouseup", function(){ var table = this.table[method.toLowerCase()]
if(!isMouseUp){ if (rule.charAt(0) !== '/') {
yua.router._route('get', yua.router.hash); console.error('char "/" must be in front of router rule')
isMouseUp = true; return
} }
rule = rule.replace(/^[\/]+|[\/]+$|\s+/g, '')
var opts = {}
opts.rule = rule
opts.callback = callback
Anot.Array.ensure(table, this._getRegExp(rule, opts))
},
_route: function(method, hash) {
var hash = hash.trim()
var table = this.table[method]
var init = this.init
}) if (!init.allowReload && hash === this.history) return
if (init.historyOpen) {
//判定A标签的target属性是否指向自身 this.history = hash
//thanks https://github.com/quirkey/sammy/blob/master/lib/sammy.js#L219 if (Anot.ls) {
function targetIsThisWindow(targetWindow) { Anot.ls('lastHash', hash)
if (!targetWindow || targetWindow === window.name || targetWindow === '_self' || (targetWindow === 'top' && window == window.top)) { }
return true
}
return false
} }
yua.ui.router = '0.0.1' for (var i = 0, obj; (obj = table[i++]); ) {
var args = hash.match(obj.regexp)
if (args) {
args.shift()
return obj.callback.apply(obj, args)
}
}
this.errorFn && this.errorFn(hash)
},
on: function(rule, callback) {
var _this = this
if (Array.isArray(rule)) {
rule.forEach(function(it) {
_this._add('get', it, callback)
})
} else {
this._add('get', rule, callback)
}
}
}
return yua.router = new Router; Anot.bind(window, 'load', function() {
if (!Anot.router.started) return
var prefix = Anot.router.init.prefix
var hash = location.hash
hash = hash.replace(prefix, '').trim()
Anot.router._route('get', hash)
}) })
if ('onhashchange' in window) {
window.addEventListener('hashchange', function(event) {
if (!isMouseUp) return
var prefix = Anot.router.init.prefix
var hash = location.hash.replace(prefix, '').trim()
Anot.router._route('get', hash)
})
}
//劫持页面上所有点击事件,如果事件源来自链接或其内部,
//并且它不会跳出本页,并且以"#/"或"#!/"开头那么触发updateLocation方法
Anot.bind(document, 'mousedown', function(event) {
var defaultPrevented =
'defaultPrevented' in event
? event['defaultPrevented']
: event.returnValue === false
if (defaultPrevented || event.ctrlKey || event.metaKey || event.which === 2)
return
var target = event.target
while (target.nodeName !== 'A') {
target = target.parentNode
if (!target || target.tagName === 'BODY') {
return
}
}
if (targetIsThisWindow(target.target)) {
if (!Anot.router.started) return
var href = target.getAttribute('href') || target.getAttribute('xlink:href'),
prefix = Anot.router.init.prefix
if (href === null || !prefix.test(href)) return
Anot.router.hash = href.replace(prefix, '').trim()
event.preventDefault()
location.hash = href
isMouseUp = false
}
})
Anot.bind(document, 'mouseup', function() {
if (!isMouseUp) {
Anot.router._route('get', Anot.router.hash)
isMouseUp = true
}
})
//判定A标签的target属性是否指向自身
//thanks https://github.com/quirkey/sammy/blob/master/lib/sammy.js#L219
function targetIsThisWindow(targetWindow) {
if (
!targetWindow ||
targetWindow === window.name ||
targetWindow === '_self' ||
(targetWindow === 'top' && window == window.top)
) {
return true
}
return false
}
export default (Anot.router = new Router())

File diff suppressed because it is too large Load Diff