');
$5('._time', dtdom).removeClass('active');
$5('._timedate', dtdom).addClass('active');
var year = dtimeshow.getFullYear();
var month = dtimeshow.getMonth() + 1;
var html = '';
html += '
';
for (var i = styear; i < styear + 12; i++) {
if (year == i)
html += '
' + i + '
';
else
html += '
' + i + '
';
}
html += '
';
}
else if (op == 'month') {
html += '
';
for (var i = 1; i <= 12; i++) {
if (month == i)
html += '
' + i + '' + ciyfn.lang('月') + '
';
else
html += '
' + i + '' + ciyfn.lang('月') + '
';
}
html += '
';
} else {
html += '
' + ciyfn.lang('日') + '
' + ciyfn.lang('一') + '
' + ciyfn.lang('二') + '
' + ciyfn.lang('三') + '
' + ciyfn.lang('四') + '
' + ciyfn.lang('五') + '
' + ciyfn.lang('六') + '
';
var weekday = new Date(year, month - 1, 1).getDay();
var days = new Date(year, month, 0).getDate();
for (var i = 0; i < 6; i++) {
html += '
';
for (var j = 0; j < 7; j++) {
var daynum = i * 7 + j - weekday + 1;
if (daynum >= 1 && daynum <= days) {
html += '
' + daynum + '
';
else
html += '">' + daynum + '
';
} else {
html += '';
}
}
html += '
';
}
html += '';
}
mainseldom.html(html);
}
function showhour() {
$5('._timehour>div>span', dtdom).html(ciyfn.todatetime(dtimevalue, 'H'));
$5('._time', dtdom).removeClass('active');
$5('._timehour', dtdom).addClass('active');
var hour = dtimevalue.getHours();
var html = '';
html += '
';
for (var i = 0; i < 24; i++) {
if (hour == i)
html += '
' + i + '
';
else
html += '
' + i + '
';
}
html += '
';
mainseldom.html(html);
}
function showminute() {
$5('._timeminute>div>span', dtdom).html(ciyfn.todatetime(dtimevalue, 'i'));
$5('._time', dtdom).removeClass('active');
$5('._timeminute', dtdom).addClass('active');
var minute = dtimevalue.getMinutes();
var html = '';
html += '
';
for (var i = 0; i < 60; i += 10) {
if (toint(minute / 10) * 10 == i)
html += '
' + i + '
';
else
html += '
' + i + '
';
}
html += '
';
html += '';
html += '
';
for (var i = 0; i < 10; i++) {
if (minute % 10 == i)
html += '
' + i + '
';
else
html += '
' + i + '
';
}
html += '
';
mainseldom.html(html);
}
}
ciycmpfunc.ciydaterange = function (opn) {
var thos = this;
this.onchange = opn.onchange;
opn.initevent = opn.initevent || opn.dom.hasattr('initevent');
opn.hasmore = opn.hasmore || opn.dom.hasattr('hasmore');
opn.type = opn.type || opn.dom.attr('type') || 'date'; //date/datetime
var html = '';
html += '';
html += '
';
html += '';
html += '
~
';
html += '';
html += '
';
opn.dom.html(html);
var valuedom = opn.dom.children(0);
var rangedom = opn.dom.children(1);
var valname1dom = rangedom.children(0);
var valname2dom = rangedom.children(2);
var rangevalue = [0, 0];
var format = 'Y-m-d';
if (opn.type == 'datetime')
format = 'Y-m-d H:i:00';
this.setvalue = function (newvalue, from) {
if (newvalue !== undefined) {
if (newvalue.indexOf('~') >= 0) {
var arr = newvalue.split('~');
rangevalue[0] = tostamp(arr[0]);
rangevalue[1] = tostamp(arr[1]);
valname1dom.val(rangevalue[0]);
valname2dom.val(rangevalue[1]);
}
}
if (rangevalue[0] != 0 && rangevalue[1] != 0) {
if (rangevalue[0] > rangevalue[1]) {
var tmp = rangevalue[0];
rangevalue[0] = rangevalue[1];
rangevalue[1] = tmp;
valname1dom.val(rangevalue[0]);
valname2dom.val(rangevalue[1]);
}
}
var val = '';
if (rangevalue[0] != 0 || rangevalue[1] != 0) {
if (rangevalue[0] != 0)
val = ciyfn.todatetime(rangevalue[0], format, '');
val += '~';
if (rangevalue[1] != 0)
val += ciyfn.todatetime(rangevalue[1], format, '');
}
this.value = val;
valuedom.val(this.value);
if (from && typeof (this.onchange) == 'function')
this.onchange({ name: opn.name, dom: opn.dom, from: from, value: this.value });
}
ciycmp({
dom: valname1dom, type: opn.type, onchange: function (e) {
rangevalue[0] = e.value;
thos.setvalue(undefined, 'selectdt1');
}
});
ciycmp({
dom: valname2dom, type: opn.type, onchange: function (e) {
rangevalue[1] = e.value;
thos.setvalue(undefined, 'selectdt2');
}
});
this.setvalue(opn.value, opn.initevent ? 'init' : '');
}
ciycmpfunc.ciyswitch = function (opn) {
var thos = this;
this.onchange = opn.onchange;
opn.initevent = opn.initevent || opn.dom.hasattr('initevent');
opn.hasmore = opn.hasmore || opn.dom.hasattr('hasmore');
opn.y = opn.y || opn.dom.attr('y') || '✔';
opn.n = opn.n || opn.dom.attr('n') || '✘';
var html = '';
html += '';
html += '
';
html += '
' + ciyfn.lang(opn.y) + '
';
html += '
' + ciyfn.lang(opn.n) + '
';
html += '
';
if (opn.hasmore)
html += '';
opn.dom.html(html).css({ verticalAlign: 'middle' });
var valuedom = opn.dom.children(0);
var valnamedom = opn.dom.children(2);
this.setvalue = function (newvalue, from) {
if (newvalue !== undefined) {
if (newvalue === 1 || newvalue === '1' || newvalue === true || newvalue === 'true')
this.value = 1;
else
this.value = 2;
}
valuedom.val(this.value);
if (opn.hasmore)
valnamedom.val(this.value == 1 ? opn.y : opn.n);
$5('.y', opn.dom).css({ opacity: this.value == 1 ? 1 : 0 });
$5('.n', opn.dom).css({ opacity: this.value == 1 ? 0 : 1 });
$5('i', opn.dom).css({ opacity: 1, background: thos.value == 1 ? 'var(--man5)' : 'var(--e-inputbg)', marginLeft: thos.value == 1 ? 'calc(' + opn.dom.width() + 'px - 2.1em)' : '0.2em' });
if (from && typeof (this.onchange) == 'function')
this.onchange({ name: opn.name, dom: opn.dom, from: from, value: this.value });
}
this.setvalue(opn.value, opn.initevent ? 'init' : '');
opn.dom.on('click', function () {
thos.value = (thos.value == 1 ? 2 : 1);
thos.setvalue(undefined, 'click');
});
}
ciycmpfunc.ciyradio = function (opn) {
var thos = this;
this.onchange = opn.onchange;
opn.initevent = opn.initevent || opn.dom.hasattr('initevent');
opn.hasmore = opn.hasmore || opn.dom.hasattr('hasmore');
opn.hasline = opn.hasline || opn.dom.hasattr('hasline');
opn.chkuse = opn.chkuse || opn.dom.hasattr('chkuse');
opn.all = opn.all || opn.dom.attr('all') || '';
opn.minwidth = opn.minwidth || opn.dom.attr('minwidth') || 'auto';
if (typeof (opn.fn_item) !== 'function')
opn.fn_item = function (range, thos) { return range.name; };
//opn.fn_item 定制显示项
var html = '';
html += '';
html += '';
if (opn.hasmore)
html += '';
opn.dom.html(html);
var valuedom = opn.dom.children(0);
var showdom = opn.dom.children(1);
var valnamedom = opn.dom.children(2);
this.setvalue = function (newvalue, from) {
if (this.range == null)
return console.error('ciy_radio range null', opn.name);
if (newvalue !== undefined) {
this.value = newvalue;
}
var html = '';
var selname = '';
for (var i in this.range) {
var range = this.range[i];
if (opn.chkuse && range.isuse == 2)
continue;
if (opn.filter && range[opn.filter.field] != opn.filter.value)
continue;
html += '
';
if (this.value == range.id) {
html += '';
selname = range.name;
}
else
html += '';
html += '' + opn.fn_item(range, thos) + '';
html += '
';
}
showdom.html(html);
valuedom.val(this.value);
if (opn.hasmore)
valnamedom.val(selname);
if (from && typeof (this.onchange) == 'function')
this.onchange({ name: opn.name, dom: opn.dom, from: from, value: this.value });
}
this.setrange = function (newrange) {
this.range = ciyfn.getdictdata(newrange);
if (this.range == null)
return console.error('ciy_radio range null', opn.name);
if (opn.all) {
this.range.unshift({ id: '', name: opn.all + '', _nofilter: true });
}
if (this.value !== undefined)
this.setvalue();
}
this.setrange(opn.range);
this.setvalue(opn.value, opn.initevent ? 'init' : '');
showdom.on('click', '.ciy-radio', function (e) {
thos.value = $5(e.currentTarget).attr('data-id') || '';
thos.setvalue(undefined, 'click');
});
}
ciycmpfunc.ciycheckbox = function (opn) {
var thos = this;
this.onchange = opn.onchange;
opn.initevent = opn.initevent || opn.dom.hasattr('initevent');
opn.hasmore = opn.hasmore || opn.dom.hasattr('hasmore');
opn.hasline = opn.hasline || opn.dom.hasattr('hasline');
opn.chkuse = opn.chkuse || opn.dom.hasattr('chkuse');
opn.range = opn.range || opn.dom.attr('range');
opn.minwidth = opn.minwidth || opn.dom.attr('minwidth') || '';
if (opn.dom.attr('text')) {
opn.range = [{ id: 'chk', name: opn.dom.attr('text') }];
}
if (typeof (opn.fn_item) !== 'function')
opn.fn_item = function (range, thos) { return range.name; };
var html = '';
html += '';
html += '';
if (opn.hasmore) {
html += '';
html += '';
html += '';
}
opn.dom.html(html);
var valuedom = opn.dom.children(0);
var showdom = opn.dom.children(1);
var nowvalue = [];
var clkvalue = '';
this.setvalue = function (newvalue, from) {
if (this.range == null)
return console.error('ciy_checkbox range null', opn.name);
if (newvalue !== undefined) {
if (newvalue == '__ALL__') {
for (var i in this.range) {
nowvalue.push(this.range[i].id);
}
} else {
var vals = (newvalue + '').split(',');
nowvalue = [];
for (var i in vals) {
if (!vals[i])
continue;
nowvalue.push(vals[i] + '');
}
}
var html = '';
var selnames = [];
for (var i in this.range) {
var range = this.range[i];
if (opn.chkuse && range.isuse == 2)
continue;
if (opn.filter && range[opn.filter.field] != opn.filter.value)
continue;
html += '
';
if (nowvalue.indexOf(range.id + '') > -1) {
html += '';
selnames.push(range.name);
} else
html += '';
html += '' + opn.fn_item(range, thos) + '';
html += '
';
}
showdom.html(html);
}
var itemdoms = showdom.children();
for (var i = 0; i < itemdoms.length; i++) {
var chkdom = $5(itemdoms[i]);
var id = chkdom.attr('data-id');
var idom = $5('i', chkdom);
if (idom.hasClass('checked')) {
if (nowvalue.indexOf(id) == -1)
idom.removeClass('checked').css({ background: 'var(--e-inputbg)', border: '0.2em solid var(--e-inputbg)', animation: null });
} else {
if (nowvalue.indexOf(id) > -1)
idom.addClass('checked').css({ background: 'var(--man5)', border: '0.2em solid var(--e-inputbr)', animation: 'ciy-scale 0.2s' });
}
}
this.value = nowvalue.length > 0 ? ',' + nowvalue.join(',') + ',' : '';
valuedom.val(this.value); //两边加逗号,便于字符串like检索。但规模化后应避免like检索。
if (opn.hasmore) {
var selnames = [];
var selnoid = [];
var selnonames = [];
for (var i = 0; i < itemdoms.length; i++) {
var id = itemdoms[i].getAttribute('data-id');
var range = null;
for (var ri in this.range) {
if (this.range[ri].id == id)
range = this.range[ri];
}
if (range == null)
continue;
if (nowvalue.indexOf(id) > -1)
selnames.push(range.name);
else {
selnoid.push(range.id);
selnonames.push(range.name);
}
}
opn.dom.children(2).val(selnames.join(','));
opn.dom.children(3).val(selnoid.join(','));
opn.dom.children(4).val(selnonames.join(','));
}
if (from && typeof (this.onchange) == 'function')
this.onchange({ name: opn.name, dom: opn.dom, from: from, value: this.value });
}
this.setrange = function (newrange) {
this.range = ciyfn.getdictdata(newrange);
if (this.range == null)
return console.error('ciy_checkbox range null', opn.name);
if (this.value !== undefined)
this.setvalue();
}
this.setrange(opn.range);
this.setvalue(opn.value, opn.initevent ? 'init' : '');
showdom.on('click', '.ciy-checkbox', function (e) {
clkvalue = $5(e.currentTarget).attr('data-id') || '';
var ind = nowvalue.indexOf(clkvalue);
if (ind > -1)
nowvalue.splice(ind, 1);
else
nowvalue.push(clkvalue);
thos.setvalue(undefined, 'click');
if (typeof (opn.fn_click) == 'function')
opn.fn_click({ name: opn.name, value: clkvalue });
});
}
ciycmpfunc.ciyselect = function (opn) {
var thos = this;
this.onchange = opn.onchange;
opn.initevent = opn.initevent || opn.dom.hasattr('initevent');
opn.hasmore = opn.hasmore || opn.dom.hasattr('hasmore');
opn.chkuse = opn.chkuse || opn.dom.hasattr('chkuse');
opn.minsearch = toint(opn.minsearch || opn.dom.attr('minsearch') || 0);
opn.all = opn.all || opn.dom.attr('all') || '';
opn.range = opn.range || opn.dom.attr('range');
opn.minwidth = opn.minwidth || opn.dom.attr('minwidth') || '';
opn.placeholder = ciyfn.lang(opn.placeholder || opn.dom.attr('placeholder') || '请选择');
if (typeof (opn.fn_li) != 'function')
opn.fn_li = function (range, thos) { return ciyfn.lang(range.name) };
var csstxt = '';
csstxt += 'ciy-select{display: block;user-select:none;}';
csstxt += 'ciy-select.mini{display: inline-block;}';
csstxt += 'ciy-select>._show{display: flex;align-items: center;position: relative;height: 2.1em;line-height: 2.1em;vertical-align: top;width: 100%;cursor: pointer;min-height: 2.4em;color: var(--txt8);background-color: var(--bg1);border: 1px solid var(--bg6);border-radius: 4px;}';
csstxt += 'ciy-select>._show>i{width: 1em;height: 1em;margin-right:0.5em;background-image: url("data:image/svg+xml;base64,PHN2ZyB2aWV3Qm94PSIwIDAgMTAyNCAxMDI0IiB2ZXJzaW9uPSIxLjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+PHBhdGggZD0iTTExNC4wNDg0OTkgNTk2LjkyNDE4MWwzMzcuNTI2MjkzIDMzNy41MjYyOTNjMzMuMzcwMDE1IDMzLjM3MDAxNSA4Ny40NzkzNzcgMzMuMzcwMDE1IDEyMC44NDkzOTIgMGwzMzcuNTI2MjkzLTMzNy41MjYyOTNMMTE0LjA0ODQ5OSA1OTYuOTI0MTgxek01NzIuNDI0MTg0IDg4LjQ5NzU2N2MtMzMuMzcwMDE1LTMzLjM3MDAxNS04Ny40NzkzNzctMzMuMzcwMDE1LTEyMC44NDkzOTIgMEwxMTQuMDU2Njg2IDQyNi4wMjQ4ODNsNzk1Ljg4NTYwNiAwTDU3Mi40MjQxODQgODguNDk3NTY3eiIgZmlsbD0iIzc3Nzc3NyI+PC9wYXRoPjwvc3ZnPg==");}';
csstxt += 'ciy-select>._pullul{position: fixed;top: 0;left: 0;right: 0;bottom: 0;display:none;z-index:100000;}';
csstxt += 'ciy-select>._pullul>ul{display: inline-flex;height: auto;flex-direction: column;position: fixed;overflow: auto;background:var(--bg1);box-shadow: rgb(204 204 204) 1px 1px 2px;border-radius: 5px;}';
csstxt += 'ciy-select>._pullul input{position: fixed;border-radius: 3px;line-height:1.5em;padding-left:0.5em;border:1px solid var(--bg4);border-radius:0;}';
csstxt += 'ciy-select>._pullul input:focus{box-shadow:none;border:1px solid var(--bg4);}';
csstxt += 'ciy-select>._pullul input::placeholder{color:var(--bg4);}';
csstxt += 'ciy-select>._pullul>ul>li{white-space: nowrap;line-height:1.3em;padding:0.5em 1em;border-left: 4px solid var(--bg1);background:var(--bg1);color:var(--txt9);cursor:pointer;}';
csstxt += 'ciy-select>._pullul>ul>li.selected{background:var(--bg3);border-left: 4px solid var(--man4);}';
csstxt += 'ciy-select>._pullul>ul>li:hover{background:var(--bg5);border-left: 4px solid var(--bg4);}';
opn.dom.setstyle('ciy_select', csstxt);
var html = '';
html += '';
html += '
';
html += '
';
html += '';
html += '
';
html += '
';
if (opn.hasmore && opn.name)
html += '';
opn.dom.html(html);
if (opn.minwidth)
opn.dom.addClass('mini');
var valuedom = opn.dom.children(0);
var showmaindom = opn.dom.children(1);
var showdom = showmaindom.children(0);
var ulpdom = opn.dom.children(2);
var searchdom = ulpdom.children(0);
var uldom = ulpdom.children(1);
var valnamedom = opn.dom.children(3);
var lishow = false;
this.setvalue = function (newvalue, from) {
if (this.range == null)
return console.error('ciy_select range null', opn.name);
if (newvalue !== undefined) {
this.value = newvalue;
}
var range = null;
for (var i in this.range) {
if (this.value == this.range[i].id) {
range = this.range[i];
break;
}
}
if (range != null) {
showdom.html(range.name);
showdom.attr('title', range.name);
valuedom.val(range.id);
valnamedom.val(range.name);
} else {
showdom.html('' + opn.placeholder + '');
showdom.attr('title', '');
valuedom.val('');
valnamedom.val('');
}
if (from && typeof (this.onchange) == 'function')
this.onchange({ name: opn.name, dom: opn.dom, from: from, value: this.value });
}
this.setrange = function (newrange, badd) {
var ranges = ciyfn.getdictdata(newrange);
if (ranges == null)
return console.error('ciy_select range null', opn.name);
if (!badd)
this.range = [];
for (var i in ranges) {
if (opn.chkuse && ranges[i].isuse == 2)
continue;
if (!ranges[i]._nofilter && opn.filter && ranges[i][opn.filter.field] != opn.filter.value)
continue;
ranges[i].name = ranges[i].name + '';
this.range.push(ranges[i]);
}
if (opn.first && typeof (opn.first) == 'object') {
opn.first._nofilter = true;
this.range.unshift(opn.first);
}
if (opn.all) {
this.range.unshift({ id: '', name: opn.all + '', _nofilter: true });
}
if (ciyfn.topinyin) {
for (var i in this.range)
this.range[i]._py = ciyfn.topinyin(this.range[i].name);
}
if (this.value !== undefined)
this.setvalue();
}
this.setrange(opn.range);
this.setvalue(opn.value, opn.initevent ? 'init' : '');
showmaindom.on('click', function (e) {
searchdom.val('');
thos.showoption();
searchdom[0].focus();
});
searchdom.on('keydown', function (e) {
if (e.keyCode != 13) return;
e.preventDefault();
if (uldom.children().length == 1)
selectli(uldom.children(0));
return false;
});
searchdom.on('keyup', function (e) {
if (e.keyCode == 13) return;
thos.showoption();
});
uldom.on('click', function (e) {
if (e.target.tagName !== 'LI') return;
selectli(e.target);
});
ulpdom.on('click', function (e) {
thos.hideoption();
});
function selectli(lidom) {
thos.value = $5(lidom).attr('data-id') || '';
thos.hideoption();
thos.setvalue(undefined, 'select');
}
function panelrect() {
var pos = showmaindom.rect();
var ulwidth = uldom.rect().width;
var ulheight = 2;
for (var i = 0; i < uldom.children().length; i++) {
ulheight += uldom.children(i).rect().height;
}
var twidth = showmaindom.rect().width;
var gulwidth = Math.max(145, ulwidth, twidth);
var lef = pos.left;
var lefw = $5(opn.dom).winwidth() - lef - 5;
if (gulwidth > lefw)
lef -= gulwidth - lefw;
if (lef <= 0)
lef = 0;
uldom.css({ left: lef + 'px', width: gulwidth + 'px' });
searchdom.css({ left: lef + 'px', width: gulwidth + 'px' });
var searchheight = 0;
if (thos.range.length > opn.minsearch) {
searchheight = searchdom.rect().height;
searchdom.css({ display: 'block' });
searchdom[0].focus();
} else {
searchdom.css({ display: 'none' });
}
if (window.innerHeight * 0.6 > (pos.top)) {
// 下方显示
var hei = pos.top + showmaindom.rect().height;
if (hei < 0)
hei = 0;
if (searchheight > 0)
searchdom.css({ top: hei + 'px' });
uldom.css({ top: (hei + searchheight) + 'px' });
hei = window.innerHeight - hei - 20 - searchheight;
uldom.css({ height: (ulheight > hei ? hei : ulheight) + 'px', flexDirection: 'column' });
} else {
// 上方显示
var hei = pos.top;
if (searchheight > 0)
searchdom.css({ top: (hei - searchheight - 3) + 'px' });
uldom.css({ flexDirection: 'column-reverse' });
if (ulheight > hei) {
uldom.css({ top: '3px', height: (hei - searchheight - 6) + 'px' });
} else {
uldom.css({ top: (hei - ulheight - searchheight - 3) + 'px', height: ulheight + 'px' });
}
}
ulpdom.css({ display: 'block', opacity: 1 });
}
this.hideoption = function () {
if (!lishow)
return;
window.removeEventListener('scroll', thos.hideoption);
lishow = false;
ulpdom.aniout('translateY(30px)', 0.2);
}
this.showoption = function () {
var keystr = searchdom.val();
var html = '';
var id = valuedom.val();
for (var i in thos.range) {
if ((thos.range[i].name.toUpperCase().indexOf(keystr.toUpperCase()) == -1) && (tostr(thos.range[i]._py).indexOf(keystr.toUpperCase()) == -1))
continue;
html += '
';
html += opn.fn_li(thos.range[i], thos);
html += '
';
}
uldom.html(html);
if (!lishow) {
lishow = true;
ulpdom.css({ opacity: 0, display: 'block' });
window.addEventListener('scroll', thos.hideoption);
}
panelrect();
}
}
ciycmpfunc.ciyinputbet = function (opn) {
var thos = this;
this.onchange = opn.onchange;
opn.initevent = opn.initevent || opn.dom.hasattr('initevent');
opn.hasmore = opn.hasmore || opn.dom.hasattr('hasmore');
opn.inpstyle = opn.inpstyle || opn.dom.attr('inpstyle') || '';
opn.bets = ciyfn.split(opn.bet || opn.dom.attr('bet'), '.');
opn.units = ciyfn.split(opn.unit || opn.dom.attr('unit'), '.');
if (opn.bets.length < opn.units.length)
opn.units.splice(opn.bets.length);
if (opn.bets.length > opn.units.length)
opn.bets.splice(opn.units.length);
if (opn.bets.length == 0) {
opn.bets = [1];
opn.units = [''];
}
opn.betidx = 0;
for (var i = 0; i < opn.bets.length; i++) {
opn.bets[i] = toint(opn.bets[i]);
if (opn.bets[i] < 1)
opn.bets[i] = 1;
if (opn.units[i].substring(0, 1) == '*') {
opn.betidx = i;
opn.units[i] = opn.units[i].substring(1);
}
}
opn.width = opn.width || opn.dom.attr('width') || '6em';
opn.align = opn.align || opn.dom.attr('align') || 'right';
var html = '';
html += '';
html += '';
if (opn.hasmore)
html += '';
if (opn.units.length > 1)
html += '';
if (opn.units.length == 1)
html += '' + opn.units[0] + '';
opn.dom.html(html).css({ display: 'inline-flex', alignItems: 'center' });
if (opn.units.length > 1) {
var ranges = [];
for (var i = 0; i < opn.units.length; i++)
ranges.push({ id: i, name: opn.units[i] });
ciycmp({
dom: $5('ciy-select', opn.dom), range: ranges, onchange: function (e) {
opn.betidx = toint(e.value);
thos.value = tofloat(showinpdom.val()) * opn.bets[opn.betidx];
thos.setvalue(undefined, 'unit');
}
});
}
var valuedom = opn.dom.children(0);
var showinpdom = opn.dom.children(1);
var showinpunitdom = null;
if (opn.hasmore)
showinpunitdom = opn.dom.children(2);
this.setvalue = function (newvalue, from) {
if (newvalue !== undefined) {
this.value = toint(newvalue);
for (var i = opn.bets.length - 1; i >= 0; i--) {
if (this.value / opn.bets[i] >= 0.1) {
if ((opn.bets[i] >= 1000 && this.value % parseInt(opn.bets[i] / 1000) == 0) || i < opn.betidx) {
opn.betidx = i;
break;
}
}
if (this.value != 0 && this.value % opn.bets[i] == 0) {
opn.betidx = i;
break;
}
}
$5('ciy-select', opn.dom).val(opn.betidx);
if (newvalue !== '')
showinpdom.val(this.value * 1.0 / opn.bets[opn.betidx]);
else
showinpdom.val('');
}
if (showinpunitdom)
showinpunitdom.val(opn.units[opn.betidx]);
valuedom.val(this.value);
if (from && typeof (this.onchange) == 'function')
this.onchange({ name: opn.name, dom: opn.dom, from: from, value: this.value });
}
this.setvalue(opn.value, opn.initevent ? 'init' : '');
showinpdom.on('keyup', function () {
thos.value = tofloat(showinpdom.val()) * opn.bets[opn.betidx];
thos.setvalue(undefined, 'keyup');
});
}
ciycmpfunc.ciyupload = function (opn) { // v2
var thos = this;
this.onchange = opn.onchange;
opn.initevent = opn.initevent || opn.dom.hasattr('initevent');
opn.hasmore = opn.hasmore || opn.dom.hasattr('hasmore');
opn.stor = opn.stor || opn.dom.attr('stor') || ciy_vars.storselect;
opn.num = toint(opn.num || opn.dom.attr('num') || 1);
if (opn.num < 1)
opn.num = 1;
opn.type = opn.type || opn.dom.attr('type');
if (opn.type)
opn.type = opn.type.toUpperCase().split(',');
opn.imgwidth = toint(opn.imgwidth || opn.dom.attr('imgwidth'));
opn.imgheight = toint(opn.imgheight || opn.dom.attr('imgheight'));
opn.maxsize = toint(opn.maxsize || opn.dom.attr('maxsize'));
opn.zipjpg = toint(opn.zipjpg || opn.dom.attr('zipjpg'));
opn.zipext = opn.zipext || opn.dom.attr('zipext') || 'jpg,png,webp';
if (opn.zipext)
opn.zipext = opn.zipext.toUpperCase().split(',');
opn.waterfont = opn.waterfont || opn.dom.attr('waterfont') || '28px Arial';
opn.watertext = opn.watertext || opn.dom.attr('watertext') || '';
//opn.fn_imgdraw 图片绘制回调
opn.showwh = opn.showwh || opn.dom.attr('showwh') || '100px'; //显示宽高
opn.action = opn.action || opn.dom.attr('action');
if (!opn.action) {
opn.action = "/z/?func=" + ciy_vars.uploadurl;
}
var now = new Date();
opn.path = opn.path || opn.dom.attr('path') || 'nopath';
opn.path = opn.path.replace('{Y}', now.getFullYear()).replace('{m}', ciyfn.topad0(now.getMonth() + 1)).replace('{d}', ciyfn.topad0(now.getDate()));
opn.valname = opn.valname || opn.dom.attr('valname') || '';
var csstxt = '';
csstxt += 'ciy-upload{display:flex;align-items:center}';
csstxt += '.ciy-upload>div>.item,.ciy-upload>div>.add{display:flex;justify-content: center;align-items: center;background:var(--bg1);margin: 0 0.3em 0.3em 0;position:relative;border-radius:0.5em;background-size:contain;background-position:center center;background-repeat:no-repeat;border:1px solid var(--bg6);overflow:hidden;}';
csstxt += '.ciy-upload>div>.add>svg{width: 50%;opacity:0.6;transition:all .3s;}';
csstxt += '.ciy-upload>div>.add .progress{position: absolute;bottom: 0;right: 0;left: 0;height: 0%;background: #71c0e9;}';
csstxt += '.ciy-upload>div>.item a{color:#00000055;white-space: nowrap;}';
csstxt += '.ciy-upload>div>.item i{cursor:pointer;position: absolute;top: 0;right: 0;width: 1.2em;height: 1.2em;background-image: url("data:image/svg+xml;base64,PHN2ZyB2aWV3Qm94PSIwIDAgMTAyNCAxMDI0IiB2ZXJzaW9uPSIxLjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+PHBhdGggZD0iTTUxMiAwQzIyNy44NCAwIDAgMjI3Ljg0IDAgNTEyczIyNy44NCA1MTIgNTEyIDUxMmMyODQuMDk2IDAgNTEyLTIyNy44NCA1MTItNTEyUzc5Ni4wOTYgMCA1MTIgMEw1MTIgMHpNNzY4IDY5Ni4zMiA2OTYuMjU2IDc2OCA1MTIgNTgzLjY4IDMyNy42MTYgNzY4IDI1NiA2OTYuMzIgNDQwLjI1NiA1MTIgMjU2IDMyNy42OCAzMjcuNjE2IDI1NiA1MTIgNDQwLjMyIDY5Ni4yNTYgMjU2IDc2OCAzMjcuNjggNTgzLjYxNiA1MTIgNzY4IDY5Ni4zMiA3NjggNjk2LjMyek03NjggNjk2LjMyIiBmaWxsPSIjZDgxZTA2Ij48L3BhdGg+PC9zdmc+");}';
opn.dom.setstyle('ciy_upload', csstxt);
function upfiles(files) {
var progressdom = $5('.add .progress', showuploaddom);
ciyfn.file_uploads(opn.num - nowvalue.length, files, opn, {
success: function (url, file) {
progressdom.css({ height: '0%' });
nowvalue.push(url);
nowvalname.push(file.name);
thos.setvalue(undefined, 'add.' + opn.stor);
}
, fail: function (err) {
progressdom.css({ height: '0%' });
ciyfn.alert(err.errmsg);
}
, progress: function (pct) {
progressdom.css({ height: pct + "%" });
}
});
}
var html = '';
html += '';
html += '
';
html += ' 1 ? ' multiple' : '') + ' />';
if (opn.hasmore)
html += '';
opn.dom.html(html);
var valuedom = opn.dom.children(0);
var showpdom = opn.dom.children(1);
var showuploaddom = showpdom.children(0);
var filedom = opn.dom.children(2);
var valnamedom = opn.dom.children(3);
this.setvalue = function (newvalue, from) {
if (newvalue !== undefined) {
var vals = newvalue.split("~");
var valnames = [];
if (from == 'init')
valnames = opn.valname.split("~");
nowvalue = [];
nowvalname = [];
for (var i = 0; i < opn.num; i++) {
if (!vals[i])
continue;
nowvalue.push(vals[i]);
nowvalname.push(valnames[i] ? valnames[i] : '');
}
}
var html = '';
for (var x in nowvalue) {
var val = nowvalue[x];
var realval = ciyfn.file_stor(val);
var ext = ciyfn.file_ext(val);
html += '
';
if (ciyfn.isimg(ext)) {
html += '' + ext + '';
} else {
html += '' + ext + '';
}
html += '
';
}
if (nowvalue.length < opn.num) {
var tip = '';
if (opn.num > 1) {
tip += '最多上传' + opn.num + '个\n';
tip += '还能上传' + (opn.num - nowvalue.length) + '个\n';
}
if (opn.type)
tip += '可上传' + opn.type.join(',') + '\n';
html += '
';
}
showuploaddom.html(html);
this.value = nowvalue.join('~');
valuedom.val(this.value);
valnamedom.val(nowvalname.join('~'));
if (from == 'init' && !opn.initevent)
return;
if (typeof (this.onchange) == 'function')
this.onchange({ name: opn.name, dom: opn.dom, from: from, value: this.value });
}
var nowvalue = [];
var nowvalname = [];
this.setvalue(opn.value, 'init');
var enablepaste = false;
showuploaddom.on('click', 'i', function (e) {
var idx = toint($5(e.currentTarget).attr('data-idx'));
nowvalue.splice(idx, 1);
nowvalname.splice(idx, 1);
thos.setvalue(undefined, 'delete');
});
showuploaddom.on('click', '.add', function () {
filedom.trigger('click');
});
filedom.on('change', function (e) {
upfiles(e.currentTarget.files);
});
showuploaddom.on('mouseenter', function (e) {
enablepaste = true;
$5('.add>svg', showuploaddom).css({ opacity: 1 });
window.focus();
});
showuploaddom.on('mouseleave', function (e) {
enablepaste = false;
$5('.add>svg', showuploaddom).css({ opacity: 0.6 });
});
showuploaddom.on('dragover', function (e) {
e.preventDefault();
});
opn.dom.on('drop', function (e) {
e.preventDefault();
upfiles(e.dataTransfer.files);
});
$5(document).on('paste', function (e) {
if (!enablepaste)
return;
if (!e.clipboardData)
return console.warn('Cannot support clipboard pasting');
if (!e.clipboardData.items)
return console.warn('Paste clipboard without item');
var len = e.clipboardData.items.length;
var files = [];
for (var i = 0; i < len; i++) {
if (e.clipboardData.items[i].type.indexOf("image") == -1)
continue;
var blob = e.clipboardData.items[i].getAsFile();
files.push(blob);
}
upfiles(files);
});
}
ciycmpfunc.ciytextarea = function (opn) {
var thos = this;
this.onchange = opn.onchange;
opn.initevent = opn.initevent || opn.dom.hasattr('initevent');
opn.inpstyle = opn.inpstyle || opn.dom.attr('inpstyle') || '';
opn.total = opn.total || opn.dom.attr('total') || '';
opn.tab = opn.tab || opn.dom.attr('tab') || ' ';
opn.autoheight = opn.autoheight || opn.dom.hasattr('autoheight') || false;
opn.minheight = opn.minheight || opn.dom.attr('minheight') || '5em';
var html = '';
html += '';
html += '';
opn.dom.html(html);
var valuedom = opn.dom.children(0);
var showtotaldom = opn.dom.children(1);
this.autoheight = function () {
if (!opn.autoheight)
return;
valuedom[0].style.overflow = 'hidden';
valuedom[0].style.resize = 'none';
valuedom[0].style.height = 'auto';
valuedom[0].style.height = valuedom[0].scrollHeight + 'px';
}
this.setvalue = function (newvalue, from) {
if (newvalue !== undefined) {
this.value = newvalue + '';
valuedom.val(this.value);
}
thos.autoheight();
var totaltxt = tostr(opn.total).replace('{word}', this.value.length).replace('{line}', this.value.split('\n').length);
if (totaltxt)
showtotaldom.show().html(totaltxt);
else
showtotaldom.hide();
if (from && typeof (this.onchange) == 'function')
this.onchange({ name: opn.name, dom: opn.dom, from: from, value: this.value });
}
this.setvalue(opn.value, opn.initevent ? 'init' : '');
valuedom.on('keyup', function (e) {
thos.value = valuedom.val();
thos.setvalue(undefined, 'keyup');
if (e.key == "@") {
if (typeof (opn.popfn) == 'function') {
opn.popfn(e);
}
}
});
valuedom.on('keydown', function (e) {
if (e.keyCode == 9 && opn.tab) {
e.preventDefault();
var indent = opn.tab;
if (e.shiftKey) {
var start = valuedom[0].selectionStart;
var end = valuedom[0].selectionEnd;
var selected = window.getSelection().toString();
var lines = selected.split('\n');
var newlines = [];
for (var i = 0; i < lines.length; i++) {
var line = lines[i];
if (line.length >= indent.length && line.substring(0, indent.length) == indent)
line = line.substring(indent.length);
newlines.push(line);
}
selected = newlines.join('\n');
valuedom.val(valuedom.val().substring(0, start) + selected + valuedom.val().substring(end));
valuedom[0].setSelectionRange(start, start + selected.length);
thos.autoheight();
} else {
var val = valuedom.val();
var start = valuedom[0].selectionStart;
var end = valuedom[0].selectionEnd;
var selected = window.getSelection().toString();
if (start != end && val[end - 1] == '\n') {
end--;
selected = selected.substring(0, selected.length - 1);
}
selected = indent + selected.replace(/\n/g, '\n' + indent);
valuedom.val(val.substring(0, start) + selected + val.substring(end));
if (start == end)
valuedom[0].selectionStart = valuedom[0].selectionEnd = start + selected.length;
else
valuedom[0].setSelectionRange(start, start + selected.length);
thos.autoheight();
}
}
if (e.keyCode == 13) {
//自动给组件增加高度,自适应高度
// setTimeout(function () {
// valuedom.css('height', height + 10);
// }, 100);
var currpos = valuedom[0].selectionStart;
var val = valuedom.val();
var line = val.substring(val.lastIndexOf('\n', currpos - 1) + 1, currpos);
if (line.length == 0)
return;
var space = '';
var spaces = 0;
while (line[spaces] == ' ' || line[spaces] == '\t') {
space += line[spaces];
spaces++;
}
if (spaces == 0)
return;
e.preventDefault();
valuedom.val(val.substring(0, currpos) + '\n' + space + val.substring(currpos));
var newpos = currpos + 1 + space.length;
valuedom[0].setSelectionRange(newpos, newpos);
thos.autoheight();
}
});
}
function ciycmp(opn) {
opn.dom = $5(opn.dom);
if (opn.dom.length == 0)
return;
opn.value = opn.value || opn.dom.attr('value') || '';
opn.name = opn.name || opn.dom.attr('com') || '';
var node = opn.dom.node().replace('ciy-', 'ciy');
if (!ciycmpfunc[node]) {
console.warn(node + '组件不存在');
return null;
}
var cths = new ciycmpfunc[node](opn);
if (!cths) {
console.warn(node + '组件初始化失败');
return null;
}
opn.dom[0].ciycmp = cths;
return cths;
}
/*
*****ciycmp.js*****
datetime 时间日期选择器
daterange 日期范围选择器
switch 开关
radio 单选
checkbox 复选
select 下拉选择,带搜索
upload 上传文件,拖入文件/粘贴截图/水印图/压缩缩小图
textarea 多行文本框,带统计、tab加空格、首行自动加空格
*****ciycmp2.js*****
selcas 联级select
selmulti 下拉多选,带搜索
inputbet 倍数数字输入
inputunitedit 三级单位
inputcyc 时间周期
md 简化Markdown编辑器
map 弹出地图选择经纬度
https://element-plus.org/zh-CN/component/overview.html
参考element及其他前端库样式。
原生实现,不依赖vue等第三方。
slider 滑块(表单)
aninum 动态数值动效
inputnumber 计数器(表单)
rate 评分(表单)
inputcolor 颜色选择器(表单)
notify 通知叠加
steps 步骤
swiper 轮播
timeline 时间线
drawer 侧边抽屉
calendar 日历显示
calwork 日历工作分布
seltransfer 穿梭框(表单) 重写
skeleton 骨架
seltree 树形选择(表单)
selmultitree 多选树形选择(表单)
selcas2 箭头式联级选择(表单)
*/