lxp_Maxcess/stores/sqlite.ts

73 lines
1.6 KiB
TypeScript
Raw Normal View History

2025-04-09 18:55:14 +08:00
import { defineStore } from 'pinia';
/**
*
* @createTableSQL
* @id
* @create_time
* @data_type
*/
export const sqlite = defineStore('sqlite', {
state: () => ({
dbName: 'dataRecording', // 数据库名称
dbPath: '_downloads/dataRecording.db', // 数据库地址
//扫描记录表结构
createTableSQL: `
CREATE TABLE IF NOT EXISTS scan_records (
id TEXT PRIMARY KEY,
create_time TEXT ,
data_type TEXT,
doc_number TEXT,
barcode TEXT,
material_code TEXT,
scan_quantity TEXT,
material_id INTEGER,
batch_number TEXT,
warehouse_code TEXT,
warehouse_id INTEGER,
location_code TEXT,
location_id INTEGER
)`
}),
actions: {
//创建数据库
isOpenSql() {
return new Promise((resolve, reject) => {
plus.sqlite.openDatabase({
name: this.dbName,
path: this.dbPath,
success(e) {
resolve(e)
},
fail(e) {
reject(e)
}
})
})
},
//打开数据库
isOpen() {
return plus.sqlite.isOpenDatabase({
name: this.dbName, // 数据库名称
path: this.dbPath // 数据库地址
})
},
//创建扫码记录表结构
createScanRecord() {
},
//初始化数据库信息返回结果
initializeSqlite() {
this.isOpenSql().then((res : any) => {
//数据库创建成功
if (this.isOpen()) {
console.log('创建成功,并且一打开数据库');
}
}).catch((err : any) => {
if (err.code = -1402 && this.isOpen()) {
console.log('数据库已打开');
}
})
},
}
});