declare var wx; let defaultConfig = { title: '温馨提示', content: '', okText: '确认', okColor: '#aa8535', cancelText:'取消', cancelColor: '#262626', }; // == 解析配置 function parse(content) { let config:any = {}; if(typeof content === 'string'){ config.content = content; }else if(typeof content === 'object'){ config = content; } config = (Object).assign({}, defaultConfig, config); return config; } function create(type, config, cb) { wx.showModal({ title: config.title, content: config.content, cancelText: config.cancelText, cancelColor: config.cancelColor, confirmText: config.okText, confirmColor: config.okColor, showCancel: type == 'confirm' ? true : false, success: (res) => { if(cb) cb(res.confirm); } }); } export const modal = { init: (config) => { defaultConfig = (Object).assign({}, defaultConfig, config); }, alert: (content, cb) => { const config = parse(content); create('alert', config, cb); }, confirm: (content, cb) => { const config = parse(content); create('confirm', config, cb); } }