对时设置
This commit is contained in:
parent
9d5166414f
commit
ff9ad0be8f
@ -143,3 +143,11 @@ export async function saveDeviceUart(payload: any[]): Promise<any> {
|
|||||||
const response = await http.post<ApiResponse<any>>('/config/device/uart', payload)
|
const response = await http.post<ApiResponse<any>>('/config/device/uart', payload)
|
||||||
return response.data.data
|
return response.data.data
|
||||||
}
|
}
|
||||||
|
export async function saveTimeSync(payload: { time_sync: string }): Promise<ApiResponse<{ send_status: string }>> {
|
||||||
|
const response = await http.post<ApiResponse<{ send_status: string }>>('/config/time-sync', payload)
|
||||||
|
return response.data
|
||||||
|
}
|
||||||
|
export async function getTimeSync(): Promise<ApiResponse<{ send_status: string }>> {
|
||||||
|
const response = await http.get<ApiResponse<{ send_status: string }>>('/config/time-sync')
|
||||||
|
return response.data
|
||||||
|
}
|
||||||
|
|||||||
@ -1,58 +1,71 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref, onMounted, onUnmounted } from 'vue'
|
import { ref, onMounted, onUnmounted } from 'vue'
|
||||||
import type { FormInstance, FormRules } from 'element-plus'
|
import type { FormInstance, FormRules } from 'element-plus'
|
||||||
import { fetchSystemConfig, saveSystemConfig } from '@/api/platform'
|
import { getTimeSync, saveTimeSync } from '@/api/platform'
|
||||||
import { ElMessage } from 'element-plus'
|
import { ElMessage } from 'element-plus'
|
||||||
import { connectTimeSync } from '@/websocket/client'
|
import { connectTimeSync } from '@/websocket/client'
|
||||||
|
|
||||||
const formRef = ref<FormInstance>()
|
const formRef = ref<FormInstance>()
|
||||||
|
// 标记用户是否手动编辑(true=屏蔽ws推送覆盖)
|
||||||
const isUserEdited = ref(false)
|
const isUserEdited = ref(false)
|
||||||
const form = ref({
|
const form = ref({
|
||||||
time_sync: '',
|
time_sync: '',
|
||||||
brightness: 0,
|
brightness: 0,
|
||||||
screen_saver: 0,
|
screen_saver: 0,
|
||||||
})
|
})
|
||||||
|
const queryData = ref({
|
||||||
|
time_sync: '',
|
||||||
const rules: FormRules = {
|
brightness: 0,
|
||||||
|
screen_saver: 0,
|
||||||
}
|
})
|
||||||
|
const rules: FormRules = {}
|
||||||
|
// 保存防抖锁
|
||||||
const isswitch = ref(false)
|
const isswitch = ref(false)
|
||||||
const handleSubmit = async () => {
|
|
||||||
if (isswitch.value) {
|
// 按钮点击事件:切换编辑状态 / 提交保存
|
||||||
|
const handleBtnClick = async () => {
|
||||||
|
// 未进入编辑模式:切换为编辑,屏蔽ws
|
||||||
|
if (!isUserEdited.value) {
|
||||||
|
isUserEdited.value = true
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
// 已在编辑模式:执行保存
|
||||||
|
if (isswitch.value) return
|
||||||
isswitch.value = true
|
isswitch.value = true
|
||||||
saveSystemConfig(form.value).then((res: any) => {
|
|
||||||
if (res.code == 200) {
|
try {
|
||||||
ElMessage({
|
const res = await saveTimeSync({ time_sync: form.value.time_sync })
|
||||||
type: 'success',
|
if (res.code === 200) {
|
||||||
message: `保存成功`,
|
ElMessage.success('保存成功')
|
||||||
})
|
isUserEdited.value = false
|
||||||
isswitch.value = false
|
|
||||||
} else {
|
} else {
|
||||||
ElMessage({
|
ElMessage.info('保存失败')
|
||||||
type: 'info',
|
|
||||||
message: '保存失败',
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
} catch (err) {
|
||||||
|
ElMessage.error('接口请求异常')
|
||||||
|
isUserEdited.value = false
|
||||||
|
} finally {
|
||||||
isswitch.value = false
|
isswitch.value = false
|
||||||
})
|
isUserEdited.value = false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let ws: WebSocket | null = null
|
let ws: WebSocket | null = null
|
||||||
function init() {
|
function init() {
|
||||||
fetchSystemConfig().then((res: any) => {
|
getTimeSync().then((res: any) => {
|
||||||
form.value = res
|
queryData.value = res.data.time_sync
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
init()
|
init()
|
||||||
ws = connectTimeSync((event) => {
|
ws = connectTimeSync((event) => {
|
||||||
|
// 用户未手动编辑时,才接收ws更新时间
|
||||||
if (!isUserEdited.value) {
|
if (!isUserEdited.value) {
|
||||||
form.value.time_sync = event.data.time_sync
|
form.value.time_sync = event.data.time_sync
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
onUnmounted(() => {
|
onUnmounted(() => {
|
||||||
if (ws) {
|
if (ws) {
|
||||||
ws.close()
|
ws.close()
|
||||||
@ -69,20 +82,22 @@ onUnmounted(() => {
|
|||||||
<span class="title-line"></span>
|
<span class="title-line"></span>
|
||||||
对时设置
|
对时设置
|
||||||
</div>
|
</div>
|
||||||
<!-- 表单 -->
|
<div style="display: flex;align-items: flex-start;">
|
||||||
<el-form ref="formRef" :model="form" :rules="rules" label-width="90px" class="time-form">
|
<div style="width: 90px;color: #787878;font-size: 14px;">
|
||||||
<el-form-item label="选择时间" prop="time_sync">
|
选择时间:
|
||||||
<el-date-picker v-model="form.time_sync" type="datetime" placeholder="请选择时间"
|
|
||||||
@focus="isUserEdited = true" format="YYYY-MM-DD HH:mm:ss" value-format="YYYY-MM-DD HH:mm:ss"
|
|
||||||
style="width: 100%;" />
|
|
||||||
</el-form-item>
|
|
||||||
</el-form>
|
|
||||||
</div>
|
</div>
|
||||||
<el-button type="primary" style="background-color: #0099ff;width: 150px;height: 40px;" class="save-btn"
|
<el-date-picker-panel v-model="form.time_sync" value-format="YYYY-MM-DD HH:mm:ss"
|
||||||
@click="handleSubmit">
|
format="YYYY-MM-DD HH:mm:ss" :disabled="!isUserEdited" type="datetime" />
|
||||||
更改
|
<el-button
|
||||||
|
type="primary"
|
||||||
|
style="background-color: #0099ff;width: 60px;height: 35px;margin-left: 10px;"
|
||||||
|
@click="handleBtnClick"
|
||||||
|
>
|
||||||
|
{{ isUserEdited ? '确定' : '更改' }}
|
||||||
</el-button>
|
</el-button>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<style scoped lang="scss">
|
<style scoped lang="scss">
|
||||||
@ -93,9 +108,9 @@ onUnmounted(() => {
|
|||||||
|
|
||||||
.time-container-content {
|
.time-container-content {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: calc(100vh - 230px);
|
height: 475px;
|
||||||
background-color: #ffffff;
|
background-color: #ffffff;
|
||||||
padding: 20px 50px;
|
padding: 15px 30px;
|
||||||
border-radius: 4px;
|
border-radius: 4px;
|
||||||
box-shadow: 0px 0px 10px rgba(219, 225, 236, 1);
|
box-shadow: 0px 0px 10px rgba(219, 225, 236, 1);
|
||||||
}
|
}
|
||||||
@ -104,7 +119,7 @@ onUnmounted(() => {
|
|||||||
font-size: 18px;
|
font-size: 18px;
|
||||||
font-weight: 700;
|
font-weight: 700;
|
||||||
color: #303133;
|
color: #303133;
|
||||||
margin-bottom: 24px;
|
margin-bottom: 15px;
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user