123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- /**
- * 进用作参考,不需要继承该类
- * 主要目的:规范 Mgr 的几个方法命名
- */
- let AlertMgr = {
- /**
- * 初始化
- *
- * @author Pyden
- * @date 2019-03-28
- */
- init () {
- if (CC_EDITOR) {
- return;
- }
- cc.game.on('e_mgr_load_config_done', this.initLocalConfig, this);
- },
- /**
- * 初始化本地配置
- *
- * @author Pyden
- * @date 2019-03-28
- */
- initLocalConfig () {
- this.alertConfigMap = {};
- G.MgrUtils.loadConfig(this, 'AlertConfig', (list) => {
- for (let i = 0, len = list.length; i < len; i++) {
- let alert = list[i];
- alert.tmpMsg = alert.msg;
- this.alertConfigMap[alert.id] = alert;
- }
- });
- },
- /**
- * 获取弹框配置
- *
- * @author Pyden
- * @date 2019-03-28
- * @param {JMC.ALERT_ID} alertId 弹框 Id
- * @param {any} userdata 用户数据,替换##间的配置
- * @returns {AlertConfig}
- */
- getConfig (alertId, userdata) {
- let config = this.alertConfigMap[alertId];
- if (config && userdata) {
- if (config.tmpMsg) {
- config.msg = config.tmpMsg;
- for (let key in userdata) {
- let value = userdata[key];
- if (G.FuncUtils.isNumber(value)) {
- value = value.toString();
- } else if (!G.FuncUtils.isString(value)) {
- continue;
- }
- config.msg = config.msg.replace('#' + key + '#', value);
- }
- }
- }
- if (!config) {
- G.LogUtils.error('Bug: not found alert config', alertId);
- }
- return config;
- }
- };
- module.exports = AlertMgr;
|