提交 7409b5f4 authored 作者: zs's avatar zs

edit

上级 cb6b97ee
...@@ -31,7 +31,7 @@ export default { ...@@ -31,7 +31,7 @@ export default {
} catch (e) { } catch (e) {
console.log(e.message) console.log(e.message)
} finally { } finally {
await sqllitedb.closeDB(); // await sqllitedb.closeDB();
} }
}, },
async info(id) { async info(id) {
...@@ -45,7 +45,7 @@ export default { ...@@ -45,7 +45,7 @@ export default {
} catch (e) { } catch (e) {
console.log(e.message) console.log(e.message)
} finally { } finally {
await sqllitedb.closeDB(); // await sqllitedb.closeDB();
} }
}, },
......
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();
try { try {
let rs = await sqllitedb.selectSQL( let rs = await sqllitedb.selectSQL(
`select * from ${table.inspectionRecordName}` `select * from ${table.inspectionRecordName}`
); );
return rs; return rs;
} catch (e) { } catch (e) {
console.log(e.message); console.log(e.message);
} finally { } finally {
await sqllitedb.closeDB(); await sqllitedb.closeDB();
} }
}, },
async selectDataForTime() { async selectDataForTime(data) {
let sqllitedb = await SqlliteDbUtil.initSqlliteDB(); let sqllitedb = await SqlliteDbUtil.initSqlliteDB();
try { try {
let rs = await sqllitedb.selectSQL( let rs = await sqllitedb.selectSQL(
`SELECT * FROM ${table.inspectionRecordName} order by createTime desc` `SELECT id,inspectionType,inspectionCode
); ,recordName
return rs; ,userName
} catch (e) { ,userId
console.log(e.message); ,inspectionTime
} finally { ,isException
await sqllitedb.closeDB(); ,synFlag
} ,createTime
}, FROM ${table.inspectionRecordName}
async info(id) { where 1=1
let sqllitedb = await SqlliteDbUtil.initSqlliteDB(); ${data.inspectionType ? `AND inspectionType = '${data.inspectionType}'` : ''}
try { ${data.synFlag ? `AND synFlag = '${data.synFlag}'` : ''}
let sql = `select * from ${table.inspectionRecordName} where id = '${id}'`; ${data.isException ? `AND isException = '${data.isException}'` : ''}
let res = await sqllitedb.selectSQL(sql); ${data.inspectionTime ? `AND inspectionTime >='${new Date(data.inspectionTime[0]).getTime() }'` : ''}
if (res && res.length > 0) { ${data.inspectionTime ? `AND inspectionTime <='${new Date(data.inspectionTime[1]).getTime() }'` : ''}
return res[0]; order by createTime desc`
} );
} catch (e) { return rs;
console.log(e.message); } catch (e) {
} finally { console.log(e.message);
await sqllitedb.closeDB(); } finally {
} await sqllitedb.closeDB();
}, }
async remove(id) { },
if (!id) { async info(id) {
return; let sqllitedb = await SqlliteDbUtil.initSqlliteDB();
} try {
let sql = `delete from ${table.inspectionRecordName} where id = '${id}'`; let sql = `select * from ${table.inspectionRecordName} where id = '${id}'`;
try { let res = await sqllitedb.selectSQL(sql);
let sqllitedb = await SqlliteDbUtil.initSqlliteDB(); if (res && res.length > 0) {
await sqllitedb.executeSQL(sql); return res[0];
} catch (e) { }
console.log(e.message); } catch (e) {
} finally { console.log(e.message);
await sqllitedb.closeDB(); } finally {
} // await sqllitedb.closeDB();
}, }
async saveBatch(list) { },
if (list.length === 0) { async remove(id) {
return; if (!id) {
} return;
console.log("开始保存用户信息...." + list.length); }
let sqllitedb = await SqlliteDbUtil.initSqlliteDB(); let sql = `delete from ${table.inspectionRecordName} where id = '${id}'`;
try { try {
for (let data of list) { let sqllitedb = await SqlliteDbUtil.initSqlliteDB();
let column = ""; await sqllitedb.executeSQL(sql);
let values = ""; } catch (e) {
let idx = 0; console.log(e.message);
for (let attr in data) { } finally {
let dataField = table["inspectionRecord"].find((v) => { // await sqllitedb.closeDB();
if (v.field === attr) { }
return v; },
} async saveBatch(list) {
}); if (list.length === 0) {
if (!dataField) { return;
continue; }
} console.log("开始保存用户信息...." + list.length);
column += dataField.field + ","; let sqllitedb = await SqlliteDbUtil.initSqlliteDB();
values += "'" + fixNullVal(data[attr]) + "',"; try {
idx++; 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(",") column = column.endsWith(",") ?
? column.substring(0, column.length - 1) column.substring(0, column.length - 1) :
: column; column;
values = values.endsWith(",") values = values.endsWith(",") ?
? values.substring(0, values.length - 1) values.substring(0, values.length - 1) :
: values; values;
let sql = `insert into ${table.inspectionRecordName}(${column}) values(${values})`; let sql = `insert into ${table.inspectionRecordName}(${column}) values(${values})`;
let has = await this.info(data.id); let has = await this.info(data.id);
if (has && has.id) { if (has && has.id) {
await this.remove(data.id); await this.remove(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("导入完成...");
}, },
async save(data) { async save(data) {
console.log("开始保存巡检记录", data); console.log("开始保存巡检记录", data);
let sqllitedb = await SqlliteDbUtil.initSqlliteDB(); let sqllitedb = await SqlliteDbUtil.initSqlliteDB();
try { try {
let sql = `insert into ${table.inspectionRecordName}( let sql = `insert into ${table.inspectionRecordName}(
inspectionType, inspectionType,
inspectionCode, inspectionCode,
recordName, recordName,
...@@ -138,24 +155,24 @@ export default { ...@@ -138,24 +155,24 @@ export default {
'${JSON.stringify(data.inspectionData)}' '${JSON.stringify(data.inspectionData)}'
); );
`; `;
let result = await sqllitedb.executeReturnDataSQL(sql); let result = await sqllitedb.executeReturnDataSQL(sql);
console.log(result, "有有有有有有"); console.log(result, "有有有有有有");
return result; return result;
} catch (e) { } catch (e) {
console.log(e.message); console.log(e.message);
} finally { } finally {
await sqllitedb.closeDB(); await sqllitedb.closeDB();
} }
console.log("导入完成..."); console.log("导入完成...");
}, },
async update(data) { async update(data) {
console.log("开始更新巡检记录", data); console.log("开始更新巡检记录", data);
let sqllitedb = await SqlliteDbUtil.initSqlliteDB(); let sqllitedb = await SqlliteDbUtil.initSqlliteDB();
try { try {
if (!data.id) { if (!data.id) {
throw new Error("更新操作需要提供 id"); throw new Error("更新操作需要提供 id");
} }
let sql = `UPDATE ${table.inspectionRecordName} SET let sql = `UPDATE ${table.inspectionRecordName} SET
inspectionType = '${data.inspectionType}', inspectionType = '${data.inspectionType}',
inspectionCode = '${data.inspectionCode}', inspectionCode = '${data.inspectionCode}',
recordName = '${data.recordName}', recordName = '${data.recordName}',
...@@ -170,30 +187,30 @@ export default { ...@@ -170,30 +187,30 @@ 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("更新完成...");
}, },
async updateSignImg(data) { async updateSignImg(data) {
console.log("开始更新巡检签名图片", data); console.log("开始更新巡检签名图片", data);
let sqllitedb = await SqlliteDbUtil.initSqlliteDB(); let sqllitedb = await SqlliteDbUtil.initSqlliteDB();
try { try {
if (!data.id) { if (!data.id) {
throw new Error("更新操作需要提供 id"); throw new Error("更新操作需要提供 id");
} }
let sql = `UPDATE ${table.inspectionRecordName} SET let sql = `UPDATE ${table.inspectionRecordName} SET
signImg = '${data.signImg}' signImg = '${data.signImg}'
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
...@@ -60,14 +60,10 @@ export default { ...@@ -60,14 +60,10 @@ export default {
}, },
////////// 初始化数据库//////////// ////////// 初始化数据库////////////
async initSqlLite() { async initSqlLite(sqllitedb) {
console.log('初始化数据库开始...') console.log('初始化数据库开始...')
let sqllitedb = null
try { try {
// 创建打开数据库,已经存在表则跳过 // 创建打开数据库,已经存在表则跳过
sqllitedb = await SqlliteDbUtil.initSqlliteDB()
console.log(sqllitedb, '是否存在')
// console.log('创建用户表...')
await sqllitedb.createTable(table.metadataName, table.metadata) await sqllitedb.createTable(table.metadataName, table.metadata)
await sqllitedb.createTable(table.userName, table.user) await sqllitedb.createTable(table.userName, table.user)
await sqllitedb.createTable(table.inspectionRecordName, table.inspectionRecord) // 巡检记录表 await sqllitedb.createTable(table.inspectionRecordName, table.inspectionRecord) // 巡检记录表
......
...@@ -2,17 +2,17 @@ ...@@ -2,17 +2,17 @@
<view class="inspect-item" @click="toPage"> <view class="inspect-item" @click="toPage">
<view class="content" :class="details.synFlag == 1 ? 'synchronization' : ''"> <view class="content" :class="details.synFlag == 1 ? 'synchronization' : ''">
<view class="name">{{ <view class="name">{{
details.synFlag == 0 ? "未同步" : "已同步" synFlags[details.synFlag]
}}</view> }}</view>
<view class="info"> <view class="info">
<view class="info-row"> <view class="info-row">
<text class="title">{{ getLabel(details.inspectionType) }}</text> <text class="title">{{ getLabel(details.inspectionType) }}</text>
<text class="status">{{ Exception[details.isException] <text class="status" :class="{'error':details.isException == 1}">{{ details.isException == 0 ?'正常':'异常'
}}</text> }}</text>
</view> </view>
<view class="info-row info-row-code"> <view class="info-row info-row-code">
<text>巡检人:</text> <text>巡检人:</text>
<text class="code-num">{{details.inspectionBy}}</text> <text class="code-num">{{details.userName}}</text>
<text>编号:</text> <text>编号:</text>
<text class="code-num">{{ details.inspectionCode }}</text> <text class="code-num">{{ details.inspectionCode }}</text>
<text>巡检日期:</text> <text>巡检日期:</text>
...@@ -43,23 +43,23 @@ ...@@ -43,23 +43,23 @@
}, },
data() { data() {
return { return {
Exception: { synFlags: {
0: '正常', 0: '未同步',
1: '异常', 1: '已同步',
2: '巡检中' 2: '巡检中'
} }
} }
}, },
computed: { computed: {
formattedDate() { formattedDate() {
if (!this.details.createTime) { if (!this.details.createTime) {
return '无效日期'; return '无效日期';
} }
// 转换为数字并使用 moment 格式化日期 // 转换为数字并使用 moment 格式化日期
const createTime = parseInt(this.details.createTime, 10); const createTime = parseInt(this.details.createTime, 10);
return moment(createTime).format('YYYY-MM-DD HH:mm:ss'); return moment(createTime).format('YYYY-MM-DD');
}, },
}, },
mounted() { mounted() {
console.log(" this.details", this.details) console.log(" this.details", this.details)
}, },
...@@ -137,12 +137,18 @@ ...@@ -137,12 +137,18 @@
.status { .status {
padding: 0 6.4px; padding: 0 6.4px;
font-size: 9.6px; font-size: 9.6px;
color: #ffffff; color: #0CC991;
text-align: center; text-align: center;
line-height: 16px; line-height: 16px;
font-weight: 400; font-weight: 400;
background: #ffab24; background: #E6F9F3;
border-radius: 8px; border-radius: 11px;
}
.error {
background: #FDEBE9;
border-radius: 11px;
color: #F55A42
} }
.alarm { .alarm {
...@@ -199,10 +205,7 @@ ...@@ -199,10 +205,7 @@
color: #4a4a4a; color: #4a4a4a;
} }
.status {
background: #9c9c9c16 !important;
color: #4a4a4a !important;
}
} }
} }
</style> </style>
\ No newline at end of file
<template> <template>
<!-- 巡检管理搜索页 --> <!-- 巡检管理搜索页 -->
<view class="search-com"> <view class="search-com">
<view class="search-com-left"> <view class="search-com-left">
<uni-data-select <uni-data-select v-if="!hiddenSearch.includes('inspectionType')" class="uni-search-item"
v-if="!hiddenSearch.includes('inspectionType')" v-model="searchFrom.inspectionType" :localdata="inspectArr" @change="(e) => change(e, 'inspectionType')"
class="uni-search-item" placeholder="类型"></uni-data-select>
v-model="searchFrom.inspectionType"
:localdata="inspectArr"
@change="(e) => change(e, 'inspectionType')"
placeholder="类型"
:clear="true"
:key="new Date().getTime()"
></uni-data-select>
<uni-data-select <uni-data-select v-if="!hiddenSearch.includes('synFlag')" class="uni-search-item" v-model="searchFrom.synFlag" :localdata="synchronization" placeholder="状态"
v-if="!hiddenSearch.includes('synchronization')" @change="(e) => change(e, 'synFlag')"></uni-data-select>
class="uni-search-item"
v-model="searchFrom.synchronization"
:localdata="synchronization"
placeholder="状态"
@change="(e) => change(e, 'synchronization')"
:clear="true"
:key="new Date().getTime()"
></uni-data-select> <uni-data-select v-if="!hiddenSearch.includes('isException')" class="uni-search-item"
v-model="searchFrom.isException" :localdata="exceptionArr" placeholder="异常"
@change="(e) => change(e, 'isException')" :key="new Date().getTime()"></uni-data-select>
</view>
<uni-data-select <view class="search-com-right" v-if="!hiddenSearch.includes('inspectionTime')">
v-if="!hiddenSearch.includes('isException')" <uni-datetime-picker class="uni-datetime-picker" type="daterange" v-model="searchFrom.inspectionTime"
class="uni-search-item" :border="false" @change="(e) => change(e, 'inspectionTime')" />
v-model="searchFrom.isException" </view>
:localdata="exceptionArr" </view>
placeholder="异常"
@change="(e) => change(e, 'isException')"
:clear="true"
:key="new Date().getTime()"
></uni-data-select>
</view>
<view
class="search-com-right"
v-if="!hiddenSearch.includes('inspectionTime')"
>
<uni-datetime-picker
class="uni-datetime-picker"
type="daterange"
v-model="searchFrom.inspectionTime"
:border="false"
@change="(e) => change(e, 'inspectionTime')"
/>
</view>
</view>
</template> </template>
<script> <script>
export default { export default {
props: { props: {
hiddenSearch: { hiddenSearch: {
// 隐藏搜索项 // 隐藏搜索项
type: Array, type: Array,
default: () => { default: () => {
return []; return [];
}, },
}, },
}, },
data() { data() {
return { return {
searchFrom: { searchFrom: {
inspectionType: "", // 巡检类型 inspectionType: "", // 巡检类型
synchronization: "", // 同部数据 synFlag: "", // 同部数据
isException: "", // 有无异常 isException: "", // 有无异常
inspectionTime: "", // 时间选择 inspectionTime: "", // 时间选择
}, },
inspectArr: [
{ value: "all", text: "全部" },
{ value: "1", text: "机房巡检" },
{ value: "2", text: "井道巡检" },
],
synchronization: [
{ value: "all", text: "全部" },
{ value: "2", text: "编辑中" },
{ value: "0", text: "待同步" },
{ value: "1", text: "已同步" },
],
exceptionArr: [
{ value: "all", text: "全部" },
{ value: "1", text: "有" },
{ value: "0", text: "无" },
],
};
},
methods: {
change(e, key) {
this.searchFrom[key] = e;
this.$emit("change", this.searchFrom); inspectArr: [{
}, value: "",
}, text: "全部巡检"
}; },
{
value: "1",
text: "机房巡检"
},
{
value: "2",
text: "井道巡检"
},
],
synchronization: [{
value: "",
text: "全部"
},
{
value: "2",
text: "编辑中"
},
{
value: "0",
text: "未同步"
},
{
value: "1",
text: "已同步"
},
],
exceptionArr: [{
value: "",
text: "全部"
},
{
value: "1",
text: "有"
},
{
value: "0",
text: "无"
},
],
};
},
methods: {
change(e, key) {
this.searchFrom[key] = e;
this.$emit("change", this.searchFrom);
},
},
};
</script> </script>
<style lang="less" scoped> <style lang="less" scoped>
.search-com { .search-com {
display: flex; display: flex;
align-items: center; align-items: center;
margin-top: 8px; margin-top: 8px;
// width: 50%;
.search-com-left { // width: 50%;
display: flex; .search-com-left {
flex:1; display: flex;
align-items: center; align-items: center;
.uni-search-item {
width: 132px; .uni-search-item {
height: 36px; width: 132px;
margin-right: 16px; height: 36px;
background: #fff; margin-right: 16px;
border-radius: 10px; background: #fff;
border: none !important; border-radius: 10px;
} border: none !important;
} }
.search-com-right { }
width: 300px;
.uni-datetime-picker { .search-com-right {
height: 36px; width: 300px;
background: #fff;
border-radius: 10px; .uni-datetime-picker {
border: none !important; height: 36px;
} background: #fff;
} border-radius: 10px;
} border: none !important;
</style> }
}
}
</style>
\ No newline at end of file
...@@ -63,9 +63,7 @@ export default { ...@@ -63,9 +63,7 @@ export default {
props: { props: {
list: { list: {
type: Array, type: Array,
default: () => { default: () => {},
return [];
},
}, },
}, },
components: {}, components: {},
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
</block> </block>
</uni-nav-bar> </uni-nav-bar>
<!-- 搜索项 --> <!-- 搜索项 -->
<!-- <SearchCom @change="change" /> --> <SearchCom @change="change" />
<!-- 结果 --> <!-- 结果 -->
<view class="inspection-management-content"> <view class="inspection-management-content">
<view class="count-tatal"> <view class="count-tatal">
...@@ -26,11 +26,11 @@ ...@@ -26,11 +26,11 @@
<view class="month-list"> <view class="month-list">
<!-- 每月记录 --> <!-- 每月记录 -->
<view class="month-record-item" v-for="(item, index) in list" :key="index"> <view class="month-record-item" v-for="(item, index) in list" :key="index">
<view class="seconed-title"> <view class="seconed-title">
{{ '2025-04'}} {{index}}
</view> </view>
<view class="inspect-list"> <view class="inspect-list">
<InspectionItem :details="item" /> <InspectionItem v-for="(its,index) in item" :key="its.id" :details="its" />
</view> </view>
</view> </view>
...@@ -41,7 +41,7 @@ ...@@ -41,7 +41,7 @@
<!-- 开始巡检 --> <!-- 开始巡检 -->
<!-- <view class="inspection-button" @click="toPage">开始巡检</view> --> <!-- <view class="inspection-button" @click="toPage">开始巡检</view> -->
<view class="inspection-button" @click="openDialog(true)">同步数据</view><!-- 打包弹窗 --> <view class="inspection-button" @click="openDialog(true)">同步数据</view><!-- 打包弹窗 -->
<Dialog v-show="isDialog && list.length" :list="list" @close="openDialog(false)"></Dialog> <Dialog v-show="isDialog" :list="propList" @close="openDialog(false)"></Dialog>
</view> </view>
</template> </template>
...@@ -56,7 +56,7 @@ ...@@ -56,7 +56,7 @@
getAllInspections getAllInspections
} from "@/request/index.js"; } from "@/request/index.js";
import Empty from "@/components/empty/index.vue"; import Empty from "@/components/empty/index.vue";
import moment from "moment";
import inspectApi from "@/api/inspect"; import inspectApi from "@/api/inspect";
export default { export default {
components: { components: {
...@@ -69,6 +69,7 @@ ...@@ -69,6 +69,7 @@
return { return {
isDialog: false, // isDialog: false, //
list: [], // 展示数据 list: [], // 展示数据
propList: [],
all_data: [], // 所有数据 all_data: [], // 所有数据
searchForm: { searchForm: {
// 搜索条件 // 搜索条件
...@@ -77,10 +78,8 @@ ...@@ -77,10 +78,8 @@
}; };
}, },
async mounted() { async mounted() {
// this.getInspectRecord() this.init(this.searchForm)
let res = await inspectApi.selectDataForTime()
this.list = res
console.log(res.length, '永远永远永远永远=---=>')
}, },
computed: { computed: {
userInfo() { userInfo() {
...@@ -88,13 +87,6 @@ ...@@ -88,13 +87,6 @@
}, },
}, },
methods: { methods: {
async getInspectRecord() {
let res = await inspectApi.selectList()
console.log('阿斗者', res)
this.list = res || []
this.countNum = this.list.length
},
// 返回 // 返回
back() { back() {
uni.navigateTo({ uni.navigateTo({
...@@ -112,7 +104,29 @@ ...@@ -112,7 +104,29 @@
}); });
} }
}, },
init() { async init() {
console.log('这都是个啥', this.searchForm)
let res = await inspectApi.selectDataForTime(this.searchForm)
this.propList = res
this.countNum = res.length
const resultMap = {};
res.forEach(e => {
if (e.createTime) {
const createTime = parseInt(e.createTime, 10);
const yearMonth = moment(createTime).format('YYYY年M月');
e.yearMonth = yearMonth
if (!resultMap[yearMonth]) {
resultMap[yearMonth] = [];
}
// 将当前记录添加到对应的 yearMonth 数组中
resultMap[yearMonth].push({
...e
});
}
});
this.list = resultMap
return
const all_data = this.all_data || []; const all_data = this.all_data || [];
// this.isPackedDataBtn = // this.isPackedDataBtn =
// all_data.filter((item) => item.synchronization == 0).length > 0; // all_data.filter((item) => item.synchronization == 0).length > 0;
...@@ -194,8 +208,11 @@ ...@@ -194,8 +208,11 @@
}, },
change(e) { change(e) {
this.searchForm = e; this.searchForm = e;
if (e.inspectionTime && e.inspectionTime.length == 0) {
this.init(); delete this.searchForm.inspectionTime
}
console.log('搜索',this.searchForm)
this.init(this.searchForm);
}, },
toPage() { toPage() {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论