admin
2021-09-18 5a3878eb706a5e81b67d9e3ea70b5cffae95911d
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>奖励铂金会员</title>
        <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
        <script src="https://cdn.bootcss.com/vConsole/3.3.0/vconsole.min.js"></script>
        <script>
            window.onresize = function() {
                document.documentElement.style.fontSize = document.documentElement.clientWidth / 7.5 + 'px';
            };
            window.onresize();
        </script>
        <style>
            body {
                background: #F3F3F3;
                margin: 0;
                padding: 0;
                font-family: Arial, "Microsoft YaHei";
            }
 
            button {
                display: block;
            }
        </style>
 
    </head>
    <body>
        <button onclick="toast()">toast</button>
        <button onclick="dstoast()">showAwardAd</button>
        <button onclick="jumpGoodsDetail()">jumpGoodsDetail</button>
        <button onclick="showAd()">showAd</button>
        <button onclick="jumpThirdPlatform()">jumpThirdPlatform</button>
        <button onclick="buyVip()">buyVip</button>
        <button onclick="vipPayFinish()">苹果内购支付结果通知</button>
        <button onclick="getUid()">getUid</button>
        <button onclick="getRequestBaseParams()">.getRequestBaseParams</button>
        <button onclick="showLoading()">showLoading</button>
 
 
    </body>
 
    <script src="https://cdn.bootcdn.net/ajax/libs/dsbridge/3.1.4/dsbridge.min.js"></script>
    <script src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js">
    </script>
 
    <script>
        function toast() {
            bridge.call("yestv.toast", "123123");
        }
 
        function dstoast() {
            bridge.call("yestv.showAwardAd", {
                id: '123123'
            }, function(res) {
                yestv.toast("广告回调");
            });
        }
 
 
        function jumpGoodsDetail() {
            bridge.call("yestv.jumpGoodsDetail", {
                id: '640225471587',
                goodsType: 1,
                from: 'test'
            });
 
        }
 
        function showAd() {
            // bridge.call("yestv.showAwardAd", {
            //     pid: '946119116',
            //     type: 'csj',
            // }, function(res) {
            //     res=JSON.parse(res);
            //     if (res.code == 0) {
            //         yestv.toast("广告展示成功");
            //     }
            // });
            bridge.call("yestv.toastAwardSuccess", "成功获得1天铂金会员权益");
        }
 
        function jumpThirdPlatform() {
            bridge.call("yestv.jumpThirdPlatform", {
                sourceType: 2,
                jumpLink: "https://u.jd.com/GfjARui",
                wxxcxJumpInfo: {
                    path: "pages/union/proxy/proxy?spreadUrl=https%3A%2F%2Fu.jd.com%2FGfjARui",
                    userName: "gh_45b306365c3d"
                }
            });
        }
 
        function buyVip() {
            bridge.call("yestv.buyVip", {
                code: "ysdq_month",
                orderNo: "213123"
            }, function(auth) {
                yestv.toast("支付凭证回调成功:" + auth)
            });
        }
 
        function vipPayFinish() {
            bridge.call("yestv.vipPayFinish", 1);
        }
 
        function getUid() {
            var uid = bridge.call("yestv.getUid");
            bridge.call("yestv.toast", "uid:" + uid);
        }
 
        function getRequestBaseParams() {
            var result = bridge.call("yestv.getRequestBaseParams", {
                id: 123
            });
            bridge.call("yestv.toast", "结果:" + result);
        }
 
        function showLoading() {
            bridge.call("yestv.showLoading");
            setTimeout(function() {
                bridge.call("yestv.hideLoading");
            }, 3000);
        }
 
 
 
        $(function() {
            const formUtil = {
 
                /**
                 * 将表单转为对象
                 * @param fileds
                 */
                formFieldsToJSON: function(fileds) {
                    var finalResult = {};
                    for (key in fileds) {
                        var obj = {};
                        obj[key] = fileds[key];
                        var tempResult = this.formFieldToJSON(obj);
                        var keys = new Array();
 
                        while (Object.prototype.toString.call(tempResult) === '[object Object]') {
                            var key = Object.keys(tempResult)[0];
                            keys.push(key);
                            tempResult = tempResult[key];
                        }
 
                        var temp = "finalResult";
                        for (var i = 0; i < keys.length; i++) {
                            temp += "['" + keys[i] + "']";
                            if (i != keys.length - 1) {
                                if (eval(temp + "==undefined") == true) {
                                    eval(temp + "={}");
                                }
                            } else {
                                eval(temp + "=" + (isNaN(tempResult) ? "'" + tempResult + "'" : tempResult));
                            }
                        }
                    }
 
                    return finalResult;
                },
                formFieldToJSON: function(field) {
                    var key = Object.keys(field)[0];
                    var value = field[key];
                    var keys = key.split(".");
                    if (keys.length > 1) {
                        var newValue = {};
                        var k = keys[keys.length - 1];
                        keys.splice(keys.length - 1, 1);
                        newValue[k] = value;
                        var final = {};
                        final[keys.join(".")] = newValue;
                        return this.formFieldToJSON(final);
                    } else {
                        return field;
                    }
                },
                jsonToFormField: function(data) {
                    var result = {};
                    for (key in data) {
                        if (Object.prototype.toString.call(data[key]) === '[object Object]') {
                            for (ckey in data[key]) {
                                result[key + "." + ckey] = data[key][ckey];
                            }
                        } else {
                            result[key] = data[key];
                        }
                    }
                    return result;
                }
            };
 
            var form = {
                "app.id": 123,
                "app.name": "测试",
                "app.p.id": "id",
                "app.p.key": "key",
                id: 12312312,
                name: "测试123"
            };
 
            var result = formUtil.formFieldsToJSON(form);
            console.log(result)
 
            var json = {
                app: {
                    id: 123,
                    name: "测试"
                },
                id: 1
            }
            result = formUtil.jsonToFormField(json);
            console.log(result)
        })
    </script>
 
 
 
 
</html>