Report.vue
5.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
<!--
* @Author: 前端 qianduan01@didihu.com.cn
* @Date: 2024-09-04 21:58:42
* @LastEditors: 前端 qianduan01@didihu.com.cn
* @LastEditTime: 2025-01-14 17:56:57
* @FilePath: \Apper-Admin-master\src\views\log\list\components\Report.vue
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<!--
* @Author: 前端 qianduan01@didihu.com.cn
* @Date: 2024-09-04 21:13:18
* @LastEditors: 前端 qianduan01@didihu.com.cn
* @LastEditTime: 2024-09-05 09:40:12
* @FilePath: \Apper-Admin-master\src\views\log\dictionary\components\Dailog.vue
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
<el-dialog v-model="showReport" width="30%" :before-close="handleClose" title="开启通信">
<el-form ref="ruleFormRef" label-width="120px" label-suffix=" :" :rules="rules" :model="dialogProps">
<el-form-item label="指令" prop="command">
<el-select v-model="dialogProps.command" placeholder="请选择日志字段" clearable>
<el-option v-for="item in cmdList" :key="item.value" :label="item.label" :value="item.value" />
</el-select>
</el-form-item>
<template v-for="(item, index) in formList[dialogProps.command]" :key="index">
<el-form-item :label="item.label" :prop="item.name">
<el-select v-model="dialogProps[item.name]" placeholder="请选择" v-if="item.type === 'select'" clearable>
<el-option
v-for="i in item.optionList"
:key="i[item.optionId]"
:label="i[item.optionLabel]"
:value="i[item.optionId]"
/></el-select>
<el-input
v-model="dialogProps[item.name]"
:maxlength="item.maxlength"
placeholder="请输入"
v-if="item.type === 'input'"
clearable
></el-input>
<el-input
v-model="dialogProps[item.name]"
:maxlength="item.maxlength"
placeholder="请输入"
v-if="item.type === 'textarea'"
type="textarea"
:rows="10"
clearable
></el-input>
<el-input-number v-model="dialogProps[item.name]" v-if="item.type === 'number'" :min="1" />
<el-date-picker
v-model="dialogProps[item.name]"
type="daterange"
v-if="item.type === 'daterange'"
range-separator="至"
value-format="YYYY-MM-DD"
start-placeholder="开始日期"
end-placeholder="结束日期"
>
</el-date-picker>
<el-radio-group v-model="dialogProps[item.name]" v-if="item.type === 'radio'">
<el-radio :value="i[item.optionId]" size="large" v-for="i in item.optionList" :key="i[item.optionId]">{{
i[item.optionLabel]
}}</el-radio>
</el-radio-group>
</el-form-item>
</template>
</el-form>
<template #footer>
<el-button @click="handleClose">取消</el-button>
<el-button type="primary" @click="handleSubmit" :loading="loading">确定</el-button>
</template>
</el-dialog>
</template>
<script setup lang="ts" name="logReport">
import { ref, reactive, toRefs, watch } from "vue";
import { FormInstance } from "element-plus";
import { useCmd } from "@/hooks/useCmd";
import { cmdList } from "@/utils/dict";
import { formList } from "@/utils/dict";
const rules = reactive({
command: [{ required: true, message: "请选择指令" }],
storage: [{ required: true, message: "请用户信息" }],
days: [{ required: true, message: "请输入天数" }],
id: [{ required: true, message: "请输入id" }],
key: [{ required: true, message: "请选择缓存字段" }],
times: [{ required: true, message: "请选择时间" }],
data: [{ required: true, message: "请输入记录" }]
});
interface DialogProps {
id?: string;
days?: number;
data?: string;
interval?: number;
command: string;
key?: string;
storage?: string;
times?: string[];
beginDate?: string;
endDate?: string;
force?: number;
}
const props = defineProps<{
showReport: boolean;
deviceId: number;
}>();
const { showReport, deviceId } = toRefs(props);
console.log(deviceId);
const dialogProps = ref<DialogProps>({
command: cmdList[0].value,
interval: 300,
force: 0,
days: 1
});
watch(
() => dialogProps.value.command,
val => {
console.log(val);
}
);
const emit = defineEmits<{
(e: "close"): void;
}>();
const handleClose = () => {
emit("close");
};
const loading = ref(false);
// 提交数据
const ruleFormRef = ref<FormInstance>();
const handleSubmit = () => {
loading.value = true;
ruleFormRef.value!.validate(async valid => {
if (!valid) return;
try {
let { times } = dialogProps.value;
const data = dialogProps.value;
if (data.data) {
const value = data.data.replace(/\s+/g, "");
data.data = new Function("return " + value)();
}
if (times) {
Object.assign(data, { beginDate: times[0], endDate: times[1] });
}
const params = {
event: "private",
device_id: deviceId.value,
data
};
await useCmd(params);
handleClose();
} catch (error) {
console.log(error);
handleClose();
} finally {
handleClose();
loading.value = false;
}
});
};
</script>