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('数据库已打开'); } }) }, } });