Skip to content

Commit f21de73

Browse files
author
wanglei48
committed
demo
1 parent 685c8ab commit f21de73

File tree

117 files changed

+16008
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

117 files changed

+16008
-0
lines changed

.idea/.name

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules.xml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/mvc.iml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/vcs.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

webapp/blade/common.js

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
/**
2+
* @file 公共配置文件
3+
* @author wanglei48@baidu.com, zhaozhixin@baidu.com
4+
*/
5+
6+
(function () {
7+
8+
// 项目根路径,这个会跟着外层入口index.html而变化
9+
var app = '../blade/';
10+
var common = '../common/';
11+
// 模板路径
12+
13+
require.config({
14+
waitSeconds: 60,
15+
shim: {
16+
17+
},
18+
paths: {
19+
'text': app + 'libs/require.text',
20+
'css': app + 'libs/require.css',
21+
'PbMain': common + 'public/pb.main',
22+
'PbModel': common + 'public/pb.model',
23+
'AbstractApp': app + 'mvc/abstract.app',
24+
'AbstractView': app + 'mvc/abstract.view',
25+
'ModuleView': app + 'mvc/module.view',
26+
27+
'AbstractModel': app + 'data/abstract.model',
28+
'AbstractEntity': app + 'mvc/abstract.entity',
29+
'AbstractStore': app + 'data/abstract.store',
30+
'AbstractStorage': app + 'data/abstract.storage',
31+
32+
'cValidate': app + 'common/c.validate',
33+
'cUser': app + 'common/c.user',
34+
35+
'HybridHeader': app + 'hybrid/ui.header',
36+
37+
38+
'UIAbstractView': app + 'ui/ui.abstract.view',
39+
'UIMask': app + 'ui/ui.mask',
40+
'UILayer': app + 'ui/ui.layer',
41+
'UIPageView': app + 'ui/ui.page.view',
42+
43+
'UIScroll': app + 'ui/ui.scroll',
44+
45+
'UISlider': app + 'ui/ui.slider',
46+
'T_UISlider': app + 'ui/ui.slider.html',
47+
'UIImageSlider': app + 'ui/ui.image.slider',
48+
49+
50+
'UIScrollLayer': app + 'ui/ui.scroll.layer',
51+
'T_UIScrollLayer': app + 'ui/ui.scroll.layer.html',
52+
53+
'UIAlert': app + 'ui/ui.alert',
54+
'T_UIAlert': app + 'ui/ui.alert.html',
55+
56+
// 日历
57+
'UICalendar': app + 'ui/ui.calendar',
58+
'T_UICalendar': app + 'ui/ui.calendar.html',
59+
60+
// 日历
61+
'UICalendarBox': app + 'ui/ui.calendar.box',
62+
'T_UICalendarBox': app + 'ui/ui.calendar.box.html',
63+
64+
'APPUIHeader': app + 'ui/app.ui.header',
65+
'T_APPUIHeader': app + 'ui/app.ui.header.html',
66+
67+
'UIHeader': app + 'ui/ui.header',
68+
'T_UIHeader': app + 'ui/ui.header.html',
69+
70+
'UIToast': app + 'ui/ui.toast',
71+
'T_UIToast': app + 'ui/ui.toast.html',
72+
73+
'UILoading': app + 'ui/ui.loading',
74+
'T_UILoading': app + 'ui/ui.loading.html',
75+
76+
77+
'UILayerList': app + 'ui/ui.layer.list',
78+
'T_UILayerList': app + 'ui/ui.layer.list.html',
79+
80+
'T_UICalendarBox': app + 'ui/ui.calendar.box.html'
81+
82+
}
83+
});
84+
85+
})();

webapp/blade/data/abstract.model.js

Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
define([], function () {
2+
3+
var Model = _.inherit({
4+
//默认属性
5+
propertys: function () {
6+
this.protocol = 'http';
7+
this.domain = '';
8+
this.path = '';
9+
this.url = null;
10+
this.param = {};
11+
this.validates = [];
12+
// this.contentType = 'application/json';
13+
14+
this.ajaxOnly = true;
15+
16+
this.contentType = 'application/x-www-form-urlencoded';
17+
this.type = 'GET';
18+
this.dataType = 'json';
19+
},
20+
21+
setOption: function (options) {
22+
_.extend(this, options);
23+
},
24+
25+
assert: function () {
26+
if (this.url === null) {
27+
throw 'not override url property';
28+
}
29+
},
30+
31+
initialize: function (opts) {
32+
this.propertys();
33+
this.setOption(opts);
34+
this.assert();
35+
36+
},
37+
38+
pushValidates: function (handler) {
39+
if (typeof handler === 'function') {
40+
this.validates.push($.proxy(handler, this));
41+
}
42+
},
43+
44+
setParam: function (key, val) {
45+
if (typeof key === 'object') {
46+
_.extend(this.param, key);
47+
} else {
48+
this.param[key] = val;
49+
}
50+
},
51+
52+
removeParam: function (key) {
53+
delete this.param[key];
54+
},
55+
56+
getParam: function () {
57+
return this.param;
58+
},
59+
60+
//构建url请求方式,子类可复写,我们的model如果localstorage设置了值便直接读取,但是得是非正式环境
61+
buildurl: function () {
62+
// var baseurl = AbstractModel.baseurl(this.protocol);
63+
// return this.protocol + '://' + baseurl.domain + '/' + baseurl.path + (typeof this.url === 'function' ? this.url() : this.url);
64+
throw "[ERROR]abstract method:buildurl, must be override";
65+
66+
},
67+
68+
onDataSuccess: function () {
69+
},
70+
71+
/**
72+
* 取model数据
73+
* @param {Function} onComplete 取完的回调函
74+
* 传入的第一个参数为model的数第二个数据为元数据,元数据为ajax下发时的ServerCode,Message等数
75+
* @param {Function} onError 发生错误时的回调
76+
* @param {Boolean} ajaxOnly 可选,默认为false当为true时只使用ajax调取数据
77+
* @param {Boolean} scope 可选,设定回调函数this指向的对象
78+
* @param {Function} onAbort 可选,但取消时会调用的函数
79+
*/
80+
execute: function (onComplete, onError, ajaxOnly, scope) {
81+
var __onComplete = $.proxy(function (data) {
82+
var _data = data;
83+
if (typeof data == 'string') _data = JSON.parse(data);
84+
85+
// @description 开发者可以传入一组验证方法进行验证
86+
for (var i = 0, len = this.validates.length; i < len; i++) {
87+
if (!this.validates[i](data)) {
88+
// @description 如果一个验证不通过就返回
89+
if (typeof onError === 'function') {
90+
return onError.call(scope || this, _data, data);
91+
} else {
92+
return false;
93+
}
94+
}
95+
}
96+
97+
// @description 对获取的数据做字段映射
98+
var datamodel = typeof this.dataformat === 'function' ? this.dataformat(_data) : _data;
99+
100+
if (this.onDataSuccess) this.onDataSuccess.call(this, datamodel, data);
101+
if (typeof onComplete === 'function') {
102+
onComplete.call(scope || this, datamodel, data);
103+
}
104+
105+
}, this);
106+
107+
var __onError = $.proxy(function (e) {
108+
if (typeof onError === 'function') {
109+
onError.call(scope || this, e);
110+
}
111+
}, this);
112+
113+
this.sendRequest(__onComplete, __onError);
114+
115+
},
116+
117+
sendRequest: function (success, error) {
118+
var url = this.buildurl();
119+
var params = _.clone(this.getParam() || {});
120+
var crossDomain = {
121+
'json': true,
122+
'jsonp': true
123+
};
124+
125+
// if (this.type == 'json')
126+
// if (this.type == 'POST') {
127+
// this.dataType = 'json';
128+
// } else {
129+
// this.dataType = 'jsonp';
130+
// }
131+
132+
if (this.type == 'POST') {
133+
this.dataType = 'json';
134+
}
135+
136+
//jsonp与post互斥
137+
$.ajax({
138+
url: url,
139+
type: this.type,
140+
data: params,
141+
dataType: this.dataType,
142+
contentType: this.contentType,
143+
crossDomain: crossDomain[this.dataType],
144+
timeout: 50000,
145+
xhrFields: {
146+
withCredentials: true
147+
},
148+
success: function (res) {
149+
success && success(res);
150+
},
151+
error: function (err) {
152+
error && error(err);
153+
}
154+
});
155+
156+
}
157+
158+
});
159+
160+
Model.getInstance = function () {
161+
if (this.instance) {
162+
return this.instance;
163+
} else {
164+
return this.instance = new this();
165+
}
166+
};
167+
168+
return Model;
169+
});

0 commit comments

Comments
 (0)