25
25
<ScrollView >
26
26
<!-- <GridLayout colums="*" rows="*">-->
27
27
<StackLayout >
28
+ <Button class =" btn btn-primary" @tap =" counter" >计数器【Counter】</Button >
29
+ <Button class =" btn btn-primary" @tap =" hello" >Vuex及相机</Button >
30
+ <Button class =" btn btn-primary" @tap =" login" >模拟登录【login】</Button >
31
+
32
+ <Button class =" btn btn-primary" @tap =" btnToast" >提示【Toast】</Button >
33
+ <Button class =" btn btn-primary" @tap =" btnAlert" >精美提示框【Alert】</Button >
34
+ <Button class =" btn btn-primary" @tap =" info" >消息通知【Info】</Button >
35
+
36
+ <Button class =" btn btn-primary" @tap =" btnDialog" >对话框【Dialog】</Button >
37
+
38
+ <Button class =" btn btn-primary" @tap =" btnPlatformModule" >平台型号【PlatformModule】</Button >
39
+
40
+ <Button class =" btn btn-primary" @tap =" btnPhone" >电话【Phone】</Button >
41
+ <Button class =" btn btn-primary" @tap =" btnSms" >短信【Sms】</Button >
42
+
43
+ <Button class =" btn btn-primary" @tap =" btnGeolocation" >定位</Button >
44
+ <Button class =" btn btn-primary" @tap =" btnPermissions" >获取权限1</Button >
45
+
46
+ <Button class =" btn btn-primary" @tap =" btnPlatformModule" >获取设备信息</Button >
47
+ <Button class =" btn btn-primary btn-green" @tap =" btnChange" ref =" btn" >改变按钮【Change Btn】</Button >
48
+
28
49
<Label class =" message" :text =" msg" col =" 0" row =" 0" />
29
50
<Button class =" btn btn-primary" text =" 路由跳转" @tap =" onButtonTap" />
30
- <Button class =" btn btn-primary" text =" 基础示例" @tap =" onButtonBase" />
31
51
<Button class =" btn btn-primary" text =" 本地存储示例" @tap =" onInput" />
32
52
<Button class =" btn btn-primary" text =" 记事薄【Fab】" @tap =" onFab" />
33
53
<Button class =" btn btn-primary" text =" 备忘录【ToDo】" @tap =" onTodo" />
55
75
</template >
56
76
57
77
<script >
78
+ import Counter from ' ./base/Counter' ;
79
+ import HelloWorlds from ' ./base/HelloWorld.vue' ;
80
+ import Login from ' ./base/Login.vue' ;
81
+
82
+ import * as Toast from ' nativescript-toast' ;
83
+ import { TNSFancyAlert , TNSFancyAlertButton } from ' nativescript-fancyalert' ;
84
+ // import * as LocalNotifications from "nativescript-local-notifications";
85
+ import { LocalNotifications } from ' nativescript-local-notifications' ;
86
+ // var LocalNotifications = require("nativescript-local-notifications");
87
+
88
+ const dialogs = require (' tns-core-modules/ui/dialogs' );
89
+
90
+ const platformModule = require (' tns-core-modules/platform' );
91
+
92
+ const phone = require (' nativescript-phone' );
93
+
94
+ const geolocation = require (' nativescript-geolocation' );
95
+ const { Accuracy } = require (' tns-core-modules/ui/enums' );
96
+
97
+ const permissions = require (' nativescript-permissions' );
98
+ // const CALL_PHONE = android.Manifest.permission.CALL_PHONE;
99
+ // const Intent = android.content.Intent;
100
+ const app = require (' application' );
101
+
58
102
import HelloWorld from ' ./hello' ;
59
- import Home from ' ./base/Home' ;
60
103
import Input from ' ./Input' ;
61
104
import Fab from ' ./Fab' ;
62
105
import Todo from ' ./todo/todo' ;
@@ -82,6 +125,200 @@ export default {
82
125
},
83
126
mounted () {},
84
127
methods: {
128
+ counter : function () {
129
+ this .$navigateTo (Counter, {
130
+ animated: true ,
131
+ transition: {
132
+ name: ' slide' ,
133
+ duration: 380 ,
134
+ curve: ' easeIn'
135
+ }
136
+ });
137
+ },
138
+ hello : function () {
139
+ this .$navigateTo (HelloWorlds, {
140
+ animated: true ,
141
+ transition: {
142
+ name: ' slide' ,
143
+ duration: 380 ,
144
+ curve: ' easeIn'
145
+ }
146
+ });
147
+ },
148
+ login : function () {
149
+ this .$navigateTo (Login, {
150
+ animated: true ,
151
+ transition: {
152
+ name: ' slide' ,
153
+ duration: 380 ,
154
+ curve: ' easeIn'
155
+ }
156
+ });
157
+ },
158
+ btnToast : function () {
159
+ console .log (' 111' );
160
+ let toast = Toast .makeText (' 你好世界【Hello World】' , ' long' );
161
+ toast .show ();
162
+ },
163
+ btnAlert : function () {
164
+ console .log (' xxx' );
165
+ // TNSFancyAlert.showSuccess('Success!', 'Fancy alerts are nice.', 'Yes they are!');
166
+ TNSFancyAlert .showSuccess (' 成功!Success!' , ' 花哨的提醒很不错。【Fancy alerts are nice.】' , ' 是的【Yes they are!】' ).then (() => {
167
+ /* user pressed the button */
168
+ });
169
+ },
170
+ info : function () {
171
+ // console.dir(LocalNotifications);
172
+ // LocalNotifications.schedule([{
173
+ // id: 2,
174
+ // title: 'Hi',
175
+ // body: 'I\'m soundless',
176
+ // sound: null,
177
+ // at: new Date(new Date().getTime() + 10*1000)
178
+ // }])
179
+
180
+ LocalNotifications .schedule ([
181
+ {
182
+ id: 1 ,
183
+ title: ' The title' ,
184
+ body: ' Recurs every minute until cancelled' ,
185
+ ticker: ' The ticker' ,
186
+ color: ' red' ,
187
+ badge: 1 ,
188
+ groupedMessages: [' The first' , ' Second' , ' Keep going' , ' one more..' , ' OK Stop' ], // android only
189
+ groupSummary: ' Summary of the grouped messages above' , // android only
190
+ ongoing: true , // makes the notification ongoing (Android only)
191
+ icon: ' res://heart' ,
192
+ image: ' https://cdn-images-1.medium.com/max/1200/1*c3cQvYJrVezv_Az0CoDcbA.jpeg' ,
193
+ thumbnail: true ,
194
+ interval: ' minute' ,
195
+ channel: ' My Channel' , // default: 'Channel'
196
+ sound: ' customsound-ios.wav' , // falls back to the default sound on Android
197
+ at: new Date (new Date ().getTime () + 10 * 1000 ) // 10 seconds from now
198
+ }
199
+ ]).then (
200
+ function () {
201
+ console .log (' Notification scheduled' );
202
+ },
203
+ function (error ) {
204
+ console .log (' scheduling error: ' + error);
205
+ }
206
+ );
207
+
208
+ // LocalNotifications.addOnMessageReceivedCallback(
209
+ // function (notificationData) {
210
+ // dialogs.alert({
211
+ // title: "Notification received",
212
+ // message: "ID: " + notificationData.id +
213
+ // "\nTitle: " + notificationData.title +
214
+ // "\nBody: " + notificationData.body,
215
+ // okButtonText: "Excellent!"
216
+ // });
217
+ // }
218
+ // ).then(
219
+ // function() {
220
+ // dialogs.alert({
221
+ // title: "Listener added",
222
+ // message: "We'll let you know when a notification is received.",
223
+ // okButtonText: "Nice :)"
224
+ // });
225
+ // }
226
+ // );
227
+ },
228
+ btnDialog : function () {
229
+ dialogs .alert ({
230
+ title: ' Notification received' ,
231
+ message: ' message' ,
232
+ okButtonText: ' Excellent!'
233
+ });
234
+ },
235
+ btnPlatformModule : function () {
236
+ console .log (' ######' );
237
+ console .log (platformModule .device .model );
238
+ console .log (' ######' );
239
+ },
240
+ btnPhone : function () {
241
+ phone .requestCallPermission ();
242
+ phone .dial (' 212-555-1234' , true );
243
+ },
244
+ btnSms : function () {
245
+ phone
246
+ .sms (' 212-555-1234' , ' 我的消息【My Message】' ) // New Method for single number is phone.sms(["212-555-1234"],"My Message")
247
+ .then (
248
+ function (args ) {
249
+ // / args.reponse: "success", "cancelled", "failed"
250
+ console .log (JSON .stringify (args));
251
+ },
252
+ function (err ) {
253
+ console .log (' Error: ' + err);
254
+ }
255
+ );
256
+ },
257
+ btnGeolocation : function () {
258
+ geolocation .enableLocationRequest ();
259
+ console .log (' xxxx' );
260
+ geolocation
261
+ .getCurrentLocation ({
262
+ desiredAccuracy: Accuracy .high ,
263
+ maximumAge: 5000 ,
264
+ timeout: 20000
265
+ })
266
+ .then (res => {
267
+ console .log (' ***' );
268
+ this .lat = res .latitude ;
269
+ this .lon = res .longitude ;
270
+ this .speed = res .speed ;
271
+ console .log (' 定位' , this .lat );
272
+ console .log (' 定位' , this .lon );
273
+ console .log (' 定位' , this .lat );
274
+ });
275
+ },
276
+ btnPermissions : function () {
277
+ // permissions
278
+ // .requestPermission(
279
+ // android.Manifest.permission.READ_CONTACTS,
280
+ // "I need these permissions because I'm cool"
281
+ // )
282
+ // .then(function() {
283
+ // console.log("Woo Hoo, I have the power!");
284
+ // })
285
+ // .catch(function() {
286
+ // console.log("Uh oh, no permissions - plan B time!");
287
+ // });
288
+ },
289
+ btnPlatformModule : function () {
290
+ console .log (' ######' );
291
+ console .log (platformModule .device .model );
292
+ console .log (' ######' );
293
+ // vm.set("deviceInformationmodel", platformModule.device.model);
294
+ // vm.set("deviceInformationdeviceType", platformModule.device.deviceType);
295
+ // vm.set("deviceInformationos", platformModule.device.os);
296
+ // vm.set("deviceInformationosVersion", platformModule.device.osVersion);
297
+ // vm.set("deviceInformationsdkVersion", platformModule.device.sdkVersion);
298
+ // vm.set("deviceInformationlanguage", platformModule.device.language);
299
+ // vm.set("deviceInformationmanufacturer", platformModule.device.manufacturer);
300
+ // vm.set("deviceInformationuuid", platformModule.device.uuid);
301
+ // vm.set("screenInformationheightDIPs", platformModule.screen.mainScreen.heightDIPs);
302
+ // vm.set("screenInformationheightPixels", platformModule.screen.mainScreen.heightPixels);
303
+ // vm.set("screenInformationscale", platformModule.screen.mainScreen.scale);
304
+ // vm.set("screenInformationwidthDIPs", platformModule.screen.mainScreen.widthDIPs);
305
+ // vm.set("screenInformationwidthPixels", platformModule.screen.mainScreen.widthPixels);
306
+ },
307
+ btnChange : function () {
308
+ let btn = this .$refs .btn .nativeView ;
309
+ btn .color = ' blue' ;
310
+ // btn.background = "red";
311
+ btn .fontSize = 50 ;
312
+ btn .text = ' xxx' ;
313
+ btn .rotate = ' 10' ;
314
+ btn .opacity = 0.5 ;
315
+ btn .padding = 10 ;
316
+
317
+ // console.log(btn._getNativeViewsCount());
318
+ // btn.on("tap", function(params) {
319
+ // console.log("呵呵");
320
+ // });
321
+ },
85
322
request : function () {
86
323
this .$navigateTo (Request);
87
324
},
@@ -108,16 +345,6 @@ export default {
108
345
}
109
346
});
110
347
},
111
- onButtonBase : function () {
112
- this .$navigateTo (Home, {
113
- animated: true ,
114
- transition: {
115
- name: ' fade' ,
116
- duration: 380 ,
117
- curve: ' easeIn'
118
- }
119
- });
120
- },
121
348
onInput : function () {
122
349
this .$navigateTo (Input, {
123
350
animated: true ,
@@ -192,4 +419,9 @@ ActionBar {
192
419
font-size : 20 ;
193
420
color : #333333 ;
194
421
}
422
+ .btn-green {
423
+ background-color : blue ;
424
+ color : green ;
425
+ font-size : 20px ;
426
+ }
195
427
</style >
0 commit comments