main.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. import Vue from 'nativescript-vue'
  2. import App from './components/App'
  3. import * as Sqlite from 'nativescript-sqlite';
  4. import RadListView from 'nativescript-ui-listview/vue';
  5. let initDb = function (db) {
  6. db.execSQL('create table answer_sheet(' +
  7. ' `sheetName` text, `questionaireId` int, ' +
  8. ' `status` int, `startTime` int, `endTime` int, ' +
  9. ' `locationLong` NUMERIC, `locationLat` NUMERIC, ' +
  10. ' `answerJson` text, `dataUploaded` int, ' +
  11. ' `hasAudio` int, `audioUploaded` int, ' +
  12. ' `userName` text)', function (error) {
  13. if (error) {
  14. console.error('create table answer_sheet failed', error);
  15. } else {
  16. console.log('create table answer_sheet success')
  17. }
  18. });
  19. db.execSQL('create table questionaire (`questionaireId` int, `version` int, `status` int, `contentJson` text )',
  20. function (error) {
  21. if (error) {
  22. console.error('create table questionaire failed', error);
  23. } else {
  24. console.log('create table questionaire success')
  25. }
  26. });
  27. db.execSQL('create table version_info (`version_no` float, `description` text)', function (error) {
  28. if (error) {
  29. console.error('create table version_info failed', error);
  30. } else {
  31. console.log('create table version_info success')
  32. }
  33. })
  34. }
  35. let updateDb = function (db) {
  36. }
  37. function getConnectionType() {
  38. const connectivityModule = require("@nativescript/core/connectivity");
  39. const myConnectionType = connectivityModule.getConnectionType();
  40. switch (myConnectionType) {
  41. case connectivityModule.connectionType.none:
  42. // Denotes no Internet connection.
  43. console.log('connection type', "No connection");
  44. return 'None';
  45. break;
  46. case connectivityModule.connectionType.wifi:
  47. // Denotes a WiFi connection.
  48. console.log('connection type', "WiFi connection");
  49. return 'WiFi';
  50. break;
  51. case connectivityModule.connectionType.mobile:
  52. // Denotes a mobile connection, i.e. cellular network or WAN.
  53. console.log('connection type', "Mobile connection");
  54. return 'Mobile';
  55. break;
  56. case connectivityModule.connectionType.ethernet:
  57. // Denotes a ethernet connection.
  58. console.log('connection type', "Ethernet connection");
  59. return 'Ethernet';
  60. break;
  61. case connectivityModule.connectionType.bluetooth:
  62. // Denotes a bluetooth connection.
  63. console.log('connection type', "Bluetooth connection");
  64. return 'Bluetooth';
  65. break;
  66. default:
  67. return 'unknown';
  68. break;
  69. }
  70. }
  71. Vue.use(RadListView);
  72. if (TNS_ENV !== 'production') {
  73. Vue.use(VueDevtools)
  74. }
  75. // Prints Vue logs when --env.production is *NOT* set while building
  76. Vue.config.silent = (TNS_ENV === 'production')
  77. // Vue.prototype.$baseUrl = 'http://127.0.0.1:8080/api';
  78. // Vue.prototype.$baseUrl = 'http://192.168.1.4:8080/api';
  79. Vue.prototype.$baseUrl = 'http://api.scxbzw.com/api';
  80. console.log('audio path', knownFolders.documents().getFolder('audio').path);
  81. let dbname = 'my.db';
  82. let dbExist = Sqlite.exists(dbname);
  83. console.log('exist db?', Sqlite.exists(dbname));
  84. new Sqlite(dbname).then(database => {
  85. Vue.prototype.$db = database;
  86. console.log("db.isOpen()? ", database.isOpen() ? "Yes" : "No");
  87. if (!dbExist) {
  88. console.log('init db...');
  89. initDb(database);
  90. }
  91. });
  92. new Vue({
  93. render: h => h('frame', [h(App)])
  94. }).$start()