提交 e0ecdcbc authored 作者: zs's avatar zs

edit

上级 09d732e8
import table from "../sqllite/table"; import table from '../sqllite/table'
import _Path from "@/constant/ioPath"; import _Path from '@/constant/ioPath'
import ioUtil from "@/utils/ioUtil"; import ioUtil from '@/utils/ioUtil'
import SqlliteDbUtil from "@/utils/sqllitedb"; import SqlliteDbUtil from '@/utils/sqllitedb'
import userApi from "@/api/user"; import userApi from '@/api/user'
import hoistwayApi from "@/api/hoistway"; import hoistwayApi from '@/api/hoistway'
import assRoomApi from "@/api/assRoom.js"; import assRoomApi from '@/api/assRoom.js'
import hoistwayjson from "../../baseData/hoistway.json"; import hoistwayjson from '../../baseData/hoistway.json'
import userjson from "../../baseData/user.json"; import userjson from '../../baseData/user.json'
import assroomjson from "../../baseData/assroom.json"; import assroomjson from '../../baseData/assroom.json'
import fileImport from "@/utils/fileImport.js"; import fileImport from '@/utils/fileImport.js'
export default { export default {
// app初始化 // app初始化
async init() { async init() {
uni.showLoading({ uni.showLoading({
title: "正在初始化...", title: '正在初始化...',
}); })
// 初始化目录 // 初始化目录
await this.initDir(); await this.initDir()
// 初始化数据库 // 初始化数据库
// cookie.set('initDB', true) await this.initSqlLite()
await this.initSqlLite(); let sqllitedb = await SqlliteDbUtil.initSqlliteDB()
let isInit = await SqlliteDbUtil.checkIfDataImported(sqllitedb)
// 导入用戶文件文件 if (!isInit) {
// await this.importFileData(); await userApi.saveBatch(userjson)
await userApi.saveBatch(userjson); await hoistwayApi.saveBatch(hoistwayjson)
await hoistwayApi.saveBatch(hoistwayjson); await assRoomApi.saveBatch(assroomjson)
await assRoomApi.saveBatch(assroomjson); await SqlliteDbUtil.markDataAsImported(sqllitedb)
}
// 初始化完成通知首页 // 初始化完成通知首页
uni.$emit("initDone", "ok"); uni.hideLoading()
uni.hideLoading();
}, },
// 检查文件导入 // 检查文件导入
async importFileData() { async importFileData() {
// 解压缩需要导入的zip,导入后删除 // 解压缩需要导入的zip,导入后删除
try { try {
console.log("解压导入开始...."); console.log('解压导入开始....')
console.log("导入基础数据开始"); console.log('导入基础数据开始')
await fileImport.importBaseFile(); await fileImport.importBaseFile()
console.log("导入基础数据结束!"); console.log('导入基础数据结束!')
console.log("解压导入完成...."); console.log('解压导入完成....')
} catch (e) { } catch (e) {
console.log(e.message); console.log(e.message)
uni.showToast({ uni.showToast({
icon: "none", icon: 'none',
title: e.message, title: e.message
}); })
uni.hideLoading(); uni.hideLoading()
} }
}, },
////////// 初始化数据库//////////// ////////// 初始化数据库////////////
async initSqlLite() { async initSqlLite() {
console.log("初始化数据库开始..."); console.log('初始化数据库开始...')
let sqllitedb = null; let sqllitedb = null
try { try {
// 创建打开数据库,已经存在表则跳过 // 创建打开数据库,已经存在表则跳过
sqllitedb = await SqlliteDbUtil.initSqlliteDB(); sqllitedb = await SqlliteDbUtil.initSqlliteDB()
console.log(sqllitedb, "是否存在"); console.log(sqllitedb, '是否存在')
// console.log('创建用户表...') // console.log('创建用户表...')
await sqllitedb.createTable(table.userName, table.user); await sqllitedb.createTable(table.metadataName, table.metadata)
await sqllitedb.createTable( await sqllitedb.createTable(table.userName, table.user)
table.inspectionRecordName, await sqllitedb.createTable(table.inspectionRecordName, table.inspectionRecord) // 巡检记录表
table.inspectionRecord await sqllitedb.createTable(table.assRoomName, table.assRoom) // 机房、井道信息表
); // 巡检记录表 await sqllitedb.createTable(table.assBuildingName, table.assBuilding) // 楼宇信息
await sqllitedb.createTable(table.assRoomName, table.assRoom); // 机房、井道信息表
await sqllitedb.createTable(table.assBuildingName, table.assBuilding); // 楼宇信息
} catch (e) { } catch (e) {
console.log(e.message); console.log(e.message)
} finally { } finally {
return; return
// 关闭数据库 // 关闭数据库
if (sqllitedb) { if (sqllitedb) {
await sqllitedb.closeDB(); await sqllitedb.closeDB()
} }
// 初始化完成后重启APP/退出APP // 初始化完成后重启APP/退出APP
uni.showToast({ uni.showToast({
icon: "none", icon: 'none',
title: "初始化完毕即将重新加载...", title: '初始化完毕即将重新加载...',
duration: 3000, duration: 3000
}); })
let that = this; let that = this
setTimeout(function () { setTimeout(function() {
that.restartApp(); that.restartApp()
}, 3000); }, 3000)
} }
}, },
// 初始化目录 // 初始化目录
async initDir() { async initDir() {
try { try {
const _www = _Path.getPrivateWWW(); const _www = _Path.getPrivateWWW()
const _doc = _Path.getPrivateDOC(); const _doc = _Path.getPrivateDOC()
const _download = _Path.getDownloads(); const _download = _Path.getDownloads()
const _temp = _Path.getTempPath(); const _temp = _Path.getTempPath()
const wwwEntry = await ioUtil.getFileEntry(_www); const wwwEntry = await ioUtil.getFileEntry(_www)
const docEntry = await ioUtil.getFileEntry(_doc); const docEntry = await ioUtil.getFileEntry(_doc)
const downloadEntry = await ioUtil.getFileEntry(_download); const downloadEntry = await ioUtil.getFileEntry(_download)
if (downloadEntry) { if (downloadEntry) {
await ioUtil.createDir(downloadEntry.fullPath, "base"); await ioUtil.createDir(downloadEntry.fullPath, 'base')
await ioUtil.createDir(downloadEntry.fullPath, "export"); await ioUtil.createDir(downloadEntry.fullPath, 'export')
await ioUtil.createDir(downloadEntry.fullPath, "import"); await ioUtil.createDir(downloadEntry.fullPath, 'import')
await ioUtil.createDir(downloadEntry.fullPath, "doc"); await ioUtil.createDir(downloadEntry.fullPath, 'doc')
await ioUtil.createDir(downloadEntry.fullPath, "error"); await ioUtil.createDir(downloadEntry.fullPath, 'error')
} }
// 获取设备名称 // 获取设备名称
uni.getSystemInfo({ uni.getSystemInfo({
success: async function (e) { success: async function(e) {
const deviceData = { const deviceData = {
deviceId: e.deviceId, deviceId: e.deviceId,
brand: e.deviceBrand, brand: e.deviceBrand,
deviceModel: e.deviceModel, deviceModel: e.deviceModel,
}; }
const deviceFilePath = downloadEntry.fullPath + "name.txt"; const deviceFilePath = downloadEntry.fullPath + 'name.txt'
await ioUtil.removeExistFile(deviceFilePath); await ioUtil.removeExistFile(deviceFilePath)
await ioUtil.writeFile( await ioUtil.writeFile('name.txt', downloadEntry, JSON.stringify(deviceData))
"name.txt",
downloadEntry,
JSON.stringify(deviceData)
);
}, },
}); });
// 文件目录 // 文件目录
if (docEntry) { if (docEntry) {
await ioUtil.createDir(docEntry.fullPath, "file"); await ioUtil.createDir(docEntry.fullPath, 'file')
} }
// 临时目录 // 临时目录
let tempEntry = await ioUtil.getFileEntry(_temp); let tempEntry = await ioUtil.getFileEntry(_temp)
if (!tempEntry) { if (!tempEntry) {
await ioUtil.createDir(_temp); await ioUtil.createDir(_temp)
tempEntry = await ioUtil.createDir( tempEntry = await ioUtil.createDir(_Path.getTempParent(), 'inspectTemp')
_Path.getTempParent(),
"inspectTemp"
);
} }
await ioUtil.createDir(tempEntry.fullPath, "db"); await ioUtil.createDir(tempEntry.fullPath, 'db')
} catch (e) { } catch (e) {
console.log(e.message); console.log(e.message)
} }
}, },
// 重启app // 重启app
restartApp() { restartApp() {
// #ifdef APP-PLUS // #ifdef APP-PLUS
if (plus.os.name.toLowerCase() === "android") { if (plus.os.name.toLowerCase() === 'android') {
plus.runtime.restart(); plus.runtime.restart();
} }
// #endif // #endif
...@@ -156,7 +150,7 @@ export default { ...@@ -156,7 +150,7 @@ export default {
// 退出app // 退出app
exitApp() { exitApp() {
// #ifdef APP-PLUS // #ifdef APP-PLUS
if (plus.os.name.toLowerCase() === "android") { if (plus.os.name.toLowerCase() === 'android') {
plus.runtime.quit(); plus.runtime.quit();
} else { } else {
const threadClass = plus.ios.importClass("NSThread"); const threadClass = plus.ios.importClass("NSThread");
...@@ -166,5 +160,5 @@ export default { ...@@ -166,5 +160,5 @@ export default {
// plus.ios.import('UIApplication').sharedApplication().performSelector('exit'); // plus.ios.import('UIApplication').sharedApplication().performSelector('exit');
} }
// #endif // #endif
}, }
}; }
\ No newline at end of file
module.exports = { module.exports = {
// 数据库设置
metadataName: 'SYS_CONFIG',
metadata: [{
field: "key",
format: "TEXT PRIMARY KEY",
}, {
field: "value",
format: "TEXT",
}],
// 用户表 // 用户表
userName: "SYS_USER", userName: "SYS_USER",
user: [{ user: [{
field: "userId", field: "userId",
format: "TEXT", format: "TEXT PRIMARY KEY",
}, },
{ {
field: "userName", field: "user",
format: "TEXT", format: "TEXT",
}, },
{ {
...@@ -18,18 +27,29 @@ module.exports = { ...@@ -18,18 +27,29 @@ module.exports = {
format: "TEXT", format: "TEXT",
}, },
{ {
field: "password", field: "passWord",
format: "TEXT",
},
{
field: "roleName",
format: "TEXT",
},
{
field: "unitName",
format: "TEXT",
},
{
field: "isAdmin",
format: "TEXT", format: "TEXT",
}, },
{ {
field: "rememberPwd", field: "LastSynchronizationTime",
format: "TEXT", format: "TEXT",
}, },
], ],
// 巡检记录表 // 巡检记录表
inspectionRecordName: "INSPECTION_RECORD", inspectionRecordName: "INSPECTION_RECORD",
inspectionRecord: [ inspectionRecord: [{
{
field: "id", field: "id",
format: "TEXT NOT NULL", format: "TEXT NOT NULL",
}, },
...@@ -94,8 +114,7 @@ module.exports = { ...@@ -94,8 +114,7 @@ module.exports = {
// 机房、井道信息表 // 机房、井道信息表
assRoomName: "ASS_ROOM", assRoomName: "ASS_ROOM",
assRoom: [ assRoom: [{
{
field: "id", field: "id",
format: "TEXT NOT NULL", format: "TEXT NOT NULL",
}, },
...@@ -180,8 +199,7 @@ module.exports = { ...@@ -180,8 +199,7 @@ module.exports = {
], ],
// 楼宇信息 // 楼宇信息
assBuildingName: "ASS_BUILDING", assBuildingName: "ASS_BUILDING",
assBuilding: [ assBuilding: [{
{
field: "id", field: "id",
format: "TEXT NOT NULL", format: "TEXT NOT NULL",
}, },
......
...@@ -19,7 +19,7 @@ export default { ...@@ -19,7 +19,7 @@ export default {
account, account,
pwd pwd
} = data } = 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); let res = await sqllitedb.selectSQL(sql);
const user = res[0] const user = res[0]
...@@ -54,7 +54,7 @@ export default { ...@@ -54,7 +54,7 @@ export default {
} = data } = data
let sqllitedb = await SqlliteDbUtil.initSqlliteDB() let sqllitedb = await SqlliteDbUtil.initSqlliteDB()
const [current] = await sqllitedb.selectSQL( 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 userName
] ]
); );
......
[ { [
{
"userId": 1, "userId": 1,
"userName": "姜安平", "user": "姜安平",
"userType": "normal",
"avatar": "", "avatar": "",
"password": "Jap@123", "passWord": "Jap@123",
"rememberPwd": "0" "roleName": "运维",
}, { "unitName": "运维",
"isAdmin": false,
"LastSynchronizationTime": ""
},
{
"userId": 2, "userId": 2,
"userName": "段树梁", "user": "段树梁",
"userType": "sys_user",
"avatar": "", "avatar": "",
"password": "Dsl@123", "passWord": "Dsl@123",
"rememberPwd": "0" "roleName": "运维",
}, { "unitName": "运维",
"isAdmin": false,
"LastSynchronizationTime": ""
},
{
"userId": 3, "userId": 3,
"userName": "孔佳真", "user": "孔佳真",
"userType": "sys_user",
"avatar": "", "avatar": "",
"password": "Kjz@123", "passWord": "Kjz@123",
"rememberPwd": "0" "roleName": "运维",
}, { "unitName": "运维",
"userId": 4, "isAdmin": false,
"userName": "钟校明", "LastSynchronizationTime": ""
"userType": "sys_user", },
{
"userId": 1,
"user": "钟校明",
"avatar": "", "avatar": "",
"password": "Zxm@123", "passWord": "Zxm@123",
"rememberPwd": "0" "roleName": "运维",
}] "unitName": "运维",
\ No newline at end of file "isAdmin": false,
"LastSynchronizationTime": ""
}
]
\ No newline at end of file
...@@ -98,6 +98,12 @@ ...@@ -98,6 +98,12 @@
uni.navigateTo({ uni.navigateTo({
url: "/pages/home/home", url: "/pages/home/home",
}); });
}else{
uni.showToast({
title: '账号密码错误,请重新输入',
icon: "none",
duration: 2000,
});
} }
}); });
}, },
......
...@@ -172,4 +172,14 @@ export default class SqlliteDB { ...@@ -172,4 +172,14 @@ export default class SqlliteDB {
async commitTransaction() { async commitTransaction() {
this.openTransaction("commit"); 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 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论