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

edit

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