@truenewx/tnxcore
Version:
互联网技术解决方案:Web核心扩展支持
74 lines (69 loc) • 2.08 kB
JavaScript
// tnxcore.js
/**
* 基于原生JavaScript的扩展支持
*/
import util from './tnxcore-util';
import app from './tnxcore-app';
import fss from './tnxcore-fss';
import $Enum from './Enum';
import $Properties from './Properties';
import $Yaml from './Yaml';
import Menu from './tnxcore-menu';
import wechat from './tnxcore-wechat';
import './tnxcore.css';
export const Enum = $Enum;
export const Properties = $Properties;
export const Yaml = $Yaml;
export function build(name, create) {
const prefix = name + '@';
let result;
if (window.tnx && window.tnx.$id && window.tnx.$id.startsWith(prefix)) {
result = window.tnx;
} else {
result = create();
result.$id = prefix + new Date().format('yyyyMMddHHmmss');
window.tnx = result;
}
result.build = build;
return result;
}
export default build('tnxcore', () => {
return {
libs: {},
util: util,
app: app,
fss: fss,
Enum: $Enum,
Properties: $Properties,
Yaml: $Yaml,
Menu: Menu,
wechat: wechat,
alert(message, title, callback) {
if (typeof title === 'function') {
callback = title;
title = undefined;
}
const content = title ? (title + ':\n' + message) : message;
alert(content);
if (typeof callback === 'function') {
callback();
}
},
success(message, callback) {
this.alert(message, '成功', callback);
},
error(message, callback) {
this.alert(message, '错误', callback);
},
confirm(message, title, callback) {
if (typeof title === 'function') {
callback = title;
title = undefined;
}
const yes = confirm(title + ':\n' + message);
if (typeof callback === 'function') {
callback(yes);
}
},
};
});