-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmainActivity.js
367 lines (297 loc) · 10.6 KB
/
mainActivity.js
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
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
define(function(require){
var $ = require("jquery");
var justep = require("$UI/system/lib/justep");
var Baas = justep.Baas;
var Model = function(){
this.callParent();
this.localUserLoaded = false;
this.username;
this.password;
this.uid;
this.login;
//显示或隐藏 消息 下的系统 评论 @我
this.showMsgSys = justep.Bind.observable(true);
this.showMsgCom = justep.Bind.observable(false);
this.showMsgAtMe = justep.Bind.observable(false);
};
Model.prototype.modelLoad = function(event) {
var self = this;
this.comp("pre_home_notification").refreshData();
// localStorage.setItem('username','测试用户');
this.loadUser();
justep.Shell.setIsSinglePage(true);
}
//图片路径转换
Model.prototype.toUrl = function(url){
return url ? require.toUrl(url) : "";
};
//dateline转换
Model.prototype.datelineToBeforeDay = function(dateline){
// var mydate = new Date();//Tue Jul 26 2016 09:24:38 GMT+0800(中国标准时间)
// mydate.toLocaleDateString(); //获取当前日期,如2016/7/26
// var mytime=mydate.toLocaleTimeString(); //获取当前时间,如上午9:35:35
var timestampNow = new Date().getTime();//结果:1280977330748获取了当前毫秒的时间戳。
var timestampPost = dateline * 1000; //帖子时间转成毫秒级
var time1 = new Date(timestampPost)//发帖标准时间
var year1 = time1.getUTCFullYear();
var mounth1 = time1.getUTCMonth()+1;
var day1 = time1.getUTCDate();
var hour1 = time1.getUTCHours();
var minite1 = time1.getUTCMinutes() ;
var second1 = time1.getUTCSeconds();
var time2 = new Date(timestampNow)//当前标准时间
var year2 = time2.getUTCFullYear();
var mounth2 = time2.getUTCMonth()+1;
var day2 = time2.getUTCDate();
var hour2 = time2.getUTCHours();
var minite2 = time2.getUTCMinutes() ;
var second2 = time2.getUTCSeconds();
var rtn = "";
if (year2 - year1 > 0){
rtn = (year2 - year1) + "年前";
}else if(mounth2 - mounth1 > 0){
rtn = (mounth2 - mounth1) + "个月前";
}else if(day2 - day1 > 0){
rtn = (day2 - day1) + "天前";
}else if(hour2 - hour1 > 0){
rtn = (hour2 - hour1) + "小时前";
}else if(minite2 - minite1 > 0){
rtn = (minite2 - minite1) + "分钟前";
}else if(second2 - second1 > 0){
rtn = (second2 - second1) + "秒前";
}
return rtn;
}
//获取浏览数
Model.prototype.getViews = function (tid){
// alert(tid);
var rows = this.comp("pre_forum_thread").find(["tid"], [tid], false, true, true, true);
if (rows.length > 0){
return rows[0].val("views");
}else{
return "-";
}
}
//找附件图片
Model.prototype.findThumbPicBytid = function(tid){
// alert("tid=" + tid);
var rows = this.comp("pre_forum_attachment").find(["tid"], [tid]);
// alert(rows.length + "/tid=" + tid + "/tableid=" + rows[0].val("tableid"));
var rows1;
var rtn = this.toUrl("./images/forum_default.jpg" );
if (rows.length >0){
if (rows[0].val("tableid") == 0){
rows1 = this.comp("pre_forum_attachment_0").find(["tid"], [tid]);
rtn = this.toUrl("./data/attachment/forum/" + rows1[0].val("attachment"));
}else if (rows[0].val("tableid") == 1){
rows1 = this.comp("pre_forum_attachment_1").find(["tid"], [tid]);
rtn = this.toUrl("./data/attachment/forum/" + rows1[0].val("attachment"));
}else if (rows[0].val("tableid") == 2){
rows1 = this.comp("pre_forum_attachment_2").find(["tid"], [tid]);
rtn = this.toUrl("./data/attachment/forum/" + rows1[0].val("attachment"));
}else if (rows[0].val("tableid") == 3){
rows1 = this.comp("pre_forum_attachment_3").find(["tid"], [tid]);
rtn = this.toUrl("./data/attachment/forum/" + rows1[0].val("attachment"));
}else if (rows[0].val("tableid") == 4){
rows1 = this.comp("pre_forum_attachment_4").find(["tid"], [tid]);
rtn = this.toUrl("./data/attachment/forum/" + rows1[0].val("attachment"));
}else if (rows[0].val("tableid") == 5){
rows1 = this.comp("pre_forum_attachment_5").find(["tid"], [tid]);
rtn = this.toUrl("./data/attachment/forum/" + rows1[0].val("attachment"));
}else if (rows[0].val("tableid") == 6){
rows1 = this.comp("pre_forum_attachment_6").find(["tid"], [tid]);
rtn = this.toUrl("./data/attachment/forum/" + rows1[0].val("attachment"));
}else if (rows[0].val("tableid") == 7){
rows1 = this.comp("pre_forum_attachment_7").find(["tid"], [tid]);
rtn = this.toUrl("./data/attachment/forum/" + rows1[0].val("attachment"));
}else if (rows[0].val("tableid") == 8){
rows1 = this.comp("pre_forum_attachment_8").find(["tid"], [tid]);
rtn = this.toUrl("./data/attachment/forum/" + rows1[0].val("attachment"));
}else if (rows[0].val("tableid") == 9){
rows1 = this.comp("pre_forum_attachment_9").find(["tid"], [tid]);
rtn = this.toUrl("./data/attachment/forum/" + rows1[0].val("attachment"));
}else{
}
}else{
}
// alert(rtn);
return rtn;
};
Model.prototype.image_searchClick = function(event){
var subject = "rycom";
var rows = this.comp("pre_forum_post").find(["subject"], [subject], false, true, true, true);
if (rows.length > 0){
//放到searchData表
var searchData = this.comp("searchData");
searchData.newData({
defaultValues:rows
});
// var rows1 = this.comp("pre_forum_post").find(["subject"], [subject], false, true, true, true);;
// var str = "";
// $.each(rows1, function(index, obj){
// str += rows1[index].val("subject")+"===";
// });
// alert ("找到" + str + rows1);
}else{
alert ("没有找到" + subject + "相关的文章");
}
};
Model.prototype.loginNow = function(event){
var url = require.toUrl('./loginActivity.w');
// window.open(url);
// if (justep.Browser.isX5App && justep.Browser.isAndroid) {
// window.open(url,"_system");
// } else {
// window.open(url, '_blank', 'toolbarposition=top,location=no,enableViewportScale=yes');
// }
justep.Shell.showPage(url);
};
//找论坛的icon
Model.prototype.getIcon = function(fid) {
// alert(fid);
var rows = this.comp("pre_forum_field").find(["fid"], [fid]);
// alert(rows.length);
var rtn;
rtn = this.toUrl("./data/attachment/common/" + rows[0].val("icon"));
if (rtn == "") {
rtn = this.toUrl("./images/common_default.png" )
}
return rtn;
}
Model.prototype.listClick = function(event){
var current = event.bindingContext.$object;//获得当前行
// var url = require.toUrl("./detailActivity.w?p1=p1Value&p2=p2Value");
var url = require.toUrl("./detailActivity.w");
var tid = this.comp("pre_forum_post").getCurrentRow().val("tid");
var params = {
from : "mainActivity",
// subject : current.val("subject"),//这里val为什么报错
data : {
// fn : function() {
// alert("将一个函数传到对话框中");
// },
// 将data中的一行数据传给对话框
data_post : this.comp("pre_forum_post").getCurrentRow().toJson()
}
}
justep.Shell.showPage(url, params);
};
//根据论坛fid打开相应的论坛帖子列表
Model.prototype.li4Click = function(event){
var current = event.bindingContext.$object;//获得当前行
var url = require.toUrl("./listActivity.w");
var params = {
from : "mainActivity",
fid : current.val("fid"),
name: current.val("name"),
data : {
// 将data中的一行数据传给对话框
// data_forum : this.comp("pre_forum_forum").getCurrentRow().toJson()
}
}
justep.Shell.showPage(url, params);
};
//获取登录状态
Model.prototype.getLoginState = function() {
// alert(JSON.stringify(this.login) );
// alert(this.login);
if (!this.localUserLoaded){//没有读取本地用户
this.username = localStorage.getItem('username');
this.password = localStorage.getItem('password');
this.uid = localStorage.getItem('uid');
this.login = localStorage.getItem('login');
this.localUserLoaded = true;
// alert("localUserLoaded");
}
// alert("登录状态:" + this.login);
var rtn ;
var latestValue = this.login;
// alert(latestValue);
// $.each(this.login, function(i, item) {
// latestValue = item.latestValue ;
// alert(latestValue);
// });
if (latestValue == 1){
rtn = true;
}else if (latestValue == 0){
rtn = false;
}else{
rtn = false;
this.localUserLoaded = false;
}
return rtn;
}
//调取登录用户信息
Model.prototype.loadUser = function(){
if (this.username){
// alert("localStorage.getItem:username,value:" + localStorage.getItem('author'));
// this.comp("output_username").set({"value": this.username});
return this.username;
}else{
return "";
}
};
//清除登录用户信息
Model.prototype.clearUser = function(event){
this.username = "";
localStorage.setItem('username', '');
this.password = "";
localStorage.setItem('password', '');
this.login = 0;
localStorage.setItem('login', 0);
this.uid = "";
localStorage.setItem("uid", "");
this.loginNow(event);
};
//点击消息-系统
Model.prototype.button_msg_sysClick = function(event){
this.showMsgSys.set(true);
this.showMsgCom.set(false);
this.showMsgAtMe.set(false);
};
//点击消息-评论
Model.prototype.button_msg_comClick = function(event){
this.showMsgSys.set(false);
this.showMsgCom.set(true);
this.showMsgAtMe.set(false);
};
//点击消息-@我
Model.prototype.button_msg_atmeClick = function(event){
this.showMsgSys.set(false);
this.showMsgCom.set(false);
this.showMsgAtMe.set(true);
};
Model.prototype.show_msg_sys = function(){
return this.showMsgSys;
};
Model.prototype.show_msg_com = function(){
return this.showMsgCom;
};
Model.prototype.show_msg_atme = function(){
return this.showMsgAtMe;
};
//发帖
Model.prototype.image_publishClick = function(event){
var url = require.toUrl('./newPostActivity.w');
justep.Shell.showPage(url);
};
return Model;
});
$(function(){
// $(".x-panel-bottom a").click(function(){
// $(".x-panel-bottom a .this").removeClass("this")
// $(this).find("span").addClass("this");
// })
// 底部导航切换
$(".content_forum .col3 ul li").click(function(){
$(".content_forum .col3 ul li h5").css("color","#444444");
$(".content_forum .col3 ul li h5").css("background","#f5f5f5");
$(this).find("h5").css("color","#21b589");
$(this).find("h5").css("background","#ffffff");
});
// 社区栏目切换
$(".content_msg .msg .x-card .list-nav a").click(function(){
$(this).addClass("this").siblings(".this").removeClass("this");
})
// 消息顶部导航切换
})