提交 748424ad authored 作者: JaxBBLL's avatar JaxBBLL
import table from "../sqllite/table";
import _Path from "@/constant/ioPath";
import ioUtil from "@/utils/ioUtil";
import SqlliteDbUtil from "@/utils/sqllitedb";
import userApi from "@/api/user";
import hoistwayApi from "@/api/hoistway";
import assRoomApi from "@/api/assRoom.js";
import hoistwayjson from "../../baseData/hoistway.json";
import userjson from "../../baseData/user.json";
import assroomjson from "../../baseData/assroom.json";
import fileImport from "@/utils/fileImport.js";
import table from '../sqllite/table'
import _Path from '@/constant/ioPath'
import ioUtil from '@/utils/ioUtil'
import SqlliteDbUtil from '@/utils/sqllitedb'
import userApi from '@/api/user'
import hoistwayApi from '@/api/hoistway'
import assRoomApi from '@/api/assRoom.js'
import hoistwayjson from '../../baseData/hoistway.json'
import userjson from '../../baseData/user.json'
import assroomjson from '../../baseData/assroom.json'
import fileImport from '@/utils/fileImport.js'
export default {
// app初始化
async init() {
uni.showLoading({
title: "正在初始化...",
});
// 初始化目录
await this.initDir();
// 初始化数据库
// cookie.set('initDB', true)
await this.initSqlLite();
// 导入用戶文件文件
// await this.importFileData();
await userApi.saveBatch(userjson);
await hoistwayApi.saveBatch(hoistwayjson);
await assRoomApi.saveBatch(assroomjson);
// 初始化完成通知首页
uni.$emit("initDone", "ok");
uni.hideLoading();
},
// app初始化
async init() {
// 检查文件导入
async importFileData() {
// 解压缩需要导入的zip,导入后删除
try {
console.log("解压导入开始....");
console.log("导入基础数据开始");
await fileImport.importBaseFile();
console.log("导入基础数据结束!");
console.log("解压导入完成....");
} catch (e) {
console.log(e.message);
uni.showToast({
icon: "none",
title: e.message,
});
uni.hideLoading();
}
},
uni.showLoading({
title: '正在初始化...',
})
// 初始化目录
await this.initDir()
// 初始化数据库
await this.initSqlLite()
let sqllitedb = await SqlliteDbUtil.initSqlliteDB()
let isInit = await SqlliteDbUtil.checkIfDataImported(sqllitedb)
if (!isInit) {
await userApi.saveBatch(userjson)
await hoistwayApi.saveBatch(hoistwayjson)
await assRoomApi.saveBatch(assroomjson)
await SqlliteDbUtil.markDataAsImported(sqllitedb)
}
// 初始化完成通知首页
uni.hideLoading()
},
////////// 初始化数据库////////////
async initSqlLite() {
console.log("初始化数据库开始...");
let sqllitedb = null;
try {
// 创建打开数据库,已经存在表则跳过
sqllitedb = await SqlliteDbUtil.initSqlliteDB();
console.log(sqllitedb, "是否存在");
// console.log('创建用户表...')
await sqllitedb.createTable(table.userName, table.user);
await sqllitedb.createTable(
table.inspectionRecordName,
table.inspectionRecord
); // 巡检记录表
await sqllitedb.createTable(table.assRoomName, table.assRoom); // 机房、井道信息表
await sqllitedb.createTable(table.assBuildingName, table.assBuilding); // 楼宇信息
} catch (e) {
console.log(e.message);
} finally {
return;
// 关闭数据库
if (sqllitedb) {
await sqllitedb.closeDB();
}
// 初始化完成后重启APP/退出APP
uni.showToast({
icon: "none",
title: "初始化完毕即将重新加载...",
duration: 3000,
});
let that = this;
setTimeout(function () {
that.restartApp();
}, 3000);
}
},
// 检查文件导入
async importFileData() {
// 解压缩需要导入的zip,导入后删除
try {
console.log('解压导入开始....')
console.log('导入基础数据开始')
await fileImport.importBaseFile()
console.log('导入基础数据结束!')
console.log('解压导入完成....')
} catch (e) {
console.log(e.message)
uni.showToast({
icon: 'none',
title: e.message
})
uni.hideLoading()
}
},
// 初始化目录
async initDir() {
try {
const _www = _Path.getPrivateWWW();
const _doc = _Path.getPrivateDOC();
const _download = _Path.getDownloads();
const _temp = _Path.getTempPath();
const wwwEntry = await ioUtil.getFileEntry(_www);
const docEntry = await ioUtil.getFileEntry(_doc);
const downloadEntry = await ioUtil.getFileEntry(_download);
////////// 初始化数据库////////////
async initSqlLite() {
console.log('初始化数据库开始...')
let sqllitedb = null
try {
// 创建打开数据库,已经存在表则跳过
sqllitedb = await SqlliteDbUtil.initSqlliteDB()
console.log(sqllitedb, '是否存在')
// console.log('创建用户表...')
await sqllitedb.createTable(table.metadataName, table.metadata)
await sqllitedb.createTable(table.userName, table.user)
await sqllitedb.createTable(table.inspectionRecordName, table.inspectionRecord) // 巡检记录表
await sqllitedb.createTable(table.assRoomName, table.assRoom) // 机房、井道信息表
await sqllitedb.createTable(table.assBuildingName, table.assBuilding) // 楼宇信息
} catch (e) {
console.log(e.message)
} finally {
return
// 关闭数据库
if (sqllitedb) {
await sqllitedb.closeDB()
}
// 初始化完成后重启APP/退出APP
uni.showToast({
icon: 'none',
title: '初始化完毕即将重新加载...',
duration: 3000
})
let that = this
setTimeout(function() {
that.restartApp()
}, 3000)
}
},
if (downloadEntry) {
await ioUtil.createDir(downloadEntry.fullPath, "base");
await ioUtil.createDir(downloadEntry.fullPath, "export");
await ioUtil.createDir(downloadEntry.fullPath, "import");
await ioUtil.createDir(downloadEntry.fullPath, "doc");
await ioUtil.createDir(downloadEntry.fullPath, "error");
}
// 初始化目录
async initDir() {
try {
const _www = _Path.getPrivateWWW()
const _doc = _Path.getPrivateDOC()
const _download = _Path.getDownloads()
const _temp = _Path.getTempPath()
const wwwEntry = await ioUtil.getFileEntry(_www)
const docEntry = await ioUtil.getFileEntry(_doc)
const downloadEntry = await ioUtil.getFileEntry(_download)
// 获取设备名称
uni.getSystemInfo({
success: async function (e) {
const deviceData = {
deviceId: e.deviceId,
brand: e.deviceBrand,
deviceModel: e.deviceModel,
};
const deviceFilePath = downloadEntry.fullPath + "name.txt";
await ioUtil.removeExistFile(deviceFilePath);
await ioUtil.writeFile(
"name.txt",
downloadEntry,
JSON.stringify(deviceData)
);
},
});
if (downloadEntry) {
await ioUtil.createDir(downloadEntry.fullPath, 'base')
await ioUtil.createDir(downloadEntry.fullPath, 'export')
await ioUtil.createDir(downloadEntry.fullPath, 'import')
await ioUtil.createDir(downloadEntry.fullPath, 'doc')
await ioUtil.createDir(downloadEntry.fullPath, 'error')
}
// 文件目录
if (docEntry) {
await ioUtil.createDir(docEntry.fullPath, "file");
}
// 获取设备名称
uni.getSystemInfo({
success: async function(e) {
const deviceData = {
deviceId: e.deviceId,
brand: e.deviceBrand,
deviceModel: e.deviceModel,
}
const deviceFilePath = downloadEntry.fullPath + 'name.txt'
await ioUtil.removeExistFile(deviceFilePath)
await ioUtil.writeFile('name.txt', downloadEntry, JSON.stringify(deviceData))
},
});
// 临时目录
let tempEntry = await ioUtil.getFileEntry(_temp);
if (!tempEntry) {
await ioUtil.createDir(_temp);
tempEntry = await ioUtil.createDir(
_Path.getTempParent(),
"inspectTemp"
);
}
await ioUtil.createDir(tempEntry.fullPath, "db");
} catch (e) {
console.log(e.message);
}
},
// 重启app
restartApp() {
// #ifdef APP-PLUS
if (plus.os.name.toLowerCase() === "android") {
plus.runtime.restart();
}
// #endif
},
// 文件目录
if (docEntry) {
await ioUtil.createDir(docEntry.fullPath, 'file')
}
// 退出app
exitApp() {
// #ifdef APP-PLUS
if (plus.os.name.toLowerCase() === "android") {
plus.runtime.quit();
} else {
const threadClass = plus.ios.importClass("NSThread");
const mainThread = plus.ios.invoke(threadClass, "mainThread");
plus.ios.invoke(mainThread, "exit");
// 或者如下
// plus.ios.import('UIApplication').sharedApplication().performSelector('exit');
}
// #endif
},
};
// 临时目录
let tempEntry = await ioUtil.getFileEntry(_temp)
if (!tempEntry) {
await ioUtil.createDir(_temp)
tempEntry = await ioUtil.createDir(_Path.getTempParent(), 'inspectTemp')
}
await ioUtil.createDir(tempEntry.fullPath, 'db')
} catch (e) {
console.log(e.message)
}
},
// 重启app
restartApp() {
// #ifdef APP-PLUS
if (plus.os.name.toLowerCase() === 'android') {
plus.runtime.restart();
}
// #endif
},
// 退出app
exitApp() {
// #ifdef APP-PLUS
if (plus.os.name.toLowerCase() === 'android') {
plus.runtime.quit();
} else {
const threadClass = plus.ios.importClass("NSThread");
const mainThread = plus.ios.invoke(threadClass, "mainThread");
plus.ios.invoke(mainThread, "exit");
// 或者如下
// plus.ios.import('UIApplication').sharedApplication().performSelector('exit');
}
// #endif
}
}
\ No newline at end of file
module.exports = {
// 数据库设置
metadataName: 'SYS_CONFIG',
metadata: [{
field: "key",
format: "TEXT PRIMARY KEY",
}, {
field: "value",
format: "TEXT",
}],
// 用户表
userName: "SYS_USER",
user: [{
field: "userId",
format: "TEXT",
format: "TEXT PRIMARY KEY",
},
{
field: "userName",
field: "user",
format: "TEXT",
},
{
......@@ -18,210 +27,219 @@ module.exports = {
format: "TEXT",
},
{
field: "password",
field: "passWord",
format: "TEXT",
},
{
field: "roleName",
format: "TEXT",
},
{
field: "unitName",
format: "TEXT",
},
{
field: "isAdmin",
format: "TEXT",
},
{
field: "rememberPwd",
field: "LastSynchronizationTime",
format: "TEXT",
},
],
// 巡检记录表
inspectionRecordName: "INSPECTION_RECORD",
inspectionRecord: [
{
field: "id",
format: "TEXT NOT NULL",
},
{
field: "inspectionType",
format: "TEXT",
},
{
field: "recordName",
format: "TEXT",
},
{
field: "userId",
format: "TEXT",
},
{
field: "userName",
format: "TEXT",
},
{
field: "inspectionTime",
format: "TEXT",
},
{
field: "inspectionCode",
format: "TEXT",
},
{
field: "synFlag",
format: "TEXT",
},
{
field: "createTime",
format: "TEXT",
},
{
field: "createBy",
format: "TEXT",
},
{
field: "updateTime",
format: "TEXT",
},
{
field: "updateBy",
format: "TEXT",
},
{
field: "delFlag",
format: "TEXT",
},
{
field: "isException",
format: "TEXT",
},
{
field: "inspectionData",
format: "TEXT",
}
],
// 机房、井道信息表
assRoomName: "ASS_ROOM",
assRoom: [
{
field: "id",
format: "TEXT NOT NULL",
},
{
field: "roomName",
format: "TEXT",
},
{
field: "buildingId",
format: "TEXT",
},
{
field: "buildingName",
format: "TEXT",
},
{
field: "roomType",
format: "TEXT",
},
{
field: "roomFile",
format: "TEXT",
},
{
field: "roomAddress",
format: "TEXT",
},
{
field: "keynoteFlag",
format: "TEXT",
},
{
field: "sort",
format: "TEXT",
},
{
field: "roomDesc",
format: "TEXT",
},
{
field: "remark",
format: "TEXT",
},
{
field: "createTime",
format: "TEXT",
},
{
field: "createBy",
format: "TEXT",
},
{
field: "updateTime",
format: "TEXT",
},
{
field: "updateBy",
format: "TEXT",
},
{
field: "delFlag",
format: "TEXT",
},
{
field: "synFlag",
format: "TEXT",
},
{
field: "SHOW",
format: "TEXT",
},
{
field: "roomFeature",
format: "TEXT",
},
{
field: "dictValue",
format: "TEXT",
}
],
// 楼宇信息
assBuildingName: "ASS_BUILDING",
assBuilding: [
{
field: "id",
format: "TEXT NOT NULL",
},
{
field: "buildingName",
format: "TEXT",
},
{
field: "sort",
format: "TEXT",
},
{
field: "remark",
format: "TEXT",
},
{
field: "createTime",
format: "TEXT",
},
{
field: "createBy",
format: "TEXT",
},
{
field: "updateTime",
format: "TEXT",
},
{
field: "updateBy",
format: "TEXT",
},
{
field: "delFlag",
format: "TEXT",
},
{
field: "synFlag",
format: "TEXT",
}
]
inspectionRecordName: "INSPECTION_RECORD",
inspectionRecord: [{
field: "id",
format: "TEXT NOT NULL",
},
{
field: "inspectionType",
format: "TEXT",
},
{
field: "recordName",
format: "TEXT",
},
{
field: "userId",
format: "TEXT",
},
{
field: "userName",
format: "TEXT",
},
{
field: "inspectionTime",
format: "TEXT",
},
{
field: "inspectionCode",
format: "TEXT",
},
{
field: "synFlag",
format: "TEXT",
},
{
field: "createTime",
format: "TEXT",
},
{
field: "createBy",
format: "TEXT",
},
{
field: "updateTime",
format: "TEXT",
},
{
field: "updateBy",
format: "TEXT",
},
{
field: "delFlag",
format: "TEXT",
},
{
field: "isException",
format: "TEXT",
},
{
field: "inspectionData",
format: "TEXT",
}
],
// 机房、井道信息表
assRoomName: "ASS_ROOM",
assRoom: [{
field: "id",
format: "TEXT NOT NULL",
},
{
field: "roomName",
format: "TEXT",
},
{
field: "buildingId",
format: "TEXT",
},
{
field: "buildingName",
format: "TEXT",
},
{
field: "roomType",
format: "TEXT",
},
{
field: "roomFile",
format: "TEXT",
},
{
field: "roomAddress",
format: "TEXT",
},
{
field: "keynoteFlag",
format: "TEXT",
},
{
field: "sort",
format: "TEXT",
},
{
field: "roomDesc",
format: "TEXT",
},
{
field: "remark",
format: "TEXT",
},
{
field: "createTime",
format: "TEXT",
},
{
field: "createBy",
format: "TEXT",
},
{
field: "updateTime",
format: "TEXT",
},
{
field: "updateBy",
format: "TEXT",
},
{
field: "delFlag",
format: "TEXT",
},
{
field: "synFlag",
format: "TEXT",
},
{
field: "SHOW",
format: "TEXT",
},
{
field: "roomFeature",
format: "TEXT",
},
{
field: "dictValue",
format: "TEXT",
}
],
// 楼宇信息
assBuildingName: "ASS_BUILDING",
assBuilding: [{
field: "id",
format: "TEXT NOT NULL",
},
{
field: "buildingName",
format: "TEXT",
},
{
field: "sort",
format: "TEXT",
},
{
field: "remark",
format: "TEXT",
},
{
field: "createTime",
format: "TEXT",
},
{
field: "createBy",
format: "TEXT",
},
{
field: "updateTime",
format: "TEXT",
},
{
field: "updateBy",
format: "TEXT",
},
{
field: "delFlag",
format: "TEXT",
},
{
field: "synFlag",
format: "TEXT",
}
]
};
\ No newline at end of file
......@@ -19,7 +19,7 @@ export default {
account,
pwd
} = data
const sql = `select * from ${table.userName} where userName = '${account}'`
const sql = `select * from ${table.userName} where user = '${account}'`
let res = await sqllitedb.selectSQL(sql);
const user = res[0]
......@@ -54,7 +54,7 @@ export default {
} = data
let sqllitedb = await SqlliteDbUtil.initSqlliteDB()
const [current] = await sqllitedb.selectSQL(
`select * from ${table.userName} where userId = '${userId}' and userName = '${userName}'`, [userId,
`select * from ${table.userName} where userId = '${userId}' and user = '${userName}'`, [userId,
userName
]
);
......
[ {
"userId": 1,
"userName": "姜安平",
"userType": "normal",
"avatar": "",
"password": "Jap@123",
"rememberPwd": "0"
}, {
"userId": 2,
"userName": "段树梁",
"userType": "sys_user",
"avatar": "",
"password": "Dsl@123",
"rememberPwd": "0"
}, {
"userId": 3,
"userName": "孔佳真",
"userType": "sys_user",
"avatar": "",
"password": "Kjz@123",
"rememberPwd": "0"
}, {
"userId": 4,
"userName": "钟校明",
"userType": "sys_user",
"avatar": "",
"password": "Zxm@123",
"rememberPwd": "0"
}]
\ No newline at end of file
[
{
"userId": 1,
"user": "姜安平",
"avatar": "",
"passWord": "Jap@123",
"roleName": "运维",
"unitName": "运维",
"isAdmin": false,
"LastSynchronizationTime": ""
},
{
"userId": 2,
"user": "段树梁",
"avatar": "",
"passWord": "Dsl@123",
"roleName": "运维",
"unitName": "运维",
"isAdmin": false,
"LastSynchronizationTime": ""
},
{
"userId": 3,
"user": "孔佳真",
"avatar": "",
"passWord": "Kjz@123",
"roleName": "运维",
"unitName": "运维",
"isAdmin": false,
"LastSynchronizationTime": ""
},
{
"userId": 1,
"user": "钟校明",
"avatar": "",
"passWord": "Zxm@123",
"roleName": "运维",
"unitName": "运维",
"isAdmin": false,
"LastSynchronizationTime": ""
}
]
\ No newline at end of file
......@@ -98,6 +98,12 @@
uni.navigateTo({
url: "/pages/home/home",
});
}else{
uni.showToast({
title: '账号密码错误,请重新输入',
icon: "none",
duration: 2000,
});
}
});
},
......
......@@ -172,4 +172,14 @@ export default class SqlliteDB {
async commitTransaction() {
this.openTransaction("commit");
}
static async checkIfDataImported(sqllitedb) {
// 假设有一个表或字段来记录数据导入状态
let result = await sqllitedb.selectSQL('SELECT value FROM SYS_CONFIG WHERE key = "data_imported"');
return result && result.length > 0 && result[0].value === 'true';
}
static async markDataAsImported(sqllitedb) {
await sqllitedb.executeSQL('INSERT OR REPLACE INTO SYS_CONFIG (key, value) VALUES ("data_imported", "true")');
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论