vesh-cli
Version:
码农村nodejs版本VESH框架脚手架搭建器
306 lines (304 loc) • 16.3 kB
JavaScript
(function (V, W, $) {
V.registScript(function (path, vm) {
var _ = this, __ = {};
{
V.inherit.apply(_, [W.Control, [path || '<div class="c_textshower"><div id="fill" _="type:\'fill\'" class="c_textshower_inner" style="position:relative;">{html}</div></div>', V.merge({
data: {
},
controls: {
fill: {}
}
}, vm)]]);
__.onLoad = _.onLoad;
__.render = _.render;
_.addDesc('textshower 对象');
_.addDesc('非必填属性:');
_.addDesc('\twidth 类型300px,100%');
_.addDesc('\theight 类型300px,不支持百分比');
_.addDesc('\ttemplate 接入texteditor的模板内容');
_.addDesc('\tvalue 接入其实际内容');
_.addDesc("\t定义:editor:{path:'ueditor.config.js;ueditor.all.min.js;lang/zh-cn/zh-cn.js;../Scripts/module/part/texteditor.js',params:['',{data:{debug:true,image:'../../Scripts/ref/images/'}}]}");
//_.addDesc('\tinit 新加的控件(icon:图标地址,tooltip:图标显示名称,command:要执行的函数)');
}
_.onLoad = function (node) {
V.forC(_.events, function (k, v) {
switch (k.toLowerCase()) {
case 'click':
break;
default:
_.bindEvent(_.node, k, v);
break;
}
}, function () {
__.onLoad(node);
});
};
_.fill = function () {
return {
value: (function () {
var val = {};
$(_.vms.fill.v.node.find('[_type]')).each(function (i, v) {
v = $(v);
var id = v.attr('id');
if (id)
switch (v[0].tagName.toLowerCase()) {
case 'input':
case 'select':
val[id] = val[id] || v.val();
break;
case 'textarea':
val[id] = val[id] || v.val() || v.text();
break;
case 'img':
val[id] = val[id] || v.attr('src');
break;
default:
val[id] = val[id] || v.html();
break;
}
});
return val;
})()
}
};
__.getTemplate = function (v) {
return V.decHtml(v).replace(/</g, '<').replace(/>/g, '>').replace(/<script/g, '<script').replace(/script>/g, 'script>').replace(/<img[^>]+>/g, function (txt) {
var id = txt.match(/id\s*=\s*['"][^'"]+['"]/);
if (id.length > 0) { id = id[0].split('\"')[1]; } else id = '';
var type = txt.match(/_type\s*=\s*['"][^'"]+['"]/);
if (type.length > 0) { type = type[0].split('\"')[1]; } else type = '';
var data = txt.match(/_data\s*=\s*['"][^'"]+['"]/);
if (data.length > 0) { data = eval('(' + (data[0].split('\"')[1]).replace(/"/g, "\"") + ')'); } else data = {};
V.merge(data, { id: id, type: type }, true);
switch (data.type) {
case 'text':
return V.format("<span id='{id}' _type='{type}' class='c_{type}'></span>", V.merge({ width: Math.max(135, data.length * 5) }, data));
case 'textarea':
return V.format("<div id='{id}' _type='{type}' class='c_{type}'></div>", data);
case 'area':
return V.format("<div id='{id}' _type='{type}' class='c_{type}' template='{Content}'></div>", data);
case 'signature':
return V.format("<span id='{id}' _type='{type}' class='c_{type}' style='width: 200px;height: 100px;position: relative;display:inline-block;background-repeat: no-repeat;background-size: cover;overflow:hidden;'></span>", data);
//return V.format("<img id='{id}' _type='{type}' class='c_{type}' style='width: 100px;height: 50px;'/>", data);
case 'seal':
return V.format("<div id='{id}' _type='{type}' class='c_{type}' style='width: 150px;height: 150px;position: absolute;right: 30px;bottom: 71px;background-repeat: no-repeat;background-size: cover;overflow: hidden;background: transparent;'></div>", data);
default:
return '';
}
});
};
__.client = null;
__.addCaClient = function (parent, func) {
//__.client ||
__.client = __.client || (function () {
if (window.ActiveXObject !== undefined) {
// IE 浏览器创建插件
try {
var plugin_embed = document.createElement("OBJECT");
plugin_embed.setAttribute("id", "npHebcaWebSealPlugin" + V.random());
plugin_embed.setAttribute("classid", "CLSID:AD05FC92-22B4-47D3-9D3A-A8558CBFB912");
//plugin_embed.setAttribute("width", 750);
//plugin_embed.setAttribute("height", 750);
return plugin_embed;
}
catch (e) {
throw Error("没有安装客户端软件或IE阻止其运行.");
}
}
else // 非IE浏览器加载使用embed方式加载插件
{
var hebcaMimeType = "application/hebca-npwebseal-plugin";
if (!(navigator.mimeTypes && navigator.mimeTypes[hebcaMimeType] && navigator.mimeTypes[hebcaMimeType].enabledPlugin)) {
throw Error("请检查是否安装河北CA电子签章多浏览器客户端或被浏览器禁用!\r\n安装或启用后重新打开浏览器再试!");
return null;
}
var plugin_embed = document.createElement("embed");
plugin_embed.setAttribute("id", "npHebcaWebSealPlugin" + V.random());
plugin_embed.setAttribute("type", hebcaMimeType);
plugin_embed.setAttribute("width", 750);
plugin_embed.setAttribute("height", 750);
return plugin_embed;
//检测是否安装成功, 若被浏览器阻止, 会抛出异常.
}
})();
parent.append(__.client);
V.once(function () {
try {
__.client.CheckBlockedByBrowser();
func(__.client);
}
catch (e) {
V.callCommand('alert', ['插件未安装或被浏览器阻止.' + e.message]);
}
}, 1000);
};
__.changeca = function (v2, v) {
try {
__.addCaClient(v2, function (client) {
//必须要等会 再替换并显示章
client.VerifyAndShowSealWithResult(v.SealResult, 1, v.SealContent);
var refresh = V.once(function () {
try {
client.RefreshSeal(); //refresh();
} catch (e) { }
}, 4000);
//refresh();
});
} catch (e) {
V.callCommand('alert', [e.message]);
}
};
__.signclient = null;
__.addSignClient = function (parent, func) {
//__.client ||
__.signclient = __.signclient || (function () {
if (window.ActiveXObject !== undefined) {
// IE 浏览器创建插件
try {
var plugin_embed = document.createElement("OBJECT");
plugin_embed.setAttribute("id", "npHebcaWebSealPlugin" + V.random());
plugin_embed.setAttribute("classid", "CLSID:AD05FC92-22B4-47D3-9D3A-A8558CBFB912");
//plugin_embed.setAttribute("width", 750);
//plugin_embed.setAttribute("height", 750);
return plugin_embed;
}
catch (e) {
throw Error("没有安装客户端软件或IE阻止其运行.");
}
}
else // 非IE浏览器加载使用embed方式加载插件
{
var hebcaMimeType = "application/hebca-npwebseal-plugin";
if (!(navigator.mimeTypes && navigator.mimeTypes[hebcaMimeType] && navigator.mimeTypes[hebcaMimeType].enabledPlugin)) {
throw Error("请检查是否安装河北CA电子签章多浏览器客户端或被浏览器禁用!\r\n安装或启用后重新打开浏览器再试!");
return null;
}
var plugin_embed = document.createElement("embed");
plugin_embed.setAttribute("id", "npHebcaWebSealPlugin" + V.random());
plugin_embed.setAttribute("type", hebcaMimeType);
plugin_embed.setAttribute("width", 750);
plugin_embed.setAttribute("height", 150);
return plugin_embed;
//检测是否安装成功, 若被浏览器阻止, 会抛出异常.
}
})();
parent.append(__.signclient);
V.once(function () {
try {
__.signclient.CheckBlockedByBrowser();
func(__.signclient);
}
catch (e) {
V.callCommand('alert', ['插件未安装或被浏览器阻止.' + e.message]);
}
}, 1000);
};
__.changesign = function (v2, v) {
try {
__.addSignClient(v2, function (client) {
//必须要等会 再替换并显示章
client.VerifyAndShowSealWithResult(v.SignResult, 1, v.SignContent);
var refresh = V.once(function () {
try {
client.RefreshSeal(); //refresh();
} catch (e) { }
}, 4000);
//refresh();
});
} catch (e) {
V.callCommand('alert', [e.message]);
}
};
__.fillNode = function (node, v) {
$($(node).find('[_type]')).each(function (i, v2) {
v2 = $(v2);
var id = V.getValue(v2.attr('id'), '');
var val = V.getValue(v[id], '');
if (val.replace) val = val.replace(/\r\n/g, '<br/>');
if (V.isValid(val) || val === '') {
switch (v2.attr('_type').toLowerCase()) {
case 'input':
case 'textarea':
case 'select':
default:
try {
v2.html(V.decHtml(val + '').replace(/<br\/>/g, '<br/> '));
} catch (e) {
console.log(id + ":" + val); console.log(e.stack);
v2.html((val + '').replace(/<br\/>/g, '<br/> '));
}
break;
case 'area':
var temp = __.getTemplate(v2.attr('template'));
v2.empty();
V.each(val, function (v3) {
var node2 = V.newEl('div', 'c_container', temp).appendTo(v2);
__.fillNode(node2, v3);
});
break;
case 'signature':
switch (id.toLowerCase()) {
case 'arbi_signature':
if (v.SignResult) __.changesign(v2, v);
else v2.css('background-image', 'url(' + GV.upload + V.getValue(val, '../style/Image/home/signature.png') + ')').css('background-size', 'cover');
break;
default:
v2.css('background-image', 'url(' + GV.upload + val + ')').css('background-size', 'cover'); ;
break;
}
break;
case 'seal':
switch (id.toLowerCase()) {
case 'arbi_seal':
if (v.SealResult) __.changeca(v2, v);
else v2.css('background-image', 'url(' + GV.upload + V.getValue(val, '../style/Image/home/ywzhang.png') + ')').css('background-size', 'cover');
break;
case 'arbi_seal2':
if (v.SealResult) __.changeca(v2, v);
else v2.css('background-image', 'url(' + GV.upload + V.getValue(val, '../style/Image/home/zczhang.png') + ')').css('background-size', 'cover');
break;
case 'arbi_signature':
if (v.SignResult) __.changesign(v2, v);
else v2.css('background-image', 'url(' + GV.upload + V.getValue(val, '../style/Image/home/signature.png') + ')').css('background-size', 'cover');
break;
default:
v2.css('background-image', 'url(' + GV.upload + val + ')').css('background-size', 'cover'); ;
break;
}
break;
}
}
});
};
_.render = function (data) {
var ret = V.merge({}, data); //处理空数据
V.forC(ret, function (k, v) {
switch (k.toLowerCase()) {
case 'template':
var val = __.getTemplate(v);
_.vms.fill.update({ value: { html: val} });
break;
case 'value':
__.fillNode(_.vms.fill.v.node, v);
var rehtml = function (node) {
//将div重新放置入p节点中
var ss = node.find('div.c_area,div.c_textarea');
V.each(ss, function (v2) {
v2 = $(v2);
var p = v2.prev();
while (p.children().length > 0) p = p.children(0);
p.append(v2);
if (v2.find('div.c_area,div.c_textarea').length > 0) rehtml(v2);
});
};
rehtml(_.vms.fill.v.node);
break;
}
}, function () {
delete data.value;
data = __.render(data);
});
return data;
}
});
})(VJ, VJ.view, jQuery);