-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
181 lines (161 loc) · 5.36 KB
/
index.html
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
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,initial-scale=1.0,width=device-width" />
<meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
<title>Root Window</title>
<link rel="stylesheet" type="text/css" href="./css/api.css" />
<style type="text/css">
</style>
</head>
<body>
</body>
<script type="text/javascript" src="./script/api.js"></script>
<script type="text/javascript" src="./script/db.js"></script>
<script type="text/javascript">
apiready = function() {
// 初始化商品分类列表
initWareTypeList();
// 初始化本地数据库及应用需要的相关表结构
initDatabase();
// 初始化第三方推送模块,个推
initPushGeTui();
// 1. 根据UI架构设计(ui-architecture.xmind),打开首页Window
// 2. 由于是次Window是首页窗口,通过设置参数slidBackEnabled,关闭iOS默认回划关闭窗口的功能
api.openWin({
name: 'main',
url: './html/main.html',
slidBackEnabled: false
});
};
// 初始化商品分类列表
function initWareTypeList() {
// 获取上一次的商品分类列表
var wareTypeList = $api.getStorage('wareTypeList');
// 如果没有商品分类列表,则使用默认的商品分类列表
if (!wareTypeList) {
wareTypeList = [{
"id": "56c80da883af652643474b6b",
"name": "水果",
"banner": {
"url": "http://7y0hol.com1.z0.glb.clouddn.com/apicloud/f761997f8fd33af25af5354737e37bcc.png",
"id": "57f63bdf0d3febfe58585568"
}
}, {
"id": "56c80db78d04c83d3d1dedea",
"name": "食材",
"banner": {
"url": "http://7y0hol.com1.z0.glb.clouddn.com/apicloud/be93f9fdeda576ad81d0c728528cef50.png",
"id": "57f63be70d3febfe5858556c"
}
}, {
"id": "56c80dc031da9e480de1cb49",
"name": "零食",
"banner": {
"url": "http://7y0hol.com1.z0.glb.clouddn.com/apicloud/be93f9fdeda576ad81d0c728528cef50.png",
"id": "57f63bec9592b3fc6a341b59"
}
}, {
"id": "56c80dc383af652643474b6d",
"name": "牛奶",
"banner": {
"url": "http://7y0hol.com1.z0.glb.clouddn.com/apicloud/f761997f8fd33af25af5354737e37bcc.png",
"id": "57f63bf0c6f05d0956108828"
}
}, {
"id": "56c80dc88d04c83d3d1dedf3",
"name": "蔬菜",
"banner": {
"url": "http://7y0hol.com1.z0.glb.clouddn.com/apicloud/be93f9fdeda576ad81d0c728528cef50.png",
"id": "57f63bf39592b3fc6a341b5d"
}
}];
}
// 从服务器端更新商品分类列表
fnGetWareTypeList();
}
// 从服务器端更新商品分类列表
function fnGetWareTypeList() {
var params = {
fields: {
createdAt: false,
updatedAt: false
},
where: {},
skip: 0,
limit: 5
}
params = $api.jsonToStr(params);
api.ajax({
url: 'http://d.apicloud.com/mcm/api/wareType?filter=' + params,
method: 'get',
headers: {
"X-APICloud-AppId": "A6921544633372",
"X-APICloud-AppKey": "2672b5911d8551540c1ea598e01c87fee217a1e5.1482500122476"
}
}, function(ret, err) {
if (ret) {
// 存储商品分类列表到本地
$api.setStorage('wareTypeList', ret);
} else {
api.toast({
msg: '更新商品分类列表失败',
duration: 2000,
location: 'bottom'
});
}
});
}
// 初始化本地数据库及应用需要的相关表结构
function initDatabase() {
$db.open();
}
// 初始化第三方推送模块,个推
function initPushGeTui() {
var pushGeTui = api.require('pushGeTui');
// 注册设备和应用信息到个推
pushGeTui.initialize(function(ret) {
var value = "";
// 区分通知和消息
switch (ret.type) {
// 返回个推平台上的ID
case 'cid':
value = 'cid:' + ret.cid;
break;
// 返回消息内容
case 'payload':
value = 'payload:' + ret.payload;
// 解析消息体
fnParsePayLoad(ret.payload);
break;
case 'occurError':
value = 'occurError';
break;
default:
break;
}
});
}
// 解析消息体,并根据约定好的消息类型,完成相关操作
function fnParsePayLoad(payload_) {
// 消息内容为JSON格式字符串
var payload = $api.strToJson(payload_);
switch (payload.type) {
// 1. 推送的是商品打折消息,点击消息可以打开商品详情Window,并通过参数传递商品ID
// 2. Window名称根据UI架构设计(ui-architecture.xmind)来指定
case 'ware':
api.openWin({
name: 'ware',
url: './html/ware.html',
pageParam: {
wareId: payload.wareId
}
});
break;
default:
break;
}
}
</script>
</html>