Просмотр исходного кода

添加数据库初始化和创建操作

zhangxike 2 месяцев назад
Родитель
Сommit
029acee303

+ 69 - 44
manifest.json

@@ -1,6 +1,6 @@
 {
 	"appid": "__UNI__899F11F",
-	"name": "QTApp800",
+	"name": "声像记录",
 	"description": "数据测控功能应用APP",
 	"versionName": "1.0.0",
 	"versionCode": "100",
@@ -263,20 +263,20 @@
 							"android"
 						] //可选,字符串数组类型,支持的平台
 					}
-					// ,
-					// "amap" : {
-					//     //可选,JSON对象,使用高德定位SDK配置
-					//     "__platform__" : [ "ios", "android" ], //可选,字符串数组类型,支持的平台
-					//     "appkey_ios" : "", //必填,字符串类型,iOS平台高德定位appkey
-					//     "appkey_android" : "" //必填,字符串类型,Android平台高德定位appkey
-					// },
-					// "baidu" : {
-					//     //可选,JSON对象,使用百度定位SDK配置
-					//     "__platform__" : [ "ios", "android" ], //可选,字符串数组类型,支持的平台
-					//     "appkey_ios" : "", //必填,字符串类型,iOS平台百度定位appkey
-					//     "appkey_android" : "" //必填,字符串类型,Android平台百度定位appkey
-					// }
 				},
+				// ,
+				// "amap" : {
+				//     //可选,JSON对象,使用高德定位SDK配置
+				//     "__platform__" : [ "ios", "android" ], //可选,字符串数组类型,支持的平台
+				//     "appkey_ios" : "", //必填,字符串类型,iOS平台高德定位appkey
+				//     "appkey_android" : "" //必填,字符串类型,Android平台高德定位appkey
+				// },
+				// "baidu" : {
+				//     //可选,JSON对象,使用百度定位SDK配置
+				//     "__platform__" : [ "ios", "android" ], //可选,字符串数组类型,支持的平台
+				//     "appkey_ios" : "", //必填,字符串类型,iOS平台百度定位appkey
+				//     "appkey_android" : "" //必填,字符串类型,Android平台百度定位appkey
+				// }
 				"maps": {
 					//可选,JSON对象,Maps(地图)模块三方SDK配置
 					"amap": {
@@ -300,34 +300,34 @@
 					"univerify": {},
 					//可选,JSON对象,使用一键登录(univerify)SDK配置,无需手动配置参数,云端打包自动获取配置参数
 					"apple": {}
-					// ,
-					//可选,JSON对象,使用苹果登录(Sign in with Apple)SDK配置,无配置参数,仅iOS平台支持
-					// "weixin" : {
-					//     //可选,JSON对象,使用微信登录SDK配置
-					//     "appid" : "", //必填,字符串类型,微信开放平台申请的appid
-					//     "appsecret" : "", //必填,字符串类型,微信开放平台申请的appsecret
-					//     "UniversalLinks" : "" //可选,字符串类型,微信开放平台配置的iOS平台通用链接
-					// },
-					// "qq" : {
-					//     //可选,JSON对象,使用QQ登录SDK配置
-					//     "appid" : "", //必填,字符串类型,QQ开放平台申请的appid
-					//     "UniversalLinks" : "" //可选,字符串类型,QQ开放平台配置的iOS平台通用链接
-					// },
-					// "sina" : {
-					//     //可选,JSON对象,使用新浪微博登录SDK配置
-					//     "appkey" : "", //必填,字符串类型,新浪微博开放平台申请的appid
-					//     "redirect_uri" : "", //必填,字符串类型,新浪微博开放平台配置的redirect_uri
-					//     "UniversalLinks" : "" //可选,字符串类型,新浪微博开放平台配置的iOS平台通用链接
-					// },
-					// "google" : {
-					//     //可选,JSON对象,使用Google登录SDK配置
-					//     "clientid" : "" //必填,字符串类型,Google开发者后台申请的clientid
-					// },
-					// "facebook" : {
-					//     //可选,JSON对象,使用Facebook登录SDK配置
-					//     "appid" : "" //必填,字符串类型,Facebook开发者后台申请的appid
-					// }
 				},
+				// ,
+				//可选,JSON对象,使用苹果登录(Sign in with Apple)SDK配置,无配置参数,仅iOS平台支持
+				// "weixin" : {
+				//     //可选,JSON对象,使用微信登录SDK配置
+				//     "appid" : "", //必填,字符串类型,微信开放平台申请的appid
+				//     "appsecret" : "", //必填,字符串类型,微信开放平台申请的appsecret
+				//     "UniversalLinks" : "" //可选,字符串类型,微信开放平台配置的iOS平台通用链接
+				// },
+				// "qq" : {
+				//     //可选,JSON对象,使用QQ登录SDK配置
+				//     "appid" : "", //必填,字符串类型,QQ开放平台申请的appid
+				//     "UniversalLinks" : "" //可选,字符串类型,QQ开放平台配置的iOS平台通用链接
+				// },
+				// "sina" : {
+				//     //可选,JSON对象,使用新浪微博登录SDK配置
+				//     "appkey" : "", //必填,字符串类型,新浪微博开放平台申请的appid
+				//     "redirect_uri" : "", //必填,字符串类型,新浪微博开放平台配置的redirect_uri
+				//     "UniversalLinks" : "" //可选,字符串类型,新浪微博开放平台配置的iOS平台通用链接
+				// },
+				// "google" : {
+				//     //可选,JSON对象,使用Google登录SDK配置
+				//     "clientid" : "" //必填,字符串类型,Google开发者后台申请的clientid
+				// },
+				// "facebook" : {
+				//     //可选,JSON对象,使用Facebook登录SDK配置
+				//     "appid" : "" //必填,字符串类型,Facebook开发者后台申请的appid
+				// }
 				"payment": {
 					//可选,JSON对象,Payment(支付)模块三方SDK配置
 					"appleiap": {},
@@ -796,9 +796,10 @@
 	"app-android": {
 		"distribute": {
 			"icons": {
-				"hdpi": "",
-				"xxhdpi": "",
-				"xxxhdpi": ""
+				"hdpi": "D:/project/QTApp_800/static/newLogo.png",
+				"xxhdpi": "D:/project/QTApp_800/static/newLogo.png",
+				"xxxhdpi": "",
+				"xhdpi": "D:/project/QTApp_800/static/newLogo.png"
 			},
 			"minSdkVersion": "22",
 			"targetSdkVersion": "35",
@@ -817,6 +818,30 @@
 				""
 			]
 		}
+	},
+	"app": {
+		"distribute": {
+			"modules": {
+				"uni-ad": {
+					"360": {},
+					"BXM-AD": {},
+					"bd": {},
+					"csj": {},
+					"gdt": {},
+					"hw": {},
+					"ks": {},
+					"ks-content": {},
+					"sigmob": {}
+				}
+			}
+		}
+	},
+	"app-ios": {
+		"distribute": {
+			"modules": {},
+			"icons": {},
+			"splashScreens": {}
+		}
 	}
 }
 //可选,字符串数组类型,应用支持的横竖屏

+ 0 - 337
static/db/downloadDemo.json

@@ -1,337 +0,0 @@
-{
-	"code" :666,
-	"msg":"处理成功",
-	"data": [
-		{
-			"pk": "0228bc10-6d42-4e0c-98a2-486fe9d80d18",
-			"fktemph": "73f1d4482aa8460cb7f4571606b5a2fb",
-			"cardno": "LK20250715076",
-			"productcode": "YH07202507000005",
-			"no":null,
-			"model": "632",
-			"workorder": "716A-SY-02-02",
-			"invname": "一级煤油箱",
-			"graphid": "1CFA1040-00",
-			"processno": "Pb/1CFA1040-E",
-			"ver": "A.1",
-			"phase": "S",
-			"status": null,
-			"createtime": "2025-09-26 16:11:57",
-			"createuser": "XXX",
-			"updatetime": null,
-			"updateuser": null,
-			"updateuserid": null,
-			"dr": "0",
-			"pk_corp": "800",
-			"qmImageTaskClist": [
-				{
-					"pk": "d5a3f01e919845bda8f882e46e67e921",
-					"pid": "0228bc10-6d42-4e0c-98a2-486fe9d80d18",
-					"fktempc": "9349c04f4eb74a2491b0b926755465a",
-					"senum": null,
-					"part": "前低-内侧",
-					"photoitem": "标准件防松",
-					"descb": "第一层防晃板对接桁条标准件开口销",
-					"partno": "3",
-					"num": 2,
-					"urlspl": null,
-					"imgname": null,
-					"urlpdt": null,
-					"createtime": "2025-09-18 09:55:46",
-					"createuser": "XXX",
-					"createuserid": "102661fe-ba54-46f1-a09b-958051942796",
-					"updatetime":null,
-					"updateuser": null,
-					"updateuserid": null,
-					"dr": "0",
-					"pk_corp": "800",
-					"photoFiles_example": [
-						{
-							"url": null,
-							"fileno": null,
-							"pk_filetype": null,
-							"filetype": null,
-							"secret_level": null,
-							"author_name": null,
-							"author_code": null,
-							"author_deptno": null,
-							"author_deptname": null,
-							"makedate": null,
-							"uploadDate": "Sep 18, 2025 10:05:38 AM",
-							"size": 1727989,
-							"sizeStr": null,
-							"status": null,
-							"metadata": null,
-							"_id": "0",
-							"fid": null,
-							"billid": "9349c04f4eb74a2491b0b9246755465a",
-							"filename": "04-17 (278)(公开).JPG",
-							"scope": null,
-							"ftype": 0,
-							"creator_name": null,
-							"creator_code": null,
-							"creator_deptcode": null,
-							"creator_deptname": null,
-							"ts": null
-							
-						},
-						{
-							"url": null,
-							"fileno": null,
-							"pk_filetype": null,
-							"filetype": null,
-							"secret_level": null,
-							"author_name": null,
-							"author_code": null,
-							"author_deptno": null,
-							"author_deptname": null,
-							"makedate": null,
-							"uploadDate": "Sep 18, 2025 10:05:38 AM",
-							"size": 1727989,
-							"sizeStr": null,
-							"status": null,
-							"metadata": null,
-							"_id": "1",
-							"fid": null,
-							"billid": "9349c04f4eb74a2491b0b9246111a",
-							"filename": "04-17 (278)(公开).JPG",
-							"scope": null,
-							"ftype": 0,
-							"creator_name": null,
-							"creator_code": null,
-							"creator_deptcode": null,
-							"creator_deptname": null,
-							"ts": null
-							
-						},
-						{
-							"url": null,
-							"fileno": null,
-							"pk_filetype": null,
-							"filetype": null,
-							"secret_level": null,
-							"author_name": null,
-							"author_code": null,
-							"author_deptno": null,
-							"author_deptname": null,
-							"makedate": null,
-							"uploadDate": "Sep 18, 2025 10:05:38 AM",
-							"size": 1727989,
-							"sizeStr": null,
-							"status": null,
-							"metadata": null,
-							"_id": "2",
-							"fid": null,
-							"billid": "9349c04f4eb74a2491b0b9246111a",
-							"filename": "04-17 (278)(公开).JPG",
-							"scope": null,
-							"ftype": 0,
-							"creator_name": null,
-							"creator_code": null,
-							"creator_deptcode": null,
-							"creator_deptname": null,
-							"ts": null
-							
-						}
-					],
-					"photoFiles_object": []
-				},
-				{
-					"pk": "d5a3f01e919845bda8f882e46e67e921",
-					"pid": "0228bc10-6d42-4e0c-98a2-486fe9d80d18",
-					"fktempc": "9349c04f4eb74a2491b0b926755465a",
-					"senum": null,
-					"part": "前低-内侧",
-					"photoitem": "标准件防松",
-					"descb": "第一层防晃板对接桁条标准件开口销",
-					"partno": "3",
-					"num": 2,
-					"urlspl": null,
-					"imgname": null,
-					"urlpdt": null,
-					"createtime": "2025-09-18 09:55:46",
-					"createuser": "XXX",
-					"createuserid": "102661fe-ba54-46f1-a09b-958051942796",
-					"updatetime":null,
-					"updateuser": null,
-					"updateuserid": null,
-					"dr": "0",
-					"pk_corp": "800",
-					"photoFiles_example": [
-						{
-							"url": null,
-							"fileno": null,
-							"pk_filetype": null,
-							"filetype": null,
-							"secret_level": null,
-							"author_name": null,
-							"author_code": null,
-							"author_deptno": null,
-							"author_deptname": null,
-							"makedate": null,
-							"uploadDate": "Sep 18, 2025 10:05:38 AM",
-							"size": 1727989,
-							"sizeStr": null,
-							"status": null,
-							"metadata": null,
-							"_id": "1",
-							"fid": null,
-							"billid": "9349c04f4eb74a2491b0b9246755465a",
-							"filename": "04-17 (278)(公开).JPG",
-							"scope": null,
-							"ftype": 0,
-							"creator_name": null,
-							"creator_code": null,
-							"creator_deptcode": null,
-							"creator_deptname": null,
-							"ts": null
-							
-						},
-						{
-							"url": null,
-							"fileno": null,
-							"pk_filetype": null,
-							"filetype": null,
-							"secret_level": null,
-							"author_name": null,
-							"author_code": null,
-							"author_deptno": null,
-							"author_deptname": null,
-							"makedate": null,
-							"uploadDate": "Sep 18, 2025 10:05:38 AM",
-							"size": 1727989,
-							"sizeStr": null,
-							"status": null,
-							"metadata": null,
-							"_id": "2",
-							"fid": null,
-							"billid": "9349c04f4eb74a2491b0b9246111a",
-							"filename": "04-17 (278)(公开).JPG",
-							"scope": null,
-							"ftype": 0,
-							"creator_name": null,
-							"creator_code": null,
-							"creator_deptcode": null,
-							"creator_deptname": null,
-							"ts": null
-							
-						}
-					],
-					"photoFiles_object": []
-				},
-				{
-					"pk": "d5a3f01e919845bda8f882e46e67e921",
-					"pid": "0228bc10-6d42-4e0c-98a2-486fe9d80d18",
-					"fktempc": "9349c04f4eb74a2491b0b926755465a",
-					"senum": null,
-					"part": "传感器安装",
-					"photoitem": "筒段",
-					"descb": "第一层防晃板对接桁条标准件开口销",
-					"partno": "3",
-					"num": 2,
-					"urlspl": null,
-					"imgname": null,
-					"urlpdt": null,
-					"createtime": "2025-09-18 09:55:46",
-					"createuser": "XXX",
-					"createuserid": "102661fe-ba54-46f1-a09b-958051942796",
-					"updatetime":null,
-					"updateuser": null,
-					"updateuserid": null,
-					"dr": "0",
-					"pk_corp": "800",
-					"photoFiles_example": [
-						{
-							"url": null,
-							"fileno": null,
-							"pk_filetype": null,
-							"filetype": null,
-							"secret_level": null,
-							"author_name": null,
-							"author_code": null,
-							"author_deptno": null,
-							"author_deptname": null,
-							"makedate": null,
-							"uploadDate": "Sep 18, 2025 10:05:38 AM",
-							"size": 1727989,
-							"sizeStr": null,
-							"status": null,
-							"metadata": null,
-							"_id": "0",
-							"fid": null,
-							"billid": "9349c04f4eb74a2491b0b9246755465a",
-							"filename": "04-17 (278)(公开).JPG",
-							"scope": null,
-							"ftype": 0,
-							"creator_name": null,
-							"creator_code": null,
-							"creator_deptcode": null,
-							"creator_deptname": null,
-							"ts": null
-							
-						},
-						{
-							"url": null,
-							"fileno": null,
-							"pk_filetype": null,
-							"filetype": null,
-							"secret_level": null,
-							"author_name": null,
-							"author_code": null,
-							"author_deptno": null,
-							"author_deptname": null,
-							"makedate": null,
-							"uploadDate": "Sep 18, 2025 10:05:38 AM",
-							"size": 1727989,
-							"sizeStr": null,
-							"status": null,
-							"metadata": null,
-							"_id": "1",
-							"fid": null,
-							"billid": "9349c04f4eb74a2491b0b9246111a",
-							"filename": "04-17 (278)(公开).JPG",
-							"scope": null,
-							"ftype": 0,
-							"creator_name": null,
-							"creator_code": null,
-							"creator_deptcode": null,
-							"creator_deptname": null,
-							"ts": null
-							
-						},
-						{
-							"url": null,
-							"fileno": null,
-							"pk_filetype": null,
-							"filetype": null,
-							"secret_level": null,
-							"author_name": null,
-							"author_code": null,
-							"author_deptno": null,
-							"author_deptname": null,
-							"makedate": null,
-							"uploadDate": "Sep 18, 2025 10:05:38 AM",
-							"size": 1727989,
-							"sizeStr": null,
-							"status": null,
-							"metadata": null,
-							"_id": "d3d4dbad-f97c-4c22-b87d-05e3ced38de2",
-							"fid": null,
-							"billid": "9349c04f4eb74a2491b0b9246111a",
-							"filename": "04-17 (278)(公开).JPG",
-							"scope": null,
-							"ftype": 0,
-							"creator_name": null,
-							"creator_code": null,
-							"creator_deptcode": null,
-							"creator_deptname": null,
-							"ts": null
-							
-						}
-					],
-					"photoFiles_object": []
-				}
-			]
-		}
-	]
-}

+ 0 - 28
static/db/uploadResponse.json

@@ -1,28 +0,0 @@
-{
-	"url": null,
-	"fileno": null,
-	"pk_filetype": null,
-	"filetype": null,
-	"secret_level": null,
-	"author_name": null,
-	"author_code": null,
-	"author_deptno": null,
-	"author_departname": null,
-	"makedate":null,
-	"uploadDate": "Sep 28, 2025 9:06:25 AM",
-	"size": 1306695,
-	"sizeStr": null,
-	"status": null,
-	"metadata": null,
-	"_id": "5b52033d-f719-4364-b9c1-42898ef20331",
-	"fid": null,
-	"billid": "e7e0e0ad061143779bf3d6fdc10b9182",
-	"filename": "filename.txt",
-	"scope": null,
-	"ftype": 0,
-	"creator_name":null,
-	"creator_code": null,
-	"creator_deptcode": null,
-	"creator_deptname":null,
-	"ts": null
-}

+ 92 - 8
uni_modules/uni-sqlContext/utssdk/app-android/index.uts

@@ -9,20 +9,100 @@ import { createSQLiteContextFailImpl } from '../unierror.uts';
 
 class SQLiteContext extends SQLiteOpenHelper {
   private dbName: string | null;
+  private forceRecreateTables: boolean;
   
-  constructor(name: string) {
-    console.log(UTSAndroid.getResourcePath("/static/db/"+name))	
-	super(UTSAndroid.getAppContext(), UTSAndroid.getResourcePath("/static/db/"+name), null, 1);
-	this.dbName = name;
+  constructor(name: string, forceRecreate: boolean = false) {
+    // 使用应用内部存储路径而不是静态资源路径
+    const context = UTSAndroid.getAppContext()!!;
+    // 版本号 - 必须在super调用前定义
+    
+    const dbPath = context.getDatabasePath(name).getAbsolutePath();
+    console.log("Creating database at: " + dbPath);    
+    
+    // 如果需要强制重新创建表,先删除现有数据库
+    // if (forceRecreate) {
+      console.log("Force recreating tables requested, deleting existing database if exists");
+      context.deleteDatabase(name);
+    // }
+    
+	//1版本号
+    super(UTSAndroid.getAppContext()!!, name, null, 1);
+    this.dbName = name;
+    this.forceRecreateTables = forceRecreate;
+    
+    // 立即获取可写数据库以触发初始化
+    console.log("Initializing database connection");
+    this.getWritableDatabase();
   }
   
     
   override onCreate(db: SQLiteDatabase):void {
-	  
+	  console.log("SQLiteContext onCreate() called - creating database tables");
+    
+    // 创建表结构的DDL语句
+    // 这里可以根据实际需要添加更多的CREATE TABLE语句
+    const createTableSQLs = [
+      // app_user表结构
+      `CREATE TABLE IF NOT EXISTS app_user (
+        id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
+        username TEXT NOT NULL,
+        name TEXT,
+        userno INTEGER,
+        password TEXT NOT NULL,
+        token TEXT,
+        status INTEGER NOT NULL DEFAULT 1,
+        avatar TEXT,
+        createtime TEXT,
+        createuser INTEGER NOT NULL DEFAULT 1,
+        updatetime TEXT,
+        updateuser INTEGER NOT NULL DEFAULT 1,
+        role TEXT,
+        UNIQUE (id ASC),
+        UNIQUE (username ASC),
+        UNIQUE (userno ASC)
+      )`
+      // 可以添加更多表结构...
+    ];
+    
+    // 执行所有建表语句
+    for (const sql of createTableSQLs) {
+      try {
+        db.execSQL(sql);
+        console.log("Created table with SQL: " + sql.substring(0, 50) + "...");
+      } catch (e) {
+        console.error("Error creating table: " + e);
+      }
+    }
+    
+    // 插入初始数据
+    console.log("Inserting initial data into app_user table");
+    const insertDataSQLs = [
+      `INSERT INTO "app_user" ("id", "username", "name", "userno", "password", "token", "status", "avatar", "createtime", "createuser", "updatetime", "updateuser", "role") 
+       VALUES (1, 'admin', '管理员', 1, 'admin123', 'token1', 1, NULL, NULL, 1, NULL, 1, 'admin');`,
+      
+      `INSERT INTO "app_user" ("id", "username", "name", "userno", "password", "token", "status", "avatar", "createtime", "createuser", "updatetime", "updateuser", "role") 
+       VALUES (2, 'xuyunliang', '许运良', 2, '123456', 'token1', 1, NULL, NULL, 1, NULL, 1, 'user');`
+    ];
+    
+    for (const sql of insertDataSQLs) {
+      try {
+        // 使用INSERT OR IGNORE避免重复插入
+        const safeSql = sql.replace("INSERT INTO", "INSERT OR IGNORE INTO");
+        db.execSQL(safeSql);
+        console.log("Inserted initial data successfully");
+      } catch (e) {
+        console.error("Error inserting initial data: " + e);
+      }
+    }
   }
   
   override onUpgrade(db: SQLiteDatabase, oldVersion:Int, newVersion:Int):void {
-  	 
+   	console.log("Upgrading database from version " + oldVersion + " to " + newVersion);
+    // 数据库版本升级逻辑
+    if (oldVersion < 2) {
+      // 版本2的升级操作
+    }
+    // 可以添加更多版本升级逻辑
   }
 
   public executeSql(options: executeSqlOptions) {
@@ -145,7 +225,11 @@ class SQLiteContext extends SQLiteOpenHelper {
 }
 
 export const createSQLiteContext = function (dbName: string): SQLiteContext {
-  const name = dbName + '.db';
-  return new SQLiteContext(name);
+  // 确保数据库名称包含.db后缀
+  const name = dbName.endsWith('.db') ? dbName : dbName + '.db';
+  
+  console.log("Initializing SQLiteContext for database: " + name);
+  // 注意:根据接口定义,只接受一个参数,默认不强制重新创建表
+  return new SQLiteContext(name, false);
 }
 

+ 83 - 9
utils/sqlite.uts

@@ -3,13 +3,12 @@ import {selectSqlOptions,executeSqlOptions, executeSqlOptionsResult,selectSqlOpt
 
 
 
-// 数据库名称
-const dbName = 'QT800'
-
-// 数据库地址,推荐以下划线为开头   _doc/xxx.db
-// 如果路径不为_downloads/xxx.db,在手机中会找不到文件夹(强烈建议:不要修改路径)
-const dbPath = '/www/static/db/qt_app_800'
+// 数据库名称 - 确保包含.db后缀
+const dbName = 'QT800.db'
 
+// 注意:根据接口定义,createSQLiteContext函数只接受一个参数
+// 不需要指定外部路径,路径相关配置已不再使用
+// const dbPath = '/www/static/db/qt_app_800'
 
 // 普通函数
 // 查询获取数据库里的数据 sql:'SELECT * FROM dbTable WHERE lname = 'lvalue''
@@ -44,14 +43,14 @@ export function selectTableData (
     if (lname == null) {
        sql = `SELECT * FROM ${dbTable}`
     }
-	const sqlite = createSQLiteContext(dbName);
+	// 注意:根据接口定义,createSQLiteContext函数只接受一个参数
+const sqlite = createSQLiteContext(dbName);
 	console.log(sql)
 	return new Promise<UTSJSONObject>((resolve, reject) => {
 	  const selectSqlOptions ={		
 		  sql: sql,
 		  success: (e: selectSqlOptionsResult) => {
 		    console.log(e)
-			
 		  },
 		  fail: (e: selectSqlOptionsResult) => {
 		    console.error(e)
@@ -846,7 +845,82 @@ export function selectLatestInfoData (
    } 
    
    
-   export function selectTableDataByOrder (
+   // 检查表是否存在
+export const checkTableExists = (tableName: string): Promise<UTSJSONObject> => {
+  return new Promise((resolve) => {
+    try {
+      // 注意:这个方法不使用forceRecreate选项,避免在检查过程中删除表
+      console.log(`检查数据库表是否存在: ${tableName}`);
+      const db = createSQLiteContext(dbName);
+      const sql = `SELECT name FROM sqlite_master WHERE type='table' AND name='${tableName}'`;
+      
+      db.selectSql({
+        sql: sql,
+        success: (e: UTSJSONObject) => {
+          const data = e.data !== undefined && e.data !== null ? e.data : [];
+          const exists = Array.isArray(data) && data.length > 0;
+          console.log(`表 ${tableName} 存在: ${exists}`);
+          resolve({
+            errMsg: '',
+            exists: exists
+          });
+        },
+        fail: (e: UTSJSONObject) => {
+          const errMsg = e.errMsg !== undefined && typeof e.errMsg === 'string' ? e.errMsg : '查询失败';
+          console.error(`检查表 ${tableName} 存在性时失败:`, errMsg);
+          resolve({
+            errMsg: errMsg,
+            exists: false
+          });
+        }
+      });
+    } catch (error) {
+      console.error('检查表是否存在时发生异常:', error);
+      resolve({
+        errMsg: '数据库操作异常',
+        exists: false
+      });
+    }
+  });
+};
+
+// 初始化数据库表
+export const initializeDatabase = async (): Promise<UTSJSONObject> => {
+  try {
+    console.log('开始初始化数据库...');
+    
+      // 注意:根据接口定义,createSQLiteContext函数只接受一个参数
+    const db = createSQLiteContext(dbName);
+    
+    // 检查表是否存在
+    const tableExists = await checkTableExists('app_user');
+    
+    if (tableExists.exists) {
+      console.log('数据库初始化成功,app_user表已创建');
+      return {
+        errMsg: '',
+        success: true,
+        message: '数据库初始化成功'
+      };
+    } else {
+      console.error('数据库初始化失败,app_user表未创建');
+      return {
+        errMsg: '数据库表创建失败',
+        success: false,
+        message: '数据库表创建失败'
+      };
+    }
+  } catch (error) {
+    console.error('数据库初始化异常:', error);
+    return {
+      errMsg: '数据库初始化异常',
+      success: false,
+      message: '数据库初始化异常'
+    };
+  }
+};
+
+export function selectTableDataByOrder (
      dbTable: string,
      lname?: string,
      lvalue?: string,