c81b05de-adb4-44f1-a5ad-15b9193cf1cf.js 3.42 KB
"use strict";
cc._RF.push(module, 'c81b0XerbRE8aWtFbkZPPHP', 'CustomerServiceDataCenter');
// script/customerService/script/CustomerServiceDataCenter.ts

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const GameConfig_1 = require("../../GameConfig");
const HttpClient_1 = require("../../network/HttpClient");
let CustomerServiceDataCenter = /** @class */ (() => {
    class CustomerServiceDataCenter {
        constructor() {
            /**网络请求对象 */
            this._httpObj = new HttpClient_1.HttpClient("");
            this._showCustomerServiceBtn = true;
            this._tipLabel = "";
            this._qrCodePath = "";
        }
        init() {
            this.requestCooperationDataFromOSS();
        }
        /**获取数据中心单例对象 */
        static getInstance() {
            return CustomerServiceDataCenter._instance;
        }
        /**从oss上拉取配置文件 */
        async requestCooperationDataFromOSS() {
            try {
                let configPath = `https://weixingame.icesimba.com/weixingame/icesimba/${GameConfig_1.GameConfig.debug ? "dev" : "release"}/customerService/${GameConfig_1.channel}/${GameConfig_1.GameConfig.gameId}/config.json`;
                let resStr = await this._httpObj.get(configPath);
                let res = JSON.parse(resStr);
                if (res) {
                    let items = res.items;
                    if (items) {
                        for (let i = 0; i < items.length; i++) {
                            let item = items[i];
                            if (item && item.qrCodeImg && "" !== item.qrCodeImg) {
                                if (item.showCustomerServiceBtn) {
                                    this._showCustomerServiceBtn = item.showCustomerServiceBtn;
                                }
                                if (item.tipLabel) {
                                    this._tipLabel = item.tipLabel;
                                }
                                if (item.qrCodeImg) {
                                    this._qrCodePath = item.qrCodeImg;
                                }
                            }
                        }
                    }
                }
            }
            catch (e) {
                console.error(e);
            }
        }
        /**刷新QRCode */
        refreshQRCode(imgPath, spr) {
            return new Promise((resolve, reject) => {
                let path = `https://weixingame.icesimba.com/weixingame/icesimba/${GameConfig_1.GameConfig.debug ? "dev" : "release"}/customerService/${GameConfig_1.channel}/${GameConfig_1.GameConfig.gameId}/${imgPath}`;
                cc.assetManager.loadRemote(path, (err, sprite) => {
                    if (err) {
                        reject(err);
                    }
                    else {
                        spr.spriteFrame = new cc.SpriteFrame(sprite);
                        resolve(true);
                    }
                });
            });
        }
        getShowCustomerServiceBtn() {
            return this._showCustomerServiceBtn;
        }
        getTipLabel() {
            return this._tipLabel;
        }
        getQRCodePath() {
            return this._qrCodePath;
        }
    }
    /**单例对象 */
    CustomerServiceDataCenter._instance = new CustomerServiceDataCenter();
    return CustomerServiceDataCenter;
})();
exports.default = CustomerServiceDataCenter;

cc._RF.pop();