From e46bfa3ff94a8a1b4daf37c7fcb79c2fab22a72c Mon Sep 17 00:00:00 2001
From: doum <doum>
Date: 星期五, 29 五月 2026 17:10:00 +0800
Subject: [PATCH] 新增智能电表、空调管理
---
admin/src/views/business/ywelectricaldata.vue | 137 ++++++++++++++++++++++++++++++++++++++++-----
1 files changed, 121 insertions(+), 16 deletions(-)
diff --git a/admin/src/views/business/ywelectricaldata.vue b/admin/src/views/business/ywelectricaldata.vue
index 7dc1ab5..3235191 100644
--- a/admin/src/views/business/ywelectricaldata.vue
+++ b/admin/src/views/business/ywelectricaldata.vue
@@ -80,6 +80,33 @@
:pagination="tableData.pagination"
/>
</template>
+ <el-dialog
+ title="绔嬪嵆鎶勮〃"
+ :visible.sync="syncDialogVisible"
+ width="520px"
+ append-to-body
+ @closed="resetSyncForm"
+ >
+ <el-form ref="syncFormRef" :model="syncForm" :rules="syncRules" label-width="110px">
+ <el-form-item label="鎶勮〃鏃堕棿娈�" prop="readTimeRange">
+ <el-date-picker
+ v-model="syncForm.readTimeRange"
+ type="datetimerange"
+ value-format="yyyy-MM-dd HH:mm:ss"
+ range-separator="-"
+ start-placeholder="寮�濮嬫椂闂�"
+ end-placeholder="缁撴潫鏃堕棿"
+ :picker-options="syncPickerOptions"
+ style="width: 100%"
+ />
+ </el-form-item>
+ <p class="sync-tip">鏃堕棿娈垫渶闀夸笉瓒呰繃7澶�</p>
+ </el-form>
+ <template v-slot:footer>
+ <el-button @click="syncDialogVisible = false">鍙栨秷</el-button>
+ <el-button type="primary" :loading="isReading" @click="submitSync">纭鎶勮〃</el-button>
+ </template>
+ </el-dialog>
</TableLayout>
</template>
@@ -108,7 +135,32 @@
readTimeRange: []
},
roomOptions: [],
- isReading: false
+ isReading: false,
+ syncDialogVisible: false,
+ syncMinDate: null,
+ syncForm: {
+ readTimeRange: []
+ },
+ syncRules: {
+ readTimeRange: [{ required: true, message: '璇烽�夋嫨鎶勮〃鏃堕棿娈�', trigger: 'change' }]
+ }
+ }
+ },
+ computed: {
+ syncPickerOptions () {
+ return {
+ onPick: ({ minDate, maxDate }) => {
+ this.syncMinDate = minDate && !maxDate ? minDate : null
+ },
+ disabledDate: (time) => {
+ if (!this.syncMinDate) return false
+ const anchor = dayjs(this.syncMinDate)
+ const min = anchor.subtract(7, 'day').startOf('day')
+ const max = anchor.add(7, 'day').endOf('day')
+ const current = dayjs(time)
+ return current.isBefore(min) || current.isAfter(max)
+ }
+ }
}
},
created () {
@@ -181,22 +233,69 @@
this.search()
},
handleReadNow () {
- this.$dialog.actionConfirm('纭绔嬪嵆浠庣涓夋柟骞冲彴鍚屾鎶勮〃鏁版嵁鍚楋紵', '鎿嶄綔纭鎻愰啋')
- .then(() => {
- this.isReading = true
- dataApi.syncAll({})
- .then(res => {
- this.$tip.apiSuccess(res || '鎶勮〃鍚屾鎴愬姛')
- this.search()
- })
- .catch(e => {
- this.$tip.apiFailed(e)
- })
- .finally(() => {
- this.isReading = false
- })
+ this.syncForm.readTimeRange = this.defaultSyncRange()
+ this.syncDialogVisible = true
+ this.$nextTick(() => {
+ if (this.$refs.syncFormRef) {
+ this.$refs.syncFormRef.clearValidate()
+ }
+ })
+ },
+ defaultSyncRange () {
+ const end = dayjs()
+ const start = end.subtract(24, 'hour')
+ return [start.format('YYYY-MM-DD HH:mm:ss'), end.format('YYYY-MM-DD HH:mm:ss')]
+ },
+ resetSyncForm () {
+ this.syncMinDate = null
+ this.syncForm.readTimeRange = []
+ if (this.$refs.syncFormRef) {
+ this.$refs.syncFormRef.resetFields()
+ }
+ },
+ validateSyncRange (range) {
+ if (!range || range.length !== 2) {
+ this.$tip.warning('璇烽�夋嫨鎶勮〃鏃堕棿娈�')
+ return false
+ }
+ const start = dayjs(range[0])
+ const end = dayjs(range[1])
+ if (!start.isValid() || !end.isValid()) {
+ this.$tip.warning('鎶勮〃鏃堕棿鏍煎紡涓嶆纭�')
+ return false
+ }
+ if (!end.isAfter(start)) {
+ this.$tip.warning('鎶勮〃寮�濮嬫椂闂村繀椤绘棭浜庣粨鏉熸椂闂�')
+ return false
+ }
+ if (end.diff(start, 'day', true) > 7) {
+ this.$tip.warning('鎶勮〃鏃堕棿娈典笉鑳借秴杩�7澶�')
+ return false
+ }
+ return true
+ },
+ submitSync () {
+ this.$refs.syncFormRef.validate(valid => {
+ if (!valid) return
+ const range = this.syncForm.readTimeRange
+ if (!this.validateSyncRange(range)) return
+ this.isReading = true
+ dataApi.syncAll({
+ readTimeBegin: range[0],
+ readTimeEnd: range[1]
})
- .catch(() => {})
+ .then(res => {
+ this.$tip.apiSuccess(res || '鎶勮〃鍚屾鎴愬姛')
+ this.syncDialogVisible = false
+ this.search()
+ })
+ .catch(e => {
+ this.$tip.apiFailed(e)
+ })
+ .finally(() => {
+ this.isReading = false
+ })
+ })
},
formatJsfs (val) {
if (val == null || val === '') return '-'
@@ -235,4 +334,10 @@
<style scoped>
.red { color: #f56c6c; }
+.sync-tip {
+ margin: 0 0 0 110px;
+ color: #909399;
+ font-size: 12px;
+ line-height: 1.5;
+}
</style>
--
Gitblit v1.9.3