WebApp【公共组件库】@前端(For Git Submodule)
Tevin
2020-12-29 e717135aa986827ebf0a42cdee70ebf888d98987
common/Tools.js
@@ -177,32 +177,32 @@
        return true;
    }
    static getObjDataByPath(obj, path) {
        const arr = path.split('.');
        const reg2 = /\[(.*)]/g;
        const reg4 = /\w+(?=\[)|(?<=\[)(.*?)(?=])/g;
        let stack = [];
        let temp;
        arr.forEach(item => {
            if (reg2.test(item)) {
                while ((temp = reg4.exec(item))) {
                    stack.push(temp[0]);
                }
            } else {
                stack.push(item);
            }
        });
        stack = stack.map(item => {
            return item.replace(/^['"`]|['"`]$/g, '');
        });
        try {
            return stack.reduce((pre, next) => {
                return pre[next];
            }, obj);
        } catch (err) {
            return undefined;
        }
    }
    // static getObjDataByPath(obj, path) {
    //     const arr = path.split('.');
    //     const reg2 = /\[(.*)]/g;
    //     const reg4 = /\w+(?=\[)|(?<=\[)(.*?)(?=])/g;
    //     let stack = [];
    //     let temp;
    //     arr.forEach(item => {
    //         if (reg2.test(item)) {
    //             while ((temp = reg4.exec(item))) {
    //                 stack.push(temp[0]);
    //             }
    //         } else {
    //             stack.push(item);
    //         }
    //     });
    //     stack = stack.map(item => {
    //         return item.replace(/^['"`]|['"`]$/g, '');
    //     });
    //     try {
    //         return stack.reduce((pre, next) => {
    //             return pre[next];
    //         }, obj);
    //     } catch (err) {
    //         return undefined;
    //     }
    // }
    /**
     * 统计字符串占位宽度