-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathApp.vue
More file actions
513 lines (464 loc) · 12.9 KB
/
App.vue
File metadata and controls
513 lines (464 loc) · 12.9 KB
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
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
<script>
var _self
let base = require('@/static/js/base64.js');
import permision from "@/components/wa-permission/permission.js"
import md5Libs from "uview-ui/libs/function/md5";
import Vue from 'vue'
export default {
onLaunch: function() {
_self = this
console.log('App Launch')
_self.$store.state.platform = uni.getSystemInfoSync().platform
//区分平台
for (var i=0;i<_self.$store.state.funlist.length;i++)
{
switch (_self.$store.state.platform){
case 'android':
if(_self.$store.state.funlist[i].platform == 1){
_self.$store.state.funlist.splice(i,1)
i--
}
break;
case 'ios':
if(_self.$store.state.funlist[i].platform == 2){
_self.$store.state.funlist.splice(i,1)
i--
}
break
default:
break;
}
}
const user = uni.getStorageSync('user');
if (user) {
_self.$store.state.user = user
}
//判断单功能模式是否开启
const onFun = uni.getStorageSync('oneFun');
if(onFun.status){
_self.navto(onFun.path)
}
//创建临时目录
plus.io.resolveLocalFileSystemURL('_doc', function( ent ) {
ent.getDirectory('temp', {create:true,exclusive:false}, function( dir ){
console.log("创建目录成功 目录名: " + dir.name);
plus.io.resolveLocalFileSystemURL('_doc/temp', function( ent ) {
var directoryReader = ent.createReader(); //获取读取目录对象
directoryReader.readEntries(function(entries){ //历遍子目录即可
for(var i = 0; i < entries.length; i++){
entries[i].remove( function ( entry ) {
console.log("清理目录")
}, function ( e ) {
console.log("清理目录失败")
} );
}
}
)
}, function ( e ) {
console.log( "Request file system failed: " + e.message );
} );
}, function (e) {
console.log("创建目录失败" + e.message );
} );
}, function ( e ) {
console.log( "Request file system failed: " + e.message );
} );
//创建音乐目录
plus.io.resolveLocalFileSystemURL("_doc", function( ent ) {
ent.getDirectory("music", {create:true,exclusive:false}, function( dir ){
console.log("创建目录成功 目录名: " + dir.name);
}, function (e) {
console.log("创建目录失败" + e.message );
} );
}, function ( e ) {
console.log( "Request file system failed: " + e.message );
} );
//创建加密照片目录
plus.io.resolveLocalFileSystemURL("_doc", function( ent ) {
ent.getDirectory("photo", {create:true,exclusive:false}, function( dir ){
console.log("创建目录成功 目录名: " + dir.name);
}, function (e) {
console.log("创建目录失败" + e.message );
} );
}, function ( e ) {
console.log( "Request file system failed: " + e.message );
} );
//app在线收到推送监听
plus.push.addEventListener("receive", function(msg) {
console.log("receive收到推送消息",msg)
console.log(plus.push.getClientInfo())
//这里消息载体是basr64编码
var payload = JSON.parse(base.Base64.decode(msg.payload))
console.log(payload)
switch (_self.$store.state.platform){
case 'android':
break;
case 'ios':
switch (payload.type){
case "word":
console.log("单词推送")
if(msg.aps){
plus.push.createMessage(msg.aps.alert.body,msg.payload,{title:msg.aps.alert.title})
}
break
case "TakeAShot":
console.log("拍一拍推送")
if(msg.aps){
plus.push.createMessage(msg.aps.alert.body,msg.payload,{title:msg.aps.alert.title})
}
break;
}
break
default:
break;
}
});
//离线推送点击会触法
plus.push.addEventListener( "click", function(msg){
console.log("click收到推送消息",msg)
var payload = JSON.parse(base.Base64.decode(msg.payload))
switch (_self.$store.state.platform){
case 'android':
break;
case 'ios':
switch (payload.type){
case "TakeAShot":
_self.navto("/pages/functions/TakeAshot/send?data=" + JSON.stringify(payload.user))
break;
case "word":
console.log("单词推送")
break;
}
break
default:
break;
}
});
//发送请求拦截前
_self.xhttp.interceptors.request.use((config) => { // 可使用async await 做异步操作
var cid = plus.push.getClientInfo().clientid && plus.push.getClientInfo().clientid != 'null' ? plus.push.getClientInfo().clientid : undefined;
config.header = {
...config.header,
token: _self.$store.state.user ? _self.$store.state.user.token : undefined ,
uid: _self.$store.state.user ? _self.$store.state.user.user_id : undefined ,
platform: _self.$store.state.platform ,
version: _self.$store.state.version ,
//这里返回值不是真正的null而是字符串null有点坑
cid: cid,
access: ''//服务器加密秘钥协作开发者无需修改
}
console.log("发送请求拦截前",config)
return config
}, config => { // 可使用async await 做异步操作
console.log("请求配置",config)
return Promise.reject(config)
})
//发送请求拦截后 0成功 1系统提示错误如账号密码错误 2
_self.xhttp.interceptors.response.use((response) => { /* 对响应成功做点什么 可使用async await 做异步操作*/
console.log("发送请求拦截后",response)
if(response.data.code != 0){
//清除登录信息
if(response.data.code == 4){
_self.$store.state.user = null
uni.setStorageSync('user', null);
plus.nativeUI.alert(response.data.message, function(){
}, "提示", "好的");
uni.switchTab({
url: '/pages/index/my'
});
}else{
plus.nativeUI.alert(response.data.message, function(){
}, "提示", "好的");
}
}
return response
}, (response) => { /* 对响应错误做点什么 (statusCode !== 200)*/
console.log("请求失败",response)
plus.nativeUI.alert("操作失败!请检查网络", function(){
}, "提示", "好的");
return Promise.reject(response)
})
_self.xhttp.request({
url: "/functions/index/init", //仅为示例,并非真实接口地址。
method:"POST",
data: {
},
header:{
'Content-Type':'application/x-www-form-urlencoded'
}
}).then(res => {
console.log("初始化",res)
if(res.data.code == 0){
var funlist = _self.$store.state.funlist
var newFunlist = res.data.data
for (var i = 0; i < newFunlist.length; i++) {
for (var j = 0; j < funlist.length; j++) {
if(newFunlist[i].title == funlist[j].title){
console.log("相等")
break
}
if(j == funlist.length - 1){
funlist.push(newFunlist[i])
}
}
}
}
}).catch(err => {
})
},
onShow: function() {
var pushStatus = 0
//安卓应用内提示更新
switch (_self.$store.state.platform) {
case 'android':
uni.request({
url: _self.domain + "/index/index/update", //仅为示例,并非真实接口地址。
method: "POST",
data: {
version: _self.$store.state.version
},
header: {
'Content-Type': 'application/x-www-form-urlencoded'
},
success: (res) => {
console.log(res.data);
if (res.data.code == 0) {
if (res.data.data != null) {
var url = res.data.data
uni.showModal({
title: '提示',
content: res.data.message,
success: function(res) {
if (res.confirm) {
plus.runtime.openURL(url)
} else if (res.cancel) {
console.log('用户点击取消');
}
}
});
}
} else {
plus.nativeUI.alert(res.data.message, function() {}, "提示", "好的");
}
},
fail: (err) => {
console.log(err)
},
complete: () => {
}
});
break;
case 'ios':
if(permision.judgeIosPermission("push") === 2){
pushStatus = 0
}else{
pushStatus = 1
}
console.log('运行iOS上')
break;
default:
console.log('运行在开发者工具上')
break;
}
//如果用户登录 则上报
if(_self.$store.state.user){
//上报状态
_self.xhttp.request({
url: "/user/user/v1/push", //仅为示例,并非真实接口地址。
method:"POST",
data: {
pushStatus:pushStatus
},
header:{
'Content-Type':'application/x-www-form-urlencoded'
}
}).then(res => {
}).catch(err => {
})
}
plus.sqlite.openDatabase({
name: 'ppgjx',
path: '_doc/ppgjx.db',
success: function(e){
console.log('openDatabase success!');
plus.sqlite.executeSql({
name: 'ppgjx',
sql: 'create table if not exists photo(guid text PRIMARY KEY,path text,create_time text)',
success: function(e){
console.log('executeSql success!');
},
fail: function(e){
console.log('executeSql failed: '+JSON.stringify(e));
}
});
plus.sqlite.executeSql({
name: 'ppgjx',
sql: 'create table if not exists div_calculate(guid text PRIMARY KEY,name text,data text,remark text,create_time text)',
success: function(e){
console.log('executeSql success!');
},
fail: function(e){
console.log('executeSql failed: '+JSON.stringify(e));
}
});
plus.sqlite.executeSql({
name: 'ppgjx',
sql: 'create table if not exists music(guid text PRIMARY KEY,title text,src text,singer text,coverImgUrl text,type text,create_time text)',
success: function(e){
console.log('executeSql success!');
},
fail: function(e){
console.log('executeSql failed: '+JSON.stringify(e));
}
});
plus.sqlite.executeSql({
name: 'ppgjx',
sql: 'create table if not exists womanRecord(guid text PRIMARY KEY,date text,tag text,remark text,create_time text)',
success: function(e){
console.log('executeSql success!');
},
fail: function(e){
console.log('executeSql failed: '+JSON.stringify(e));
}
});
},
fail: function(e){
console.log('openDatabase failed: '+JSON.stringify(e));
}
});
console.log('App Show')
},
onHide: function() {
console.log('App Hide')
plus.sqlite.closeDatabase({
name: 'ppgjx',
success: function(e){
console.log('closeDatabase success!');
},
fail: function(e){
console.log('closeDatabase failed: '+JSON.stringify(e));
}
});
}
}
</script>
<style lang="scss" >
@import "uview-ui/index.scss";
@import "colorui/main.css";
@import "colorui/icon.css";
@import url("static/css/icon/iconfont.css");
/*每个页面公共css */
.nav-list {
display: flex;
flex-wrap: wrap;
padding: 0px 40upx 0px;
justify-content: space-between;
}
.nav-li {
padding: 30upx;
border-radius: 12upx;
width: 45%;
margin: 0 2.5% 40upx;
background-image: url(https://cdn.nlark.com/yuque/0/2019/png/280374/1552996358352-assets/web-upload/cc3b1807-c684-4b83-8f80-80e5b8a6b975.png);
background-size: cover;
background-position: center;
position: relative;
z-index: 1;
}
.nav-li::after {
content: "";
position: absolute;
z-index: -1;
background-color: inherit;
width: 100%;
height: 100%;
left: 0;
bottom: -10%;
border-radius: 10upx;
opacity: 0.2;
transform: scale(0.9, 0.9);
}
.nav-li.cur {
color: #fff;
background: rgb(94, 185, 94);
box-shadow: 4upx 4upx 6upx rgba(94, 185, 94, 0.4);
}
.nav-title {
font-size: 32upx;
font-weight: 300;
}
.nav-title::first-letter {
font-size: 40upx;
margin-right: 4upx;
}
.nav-name {
font-size: 28upx;
text-transform: Capitalize;
margin-top: 20upx;
position: relative;
}
.nav-name::before {
content: "";
position: absolute;
display: block;
width: 40upx;
height: 6upx;
background: #fff;
bottom: 0;
right: 0;
opacity: 0.5;
}
.nav-name::after {
content: "";
position: absolute;
display: block;
width: 100upx;
height: 1px;
background: #fff;
bottom: 0;
right: 40upx;
opacity: 0.3;
}
.nav-name::first-letter {
font-weight: bold;
font-size: 36upx;
margin-right: 1px;
}
.nav-li text {
position: absolute;
right: 30upx;
top: 30upx;
font-size: 52upx;
width: 60upx;
height: 60upx;
text-align: center;
line-height: 60upx;
}
.text-light {
font-weight: 300;
}
@keyframes show {
0% {
transform: translateY(-50px);
}
60% {
transform: translateY(40upx);
}
100% {
transform: translateY(0px);
}
}
@-webkit-keyframes show {
0% {
transform: translateY(-50px);
}
60% {
transform: translateY(40upx);
}
100% {
transform: translateY(0px);
}
}
</style>
<style>
</style>