123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- /**
- * 界面相关的工具
- */
- module.exports = {
- /**
- * 防抖动。仅编辑器中编辑时用到,延后执行某函数,避免频繁刷新UI
- *
- * @author Pyden
- * @date 2019-03-21
- * @param {function} func 延后执行的函数
- * @param {int} wait 延后时长(毫秒)
- * @param {boolean} immediate 是否立刻执行。默认否
- * @returns {function} 新封装的函数
- */
- debounce (func, wait, immediate) {
- let timeout;
- return function () {
- let context = this, args = arguments;
- let later = function () {
- timeout = undefined;
- if (!immediate) {
- func.apply(context, args);
- }
- };
- let callNow = immediate && !timeout;
- clearTimeout(timeout);
- timeout = setTimeout(later, wait);
- if (callNow) {
- func.apply(context, args);
- }
- };
- },
- /**
- * @description 获取网络图片路径
- * @author Wetion
- * @date 2019-05-21
- * @param {String} imgName
- * @returns {String}
- */
- getNetImagePath (imgName) {
- if (!window.JMC.RES_ROOT_URL) {
- G.LogUtils.error('没有定义 window.JMC.RES_ROOT_URL');
- return '';
- }
- return cc.path.join(window.JMC.RES_ROOT_URL, 'ssmj/res_h5/icon_img/' + imgName);
- },
- getNode (root, path, component) {
- let node = cc.find(path, root);
- if (node && component) {
- return node.getComponent(component);
- }
- return node;
- }
- };
|