zhiyong.zhou
2024-02-26 60d911172b1dbebe0ab952ce10366b327d5744f1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
export default {
    decode(obj) {
        if (!obj) {
            return null;
        }
        if (Array.isArray(obj)) {
            return this.decodeArray(obj);
        } else if (typeof obj == "object") {
            return this.decodeObject(obj);
        } else if (typeof obj == "string") {
            try {
                return decodeURIComponent(obj);
            } catch (e) {
                return obj;
            }
        } else {
            return obj;
        }
    },
    decodeArray(data) {
        for (let i = 0; i < data.length; i++) {
            if (typeof data[i] == 'string') {
                data[i] = this.decode(data[i]);
            } else {
                data[i] = this.decodeObject(data[i]);
            }
        }
 
        return data;
    },
    decodeObject(data) {
        for (const prop in data) {
            if (data[prop]) {
                data[prop] = this.decode(data[prop]);
            }
        }
 
        return data;
    },
 
};