c5_labsci/web/jscss/ciytable.js
2026-01-27 00:52:00 +08:00

1759 lines
75 KiB
JavaScript
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
* Author: 众产® https://ciy.cn/code
* Version: 0.2.0
*/
//卡片列表 类库
ciyclass.cardtable = function (opn) {
this.dom = $5(opn.dom);
if (this.dom.length == 0)
return ciyfn.alert('未找到容器');
this.listdom = $5('ul.list', this.dom);
if (this.listdom.length == 0)
return ciyfn.alert('未找到ul.list容器');
var _pagedom = $5('.page', this.dom);
var thos = this;
this.cachecount = -1; //缓存总条数
this.pathname = opn.pathname || location.pathname.replace(".html", "");
this.data = {}; //id为索引的object
var localset = ciyfn.getstorage('_t_' + this.pathname, {});
this.pageno = 1;
this.nodatatext = opn.nodatatext || '暂无数据';
if (opn.url === undefined)
return this.showtip('数据源URL未设置');
this.post = {};
this.post.once = true;
this.post.pagecount = localset.pagecount || opn.pagecount || 12;
this.post.query = ciyfn.urlparam();
if (opn.query)
this.post.query = Object.assign(this.post.query, opn.query);
if (opn.post)
this.post = Object.assign(this.post, opn.post);
ciyfn._table_eventpage(_pagedom, this);
ciyfn._table_dragitem(this.dom, opn);
this.listdom.on('scroll', function () {
ciyfn.lazyimg();
});
this.callpage = function (page, scroll) {
if (page === undefined)
page = this.pageno;
this.post.pageno = toint(page, 1);
if (this.post.pageno < 1)
return;
this.pageno = this.post.pageno;
this.post.count = this.cachecount;
ciyfn.callfunc(opn.url, this.post, function (json) {
thos.post.once = false;
thos.json = ciyfn.objdeepmerge(thos.json, json);
if (json.once)
thos.once = json.once;
if (typeof (opn.fn_beforedata) == 'function')
json = opn.fn_beforedata(json);
if (json.count > -1)
thos.cachecount = json.count;
else if (thos.cachecount > -1)
json.count = thos.cachecount;
var html = '';
for (var i = 0; i < json.list.length; i++) {
var ldat = json.list[i];
thos.data[ldat['id']] = ldat;
html += opn.fn_lihtml(ldat, i);
}
if (json.list.length == 0 && toint(json.pageno) <= 1)
html += '<li data-none class="col-24" style="text-align:center;padding:0.5em;line-height:5em;">' + ciyfn.lang(thos.nodatatext) + '</li>';
thos.listdom.html(html).show();
if (scroll)
thos.listdom.scroll({ top: 0 });
$5('.loading', thos.dom).remove();
if (typeof (opn.fn_done) == 'function')
opn.fn_done(json, thos.post);
ciyfn.lazyimg();
ciyfn.domlang();
ciyfn._table_fillpage(_pagedom, json, false);
});
}
this.updateline = function (json, newdata) {
if (!json.data)
return;
var ids = json.ids;
if (!ids)
ids = [json.data.id];
var newdata = ciyfn.objclone(json.data);
delete json.data;
this.json = ciyfn.objdeepmerge(this.json, json);
for (var i = 0; i < ids.length; i++) {
var id = ids[i];
if (id == 0)
return;
this.data[id] = ciyfn.objdeepmerge(this.data[id], newdata);
this.data[id].id = id;
var htmltr = opn.fn_lihtml(this.data[id]);
var tr = $5('[data-id="' + id + '"]', this._tabdom);
if (tr.length > 0)
tr.outhtml(htmltr);
else {
$5('ul.list', this._tabdom).prepend(htmltr);
this.rowtotal(1);
$5('[data-none]', this._tabdom).remove();
}
}
if (typeof (opn.fn_done) == 'function')
opn.fn_done(this.json, this.post);
}
this.delline = function (json) {
if (!json.ids)
return;
var rowcnt = 0;
for (var i = 0; i < json.ids.length; i++) {
var id = json.ids[i];
if (this.data[id]) {
delete this.data[id];
var tr = $5('[data-id="' + id + '"]', this._tabdom);
if (tr.length > 0) {
rowcnt--;
tr.remove();
}
}
}
var tr = $5('[data-id]', this._tabdom);
if (tr.length == 0) {
this.cachecount = -1;
this.callpage();
}
else
this.rowtotal(rowcnt);
}
this.rowtotal = function (num) {
num = toint(num);
if (!num)
return;
var rowdom = $5('#id_rowtotal', this.dom);
rowdom.text(toint(rowdom.text()) + num);
}
//供页面搜索组件调用
this.search = function (dom, act) {
var form = ciyfn.getform(dom);
thos.post.query = form;
if (act == 'li')
thos.post.query.liid = dom.getAttribute('data-liid');
else {
var domli = dom.querySelector('li.active[data-liid]');
if (domli !== null)
thos.post.query.liid = domli.getAttribute('data-liid');
}
if (ciyfn.throttle(dom)) return;
thos.cachecount = -1;
thos.callpage(1);
}
}
//表格列表 类库
ciyclass.table = function (opn) {
this.dom = $5(opn.dom);
if (this.dom.length == 0)
return ciyfn.alert('未找到容器');
this.listdom = $5('div.list', this.dom);
if (this.listdom.length == 0)
return ciyfn.alert('未找到div.list容器');
this.pathname = opn.pathname || location.pathname.replace(".html", "");
var localset = ciyfn.getstorage('_t_' + this.pathname, {});
opn.btncolumnset = opn.btncolumnset || 1;
opn.nodatatext = opn.nodatatext || '暂无数据';
opn.domid = 'table_' + Math.floor(Math.random() * 1000);
this.dom.attr('id', opn.domid);
var _pagedom = $5('.page', this.dom);
var thos = this;
this._tabdom = null;//table dom
this.field = {}; //字段属性
this.sortfield = []; //字段列排序
this.pageno = 1;
this.cachecount = -1; //缓存总条数
this.data = {}; //id为索引的object
this.post = {};
this.post.once = true;
this.post.pagecount = localset.pagecount || opn.pagecount || 20;
this.post.query = ciyfn.urlparam();
if (opn.query)
this.post.query = Object.assign(this.post.query, opn.query);
if (opn.post)
this.post = Object.assign(this.post, opn.post);
var dataready = true;
ciyfn._table_eventpage(_pagedom, this);
this.listdom.on('scroll', function () {
ciyfn.lazyimg();
});
this.callpage = function (page, scroll) {
if (!dataready)
return ciyfn.toast('数据处理中,请稍后操作');
if (opn.url === undefined)
return ciyfn.toast('数据源URL未设置');
if (page === undefined)
page = this.pageno;
this.post.pageno = toint(page, 1);
if (this.post.pageno < 1)
return;
this.pageno = this.post.pageno;
this.post.count = this.cachecount;
this.post.field = toint(this.dom.attr('_field')) == 0;
ciyfn.callfunc(opn.url, this.post, function (json) {
if (typeof (opn.fn_beforedata) == 'function')
json = opn.fn_beforedata(json);
thos.post.once = false;
if (json.once)
thos.once = json.once;
thos.json = ciyfn.objdeepmerge(thos.json, json);
if (json.count > -1)
thos.cachecount = json.count;
else if (thos.cachecount > -1)
json.count = thos.cachecount;
thos.filldata(json, scroll);
});
}
this.updateline = function (json) {
if (!json.data)
return;
var ids = json.ids;
if (!ids)
ids = [json.data.id];
var newdata = ciyfn.objclone(json.data);
delete json.data;
this.json = ciyfn.objdeepmerge(this.json, json);
for (var i = 0; i < ids.length; i++) {
var id = ids[i];
if (id == 0)
return;
this.data[id] = ciyfn.objdeepmerge(this.data[id], newdata);
this.data[id].id = id;
var htmltr = this.tabletr_html(this.data[id]);
var tr = $5('[data-id="' + id + '"]', this._tabdom);
if (tr.length > 0)
tr.html(htmltr);
else {
$5('[data-field]', this._tabdom).after(htmltr);
this.rowtotal(1);
$5('[data-none]', this._tabdom).remove();
}
}
if (typeof (opn.fn_done) == 'function')
opn.fn_done(this.json, this.post);
}
this.delline = function (json) {
if (!json.ids)
return;
var rowcnt = 0;
for (var i = 0; i < json.ids.length; i++) {
var id = json.ids[i];
if (this.data[id]) {
delete this.data[id];
var tr = $5('[data-id="' + id + '"]', this._tabdom);
if (tr.length > 0) {
rowcnt--;
tr.remove();
}
}
}
var tr = $5('[data-id]', this._tabdom);
if (tr.length == 0) {
this.cachecount = -1;
this.callpage();
} else
this.rowtotal(rowcnt);
}
this.rowtotal = function (num) {
num = toint(num);
if (!num)
return;
var rowdom = $5('#id_rowtotal', this.dom);
rowdom.text(toint(rowdom.text()) + num);
}
this.filldata = function (json, scroll) {
var html;
if (json.field) {
this.field = json.field;
this.dom.attr('_field', 1);
var index = 0;
thos.sortfield = [];
var sortfields = localset.thsort || json.fshow;
if (sortfields) {
thos.sortfield = sortfields.split(',');
} else {
for (var key in thos.field) {
thos.sortfield.push(key);
}
}
html = '<table><tr data-field>';
if (opn.chkbox)
html += '<th> </th>';
for (var ki in thos.sortfield) {
var key = thos.sortfield[ki];
if (!thos.field[key].c)
continue;
var colname = thos.field[key].c;
var colhide = false;
if (colname[0] == '#') {//默认隐藏列设置
colhide = true;
colname = colname.substring(1);
}
var colext = '';
if (colname[0] == ',') {//列表不显示
var ind = colname.indexOf(',', 1);
if (ind > 0) {
colext = colname.substring(ind + 1);
}
colname = '';
} else {
var ind = colname.indexOf(',');
if (ind > 0) {
colext = colname.substring(ind + 1);
colname = colname.substring(0, ind);
}
}
var ind = colext.indexOf(' //');
if (ind > 0)
colext = colext.substring(0, ind).trim();
thos.field[key].ext = colext;
//var ind2 = colext.indexOf(',');
//thos.field[key].exdata = ind2 > -1 ? colext.substring(ind2 + 1) : '';
//处理字段名称两侧竖线,代表数据对齐方式。|状态|
thos.field[key].align = 'left';
if (colname.substring(colname.length - 1) == '|') {
if (colname.substring(0, 1) == '|') {
colname = colname.substring(1, colname.length - 1);
thos.field[key].align = 'center';
} else {
colname = colname.substring(0, colname.length - 1);
thos.field[key].align = 'right';
}
}
if (colname.substring(0, 1) == '|')
colname = colname.substring(1);
if (colname.length == 0)
continue;
html += '<th class="lang"';
var style = thos.field[key].thstyle || '';
if (thos.field[key].thwidth) {
if (style.indexOf('width') == -1) {
style += ';width:' + thos.field[key].thwidth + ';';
}
}
if (thos.field[key].order !== undefined) {
style += ';padding-right:2em;';
}
if (style)
html += ' style="' + style + '"';
else if (thos.field[key].thprop)
html += ' ' + thos.field[key].thprop;
html += ' data-index="' + (++index) + '"' + ' data-field="' + key + '"';
thos.field[key].index = index;
thos.field[key].ext = colext;
if (colext.length > 0)
html += ' data-ext="' + colext + '"';
if (colhide)
html += ' data-hide="1"';
html += ' data-align="' + thos.field[key].align + '">';
if (typeof (opn.thfield) == 'function') {
var fieldbk = opn.thfield(colname, key, thos.field[key], json);
if (fieldbk)
html += fieldbk;
else
html += ciyfn.lang(colname);
} else
html += ciyfn.lang(colname);
if (opn.help && opn.help[key]) {
html += '<span class="help" onclick="ciyfn.alert(\'' + opn.help[key] + '\')"></span>';
}
if (thos.field[key].order !== undefined) {
var style = '';
if (thos.field[key].order == 'r')
style = ' style="right:0.5em;"';
html += '<i' + style + ' data-order="' + key + '" class="asc" title="升序排序"></i>';
html += '<i' + style + ' data-order="' + key + ' desc" class="desc" title="降序排序"></i>';
}
html += '</th>';
}
html += '</tr></table>';
this.listdom.html(html).show('up', 0.5);
thos._tabdom = $5('table', this.listdom);
$5('.loading', this.dom).remove();
table_adjust();
ciyfn._table_dragitem(this.dom, opn);
this.dom.on('click', 'i[data-order]', function (e) {//点击排序
var orderdom = $5(e.currentTarget);
if (orderdom.hasClass('db'))
return;
if (orderdom.hasClass('js')) {
thos.post.query = thos.post.query || {};
thos.post.query.order = orderdom.attr('data-order');
thos.callpage(1);
return;
}
$5('th>i.sort', thos.dom).removeClass('js').removeClass('db');
orderdom.addClass('sort').addClass('js');
var trdoms = $5('[data-id]', thos.dom);
var ani = new ciyclass.anidom(trdoms, 'data-id');
var arr = [];
for (var i = 0; i < trdoms.length; i++) {
arr.push(trdoms[i]);
}
var fod = (orderdom.attr('data-order').indexOf(' desc') > 0);
var findex = e.currentTarget.parentNode.getAttribute('data-index');
arr.sort(function (div1, div2) { //Intl
var val1 = div1.querySelector('td:nth-child(' + findex + ')').getAttribute('data');
var val2 = div2.querySelector('td:nth-child(' + findex + ')').getAttribute('data');
if (/^(-?\d*)(\.\d+)?$/.test(val1) && /^(-?\d*)(\.\d+)?$/.test(val2)) {
if (fod)
return tofloat(val2) - tofloat(val1);
else
return tofloat(val1) - tofloat(val2);
} else {
if (fod)
return val2.localeCompare(val1, "zh");
else
return val1.localeCompare(val2, "zh");
}
});
for (var i = 0; i < arr.length; i++)
thos._tabdom.append(arr[i]);
thos._tabdom.append($5('[data-none]', thos.dom));
ani.animate();
});
}
if (this._tabdom == null)
return;
$5('[data-id]', this._tabdom).remove();
$5('[data-none]', this._tabdom).remove();
html = '';
var colspan = thos.sortfield.length;
if (opn.chkbox)
colspan++;
if (json.list) {
for (var i = 0; i < json.list.length; i++) {
var ldat = json.list[i];
ldat._idx = i;
this.data[ldat['id']] = ldat;
html += this.tabletr_html(ldat);
}
if (json.list.length == 0 && json.pageno == 1)
html += '<tr data-none><td colspan="' + colspan + '" style="text-align:center;padding:0.5em;">' + ciyfn.lang(opn.nodatatext) + '</td></tr>';
} else {
html += '<tr data-none><td colspan="' + colspan + '" style="text-align:center;padding:0.5em;font-size:0.8em;color:var(--txt1);">' + ciyfn.lang("等待操作") + '</td></tr>';
}
ciyfn._table_fillpage(_pagedom, json, opn.btncolumnset == 1);
$5('th>i.sort', this.dom).removeClass('js').removeClass('db');
if (json.searchwhere) {
$5('i[data-order="' + json.searchwhere.order + '"]', this.dom).addClass('sort').addClass('db');
}
dataready = false;
pubhtml(html);
if (scroll)
this.listdom.scroll({ top: 0 });
function pubhtml(htmlshow) {
var ind = htmlshow.indexOf('<tr ', 300000);
if (ind > -1) {
htmlappend = htmlshow.substring(ind);
setTimeout(function () {
console.log('pubhtml', htmlappend.length);
pubhtml(htmlappend);
}, 100);
thos._tabdom.append(htmlshow.substring(0, ind));
return;
}
thos._tabdom.append(htmlshow);
dataready = true;
thos._shcolumn(localset);
if (typeof (opn.fn_done) == 'function')
opn.fn_done(json, thos.post);
setTimeout(function () {
ciyfn.lazyimg();
}, 1000);
}
}
this.tabletr_html = function (ldat) {
var html = '<tr data-id="' + ldat['id'] + '" ';
if (typeof (opn.fn_trprop) == 'function')
html += opn.fn_trprop(ldat, this.json);
html += '>';
if (opn.chkbox)
html += '<td class="chkbox"></td>';
for (var ki in this.sortfield) {
var key = this.sortfield[ki];
var ftf = this.field[key];
if (ftf.c == '' || ftf.c[0] == ',')
continue;
var dataori = ldat[key];
if (dataori === undefined)
dataori = '';
dataori = dataori + '';
var datashow = ciyfn.tdshow(key, dataori, ftf.ext, ldat, this.json);
var fdata = undefined;
if (typeof (opn.fn_tdcontent) == 'function')
fdata = opn.fn_tdcontent(key, datashow, ftf, ldat, this.json);
if (typeof (fdata) == 'object') { //自定义td单元格
html += '<td field="' + key + '" data="' + dataori.replace(/\"/g, '&quot;') + '" ' + (fdata.tdprop || '') + '><div ' + (fdata.divprop || '') + '>' + (fdata.datashow || datashow) + '</div></td>';
} else {
if (typeof (fdata) == 'string')
datashow = fdata;
html += '<td field="' + key + '" style="text-align:' + ftf.align + '" data="' + dataori.replace(/\"/g, '&quot;') + '"><div>' + datashow + '</div></td>';
}
}
html += '</tr>';
return html;
}
//调整表格列宽。
function table_adjust() {
var localset = ciyfn.getstorage('_t_' + thos.pathname, {});
var thdoms = $5('th', thos._tabdom);
var txtstyle = '';
if (isobj(localset.thwidth)) {
for (var field in localset.thwidth) {
txtstyle += "#" + opn.domid + " [field=\"" + field + "\"] > div { max-width: initial;width: " + localset.thwidth[field] + ";}";
}
} else {
for (var i = 0; i < thdoms.length; i++) {
if (!thdoms[i].style.width)
continue;
txtstyle += "#" + opn.domid + " [field=\"" + thdoms[i].getAttribute('data-field') + "\"] > div { max-width: initial;width: " + thdoms[i].style.width + ";}";
}
}
for (var i = 0; i < thdoms.length; i++) {
thdoms[i].style.width = null;
}
var tabstyle = document.createElement('style');
thos.dom.append(tabstyle);
if (txtstyle) {
tabstyle.innerText = txtstyle;
}
if (thos.dom[0].scrollWidth <= thos.dom[0].clientWidth)
thos.dom[0].style.borderRight = null;
else
thos.dom[0].style.borderRight = '1px solid var(--bg6)';
var dodrag = null;
$5(thos._tabdom).on("mousedown", 'th', function (ev) {
if (dodrag == null)
return;
ev.preventDefault();
var field = dodrag.getAttribute('data-field');
var sheet = tabstyle.sheet || tabstyle.styleSheet || {};
var rules = sheet.cssRules || sheet.rules;
dodrag.opstyle = null;
for (var i = 0; i < rules.length; i++) {
var item = rules[i];
if (item.selectorText !== ("#" + opn.domid + " [field=\"" + field + "\"] > div"))
continue;
dodrag.opstyle = item;
break;
}
if (dodrag.opstyle == null) {
var i = 0;
if ("insertRule" in sheet)
i = sheet.insertRule("#" + opn.domid + " [field=\"" + field + "\"] > div{max-width: initial;}", 0);
else if ("addRule" in sheet)
i = sheet.addRule("#" + opn.domid + " [field=\"" + field + "\"] > div", "max-width: initial;");
dodrag.opstyle = rules[i];
}
dodrag.mouseDown = true;
});
$5(thos._tabdom).on("mouseup", function (ev) {
if (dodrag == null)
return;
dodrag.mouseDown = false;
dodrag = null;
var sheet = tabstyle.sheet || tabstyle.styleSheet || {};
var rules = sheet.cssRules || sheet.rules;
var thobj = {};
for (var i = 0; i < rules.length; i++) {
var arr = /field="([^"]+)"/.exec(rules[i].selectorText);
thobj[arr[1]] = rules[i].style.width;
}
var localset = ciyfn.getstorage('_t_' + thos.pathname, {});
localset.thwidth = thobj;
ciyfn.setstorage('_t_' + thos.pathname, localset);
});
$5(thos._tabdom).on("mousemove", 'th', function (ev) {
if (dodrag != null && dodrag.mouseDown) {
dodrag.opstyle.style.width = (ev.clientX - dodrag.oset - dodrag.getBoundingClientRect().left) + "px";
if (thos.listdom[0].scrollWidth <= thos.listdom[0].clientWidth)
thos.listdom[0].style.borderRight = null;
else
thos.listdom[0].style.borderRight = '1px solid var(--bg6)';
return;
}
if (ev.target.nodeName != 'TH')
return;
if (ev.target.clientWidth - ev.offsetX < 8) {
dodrag = ev.target;
dodrag.oset = ev.offsetX - ev.target.clientWidth;
ev.target.style.cursor = 'col-resize';
} else {
if (dodrag != null) {
dodrag.style.cursor = null;
}
dodrag = null;
if (ev.offsetX < 8) {
dodrag = ev.target.previousElementSibling;
if (dodrag != null) {
dodrag.oset = ev.offsetX;
ev.target.style.cursor = 'col-resize';
}
} else {
ev.target.style.cursor = null;
}
}
});
}
this._shcolumn = function (localset, trselector) {
trselector = trselector || 'tr[data-id]';
var thdoms = $5('th', thos._tabdom);
var fieldids = [];
for (var i = 0; i < thdoms.length; i++) {
var bshow = true;
if (localset.thhide) {
if (localset.thhide.indexOf(thdoms[i].getAttribute('data-field')) > -1)
bshow = false;
} else if (thdoms[i].getAttribute('data-hide') === '1')
bshow = false;
fieldids.push(bshow);
thdoms[i].style.display = bshow ? null : "none";
}
var trdoms = $5(trselector, thos.dom);
for (var x = 0; x < trdoms.length; x++) {
var tddoms = $5('td', trdoms[x]);
if (tddoms.length < 2)
continue;
for (var i = 0; i < tddoms.length; i++) {
if (fieldids[i])
tddoms[i].style.display = null;
else
tddoms[i].style.display = "none";
if (tddoms[i].getAttribute('field') == '_btn')
continue;
var txt = tddoms[i].textContent;
if (txt && txt.length * 14 > tddoms[i].getBoundingClientRect().width)
tddoms[i].setAttribute('title', txt);
}
}
}
this.filltable = function (html, scroll) {
this.listdom.html(html).show();
if (scroll)
this.listdom.scroll({ top: 0 });
$5('.loading', this.dom).remove();
}
//供页面搜索组件调用
this.search = function (dom, act) {
var form = ciyfn.getform(dom);
thos.post.query = form;
if (act == 'li')
thos.post.query.liid = dom.getAttribute('data-liid');
else {
var domli = dom.querySelector('li.active[data-liid]');
if (domli !== null)
thos.post.query.liid = domli.getAttribute('data-liid');
}
//Object.assign(thos.post, form); //ES6
if (ciyfn.throttle(dom)) return;
thos.cachecount = -1;
thos.callpage(1);
}
this.tree = function () {
thos.dom.on("click", '.exfold', function (ev) {
thos.dom.find('div[data-treeid][data-deep=0]').trigger('click');
});
thos.dom.on("click", 'div[data-treeid]', function (ev) {
var treedom = $5(ev.currentTarget);
treedom.toggleClass('ciy-tree-spread');
var id = treedom.attr('data-treeid');
var min = 99999;
var max = 0;
var trdoms = thos.dom.find('tr');
thos.dom.find('tr[data-upid="' + id + '"]').each(function (e) {
var index = trdoms.index(e);
if (min > index)
min = index;
if (max < index)
max = index;
});
while (true) {
var mmax = max;
var n = toint(trdoms.eq(max).attr('data-id'));
$5('tr[data-upid="' + n + '"]').each(function (e) {
var index = trdoms.index(e);
if (max < index)
max = index;
});
if (mmax == max)
break;
}
var open = false;
if (treedom.hasClass('ciy-tree-spread'))
open = true;
for (var i = min; i <= max; i++) {
if (open) {
trdoms.eq(i).show('', 0, 'table-row');
trdoms.eq(i).find('[data-treeid]').addClass('ciy-tree-spread');
} else {
trdoms.eq(i).hide();
trdoms.eq(i).find('[data-treeid]').removeClass('ciy-tree-spread');
}
}
});
}
//列合并,列排序后,竖向合并相同内容单元格
this.mergecol = function (key) {
var trs = thos._tabdom.find('tr[data-id]');
var tds = [];
var txt = null;
for (var i = 0; i < trs.length; i++) {
var td = $5(trs[i]).find('td[field="' + key + '"]');
var tdtxt = td.text();
if (txt === null)
txt = tdtxt;
if (txt == tdtxt) {
tds.push(td);
} else {
txt = tdtxt;
merge(tds);
tds = [td];
}
}
merge(tds);
function merge(tds) {
if (tds.length == 0)
return;
if (tds.length == 1)
return tds[0].css('background', 'var(--bg3)');
tds[0].attr('rowspan', tds.length).css('background', 'var(--bg3)');
for (var i = 1; i < tds.length; i++) {
tds[i].remove();
}
}
}
//任意合并
this.mergefix = function (html, align, col1, row1, col2, row2) {
var td = this._tabdom.find('tr').eq(col1).find('td').eq(row1);
td.html(html).css('textAlign', align);
for (var c = col2; c >= col1; c--) {
for (var r = row2; r >= row1; r--) {
if (c == col1 && r == row1)
continue;
this._tabdom.find('tr').eq(c).find('td').eq(r).remove();
}
}
if (col1 < col2)
td.attr('rowspan', col2 - col1 + 1);
if (row1 < row2)
td.attr('colspan', row2 - row1 + 1);
}
//挂接汇总数据
this.footertotal = function () {
if (thos.data.length == 0)
return;
ciyfn.callfunc('total', thos.post, function (json) {
var html = '<tr data-none>';
$5('th', thos._tabdom).each(function (dom) {
var key = dom.getAttribute('data-field');
var field = thos.field[key];
html += '<td field="' + key + '" style="text-align:' + field.align + ';background:var(--bg5);"><div>';
if (key == '_btn') {
html += '<div style="text-align:right;"><b class="lang">汇总</b></div>';
} else if (json.total[key] !== undefined) {
if (json.total[key][0] == '_')
html += json.total[key].substring(1);
else
html += ciyfn.tdshow(key, json.total[key], field.ext, json.total, json);
}
html += '</div></td>';
});
html += '</tr>';
thos._tabdom.append(html);
thos._shcolumn(localset, 'tr[data-id],tr[data-none]');
});
}
}
ciyfn.fillsearch = function (opn) {
opn.data = opn.data || {};
var urlp = ciyfn.urlparam();
opn.more = (opn.more === undefined ? true : opn.more);
if (isobj(opn.data.searchwhere)) {
for (var w in opn.data.searchwhere) {
if (!opn.data.searchwhere[w])
continue;
if (w == 'liid') {
$5('li[data-liid]', '.search').removeClass('active');
$5('li[data-liid="' + opn.data.searchwhere[w] + '"]', '.search').addClass('active');
} else if (w)
$5('[sechr=' + w + ']', '.search').val(opn.data.searchwhere[w]);
}
}
if (!opn.data.once || !opn.data.searchinput)
return;
if (opn.lidata) {
opn.lidata = ciyfn.filterdictdata(ciyfn.getdictdata(opn.lidata, opn.data), {
limit: opn.lilimit
, filter: opn.lifilter
, rename: opn.lirename
, all: opn.liall
});
var uldom = $5('ul', opn.searchdom);
var html = '';
for (var i in opn.lidata) {
html += '<li data-liid="' + opn.lidata[i].id + '"' + (opn.lidata[i].id == tostr(urlp.liid) ? ' class="active"' : '') + '>' + opn.lidata[i].name + '</li>';
}
uldom.html(html);
uldom.on('click', 'li', function (ev) {
$5('.active', uldom).removeClass('active');
var lidom = $5(ev.currentTarget);
lidom.addClass('active');
if (typeof (opn.liclick) == 'function')
opn.liclick(ev.currentTarget);
});
}
var inpsdom = $5('.sinps', opn.dom);
if (inpsdom.length == 0)
return console.warn('search input not found');
inpsdom.children().remove();
for (var idx in opn.data.searchinput) {
var html = '';
var sp = opn.data.searchinput[idx];
var name = sp.form;
if (sp.type == 'hidden') {
html = '<input type="hidden" name="' + name + '" value="' + sp.def + '" />';
inpsdom.append(html);
continue;
}
html += '<div class="ciy-form inline">';
if (sp.name)
html += '<label class="lang">' + sp.name + '</label>';
html += '<div>';
var val;
val = sp.def || '';
if (urlp[sp.form])
val = urlp[sp.form];
var prop = '';
var seldata = [];
if (sp.prop)
prop = ' ' + sp.prop;
if (sp.type == 'input')
html += '<input type="text" sechr="' + name + '" name="' + name + '" value="' + val + '"' + prop + '/>';
else if (sp.type == 'num')
html += '<input type="text" sechr="' + name + '_1" name="' + name + '_1"' + prop + '/> - <input type="text" sechr="' + name + '_2" name="' + name + '_2"' + prop + '/>';
else if (sp.type == 'select' || sp.type == 'radio') {
if (sp.type == 'select')
html += '<ciy-select sechr="' + name + '" com="' + name + '" value="' + val + '"' + prop + '></ciy-select>';
if (sp.type == 'radio')
html += '<ciy-radio sechr="' + name + '" com="' + name + '" value="' + val + '"' + prop + '></ciy-radio>';
sp.def = sp.def || '';
seldata = ciyfn.filterdictdata(ciyfn.getdictdata(sp.select, opn.data), {
limit: sp.limit
, first: sp.first
, filter: sp.filter
, rename: sp.rename
, all: sp.all
});
} else if (sp.type == 'switch') {
var vals = sp.value;
if (typeof (vals) == 'string')
vals = vals.split(',');
else {
vals[0] = vals[0].name;
if (vals[1])
vals[1] = vals[1].name;
}
if (vals.length == 1)
vals[1] = ' ';
html += '<ciy-switch sechr="' + name + '" com="' + name + '" y="' + vals[0] + '" n="' + vals[1] + '" value="' + val + '"' + prop + '></ciy-switch>';
} else if (sp.type == 'daterange') {
html += '<ciy-daterange sechr="' + name + '" com="' + name + '" value="' + val + '"' + prop + '></ciy-daterange>';
} else if (sp.type == 'month') {
html += '<ciy-datetime type="month" sechr="' + name + '" com="' + name + '" value="' + val + '"' + prop + '></ciy-datetime>';
} else if (sp.type == 'day') {
html += '<ciy-datetime sechr="' + name + '" com="' + name + '" value="' + val + '"' + prop + '></ciy-datetime>';
} else {
html += 'type错误:' + sp.type + '';
}
if (sp.behind)
html += sp.behind;
html += '</div></div>';
inpsdom.append(html);
if (sp.type == 'select' || sp.type == 'radio') {
ciycmp({ dom: '[com=' + name + ']', range: seldata });
}
if (sp.type == 'switch' || sp.type == 'daterange' || sp.type == 'month' || sp.type == 'day') {
ciycmp({ dom: '[com=' + name + ']' });
}
}
if (opn.more) { //如果高度超过则折叠并且在sinps后加展开按钮
var rect = inpsdom.rect();
if (rect.height > 50) {
inpsdom.css('height', '3em').css('overflow', 'hidden').attr('data-height', rect.height + 'px');
var moredom = $5('<div><div class="smore">🔽</div></div>');
moredom.on('click', '.smore', function (e) {
if (inpsdom.css('height') == '3em') {
$5(e.currentTarget).css('transform', 'rotate(180deg)');
inpsdom.css('height', inpsdom.attr('data-height'));
} else {
$5(e.currentTarget).css('transform', '');
inpsdom.css('height', '3em');
}
});
inpsdom.after(moredom);
}
}
}
ciyfn.select_all = function (table) {
$5('[data-id]', table.dom).each(function (dom) {
$5(dom).addClass("selected");
});
}
ciyfn.select_diff = function (table) {
$5('[data-id]', table.dom).each(function (dom) {
$5(dom).toggleClass("selected");
});
}
ciyfn.select_callfunc = function (table, dombtn, funcname, confirmmsg, postparam, successfunc) {
if (ciygv._clickduptime)
return;
postparam = postparam || {};
var array = [];
$5('[data-id]', table.dom).each(function (dom) {
if ($5(dom).hasClass("selected"))
array.push($5(dom).attr("data-id"));
});
postparam.ids = array.join(",");
if (postparam.ids == "")
return ciyfn.toast("请至少选择一条信息");
if (confirmmsg) {
ciyfn.alert(ciyfn.lang(confirmmsg).replace(/{n}/g, '<span class="txt-lggg px1">' + array.length + '</span>'), function (altopn) {
altopn.close();
postparam = Object.assign(postparam, altopn.inputs);
if (altopn.btn == "继续") {
callfunc(funcname, postparam, successfunc);
}
}, { btns: ["继续", "*取消"] });
} else {
callfunc(funcname, postparam, successfunc);
}
function callfunc(funcname, postparam, successfunc) {
if (typeof (funcname) == 'function') {
funcname(postparam.ids);
} else {
if (ciyfn.throttle(dombtn)) return;
ciyfn.callfunc(funcname, postparam, function (json) {
$5('[data-id]', table.dom).removeClass("selected");
if (typeof (successfunc) === "function")
successfunc(json);
else
location.reload();
});
}
}
}
ciyfn._table_eventpage = function (_pagedom, thos) {
if (_pagedom.length == 0)
return;
document.addEventListener('keydown', function (e) {
var keyCode = e.keyCode || e.which;
if (e.ctrlKey && keyCode === 37) {
if (ciyfn.callfrequency(2))
return;
$5('.pageprev', _pagedom).trigger('click');
} else if (e.ctrlKey && keyCode === 39) {
if (ciyfn.callfrequency(2))
return;
$5('.pagenext', _pagedom).trigger('click');
}
});
_pagedom.on('keydown', function (e) {
if (e.keyCode != 13)
return;
if (e.target.name == 'topage') {
thos.callpage(e.target.value);
}
if (e.target.name == 'pcount') {
var localset = ciyfn.getstorage('_t_' + thos.pathname, {});
localset.pagecount = toint(e.target.value);
if (localset.pagecount < 2) {
ciyfn.removestorage('_t_' + thos.pathname);
location.reload();
return;
}
ciyfn.setstorage('_t_' + thos.pathname, localset);
thos.post.pagecount = localset.pagecount;
thos.callpage(1);
}
});
_pagedom.on('click', 'a', function (e) {
var act = e.currentTarget.getAttribute('data-act');
if (act == 'pagego') {
if (ciyfn.throttle(e.currentTarget)) return;
thos.callpage($5('input[name="topage"]', _pagedom).val(), true);
} else if (act == 'fulltable') {
if (thos.dom.css('position') == 'fixed') {
ciyfn.sendsignal(window.top, 'manage_fulldiv', { full: true });
thos.dom.css({ position: null, top: null, left: null, right: null, bottom: null, zIndex: null });
} else {
ciyfn.sendsignal(window.top, 'manage_fulldiv', { full: false });
thos.dom.css({ position: 'fixed', top: '0', left: '1em', right: '1em', bottom: '0.5em', zIndex: 20 });
}
} else if (act == 'columnset') {
var localset = ciyfn.getstorage('_t_' + thos.pathname, {});
var thdoms = $5('th', thos._tabdom);
var range = [];
var values = [];
for (var i = 0; i < thdoms.length; i++) {
var key = thdoms[i].getAttribute('data-field');
if (key === null)
continue;
range.push({ id: key, name: thdoms[i].textContent });
if (isarray(localset.thhide)) {
if (localset.thhide.indexOf(key) == -1)
values.push(key);
}
else if (thdoms[i].getAttribute('data-hide') !== '1')
values.push(key);
}
var sorted = false;
var html = '';
html += '<div class="lang">请选择需要显示/隐藏的列</div><div>';
html += '<ciy-checkbox com="sh" hasmore hasline></ciy-checkbox>';
html += '</div>';
ciyfn.alert({
title: '显示隐藏列操作'
, width: 'mb'
, content: html
, fn_showed: function (doc, dom) {
ciycmp({ dom: $5('[com=sh]', dom), value: values.join(','), range: range });
var chkdom = dom[0].querySelector('ciy-checkbox>div');
for (var i = 0; i < chkdom.children.length; i++) {
chkdom.children[i].setAttribute('draggable', true);
}
ciyclass.dragdom({
dom: chkdom
, key: 'data-id'
, fn_sort: function () {
sorted = true;
}
});
}
, btns: ["!重置", "确定", "*关闭"]
, cb: function (altopn) {
if (altopn.btn == '关闭')
return altopn.close();;
if (altopn.btn == '重置') {
ciyfn.removestorage('_t_' + thos.pathname, {});
altopn.close();
location.reload();
return;
}
var nos = altopn.inputs.sh_noid.split(',');
localset.thhide = [];
for (var noi in nos)
localset.thhide.push(nos[noi]);
if (sorted) {
var sfields = [];
altopn.dom.find('.ciy-checkbox').each(function (dom, idx) {
sfields.push(dom.getAttribute('data-id'));
});
localset.thsort = sfields.join(',');
}
ciyfn.setstorage('_t_' + thos.pathname, localset);
altopn.close();
if (sorted)
return location.reload();
thos._shcolumn(localset);
ciyfn.lazyimg();
}
});
} else {
if (ciyfn.throttle(e.currentTarget)) return;
thos.callpage(e.currentTarget.getAttribute('data-page'), true);
}
});
}
ciyfn._table_fillpage = function (_pagedom, json, btncolumnset) {
if (_pagedom.length == 0)
return;
var showpages = 3;
var pagemax;
if (json.count > -1)
pagemax = Math.ceil(json.count / json.pagecount);
else if (json.list.length < json.pagecount) {
pagemax = json.pageno;
} else {
pagemax = json.pageno + showpages;
}
html = '<div class="totaltxt">';
if (json.count > -1)
html += '<span id="id_rowtotal">' + json.count + '</span>' + ciyfn.lang('条') + ' ';
html += '<input type="text" class="tran" title="' + ciyfn.lang('请按回车确认') + '" name="pcount" value="' + json.pagecount + '" style="width: 1.6em;padding: 0;vertical-align: text-bottom;min-height: 1em;text-align: right;margin-right: 0.3em;color: var(--txt3);"/>';
html += ciyfn.lang('条/页') + '</div>';
if (json.pageno > 1) {
html += '<a data-page="1">&lt;&lt;</a>';
html += '<a data-page="' + (json.pageno - 1) + '" class="pageprev">&lt;</a>';
}
var spage = 1;
if (json.pageno > showpages)
spage = json.pageno - showpages;
var epage = pagemax;
if (json.pageno < pagemax - showpages)
epage = json.pageno + showpages;
for (var i = spage; i <= epage; i++) {
if (i == json.pageno)
html += '<a data-page="' + i + '" class="current">' + i + '</a>';
else
html += '<a data-page="' + i + '">' + i + '</a>';
}
if (json.pageno < pagemax) {
html += '<a data-page="' + (json.pageno + 1) + '" class="pagenext">&gt;</a>';
html += '<a data-page="' + pagemax + '">&gt;&gt;</a>';
}
if (pagemax > showpages)
html += '<input type="text" name="topage" value="' + json.pageno + '" style="width:3em;min-height:2.2em;height:2.2em;text-align:center;margin:0 4px;"/><a class="btn def" data-act="pagego" style="line-height: 2em;vertical-align: top;">GO</a>';
if (btncolumnset)
html += '<a class="btn def svg" data-act="columnset"><svg viewBox="0 0 1024 1024" version="1.1"><path class="svgfill" d="M918.52127844 266.06914531a29.03723438 29.03723438 0 1 0 0 58.07446782v85.31139468H105.47872156V324.14361313h578.94437531c16.11566531 0 29.03723438-13.00868063 29.03723438-29.03723438s-12.92156906-29.03723438-29.03723438-29.03723344H105.47872156c-32.02806938 0-58.07446875 26.04639938-58.07446875 58.07446781v609.78191813c0 32.05710656 26.04639938 58.07446875 58.07446875 58.07446875h813.04255688a58.07446875 58.07446875 0 0 0 58.07446875-58.07446875V324.14361313c0-32.02806938-26.01736219-58.07446875-58.07446875-58.07446782zM395.85106345 757.9018175v-116.14893656h232.29787312v116.14893656h-232.29787312z m232.29787312 58.07446874V933.92553125h-232.29787312v-117.97828219h232.29787312v0.0290372z m-522.67021501-174.2234053h232.29787312v116.14893656h-232.29787312v-116.14893656z m522.67021501-58.07446875h-232.29787312v-111.90950063c0-1.50993657-0.63881906-2.78757469-0.84208034-4.23943593h233.98203378c-0.2322975 1.42282406-0.84207937 2.72950031-0.84208032 4.21039875v111.93853781z m58.07446873 58.07446875h232.29787314v116.14893656h-232.29787314v-116.14893656z m232.29787314-58.07446875h-232.29787314v-111.90950063c0-1.50993657-0.60978187-2.78757469-0.8420803-4.23943593H918.52127844v116.14893656z m-579.90260344-116.14893656c-0.20326031 1.42282406-0.84207937 2.72950031-0.84208032 4.21039875v111.90950062h-232.29787312v-116.14893655l233.13995344 0.02903717z m-233.13995344 348.44681061h232.29787312V933.92553125h-232.29787312v-117.94924499zM686.22340532 933.92553125v-117.97828219h232.29787312V933.92553125h-232.29787312z"></path><path class="svgfill" d="M780.01367188 284.79816125a28.95012281 28.95012281 0 0 0 41.05864874 0l86.58903282-86.64710719c11.41163344-11.35355812 11.41163344-29.70509063 0-41.05864875s-29.64701625-11.35355812-41.05864969 0l-36.90632437 36.87728719v-132.93245812a29.03723438 29.03723438 0 1 0-58.07446875 0v133.39705406l-36.87728718-36.87728813a29.00819719 29.00819719 0 1 0-41.05864876 41.0586497l86.32769718 86.18251124z"></path></svg></a>';
html += '<a class="btn def svg" data-act="fulltable"><svg viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg"><path class="svgfill" d="M983.04 727.04a40.96 40.96 0 0 0-40.96 40.96v173.592381h-174.08a40.96 40.96 0 1 0 0 82.407619h173.592381A82.407619 82.407619 0 0 0 1024 941.592381v-173.592381a40.96 40.96 0 0 0-40.96-40.96zM941.592381 0h-173.592381a40.96 40.96 0 1 0 0 82.407619h173.592381v173.592381a40.96 40.96 0 1 0 82.407619 0V82.407619A82.407619 82.407619 0 0 0 941.592381 0zM256 941.592381H82.407619v-173.592381a40.96 40.96 0 1 0-82.407619 0v173.592381A82.407619 82.407619 0 0 0 82.407619 1024h173.592381a40.96 40.96 0 1 0 0-82.407619zM40.96 296.96a40.96 40.96 0 0 0 40.96-40.96V82.407619h174.08a40.96 40.96 0 1 0 0-82.407619H82.407619A82.407619 82.407619 0 0 0 0 82.407619v173.592381a40.96 40.96 0 0 0 40.96 40.96z m682.666667 425.20381H301.83619V301.83619h420.815239z m82.407619 0V301.83619a82.407619 82.407619 0 0 0-83.870476-82.407619H301.83619A82.407619 82.407619 0 0 0 219.428571 301.83619v420.815239a82.407619 82.407619 0 0 0 82.407619 81.92h420.815239a82.407619 82.407619 0 0 0 81.92-82.407619z"></path></svg></a>';
_pagedom.html(html);
}
ciyfn._table_dragitem = function (dom, opn) {
dom.on('mousedown', '[data-id]', function (e) {
if (opn.chkbox) {
if (e.target.className != 'chkbox')
return;
} else {
if (e.target.parentNode.nodeName != 'TD' && e.target.parentNode.nodeName != 'TR')
return;
}
var itemdom = $5(e.currentTarget);
var _table_dataid = itemdom.attr('data-id');
if (_table_dataid > 0) {
if (!itemdom.hasattr('noselect'))
itemdom.toggleClass('selected');
}
dom.on('mousemove', '[data-id]', function (e) {
e.stopPropagation();
var mdom = $5(e.currentTarget);
var newtrid = mdom.attr('data-id');
if (_table_dataid == newtrid)
return;
_table_dataid = newtrid;
if (newtrid > 0) {
if (!itemdom.hasattr('noselect'))
mdom.toggleClass('selected');
}
if ("getSelection" in window)
window.getSelection().removeAllRanges();
else
document.selection.empty();
});
$5(document).one('mouseup', function (e) {
_table_dataid = -1;
dom.off('mousemove');
});
});
}
ciyfn.conv_treerow = function (rows, upid, deep) {
var ret = [];
var cnt = rows.length;
for (var i = 0; i < cnt; i++) {
if (rows[i].upid != upid)
continue;
var subrows = ciyfn.conv_treerow(rows, rows[i]['id'], deep + 1);
rows[i]['_count'] = subrows.length;
rows[i]['_deep'] = deep;
ret.push(rows[i]);
ret = ret.concat(subrows);
}
if (deep == 0) {
for (var i = 0; i < cnt; i++) {
if (rows[i]['_deep'] === undefined) {
rows[i]['_count'] = 0;
rows[i]['_deep'] = 0;
ret.push(rows[i]);
}
}
}
return ret;
}
ciyfn.table_multiin = function (func, html, fn_success) {
ciyfn.alert({
title: '导入新数据'
, width: 'pc'
, content: html
, fn_showed: function (doc, dom) {
ciycmp({ dom: $5('[com=file]', dom), path: 'tmp', type: 'xlsx', stor: '/', showwh: '160px' });
}
, btns: ["导入预览", "*关闭"]
, cb: function (opn) {
if (opn.btn == '关闭')
return opn.close();
if (!opn.inputs.file)
return ciyfn.toast('未上传文件');
opn.close();
if (ciyfn.throttle(opn.dombtn)) return;
ciyfn.callfunc(func + '_in', opn.inputs, function (json) {
ciyfn.alert({
title: '导入新数据'
, width: 'max'
, height: 'max'
, content: json.html
, btns: ['执行操作', '*关闭']
, cb: function (opn) {
if (opn.btn == '关闭')
return opn.close();
if (json.count == 0)
return ciyfn.alert('无数据可导入');
var errtit = $5('td[title]', opn.dom);
if (errtit.length > 0) {
var html = '发现' + errtit.length + '条错误。';
for (var i = 0; i < errtit.length; i++) {
html += '<br/>' + errtit[i].getAttribute('title');
}
return ciyfn.alert(html);
}
ciyfn.callfunc(func + '_data', opn.inputs, function (json) {
opn.close();
if (typeof (fn_success) == 'function')
fn_success(json);
});
}
});
});
}
});
}
ciyfn.table_exportxls = function (func, table, fn_success) {
ciyfn.alert({
content: '确认导出符合已查询的数据?'
, btns: ["导出", "*关闭"]
, cb: function (opn) {
if (opn.btn == "关闭")
return opn.close();
ciyfn.callfunc(func, table.post, function (json) {
opn.close();
if (typeof (fn_success) == 'function')
fn_success(json);
});
}
});
}
ciyfn.tonumunit = function (num, bet, pstr, defunit, data) {
var ind = pstr.indexOf(',');
if (ind > -1) {
defunit = pstr.substring(ind + 1);
pstr = pstr.substring(0, ind);
}
if (data && data[defunit])
defunit = data[defunit];
num = num / bet;
var unitarr = defunit.split('|');
var u1 = toint(unitarr[1]);
var u2 = toint(unitarr[3]);
var unit = unitarr[0];
if (u1 > 0 && u2 > 0) {
if (num >= u1 * u2) {
num = num / u1 / u2;
unit = unitarr[4];
} else if (num >= u1) {
num = num / u1;
unit = unitarr[2];
}
} else if (u1 > 0) {
if (num >= u1) {
num = num / u1;
unit = unitarr[2];
}
}
var cns = (ciyfn.tofix(num, toint(pstr)) + '').split('.');
var ret = cns[0].replace(/\d{1,3}(?=(\d{3})+$)/g, '$&,');
if (cns.length > 1)
ret += '<span style="font-size:0.7em;">.' + cns[1] + '</span> ';
ret += ciyfn.lang(unit);
return ret;
}
ciyfn.tonumbet = function (num, fixlen, bet, unit) {
var unitarr = unit.split('.');
var betarr = bet.split('.');
num = toint(num);
var betidx = 0;
for (var i = betarr.length - 1; i >= 0; i--) {
if (num / betarr[i] >= 0.1) {
if (betarr[i] >= 1000 && num % parseInt(betarr[i] / 1000) == 0) {
betidx = i;
break;
}
}
if (num != 0 && num % betarr[i] == 0) {
betidx = i;
break;
}
}
num = num / betarr[betidx];
var cns = (ciyfn.tofix(num, toint(fixlen)) + '').split('.');
var ret = cns[0].replace(/\d{1,3}(?=(\d{3})+$)/g, '$&,');
if (cns.length > 1)
ret += '<span style="font-size:0.7em;">.' + cns[1] + '</span> ';
var unit = unitarr[betidx];
if (unit.substring(0, 1) == '*')
unit = unit.substring(1);
ret += ciyfn.lang(unit);
return ret;
}
ciyfn.tdshow = function (fieldname, dataori, ext, linedata, json, isview) {
if (!ext)
return dataori;
var datashow = '';
var preext = ext.substring(0, 6);
if (preext == 'FILEMD') {
if (dataori == 0)
return '--';
if (!isview)
return 'V' + dataori;
return '<div data-mdver="' + dataori + '" style="padding-right:0.5em;"><!--mdver--></div>';
}
var preext = ext.substring(0, 5);
if (preext == 'FSIZE') {
var pint = toint(ext.substring(6));
if (pint < 1)
pint = 2;
var srcsize = toint(dataori);
if (srcsize <= 0)
return "--";
var units = new Array("Bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB");
var index = Math.floor(Math.log(srcsize) / Math.log(1024));
var size = srcsize / Math.pow(1024, index);
return size.toFixed(pint) + units[index];
}
if (preext == 'METRE') {
if (dataori == 0)
return '--';
return ciyfn.tonumunit(dataori, 1000, ext.substring(6), '米|1000|公里');
}
preext = ext.substring(0, 4);
if (preext == 'DATE') {
if (dataori == 0)
return '--';
var pstr = ext.substring(5);
return ciyfn.todatetime(dataori, pstr);
}
if (preext == 'TIME') {
if (dataori == 0)
return '--';
return ciyfn.totimepoint(dataori, ext.substring(5).indexOf(':s') > -1);
}
if (preext == 'MCNY') {
if (dataori == 0)
return '--';
var pstr = ext.substring(4) || '4';
return ciyfn.tonumunit(dataori, 10000, pstr, '|1000000|万');
}
if (preext == 'WCNY') {
if (dataori == 0)
return '--';
var pstrs = ext.substring(5).split(',');
if (!pstrs[1])
pstrs[1] = '元';
return ciyfn.tonumunit(dataori, 1000000, pstrs[0], '万' + pstrs[1] + '|10000|亿' + pstrs[1]);
}
if (preext == 'DOWN') {
if (!dataori)
return '';
var files = dataori.split('~');
for (var fidx in files) {
var fsrc = files[fidx];
if (fsrc == '')
continue;
datashow += '<a href="' + ciyfn.file_stor(fsrc) + '" target="_blank"><svg style="width: 1.7em;height:1.7em;display: inline-block;" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg"><path d="M348 443h328c4.4 0 8 3.6 8 8v48c0 4.4-3.6 8-8 8H348c-4.4 0-8-3.6-8-8v-48c0-4.4 3.6-8 8-8zM348 571h197c4.4 0 8 3.6 8 8v48c0 4.4-3.6 8-8 8H348c-4.4 0-8-3.6-8-8v-48c0-4.4 3.6-8 8-8z" fill="#264097"></path><path d="M658 896H224V128h329v215c0 17.7 14.3 32 32 32h215v130c0 4.4 3.6 8 8 8h48c4.4 0 8-3.6 8-8V343c0-8.5-3.4-16.6-9.4-22.6l-247-247c-6-6-14.1-9.4-22.6-9.4H192c-17.7 0-32 14.3-32 32v832c0 17.7 14.3 32 32 32h466c4.4 0 8-3.6 8-8v-48c0-4.4-3.6-8-8-8z m-41-722.8L754.8 311H617V173.2z" fill="#264097"></path><path d="M959.3 737.1c-1.4-1.1-3.1-1.7-4.9-1.7h-57c-4.9 0-9.6 2.3-12.6 6.1l-57 72.9v-225c0-4.4-3.6-8-8-8h-48c-4.4 0-8 3.6-8 8v225.1l-57-73c-3-3.9-7.7-6.1-12.6-6.1h-57c-4.4 0-8 3.6-8 8 0 1.8 0.6 3.5 1.7 4.9l152.3 194.9c5.4 7 15.5 8.2 22.5 2.8 1-0.8 2-1.7 2.8-2.8l152.3-194.9c2.6-3.5 2-8.5-1.5-11.2z" fill="#264097"></path></svg></a>';
}
return datashow;
}
if (preext == 'IMG1') {
var pstr = ext.substring(5);
//?0缩略图标?ww宽度缩略图
//短地址//img.cdn.ciy.cn/xxx
if (!dataori)
return '';
var imgsrc = ciyfn.file_stor(dataori);
if (isview) {
return '<a onclick="ciyfn.showimg(0, \'' + imgsrc + '\', \'' + pstr + '\');"><img src="' + imgsrc + '" style="max-width:100%;max-height:7.1em;margin:0.2em;border-radius:3px;"/></a>';
}
if (pstr.substring(0, 1) != '?')
pstr = '?100';
return '<a onclick="ciyfn.showimg(0, \'' + imgsrc + '\', \'' + pstr + '\');"><img data-src="' + imgsrc + pstr + '" style="max-width:100%;max-height:2.4em;margin-right:0.2em;border-radius:3px;"/></a>';
}
if (preext == 'BOOL') {
var pstr = ext.substring(5);
pstr = pstr || '✔.✘';
var slts = pstr.split('.');
if (dataori == 1)
return slts[0];
return slts[1] ? slts[1] : '';
}
if (preext == 'UNIT') {
var pstr = ext.substring(5);
var nums = 0;
var yuenum = 0;
var yuestr = '';
if (pstr)
nums = parseInt(linedata[pstr]);
var us = dataori.split('|');// 瓶 瓶|24|盒 瓶|24|盒|20|箱
datashow = '';
if (us.length == 5) {
datashow += '<kbd>1' + us[4] + '=' + us[3] + us[2] + '</kbd>';
yuenum = nums / (parseInt(us[3]) * parseInt(us[1]));
if (yuenum > 0.9)
yuestr = "≈" + Math.round(yuenum) + us[4];
}
if (us.length > 2) {
datashow += '<kbd>1' + us[2] + '=' + us[1] + us[0] + '</kbd>';
if (yuestr == '') {
yuenum = nums / parseInt(us[1]);
if (yuenum > 0.9)
yuestr = "≈" + Math.round(yuenum) + us[2];
}
}
if (datashow == '' && us[0] != '') {
datashow = '<kbd>' + us[0] + '</kbd>';
}
if (nums > 0 && yuestr == '' && us[0] != '')
yuestr = nums + us[0];
if (yuestr)
datashow += '<div style="position: absolute;right: 2px;bottom: 0;font-size: 0.7em;line-height: 1em;color:var(--txt3);transform: scale(0.7);">' + yuestr + '</div>';
return datashow;
}
if (preext == 'CATA' || preext == 'CATU') {
var pstr = ext.substring(5);
var catas = ciyfn.getdictdata(pstr, json);
if (dataori == 0)
return '--';
if (!isarray(catas))
return dataori + "!";
for (var a in catas) {
if (catas[a].id == dataori) {
if (catas[a].clas)
return '<span class="lang ' + catas[a].clas + '">' + catas[a].name + '</span>';
return ciyfn.lang(catas[a].name);
}
}
return '<span title="' + dataori + '">-</span>';
}
if (preext == 'CATS') {
var pstr = ext.substring(5).replace('|', ',');
var ind = pstr.indexOf(',');
var datasep = ' - ';//分隔字符
var datactn = '?';//包含html字符?表示内容
if (ind > 0) {
datasep = pstr.substring(ind + 1);
pstr = pstr.substring(0, ind);
}
if (datasep[0] == '<') {
datactn = datasep;
datasep = '';
}
if (dataori == '')
return '--';
var catas = ciyfn.getdictdata(pstr, json);
if (!isarray(catas))
return dataori + "!";
var vals = dataori.split(',');
var datastrs = [];
for (var v in vals) {
if (vals[v] == '')
continue;
for (var a in catas)
if (catas[a].id == vals[v])
datastrs.push(datactn.replace('?', ciyfn.lang(catas[a].name)));
}
return datastrs.join(datasep);
}
if (preext == 'CATM') {
var pstr = ext.substring(5).replace('|', ',');
var ind = pstr.indexOf(',');
var datasep = ' - ';//分隔字符
var datactn = '?';//包含html字符?表示内容
if (ind > 0) {
datasep = pstr.substring(ind + 1);
pstr = pstr.substring(0, ind);
}
if (datasep[0] == '<') {
datactn = datasep;
datasep = '';
}
if (dataori == '')
return '--';
var catas = ciyfn.getdictdata(pstr, json);
if (!isarray(catas))
return dataori + "!";
var mdatas = ciyfn.mcode(catas, dataori);
var datastrs = [];
for (var mdata in mdatas) {
datastrs.push(datactn.replace('?', ciyfn.lang(mdatas[mdata].name)));
}
return datastrs.join(datasep);
}
if (preext == 'TBIN') {
var pstr = ext.substring(5).replace('|', ',');
var ind = pstr.indexOf(',');
var datasep = ' - ';//分隔字符
var datactn = '?';//包含html字符?表示内容
if (ind > 0) {
datasep = pstr.substring(ind + 1);
pstr = pstr.substring(0, ind);
}
if (datasep[0] == '<') {
datactn = datasep;
datasep = '';
}
if (dataori == '')
return '--';
var catas = ciyfn.getdictdata(pstr, json);
if (!isarray(catas))
return dataori + "!";
var pstrs = {};
for (var i in catas) {
pstrs[catas[i].id - 1] = catas[i].name;
}
var ibin = toint(dataori);
var datastrs = [];
for (var x = 0; x < 16; x++) {
if ((ibin & Math.pow(2, x)) && pstrs[x])
datastrs.push(datactn.replace('?', ciyfn.lang(pstrs[x])));
}
return datastrs.join(datasep);
}
if (preext == 'TINT') {
var pstr = ext.substring(5);
var catas = ciyfn.getdictdata(pstr, json);
if (dataori == 0)
return '--';
if (!isarray(catas))
return dataori + "!";
for (var a in catas) {
if (catas[a].id == dataori) {
if (catas[a].clas)
return '<span class="' + catas[a].clas + '">' + ciyfn.lang(catas[a].name) + '</span>';
return ciyfn.lang(catas[a].name);
}
}
return '<span title="' + dataori + '">-</span>';
}
preext = ext.substring(0, 3);
if (preext == 'LNY') {
if (dataori == 0)
return '--';
var pstrs = ext.substring(4).split(',');
pstrs[0] = pstrs[0] || '元.万元.亿元';
pstrs[1] = pstrs[1] || '2';
return ciyfn.tonumbet(dataori, pstrs[1], '100.1000000.10000000000', pstrs[0]);
}
if (preext == 'SNY') {
if (dataori == 0)
return '--';
var pstrs = ext.substring(4).split(',');
pstrs[0] = pstrs[0] || '.K.M.B.T.Q';
pstrs[1] = pstrs[1] || '2';
return ciyfn.tonumbet(dataori, pstrs[1], '100.100000.100000000.100000000000.100000000000000', pstrs[0]);
}
if (preext == 'WGT') {
if (dataori == 0)
return '--';
var pstrs = ext.substring(4).split(',');
pstrs[0] = pstrs[0] || '克.千克.吨';
pstrs[1] = pstrs[1] || '2';
return ciyfn.tonumbet(dataori, pstrs[1], '1.1000.1000000', pstrs[0]);
}
if (preext == 'LGH') {
if (dataori == 0)
return '--';
var pstrs = ext.substring(4).split(',');
pstrs[0] = pstrs[0] || '厘米.米.公里';
pstrs[1] = pstrs[1] || '2';
return ciyfn.tonumbet(dataori, pstrs[1], '10.1000.1000000', pstrs[0]);
}
if (preext == 'BET') {
if (dataori == 0)
return '--';
var pstrs = ext.substring(4).split(',');
pstrs[1] = pstrs[1] || '100';
pstrs[2] = pstrs[2] || '2';
return ciyfn.tonumbet(dataori, pstrs[2], pstrs[1], pstrs[0]);
}
if (preext == 'CYC') {
if (dataori == 0)
return '--';
if (dataori < 0)
return -dataori + ciyfn.lang('月');
if (dataori >= 86400)
return toint(dataori / 86400) + ciyfn.lang('天');
return toint(dataori / 60) + ciyfn.lang('分钟');
}
if (preext == 'SEC') {
return ciyfn.totimesec(dataori, '', dataori + ciyfn.lang('秒'));
}
if (preext == 'INT') {
var pstr = ext.substring(4);
if (pstr.length == 0)
return dataori;
if (pstr.indexOf('?') === -1)
return dataori + pstr;
return pstr.replace('?', dataori);
}
if (preext == 'IMG') {
var pstr = ext.substring(4);
if (!dataori)
return '';
//多图,~分割。 图片1~图片2~图片3
var oris = dataori.split('~');
var images = [];
var pdfs = [];
for (var imgidx in oris) {
if (oris[imgidx] == '')
continue;
var realurl = ciyfn.file_stor(oris[imgidx]);
var ind = realurl.lastIndexOf('.');
var fext = ciyfn.file_ext(realurl);
if (ciyfn.isimg(fext))
images.push(realurl);
else
pdfs.push(realurl);
}
if (isview) {
for (var imgidx in images) {
datashow += '<a onclick="ciyfn.showimg(' + imgidx + ', \'' + images.join('~') + '\', \'' + pstr + '\');"><img src="' + images[imgidx] + '" style="max-height:8em;margin:0.5em 0.3em;border-radius:3px;"/></a>';
}
for (var imgidx in pdfs) {
var ext = pdfs[imgidx].substring(pdfs[imgidx].lastIndexOf('.') + 1).toUpperCase();
datashow += '<a href="' + pdfs[imgidx] + '" target="_blank" style="font-size: 0.8em;display: inline-block;padding: 0 0.3em;background: #7676b0;color: #ffffff;margin-right: 0.3em;border-radius: 5px;height: 2em;border: 1px solid #4e4e74;line-height: 2em;">' + ext + '</a>';
}
return datashow;
}
if (pstr.substring(0, 1) == '?') {
for (var imgidx in images) {
var imgsrc = images[imgidx];
datashow += '<a onclick="ciyfn.showimg(' + imgidx + ', \'' + images.join('~') + '\', \'' + pstr + '\');"><img data-src="' + imgsrc + pstr + '" style="max-width:100%;max-height:2.5em;margin-right:0.2em;border-radius:3px;"/></a>';
}
} else {
if (images.length > 0) {
datashow += '<a onclick="ciyfn.showimg(0, \'' + images.join('~') + '\', \'' + pstr + '\');" style="margin-right: 0.2em;"><svg style="display: inline-block;width: 1.5em;vertical-align: text-bottom;" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg"><path d="M897.505882 1005.929412H141.552941c-69.270588 0-126.494118-57.223529-126.494117-126.494118v-662.588235C15.058824 147.576471 72.282353 90.352941 141.552941 90.352941h758.964706c66.258824 3.011765 123.482353 60.235294 123.482353 129.505883v662.588235c0 66.258824-57.223529 123.482353-126.494118 123.482353zM141.552941 156.611765c-33.129412 0-60.235294 27.105882-60.235294 60.235294v662.588235c0 33.129412 27.105882 60.235294 60.235294 60.235294h758.964706c33.129412 0 60.235294-27.105882 60.235294-60.235294v-662.588235c0-33.129412-27.105882-60.235294-60.235294-60.235294H141.552941z" fill="#004D97" p-id="5141"></path><path d="M930.635294 978.823529c-3.011765-3.011765-424.658824-430.682353-487.905882-493.929411-12.047059-12.047059-21.082353-12.047059-24.094118-12.047059-12.047059 0-30.117647 12.047059-48.188235 30.117647-12.047059 15.058824-27.105882 27.105882-36.141177 39.152941l-262.023529 252.988235-45.176471-45.17647 262.02353-252.988236 33.129412-33.129411c15.058824-18.070588 51.2-51.2 93.364705-54.211765 18.070588 0 45.176471 3.011765 72.282353 30.117647 63.247059 63.247059 484.894118 490.917647 490.917647 493.929412l-48.188235 45.17647z" fill="#004D97" p-id="5142"></path><path d="M969.788235 755.952941s-111.435294-111.435294-177.694117-174.682353c-39.152941-39.152941-72.282353-9.035294-84.329412 0l-63.247059 63.247059-42.164706-45.176471 63.247059-63.247058c36.141176-36.141176 108.423529-63.247059 174.682353 0l174.682353 174.682353-45.176471 45.17647zM831.247059 349.364706c-36.141176 0-63.247059-30.117647-63.247059-63.247059s30.117647-63.247059 63.247059-63.247059c36.141176 0 63.247059 30.117647 63.247059 63.247059s-27.105882 63.247059-63.247059 63.247059z m0-96.376471c-18.070588 0-33.129412 15.058824-33.129412 33.129412 0 18.070588 15.058824 33.129412 33.129412 33.129412s33.129412-15.058824 33.129412-33.129412c0-18.070588-15.058824-33.129412-33.129412-33.129412z" fill="#004D97"></path></svg>';
if (images.length > 1)
datashow += '×' + images.length;
datashow += '</a>';
}
}
for (var imgidx in pdfs) {
var ext = pdfs[imgidx].substring(pdfs[imgidx].lastIndexOf('.') + 1).toUpperCase();
datashow += '<a href="' + pdfs[imgidx] + '" target="_blank" style="font-size: 0.8em;display: inline-block;padding: 0 0.3em;background: #7676b0;color: #ffffff;margin-right: 0.3em;border-radius: 5px;height: 2em;border: 1px solid #4e4e74;line-height: 2em;">' + ext + '</a>';
}
return datashow;
}
if (preext == 'TON') {
if (dataori == 0)
return '--';
return ciyfn.tonumunit(dataori, 1000000, ext.substring(4), '吨|10000|万吨');
}
if (preext == 'PCT') {
if (dataori == 0)
return '--';
var pstr = ext.substring(4) || '2';
return ciyfn.tonumunit(dataori, 100, pstr, '%');
}
if (preext == 'CNY') {
if (dataori == 0)
return '--';
var pstrs = ext.substring(4).split(',');
pstrs[0] = pstrs[0] || '2';
if (!pstrs[1])
pstrs[1] = '元';
return ciyfn.tonumunit(dataori, 100, pstrs[0], pstrs[1] + '|10000|万' + pstrs[1]);
} if (preext == 'LOC') {
var pstr = ext.substring(4);
if (pstr.length == 0)
pstr = 'lat';
var pstrs = pstr.split(',');
var lng = tofloat(dataori);
var lat = tofloat(linedata[pstrs[0]]);
var bet = 10000000;
if (pstrs.length > 1)
bet = toint(pstrs[1]);
if (ciyfn.isfloat0(lng) && ciyfn.isfloat0(lat))
return '--';
return '<a onclick="ciyfn.showmap(' + lat / bet + ',' + lng / bet + ',10)">' + ciyfn.lang('打开地图') + '</a>';
}
if (preext == 'NUM') { //小数处理 -3 整数或保留3位小数 3只保留3位小数 空 整数 小数去掉.9999999和.0000001
var dnum = tofloat(dataori);
if (Math.abs(dnum - Math.round(dnum)) < 0.00001) {
dnum = Math.round(dnum);
}
return ciyfn.tonumunit(dnum, 1, ext.substring(4), '', linedata);
}
if (preext == 'URL') {
var pstr = ext.substring(4);
if (!dataori)
return '';
if (pstr == '')
pstr = ciyfn.lang('链接');
return '<a href="' + dataori + '" target="_blank">' + pstr + '</a>';
}
if (preext == 'MSK') { //隐藏部分信息 支持****##**
var pstr = ext.substring(4);
if (dataori.length == 0)
return '';
var retstr = '';
if (dataori.length > pstr.length) {
retstr = dataori.substring(0, dataori.length - pstr.length);
dataori = dataori.substring(dataori.length - pstr.length);
}
for (var i = 0; i < Math.min(dataori.length, pstr.length); i++) {
if (pstr.charAt(i) == '*')
retstr += '*';
else
retstr += dataori.charAt(i);
}
return retstr;
}
preext = ext.substring(0, 2);
if (preext == 'KG') {
if (dataori == 0)
return '--';
return ciyfn.tonumunit(dataori, 1000, ext.substring(3), 'KG|1000|吨');
}
if (preext == 'TC') {
if (dataori == 0)
return '--';
return ciyfn.tonumunit(dataori, 1000, ext.substring(3), '℃');
}
if (preext == 'DB') {
if (dataori == 0)
return '--';
var pstr = ext.substring(3);
var catas = null;
if (!catas)
catas = json[pstr];
if (!isarray(catas))
return dataori + "!";
for (var a in catas)
if (catas[a].id == dataori)
return catas[a]['name'];
return '<span title="' + dataori + '">-</span>';
}
if (preext == 'AV') {
var pstr = ext.substring(3);
if (pstr == '')
pstr = ciyfn.lang('播放');
if (!dataori)
return '';
return '<a href="' + dataori + '" target="_blank">' + pstr + '</a>';
}
if (preext == 'BR') {
if (!dataori)
return '';
return dataori.replace(/\n/g, '<br/>');
}
if (preext == 'MD') {
if (!dataori)
return '';
return '<div style="padding-right:0.5em;">' + ciyfn.markdown(dataori) + '</div>';
}
return dataori;
};