Skip to content

Commit fd33e24

Browse files
author
wanglei48
committed
demo
1 parent 7983262 commit fd33e24

21 files changed

+2030
-4
lines changed

webapp/bus/main.js

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,27 @@
11
(function () {
22
var project = './';
33
var viewRoot = 'pages';
4+
5+
//这里仅仅需要对list页做A/B Testing
6+
var ver = 'ver/1.0.0/';
7+
8+
//在这里设置比例参数,数字0-10,默认A方案为10,只使用最新方案
9+
//a 方案所占比例为60%
10+
var APlan = 6;
11+
12+
//产生1-10随机数,如果条件满足则为plan B
13+
var abRandom = parseInt(Math.random() * 10);
14+
if (abRandom >= APlan) {
15+
project = './' + ver;
16+
viewRoot = ver + viewRoot;
17+
}
18+
19+
//如果url强制设置plan=b则使用老方案
20+
if (_.getUrlParam().plan && _.getUrlParam().plan == 'b') {
21+
project = './' + ver;
22+
viewRoot = ver + viewRoot;
23+
}
24+
425
require.config({
526
paths: {
627
//BUS相关模板根目录
@@ -15,11 +36,8 @@
1536
}
1637
});
1738
require(['AbstractApp', 'UIHeader'], function (APP, UIHeader) {
39+
1840
window.APP = new APP({
19-
//配置未组件化的城市列表路径
20-
// viewMapping: {
21-
// city: 'views/city'
22-
// },
2341
UIHeader: UIHeader,
2442
viewRootPath: viewRoot
2543
});
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
define(['AbstractModel', 'BusStore'], function (AbstractModel, BusStore) {
2+
3+
var BaseModel = _.inherit(AbstractModel, {
4+
5+
initDomain: function () {
6+
//复杂的环境问题
7+
//......
8+
this.domain = 'api.kuai.baidu.com';
9+
},
10+
11+
propertys: function ($super) {
12+
$super();
13+
14+
this.initDomain();
15+
16+
var t = (new Date().getTime()).toString();
17+
this.path = '';
18+
19+
this.cacheData = null;
20+
this.param = {
21+
head: {
22+
us: '',
23+
version: '1.0.0',
24+
ct: 3,
25+
time: t.substr(0, t.length - 3),
26+
sign:''
27+
}
28+
};
29+
this.dataType = 'jsonp';
30+
this.ajaxOnly = false;
31+
32+
this.errorCallback = function () { };
33+
34+
//统一处理分返回验证
35+
this.pushValidates(function (data) {
36+
return this.baseDataValidate(data);
37+
});
38+
39+
},
40+
41+
//首轮处理返回数据,检查错误码做统一验证处理
42+
baseDataValidate: function (data) {
43+
if (_.isString(data)) data = JSON.parse(data);
44+
if (data.errno === 0) return true;
45+
if (window.APP && data && data.msg) window.APP.showToast(data.msg, this.errorCallback);
46+
return false;
47+
},
48+
49+
dataformat: function (data) {
50+
if (_.isString(data)) data = JSON.parse(data);
51+
if (data.data) return data.data;
52+
return data;
53+
},
54+
55+
buildurl: function () {
56+
return this.protocol + '://' + this.domain + this.path + (typeof this.url === 'function' ? this.url() : this.url);
57+
},
58+
59+
getSign: function () {
60+
var param = this.getParam() || {};
61+
return JSON.stringify(param);
62+
},
63+
64+
onDataSuccess: function (fdata, data) {
65+
if (this.cacheData && this.cacheData.set)
66+
this.cacheData.set(fdata, this.getSign());
67+
},
68+
69+
execute: function ($super, onComplete, onError, ajaxOnly, scope) {
70+
var data = null;
71+
if (!ajaxOnly && !this.ajaxOnly && this.cacheData && this.cacheData.get) {
72+
data = this.cacheData.get(this.getSign());
73+
if (data) {
74+
onComplete(data);
75+
return;
76+
}
77+
}
78+
$super(onComplete, onError, ajaxOnly, scope);
79+
}
80+
81+
});
82+
83+
84+
return {
85+
86+
SCityModel: _.inherit(BaseModel, {
87+
//默认属性
88+
propertys: function ($super) {
89+
$super();
90+
this.url = '/city/getstartcitys';
91+
this.cacheData = BusStore.SCityStore.getInstance();
92+
}
93+
}),
94+
95+
ECityModel: _.inherit(BaseModel, {
96+
//默认属性
97+
propertys: function ($super) {
98+
$super();
99+
this.url = '/city/getarrivalcitys';
100+
this.cacheData = BusStore.ECityStore.getInstance();
101+
102+
}
103+
}),
104+
105+
SCitySearchModel: _.inherit(BaseModel, {
106+
//默认属性
107+
propertys: function ($super) {
108+
$super();
109+
this.url = '/city/searchstart';
110+
// this.cacheData = BusStore.ECitySearchStore.getInstance();
111+
}
112+
}),
113+
114+
ECitySearchModel: _.inherit(BaseModel, {
115+
//默认属性
116+
propertys: function ($super) {
117+
$super();
118+
this.url = '/city/searcharrival';
119+
// this.cacheData = BusStore.ECitySearchStore.getInstance();
120+
}
121+
}),
122+
123+
ListModel: _.inherit(BaseModel, {
124+
//默认属性
125+
propertys: function ($super) {
126+
$super();
127+
this.url = '/schedule/list';
128+
this.cacheData = BusStore.ListStore.getInstance();
129+
130+
}
131+
})
132+
};
133+
});
Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
define(['AbstractStore'], function (AbstractStore) {
2+
3+
return {
4+
InitAppStore: _.inherit(AbstractStore, {
5+
//默认属性
6+
propertys: function ($super) {
7+
$super();
8+
this.key = 'BUS_InitAppStore';
9+
this.lifeTime = '1D'; //缓存时间
10+
}
11+
}),
12+
13+
SCityStore: _.inherit(AbstractStore, {
14+
//默认属性
15+
propertys: function ($super) {
16+
$super();
17+
this.key = 'BUS_StartCityStore';
18+
this.lifeTime = '5D'; //缓存时间
19+
}
20+
}),
21+
22+
ECityStore: _.inherit(AbstractStore, {
23+
//默认属性
24+
propertys: function ($super) {
25+
$super();
26+
this.key = 'BUS_EndCityStore';
27+
this.lifeTime = '5D'; //缓存时间
28+
29+
}
30+
}),
31+
32+
ECitySearchStore: _.inherit(AbstractStore, {
33+
//默认属性
34+
propertys: function ($super) {
35+
$super();
36+
this.key = 'BUS_EndCitySearchStore';
37+
this.lifeTime = '1D'; //缓存时间
38+
39+
}
40+
}),
41+
42+
SHisCityStore: _.inherit(AbstractStore, {
43+
//默认属性
44+
propertys: function ($super) {
45+
$super();
46+
this.key = 'BUS_StartHisCityStore';
47+
this.lifeTime = '1D'; //缓存时间
48+
49+
}
50+
}),
51+
52+
EHisCityStore: _.inherit(AbstractStore, {
53+
//默认属性
54+
propertys: function ($super) {
55+
$super();
56+
this.key = 'BUS_EndHisCityStore';
57+
this.lifeTime = '1D'; //缓存时间
58+
59+
}
60+
}),
61+
62+
//历史选择数据
63+
HisRouteStore: _.inherit(AbstractStore, {
64+
//默认属性
65+
propertys: function ($super) {
66+
$super();
67+
this.key = 'BUS_HisRouteStore';
68+
this.lifeTime = '30D'; //缓存时间
69+
}
70+
}),
71+
72+
ListStore: _.inherit(AbstractStore, {
73+
//默认属性
74+
propertys: function ($super) {
75+
$super();
76+
this.key = 'BUS_ListStore';
77+
this.lifeTime = '1M'; //缓存时间
78+
}
79+
}),
80+
81+
startCityStore: _.inherit(AbstractStore, {
82+
//默认属性
83+
propertys: function ($super) {
84+
$super();
85+
this.key = 'BUS_StartCityObjStore';
86+
this.lifeTime = '1D';
87+
88+
}
89+
}),
90+
91+
endCityStore: _.inherit(AbstractStore, {
92+
//默认属性
93+
propertys: function ($super) {
94+
$super();
95+
this.key = 'BUS_EndCityObjStore';
96+
this.lifeTime = '1D';
97+
}
98+
}),
99+
100+
CityStatusStore: _.inherit(AbstractStore, {
101+
//默认属性
102+
propertys: function ($super) {
103+
$super();
104+
this.key = 'BUS_CityStatusStore';
105+
this.lifeTime = '1D';
106+
}
107+
}),
108+
109+
setOutDateStore: _.inherit(AbstractStore, {
110+
//默认属性
111+
propertys: function ($super) {
112+
$super();
113+
this.key = 'BUS_SetOutDateStore';
114+
this.lifeTime = '1H';
115+
}
116+
}),
117+
118+
ScheduleDetailStore: _.inherit(AbstractStore, {
119+
//默认属性
120+
propertys: function ($super) {
121+
$super();
122+
this.key = 'BUS_ScheduleDetailStore';
123+
this.lifeTime = '30S';
124+
}
125+
}),
126+
127+
UserInfoStore: _.inherit(AbstractStore, {
128+
//默认属性
129+
propertys: function ($super) {
130+
$super();
131+
this.key = 'BUS_UserInfoStore';
132+
this.lifeTime = '1H';
133+
}
134+
}),
135+
136+
ContactListStore: _.inherit(AbstractStore, {
137+
//默认属性
138+
propertys: function ($super) {
139+
$super();
140+
this.key = 'BUS_ContactListStore';
141+
this.lifeTime = '1D';
142+
}
143+
}),
144+
145+
OrderListStore: _.inherit(AbstractStore, {
146+
//默认属性
147+
propertys: function ($super) {
148+
$super();
149+
this.key = 'BUS_OrderListStore';
150+
this.lifeTime = '10S';
151+
}
152+
}),
153+
154+
OrderDetailStore: _.inherit(AbstractStore, {
155+
//默认属性
156+
propertys: function ($super) {
157+
$super();
158+
this.key = 'BUS_OrderDetailStore';
159+
this.lifeTime = '10S';
160+
}
161+
}),
162+
163+
//出发站地图相关接口
164+
stationListStore: _.inherit(AbstractStore, {
165+
//默认属性
166+
propertys: function ($super) {
167+
$super();
168+
this.key = 'BUS_StationListStore';
169+
this.lifeTime = '1D';
170+
}
171+
})
172+
173+
}
174+
175+
});

0 commit comments

Comments
 (0)