提交 3419a7e0 authored 作者: zs's avatar zs

表结构更改

上级 691cf0cd
import SqlliteDbUtil from "@/utils/sqllitedb"; import SqlliteDbUtil from "@/utils/sqllitedb";
import table from "./sqllite/table.js"; import table from "./sqllite/table.js";
import { fixNullVal } from "@/utils/common"; import {
fixNullVal
} from "@/utils/common";
// 巡检 // 巡检
export default { export default {
async selectList() { async selectList() {
let sqllitedb = await SqlliteDbUtil.initSqlliteDB(); let sqllitedb = await SqlliteDbUtil.initSqlliteDB();
let rs = await sqllitedb.selectSQL( let rs = await sqllitedb.selectSQL(
`select * from ${table.inspectionRecordName}` `select * from ${table.inspectionRecordName}`
); );
return rs; return rs;
}, },
async selectDataForTime() {
let sqllitedb = await SqlliteDbUtil.initSqlliteDB();
let rs = await sqllitedb.selectSQL(
`SELECT *,strftime( '%Y年%m月',createTime) AS yearMonth FROM ${table.inspectionRecordName} order by createTime desc`
);
return rs;
},
async info(id) {
let sqllitedb = await SqlliteDbUtil.initSqlliteDB();
let sql = `select * from ${table.inspectionRecordName} where id = '${id}'`;
let res = await sqllitedb.selectSQL(sql);
if (res && res.length > 0) {
return res[0];
}
},
async remove(id) {
if (!id) {
return;
}
let sql = `delete from ${table.inspectionRecordName} where id = '${id}'`;
let sqllitedb = await SqlliteDbUtil.initSqlliteDB();
await sqllitedb.executeSQL(sql);
},
async saveBatch(list) {
if (list.length === 0) {
return;
}
console.log("开始保存用户信息...." + list.length);
let sqllitedb = await SqlliteDbUtil.initSqlliteDB();
try {
for (let data of list) {
let column = "";
let values = "";
let idx = 0;
for (let attr in data) {
let dataField = table["inspectionRecord"].find((v) => {
if (v.field === attr) {
return v;
}
});
if (!dataField) {
continue;
}
column += dataField.field + ",";
values += "'" + fixNullVal(data[attr]) + "',";
idx++;
}
async info(id) { column = column.endsWith(",") ?
let sqllitedb = await SqlliteDbUtil.initSqlliteDB(); column.substring(0, column.length - 1) :
let sql = `select * from ${table.inspectionRecordName} where id = '${id}'`; column;
let res = await sqllitedb.selectSQL(sql); values = values.endsWith(",") ?
if (res && res.length > 0) { values.substring(0, values.length - 1) :
return res[0]; values;
}
},
async remove(id) {
if (!id) {
return;
}
let sql = `delete from ${table.inspectionRecordName} where id = '${id}'`;
let sqllitedb = await SqlliteDbUtil.initSqlliteDB();
await sqllitedb.executeSQL(sql);
},
async saveBatch(list) {
if (list.length === 0) {
return;
}
console.log("开始保存用户信息...." + list.length);
let sqllitedb = await SqlliteDbUtil.initSqlliteDB();
try {
for (let data of list) {
let column = "";
let values = "";
let idx = 0;
for (let attr in data) {
let dataField = table["inspectionRecord"].find((v) => {
if (v.field === attr) {
return v;
}
});
if (!dataField) {
continue;
}
column += dataField.field + ",";
values += "'" + fixNullVal(data[attr]) + "',";
idx++;
}
column = column.endsWith(",") let sql = `insert into ${table.inspectionRecordName}(${column}) values(${values})`;
? column.substring(0, column.length - 1) let has = await this.info(data.id);
: column; if (has && has.id) {
values = values.endsWith(",") await this.remove(data.id);
? values.substring(0, values.length - 1) }
: values; await sqllitedb.executeSQL(sql);
}
let sql = `insert into ${table.inspectionRecordName}(${column}) values(${values})`; } catch (e) {
let has = await this.info(data.id); console.log(e.message);
if (has && has.id) { } finally {
await this.remove(data.id); await sqllitedb.closeDB();
} }
await sqllitedb.executeSQL(sql); console.log("导入完成...");
} },
} catch (e) { async save(data) {
console.log(e.message); console.log("开始保存巡检记录", data);
} finally { let sqllitedb = await SqlliteDbUtil.initSqlliteDB();
await sqllitedb.closeDB(); try {
} let sql = `insert into ${table.inspectionRecordName}(
console.log("导入完成...");
},
async save(data) {
console.log("开始保存巡检记录", data);
let sqllitedb = await SqlliteDbUtil.initSqlliteDB();
try {
let sql = `insert into ${table.inspectionRecordName}(
inspectionType, inspectionType,
inspectionCode, inspectionCode,
recordName, recordName,
...@@ -90,7 +98,7 @@ export default { ...@@ -90,7 +98,7 @@ export default {
createBy, createBy,
createTime, createTime,
updateTime, updateTime,
signImg, signImg,
inspectionData inspectionData
) values( ) values(
'${data.inspectionType}', '${data.inspectionType}',
...@@ -106,23 +114,26 @@ export default { ...@@ -106,23 +114,26 @@ export default {
'${data.updateTime}', '${data.updateTime}',
'${data.signImg}', '${data.signImg}',
'${JSON.stringify(data.inspectionData)}' '${JSON.stringify(data.inspectionData)}'
)`; );
await sqllitedb.executeSQL(sql); `;
} catch (e) { debugger
console.log(e.message); let result = await sqllitedb.executeReturnDataSQL(sql);
} finally { console.log(result, '有有有有有有')
await sqllitedb.closeDB(); } catch (e) {
} console.log(e.message);
console.log("导入完成..."); } finally {
}, await sqllitedb.closeDB();
async update(data) { }
console.log("开始更新巡检记录", data); console.log("导入完成...");
let sqllitedb = await SqlliteDbUtil.initSqlliteDB(); },
try { async update(data) {
if (!data.id) { console.log("开始更新巡检记录", data);
throw new Error("更新操作需要提供 id"); let sqllitedb = await SqlliteDbUtil.initSqlliteDB();
} try {
let sql = `UPDATE ${table.inspectionRecordName} SET if (!data.id) {
throw new Error("更新操作需要提供 id");
}
let sql = `UPDATE ${table.inspectionRecordName} SET
inspectionType = '${data.inspectionType}', inspectionType = '${data.inspectionType}',
inspectionCode = '${data.inspectionCode}', inspectionCode = '${data.inspectionCode}',
recordName = '${data.recordName}', recordName = '${data.recordName}',
...@@ -137,12 +148,12 @@ export default { ...@@ -137,12 +148,12 @@ export default {
updateTime = '${data.updateTime}', updateTime = '${data.updateTime}',
inspectionData = '${JSON.stringify(data.inspectionData)}' inspectionData = '${JSON.stringify(data.inspectionData)}'
WHERE id = ${data.id}`; WHERE id = ${data.id}`;
await sqllitedb.executeSQL(sql); await sqllitedb.executeSQL(sql);
} catch (e) { } catch (e) {
console.log(e.message); console.log(e.message);
} finally { } finally {
await sqllitedb.closeDB(); await sqllitedb.closeDB();
} }
console.log("更新完成..."); console.log("更新完成...");
}, },
}; };
\ No newline at end of file
...@@ -14,13 +14,13 @@ export default { ...@@ -14,13 +14,13 @@ export default {
// app初始化 // app初始化
async init() { async init() {
uni.showLoading({ // uni.showLoading({
title: '正在初始化...', // title: '正在初始化...',
}) // })
// 初始化目录 // 初始化目录
await this.initDir() // await this.initDir()
// 初始化数据库 // 初始化数据库
this.initSqlLite() this.initSqlLite()
let sqllitedb = await SqlliteDbUtil.initSqlliteDB() let sqllitedb = await SqlliteDbUtil.initSqlliteDB()
let isInit = await SqlliteDbUtil.checkIfDataImported(sqllitedb) let isInit = await SqlliteDbUtil.checkIfDataImported(sqllitedb)
if (!isInit) { if (!isInit) {
......
...@@ -51,7 +51,7 @@ module.exports = { ...@@ -51,7 +51,7 @@ module.exports = {
inspectionRecordName: "INSPECTION_RECORD", inspectionRecordName: "INSPECTION_RECORD",
inspectionRecord: [{ inspectionRecord: [{
field: "id", field: "id",
format: "INTEGER PRIMARY KEY AUTOINCREMENT", format: "INTEGER PRIMARY KEY AUTOINCREMENT",
}, },
{ {
field: "inspectionType", field: "inspectionType",
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
<text>编号:</text> <text>编号:</text>
<text class="code-num">{{ details.inspectionCode }}</text> <text class="code-num">{{ details.inspectionCode }}</text>
<text>巡检日期:</text> <text>巡检日期:</text>
<text class="code-num">{{ details.submitTime }}</text> <text class="code-num">{{ details.inspectionTime }}</text>
</view> </view>
</view> </view>
<view class="img"> <view class="img">
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
<image <image
class="bg-img" class="bg-img"
mode="aspectFill" mode="aspectFill"
src="@/static/img/add-img/home1.png" src="@/static/img/add-img/defaultAvatar.png"
></image> ></image>
</view> </view>
<view class="card-item" @click="toSyncPage"> <view class="card-item" @click="toSyncPage">
......
...@@ -33,7 +33,7 @@ ...@@ -33,7 +33,7 @@
<view class="profile-left"> <view class="profile-left">
<view class="avatar"> <view class="avatar">
<image <image
src="@/static/img/add-img/home1.png" src="@/static/img/add-img/defaultAvatar.png"
mode="aspectFit" mode="aspectFit"
></image> ></image>
<view class="change-password" @click="updatePassword" <view class="change-password" @click="updatePassword"
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
<view class="home-page"> <view class="home-page">
<view class="left-tab"> <view class="left-tab">
<view class="user-info"> <view class="user-info">
<image class="user-img" src="@/static/img/add-img/home1.png"></image> <image class="user-img" src="@/static/img/add-img/defaultAvatar.png"></image>
<text class="text">{{ userName }}</text> <text class="text">{{ userName }}</text>
</view> </view>
......
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
<view class="profile-left"> <view class="profile-left">
<view class="avatar"> <view class="avatar">
<image <image
src="@/static/img/add-img/home1.png" src="@/static/img/add-img/defaultAvatar.png"
mode="aspectFit" mode="aspectFit"
></image> ></image>
</view> </view>
...@@ -164,7 +164,7 @@ ...@@ -164,7 +164,7 @@
<view class="first-row"> <view class="first-row">
<image <image
class="icon" class="icon"
src="@/static/img/add-img/home1.png" src="@/static/img/add-img/defaultAvatar.png"
></image> ></image>
<text class="status">{{ card.statusLable }}</text> <text class="status">{{ card.statusLable }}</text>
</view> </view>
......
...@@ -495,7 +495,7 @@ export default { ...@@ -495,7 +495,7 @@ export default {
const send = dataToSql(data); const send = dataToSql(data);
const api = this.uid ? inspectApi.update : inspectApi.save; const api = this.uid ? inspectApi.update : inspectApi.save;
api(this.uid ? { id: this.uid, ...send } : send).then((res) => { api(this.uid ? { id: this.uid, ...send } : send).then((res) => {
console.log("保存成功"); console.log("保存成功",res);
}); });
}, },
// 提交 // 提交
......
<template> <template>
<!-- 巡检管理 --> <!-- 巡检管理 -->
<view class="inspection-management"> <view class="inspection-management">
<uni-nav-bar <uni-nav-bar :fixed="true" background-color="rgba(214, 240, 255, 0.0)" status-bar rightWidth="300">
:fixed="true" <block slot="left">
background-color="rgba(214, 240, 255, 0.0)" <view class="" @click="back">
status-bar <text class="iconfont icon-fanhui"></text>
rightWidth="300" </view>
> </block>
<block slot="left"> <block slot="right" class="nav-right">
<view class="" @click="back"> <view class="header-buttons">
<text class="iconfont icon-fanhui"></text> <view class="button" @click="clickInspection(1)">机房巡检</view>
</view> <view class="button" @click="clickInspection(2)">井道巡检</view>
</block> </view>
<block slot="right" class="nav-right"> </block>
<view class="header-buttons"> </uni-nav-bar>
<view class="button" @click="clickInspection(1)">机房巡检</view> <!-- 搜索项 -->
<view class="button" @click="clickInspection(2)">井道巡检</view> <!-- <SearchCom @change="change" /> -->
</view> <!-- 结果 -->
</block> <view class="inspection-management-content">
</uni-nav-bar> <view class="count-tatal">
<!-- 搜索项 --> <text class="num">{{ countNum || 0 }}</text>
<SearchCom @change="change" /> <text calss="">查询结果</text>
</view>
<!-- 结果 -->
<view class="inspection-management-content"> <view class="month-list">
<view class="count-tatal"> <!-- 每月记录 -->
<text class="num">{{ countNum || 0 }}</text> <view class="month-record-item" v-for="(item, index) in list" :key="index">
<text calss="">查询结果</text> <view v-if="(item || []).length" class="seconed-title">
</view> {{ '2025-04'}}
</view>
<view class="month-list">
<!-- 每月记录 --> <view class="inspect-list">
<view <InspectionItem :details="item" />
class="month-record-item" </view>
v-for="(item, index) in list" </view>
:key="index"
> <Empty v-if="list.length == 0" />
<view v-if="(item.list || []).length" class="seconed-title"> </view>
{{ item.submitTime || item.time }} </view>
</view>
<!-- 开始巡检 -->
<view class="inspect-list"> <!-- <view class="inspection-button" @click="toPage">开始巡检</view> -->
<InspectionItem <view class="inspection-button" @click="openDialog(true)">同步数据</view><!-- 打包弹窗 -->
v-for="ele in item.list" <Dialog v-show="isDialog && list.length" :list="list" @close="openDialog(false)"></Dialog>
:key="ele.uid" </view>
:details="ele"
/>
</view>
</view>
<Empty v-if="list.length == 0" />
</view>
</view>
<!-- 开始巡检 -->
<!-- <view class="inspection-button" @click="toPage">开始巡检</view> -->
<view class="inspection-button" @click="openDialog(true)">同步数据</view
><!-- 打包弹窗 -->
<Dialog
v-show="isDialog && list.length"
:list="list"
@close="openDialog(false)"
></Dialog>
</view>
</template> </template>
<script> <script>
import SearchCom from "@/components/searchCom/index.vue"; import SearchCom from "@/components/searchCom/index.vue";
import InspectionItem from "@/components/inspectionItem/index.vue"; import InspectionItem from "@/components/inspectionItem/index.vue";
import { getDarft } from "@/request/index.js"; import {
import Dialog from "./dialog.vue"; getDarft
import { getAllInspections } from "@/request/index.js"; } from "@/request/index.js";
import Empty from "@/components/empty/index.vue"; import Dialog from "./dialog.vue";
import {
export default { getAllInspections
components: { } from "@/request/index.js";
SearchCom, import Empty from "@/components/empty/index.vue";
InspectionItem,
Dialog, import inspectApi from "@/api/inspect";
Empty, export default {
}, components: {
data() { SearchCom,
return { InspectionItem,
isDialog: false, // Dialog,
list: [], // 展示数据 Empty,
all_data: [], // 所有数据 },
searchForm: { data() {
// 搜索条件 return {
}, isDialog: false, //
countNum: 0, // 统计查询总数 list: [], // 展示数据
}; all_data: [], // 所有数据
}, searchForm: {
mounted() { // 搜索条件
uni.showLoading(); },
countNum: 0, // 统计查询总数
getAllInspections() };
.then((res) => { },
this.all_data = res; async mounted() {
this.init(); // this.getInspectRecord()
uni.hideLoading(); let res = await inspectApi.selectDataForTime()
}) this.list = res
.catch((error) => { console.log(res.length, '永远永远永远永远=---=>')
if (0 == error.code) { },
uni.showToast({ computed: {
title: error.msg, userInfo() {
icon: "none", return this.$store.state.now_user || {};
duration: 1000, },
}); },
} methods: {
this.all_data = []; async getInspectRecord() {
uni.hideLoading(); let res = await inspectApi.selectList()
}); console.log('阿斗者', res)
}, this.list = res || []
computed: { this.countNum = this.list.length
userInfo() {
return this.$store.state.now_user || {}; },
}, // 返回
}, back() {
methods: { uni.navigateTo({
// 返回 url: "/pages/home/home",
back() { });
uni.navigateTo({ },
url: "/pages/home/home", clickInspection(type) {
}); if (type == 1) {
}, uni.navigateTo({
clickInspection(type) { url: "/pages/inspectionContent/inspectionContentList",
if (type == 1) { });
uni.navigateTo({ } else {
url: "/pages/inspectionContent/inspectionContentList", uni.navigateTo({
}); url: "/pages/shaftInspection/shaftInspectionList",
} else { });
uni.navigateTo({ }
url: "/pages/shaftInspection/shaftInspectionList", },
}); init() {
} const all_data = this.all_data || [];
}, // this.isPackedDataBtn =
init() { // all_data.filter((item) => item.synchronization == 0).length > 0;
const all_data = this.all_data || [];
// this.isPackedDataBtn = const {
// all_data.filter((item) => item.synchronization == 0).length > 0; inspectionTime = []
} = this.searchForm;
const { inspectionTime = [] } = this.searchForm; const startTime = inspectionTime[0];
const startTime = inspectionTime[0]; const endTime = inspectionTime[1];
const endTime = inspectionTime[1];
// 第一步: 筛选有效的时间范围
// 第一步: 筛选有效的时间范围 const timeFrame = all_data.filter((item) => {
const timeFrame = all_data.filter((item) => { if (!inspectionTime.length) {
if (!inspectionTime.length) { return true;
return true; } else {
} else { return (
return ( new Date(startTime).getTime() <=
new Date(startTime).getTime() <= new Date(item.submitTime).getTime() &&
new Date(item.submitTime).getTime() && new Date(item.submitTime).getTime() <= new Date(endTime).getTime()
new Date(item.submitTime).getTime() <= new Date(endTime).getTime() );
); }
} });
});
// 属于同一个月的数据 聚合
// 属于同一个月的数据 聚合 const tempAllData = {};
const tempAllData = {}; timeFrame.forEach((item) => {
timeFrame.forEach((item) => { const val = tempAllData[item.submitMonth] || [];
const val = tempAllData[item.submitMonth] || []; if (val.length) {
if (val.length) { tempAllData[item.submitMonth].push(item);
tempAllData[item.submitMonth].push(item); } else {
} else { tempAllData[item.submitMonth] = [item];
tempAllData[item.submitMonth] = [item]; }
} });
}); const keys = Object.keys(tempAllData);
const keys = Object.keys(tempAllData); // 第二步: 根据搜索条件过滤
// 第二步: 根据搜索条件过滤 const list = keys.map((key) => {
const list = keys.map((key) => { return {
return { time: key,
time: key, list: this.coverData(tempAllData[key]),
list: this.coverData(tempAllData[key]), };
}; });
});
this.countNum = 0;
this.countNum = 0; list.forEach((item) => {
list.forEach((item) => { this.countNum += item.list.length;
this.countNum += item.list.length; });
});
this.list = list;
this.list = list; console.log("this.list", this.list);
console.log("this.list", this.list); },
},
coverData(arr = []) {
coverData(arr = []) { console.log("arr", arr);
console.log("arr", arr); const {
const { isException = "",
isException = "", inspectionType = "",
inspectionType = "", synchronization = "",
synchronization = "", } = this.searchForm;
} = this.searchForm;
return arr.filter((item) => {
return arr.filter((item) => { return (
return ( (!isException ||
(!isException || isException == "all" ||
isException == "all" || item.isException == isException) &&
item.isException == isException) && (!inspectionType ||
(!inspectionType || inspectionType == "all" ||
inspectionType == "all" || item.inspectionType == inspectionType) &&
item.inspectionType == inspectionType) && (!synchronization ||
(!synchronization || synchronization == "all" ||
synchronization == "all" || item.synchronization == synchronization)
item.synchronization == synchronization) );
); });
}); },
}, openDialog(show) {
openDialog(show) { this.isDialog = show;
this.isDialog = show; if (!show) {
if (!show) { this.init();
this.init(); }
} },
}, change(e) {
change(e) { this.searchForm = e;
this.searchForm = e;
this.init();
this.init(); },
},
toPage() {
toPage() { uni.showLoading();
uni.showLoading();
getDarft()
getDarft() .then((res) => {
.then((res) => { const darf_data = res || {};
const darf_data = res || {};
if (darf_data.inspectionType == 1) {
if (darf_data.inspectionType == 1) { uni.navigateTo({
uni.navigateTo({ url: `/pages/inspectionContent/inspectionContent?isDarf=1`,
url: `/pages/inspectionContent/inspectionContent?isDarf=1`, });
}); } else if (darf_data.inspectionType == 2) {
} else if (darf_data.inspectionType == 2) { uni.navigateTo({
uni.navigateTo({ url: `/pages/shaftInspection/shaftInspection?isDarf=1`,
url: `/pages/shaftInspection/shaftInspection?isDarf=1`, });
}); } else {
} else { uni.navigateTo({
uni.navigateTo({ url: "/pages/inspection/inspFirst",
url: "/pages/inspection/inspFirst", });
}); }
} uni.hideLoading();
uni.hideLoading(); })
}) .catch((error) => {
.catch((error) => { if (error.code == 0) {
if (error.code == 0) { uni.showToast({
uni.showToast({ title: error.msg,
title: error.msg,
icon: "none",
icon: "none", duration: 1000,
duration: 1000, });
}); }
} uni.navigateTo({
uni.navigateTo({ url: "/pages/inspection/inspFirst",
url: "/pages/inspection/inspFirst", });
});
uni.hideLoading();
uni.hideLoading(); });
}); },
}, },
}, };
};
</script> </script>
<style scoped lang="less"> <style scoped lang="less">
.uni-nav-bar-text { .uni-nav-bar-text {
height: 28.8px; height: 28.8px;
width: 28.8px; width: 28.8px;
background: #ffffff; background: #ffffff;
border: 0.32px solid rgba(224, 224, 224, 1); border: 0.32px solid rgba(224, 224, 224, 1);
border-radius: 14.4px; border-radius: 14.4px;
color: #333; color: #333;
display: flex; display: flex;
align-items: center; align-items: center;
justify-content: center; justify-content: center;
text-align: center; text-align: center;
z-index: 999; z-index: 999;
.iconfont { .iconfont {
font-size: 16px; font-size: 16px;
line-height: 28.8px; line-height: 28.8px;
} }
} }
.nav-right {
width: 192px; .nav-right {
} width: 192px;
.header-buttons { }
display: flex;
align-items: center; .header-buttons {
margin-left: auto; display: flex;
.button { align-items: center;
width: 89.6px; margin-left: auto;
height: 28.8px;
background: #ffffff; .button {
border-radius: 14.4px; width: 89.6px;
margin-left: 12.8px; height: 28.8px;
font-family: PingFangSC-Regular; background: #ffffff;
font-size: 12.8px; border-radius: 14.4px;
color: #000000; margin-left: 12.8px;
line-height: 28.8px; font-family: PingFangSC-Regular;
font-weight: 400; font-size: 12.8px;
text-align: center; color: #000000;
} line-height: 28.8px;
} font-weight: 400;
.inspection-management { text-align: center;
background-image: linear-gradient(115deg, #e8f0fb 0%, #e1ebfa 100%); }
padding: 0 25.6px; }
.inspection-management-content {
.count-tatal { .inspection-management {
font-family: PingFangSC-Medium; background-image: linear-gradient(115deg, #e8f0fb 0%, #e1ebfa 100%);
margin: 12.8px 0px 19.2px; padding: 0 25.6px;
font-size: 11.2px;
color: #4a4a4a; .inspection-management-content {
font-weight: 400; .count-tatal {
height: 22.4px; font-family: PingFangSC-Medium;
line-height: 22.4px; margin: 12.8px 0px 19.2px;
.num { font-size: 11.2px;
font-size: 16px; color: #4a4a4a;
color: #3774f6; font-weight: 400;
line-height: 22.4px; height: 22.4px;
font-weight: 500; line-height: 22.4px;
margin-right: 1.6px;
} .num {
} font-size: 16px;
.month-list { color: #3774f6;
height: calc(100vh - 20.8px - 12.8px - 6.4px - 28.8px - 49.6px - 25px); line-height: 22.4px;
overflow: auto; font-weight: 500;
// padding-bottom: 112px; margin-right: 1.6px;
.seconed-title { }
font-size: 16px; }
color: #000000;
line-height: 22.4px; .month-list {
font-weight: 500; height: calc(100vh - 20.8px - 12.8px - 6.4px - 28.8px - 49.6px - 25px);
margin-bottom: 9.6px; overflow: auto;
}
.month-record-item { // padding-bottom: 112px;
margin-bottom: 19.2px; .seconed-title {
&:last-of-type { font-size: 16px;
margin: 0; color: #000000;
} line-height: 22.4px;
.inspect-list { font-weight: 500;
display: flex; margin-bottom: 9.6px;
flex-wrap: wrap; }
justify-content: space-between;
} .month-record-item {
} margin-bottom: 19.2px;
}
} &:last-of-type {
.inspection-button { margin: 0;
display: flex; }
align-items: center;
justify-content: center; .inspect-list {
position: fixed; display: flex;
bottom: 48px; flex-wrap: wrap;
width: 192px; justify-content: space-between;
height: 38.4px; }
left: 50%; }
color: #fff; }
transform: translateX(-50%); }
background-image: linear-gradient(180deg, #3773f6 0%, #2c57f6 99%);
box-shadow: 0px 8px 19.2px 0px rgba(51, 104, 246, 0.24); .inspection-button {
border-radius: 21.6px; display: flex;
} align-items: center;
} justify-content: center;
</style> position: fixed;
bottom: 48px;
width: 192px;
height: 38.4px;
left: 50%;
color: #fff;
transform: translateX(-50%);
background-image: linear-gradient(180deg, #3773f6 0%, #2c57f6 99%);
box-shadow: 0px 8px 19.2px 0px rgba(51, 104, 246, 0.24);
border-radius: 21.6px;
}
}
</style>
\ No newline at end of file
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
<view class="profile-left"> <view class="profile-left">
<view class="avatar"> <view class="avatar">
<image <image
src="@/static/img/add-img/home1.png" src="@/static/img/add-img/defaultAvatar.png"
mode="aspectFit" mode="aspectFit"
></image> ></image>
</view> </view>
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
<view class="profile-box"> <view class="profile-box">
<view class="profile-left"> <view class="profile-left">
<view class="avatar"> <view class="avatar">
<image src="@/static/img/add-img/home1.png" mode="aspectFit"></image> <image src="@/static/img/add-img/defaultAvatar.png" mode="aspectFit"></image>
</view> </view>
<view class="info"> <view class="info">
<view class="username">井道巡检</view> <view class="username">井道巡检</view>
...@@ -54,7 +54,7 @@ ...@@ -54,7 +54,7 @@
</view> </view>
</view> </view>
<view class="tip"> <view class="tip">
<image class="tip-icon" src="@/static/img/add-img/home1.png" mode="aspectFit"></image>请点击“需巡检井道”执行巡检 <image class="tip-icon" src="@/static/img/add-img/defaultAvatar.png" mode="aspectFit"></image>请点击“需巡检井道”执行巡检
</view> </view>
<view class="tab-content"> <view class="tab-content">
<!-- 操作区域 --> <!-- 操作区域 -->
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
<view class="profile-left"> <view class="profile-left">
<view class="avatar"> <view class="avatar">
<image <image
src="@/static/img/add-img/home1.png" src="@/static/img/add-img/defaultAvatar.png"
mode="aspectFit" mode="aspectFit"
></image> ></image>
</view> </view>
......
import _Path from "@/constant/ioPath"; import _Path from "@/constant/ioPath";
export default class SqlliteDB { export default class SqlliteDB {
// 数据库名称 // 数据库名称
dbName = "inspect"; dbName = "inspect";
open = false; open = false;
inst = null; inst = null;
static async initSqlliteDB() { static async initSqlliteDB() {
if (!this.inst) { if (!this.inst) {
this.inst = new SqlliteDB(); this.inst = new SqlliteDB();
await this.inst.openDB(); await this.inst.openDB();
return this.inst; return this.inst;
} }
return this.inst; return this.inst;
} }
// 打开数据库 不存在则创建,否则打开 // 打开数据库 不存在则创建,否则打开
async openDB() { async openDB() {
if (this.isOpen()) { if (this.isOpen()) {
console.log("isOpen"); console.log("isOpen");
return; return;
} }
console.log("db path:" + _Path.getDbPath() + `${this.dbName}.db`); console.log("db path:" + _Path.getDbPath() + `${this.dbName}.db`);
let that = this; let that = this;
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
plus.sqlite.openDatabase({ plus.sqlite.openDatabase({
name: this.dbName, name: this.dbName,
path: _Path.getDbPath() + `${this.dbName}.db`, path: _Path.getDbPath() + `${this.dbName}.db`,
success(res) { success(res) {
that.open = true; that.open = true;
resolve(); resolve();
}, },
fail(e) { fail(e) {
console.log(e.message); console.log(e.message);
reject(e); reject(e);
}, },
}); });
}); });
} }
// 检查数据库 // 检查数据库
async checkDB() { async checkDB() {
if (!this.open) { if (!this.open) {
if (!this.isOpen()) { if (!this.isOpen()) {
await this.openDB(); await this.openDB();
} }
} }
} }
// 关闭数据库 // 关闭数据库
async closeDB() { async closeDB() {
let open = await this.openDB(); let open = await this.openDB();
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
if (!open) { if (!open) {
resolve(); resolve();
} else { } else {
plus.sqlite.closeDatabase({ plus.sqlite.closeDatabase({
name: this.dbName, name: this.dbName,
success(res) { success(res) {
this.inst = null; this.inst = null;
this.open = false; this.open = false;
resolve(); resolve();
}, },
fail(e) { fail(e) {
reject(e); reject(e);
}, },
}); });
} }
}); });
} }
// 是否打开了数据库 // 是否打开了数据库
isOpen() { isOpen() {
return plus.sqlite.isOpenDatabase({ return plus.sqlite.isOpenDatabase({
name: this.dbName, name: this.dbName,
path: `_doc/db/${this.dbName}.db`, path: `_doc/db/${this.dbName}.db`,
}); });
} }
// 创建表 // 创建表
async createTable(tableName, filedList) { async createTable(tableName, filedList) {
if (!tableName || !filedList || filedList.length === 0) { if (!tableName || !filedList || filedList.length === 0) {
throw new Error("数据库创建失败"); throw new Error("数据库创建失败");
} }
let fieldSql = ""; let fieldSql = "";
console.log(filedList, "filedList--------------------->>>>"); console.log(filedList, "filedList--------------------->>>>");
filedList.map((val, idx) => { filedList.map((val, idx) => {
fieldSql = fieldSql + '"' + val.field + '" ' + val.format; fieldSql = fieldSql + '"' + val.field + '" ' + val.format;
if (idx !== filedList.length - 1) { if (idx !== filedList.length - 1) {
fieldSql = fieldSql + ","; fieldSql = fieldSql + ",";
} }
}); });
return this.executeSQL( return this.executeSQL(
`CREATE TABLE IF NOT EXISTS ${tableName}(${fieldSql})` `CREATE TABLE IF NOT EXISTS ${tableName}(${fieldSql})`
); );
} }
// 移除表 // 移除表
// async removeTable(tableName) { // async removeTable(tableName) {
// return this.executeSQL(`DROP TABLE IF EXISTS ${tableName}`); // return this.executeSQL(`DROP TABLE IF EXISTS ${tableName}`);
// } // }
// 清空表 // 清空表
async deleteTable(tableName) { async deleteTable(tableName) {
return this.executeSQL(`DELETE FROM ${tableName}`); return this.executeSQL(`DELETE FROM ${tableName}`);
} }
// 增删改使用 // 增删改使用
async executeSQL(sql) { async executeSQL(sql) {
// console.log('excuteSQL:' + sql) // console.log('excuteSQL:' + sql)
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
plus.sqlite.executeSql({ plus.sqlite.executeSql({
name: this.dbName, name: this.dbName,
sql: sql, sql: sql,
success(res) { success(res) {
resolve(); console.log('SQL execution result:', res);
}, resolve(res); // 暂时直接返回,方便调试
fail(e) { },
console.log(e.message); fail(e) {
reject(e); console.log(e.message);
}, reject(e);
}); },
}); });
} });
}
// 查询使用 // 增删改返回最后增加的id
async selectSQL(sql) { async executeReturnDataSQL(sql) {
await this.checkDB(); console.log('Executing SQL:', sql);
// console.log('selectSQL:' + sql) let _ = this
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
plus.sqlite.selectSql({ plus.sqlite.executeSql({
name: this.dbName, name: _.dbName,
sql: sql, sql: sql,
success(res) { success(res) {
// console.log("数据", res); const queryLastInsertIdSql = "SELECT last_insert_rowid() AS lastId";
resolve(res); plus.sqlite.selectSql({
}, name: _.dbName,
fail(e) { sql: queryLastInsertIdSql,
console.log(e.message); success(result) {
reject(e); if (result && result.length > 0) {
}, let lastInsertId = result[0].lastId;
}); console.log('Last Insert ID:', lastInsertId);
}); resolve({ success: true, lastInsertId: lastInsertId });
} } else {
resolve({ success: true, lastInsertId: null });
// 事务 }
async openTransaction(open) { },
let oper = "open"; fail(e) {
if (open) { reject(e);
oper = open; },
} });
return new Promise((resolve, reject) => { },
plus.sqlite.transaction({ fail(e) {
name: this.dbName, console.error('SQL execution failed:', e.message);
operation: oper, reject(e);
success: function (e) { },
resolve(); });
}, });
fail: function (e) { }
reject(e.message); // 查询使用
}, async selectSQL(sql) {
}); await this.checkDB();
}); // console.log('selectSQL:' + sql)
} return new Promise((resolve, reject) => {
plus.sqlite.selectSql({
async rollbackTransaction() { name: this.dbName,
this.openTransaction("rollback"); sql: sql,
} success(res) {
// console.log("数据", res);
async commitTransaction() { resolve(res);
this.openTransaction("commit"); },
} fail(e) {
console.log(e.message);
static async checkIfDataImported(sqllitedb) { reject(e);
// 假设有一个表或字段来记录数据导入状态 },
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")'); async openTransaction(open) {
} let oper = "open";
} if (open) {
oper = open;
}
return new Promise((resolve, reject) => {
plus.sqlite.transaction({
name: this.dbName,
operation: oper,
success: function(e) {
resolve();
},
fail: function(e) {
reject(e.message);
},
});
});
}
async rollbackTransaction() {
this.openTransaction("rollback");
}
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")');
}
}
\ No newline at end of file
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论