index.vue 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586
  1. <template>
  2. <div class="app-container">
  3. <el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch" label-width="68px">
  4. <!-- <el-form-item label="指标自动ID" prop="autoId">-->
  5. <!-- <el-input-->
  6. <!-- v-model="queryParams.autoId"-->
  7. <!-- placeholder="请输入指标自动ID"-->
  8. <!-- clearable-->
  9. <!-- @keyup.enter="handleQuery"-->
  10. <!-- />-->
  11. <!-- </el-form-item>-->
  12. <el-form-item label="算法名称" prop="algoId">
  13. <el-select v-model="queryParams.algoId" placeholder="请选择算法" style="width: 260px" clearable
  14. filterable remote reserve-keyword>
  15. <el-option
  16. v-for="dict in algoList"
  17. :key="dict.algoId"
  18. :label="dict.algoName"
  19. :value="dict.algoId"
  20. ></el-option>
  21. </el-select>
  22. </el-form-item>
  23. <el-form-item label="定时分析" prop="timeSwitch">
  24. <el-select v-model="queryParams.timeSwitch" placeholder="请选择定时分析" clearable>
  25. <el-option
  26. v-for="dict in sys_yes_no"
  27. :key="dict.value"
  28. :label="dict.label"
  29. :value="dict.value"
  30. />
  31. </el-select>
  32. </el-form-item>
  33. <el-form-item label="是否告警" prop="alarmWitch">
  34. <el-select v-model="queryParams.alarmWitch" placeholder="请选择是否告警" clearable>
  35. <el-option
  36. v-for="dict in sys_yes_no"
  37. :key="dict.value"
  38. :label="dict.label"
  39. :value="dict.value"
  40. />
  41. </el-select>
  42. </el-form-item>
  43. <el-form-item>
  44. <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
  45. <el-button icon="Refresh" @click="resetQuery">重置</el-button>
  46. </el-form-item>
  47. </el-form>
  48. <el-row :gutter="10" class="mb8">
  49. <el-col :span="1.5">
  50. <el-button
  51. type="primary"
  52. plain
  53. icon="Plus"
  54. @click="handleSelect"
  55. >选择指标
  56. </el-button>
  57. </el-col>
  58. <!-- <el-col :span="1.5">-->
  59. <!-- <el-button-->
  60. <!-- type="success"-->
  61. <!-- plain-->
  62. <!-- icon="Edit"-->
  63. <!-- :disabled="single"-->
  64. <!-- @click="handleUpdate"-->
  65. <!-- >修改-->
  66. <!-- </el-button>-->
  67. <!-- </el-col>-->
  68. <el-col :span="1.5">
  69. <el-button
  70. type="danger"
  71. plain
  72. icon="Delete"
  73. :disabled="multiple"
  74. @click="handleDelete"
  75. >删除
  76. </el-button>
  77. </el-col>
  78. <right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
  79. </el-row>
  80. <el-table v-loading="loading" :data="analyList" @selection-change="handleSelectionChange">
  81. <el-table-column type="selection" width="55" align="center"/>
  82. <!-- <el-table-column label="分析ID" align="center" prop="analyId" />-->
  83. <el-table-column label="算法名称" align="center" prop="algoName"/>
  84. <el-table-column label="模型名称" align="center" prop="modelName"/>
  85. <el-table-column label="指标名称" align="center" prop="metricsName"/>
  86. <el-table-column label="对象类型" align="center" prop="objType"/>
  87. <el-table-column label="对象名称" align="center" prop="objName"/>
  88. <el-table-column label="是否告警" align="center" prop="alarmWitch">
  89. <template #default="scope">
  90. <dict-tag :options="sys_yes_no" :value="scope.row.alarmWitch"/>
  91. </template>
  92. </el-table-column>
  93. <el-table-column label="定时分析" align="center" prop="timeSwitch">
  94. <template #default="scope">
  95. <dict-tag :options="sys_yes_no" :value="scope.row.timeSwitch"/>
  96. </template>
  97. </el-table-column>
  98. <el-table-column label="执行周期" align="center" prop="scheduleCycle"/>
  99. <el-table-column label="上次执行时间" align="center" prop="lastTime" width="180">
  100. <template #default="scope">
  101. <span>{{ parseTime(scope.row.lastTime, '{y}-{m}-{d} {h}:{mi}:{s}') }}</span>
  102. </template>
  103. </el-table-column>
  104. <el-table-column label="指标恶化包含关键字" align="center" prop="alarmKey"/>
  105. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  106. <template #default="scope">
  107. <el-button link type="primary" icon="Edit" @click="handleUpdate(scope.row)">配置算法</el-button>
  108. <el-button link type="primary" icon="DataAnalysis" v-if="scope.row.algoId!=null"
  109. @click="handleAnaly(scope.row)">立即分析
  110. </el-button>
  111. <el-button link type="primary" icon="Grid" v-if="scope.row.algoId!=null" @click="handleHistory(scope.row)">
  112. 历史记录
  113. </el-button>
  114. <el-button link type="primary" icon="Delete" v-if="scope.row.algoId==null" @click="handleDelete(scope.row)">
  115. 删除
  116. </el-button>
  117. </template>
  118. </el-table-column>
  119. </el-table>
  120. <pagination
  121. v-show="total>0"
  122. :total="total"
  123. v-model:page="queryParams.pageNum"
  124. v-model:limit="queryParams.pageSize"
  125. @pagination="getList"
  126. />
  127. <!-- 添加或修改模型指标分析对话框 -->
  128. <el-dialog :title="title" v-model="open" width="1000px" append-to-body>
  129. <el-form ref="analyRef" :model="form" :rules="rules" label-width="120px">
  130. <el-row :gutter="20">
  131. <el-col :span="10" :xs="24">
  132. <el-form-item label="算法名称">
  133. {{ form.algoName }}
  134. </el-form-item>
  135. <el-form-item label="模型名称">
  136. {{ form.modelName }}
  137. </el-form-item>
  138. <el-form-item label="指标名称">
  139. {{ form.metricsName }}
  140. </el-form-item>
  141. <el-form-item label="对象类型">
  142. {{ form.objType }}
  143. </el-form-item>
  144. <el-form-item label="对象名称">
  145. {{ form.objName }}
  146. </el-form-item>
  147. <el-form-item label="告警说明">
  148. <el-alert
  149. title="启用告警后,系统将在满足算法返回结果包含选择的关键字时,在运行风险监测系统中产生告警记录。"
  150. type="warning"
  151. show-icon
  152. :closable="false"
  153. style="margin-top: 10px;"
  154. />
  155. </el-form-item>
  156. </el-col>
  157. <el-col :span="14" :xs="24">
  158. <!-- <el-table-column label="算法名称" align="center" prop="algoName"/>-->
  159. <!-- <el-table-column label="模型名称" align="center" prop="modelName"/>-->
  160. <!-- <el-table-column label="指标名称" align="center" prop="metricsName"/>-->
  161. <!-- <el-table-column label="对象类型" align="center" prop="objType"/>-->
  162. <!-- <el-table-column label="对象名称" align="center" prop="objName"/>-->
  163. <!-- <el-input v-model="form.autoId" placeholder="请输入指标自动ID"/>-->
  164. <el-form-item label="指标自动ID" prop="autoId">
  165. <el-text v-model="form.autoId" placeholder="请输入指标自动ID"/>
  166. </el-form-item>
  167. <el-form-item label="算法名称" prop="algoId">
  168. <el-select v-model="form.algoId" placeholder="请选择算法" style="width: 260px" clearable filterable remote
  169. reserve-keyword @change="handleAlgoChange">
  170. <el-option
  171. v-for="dict in algoList"
  172. :key="dict.algoId"
  173. :label="dict.algoName"
  174. :value="dict.algoId"
  175. ></el-option>
  176. </el-select>
  177. </el-form-item>
  178. <el-form-item label="定时分析" prop="timeSwitch">
  179. <el-select v-model="form.timeSwitch" placeholder="请选择定时分析">
  180. <el-option
  181. v-for="dict in sys_yes_no"
  182. :key="dict.value"
  183. :label="dict.label"
  184. :value="dict.value"
  185. ></el-option>
  186. </el-select>
  187. </el-form-item>
  188. <el-form-item label="执行周期(天)" prop="scheduleCycle">
  189. <el-input-number v-model="form.scheduleCycle" placeholder="请输入执行周期" :min="1"/>
  190. </el-form-item>
  191. <!-- <el-form-item label="上次执行时间" prop="lastTime">-->
  192. <!-- <el-date-picker clearable-->
  193. <!-- v-model="form.lastTime"-->
  194. <!-- type="date"-->
  195. <!-- value-format="YYYY-MM-DD"-->
  196. <!-- placeholder="请选择上次执行时间">-->
  197. <!-- </el-date-picker>-->
  198. <!-- </el-form-item>-->
  199. <el-form-item label="是否告警" prop="alarmWitch">
  200. <el-select v-model="form.alarmWitch" placeholder="请选择是否告警">
  201. <el-option
  202. v-for="dict in sys_yes_no"
  203. :key="dict.value"
  204. :label="dict.label"
  205. :value="dict.value"
  206. ></el-option>
  207. </el-select>
  208. </el-form-item>
  209. <el-form-item label="指标恶化包含关键字" prop="alarmKey" v-if="form.alarmWitch === 'Y'" label-width="150px">
  210. <el-select
  211. v-model="form.alarmKey"
  212. placeholder="指标恶化包含关键字"
  213. clearable
  214. >
  215. <el-option
  216. v-for="item in algoResultList"
  217. :key="item.value"
  218. :label="item.label"
  219. :value="item.value"
  220. ></el-option>
  221. </el-select>
  222. </el-form-item>
  223. <!-- <el-form-item label="告警内容">-->
  224. <!-- <editor v-model="form.alarmContent" :min-height="192"/>-->
  225. <!-- </el-form-item>-->
  226. <el-form-item label="告警内容" prop="alarmContent" v-if="form.alarmWitch === 'Y'" >
  227. <el-input v-model="form.alarmContent" type="textarea" placeholder="请输入告警内容"/>
  228. </el-form-item>
  229. </el-col>
  230. </el-row>
  231. </el-form>
  232. <template #footer>
  233. <div class="dialog-footer">
  234. <el-button type="primary" @click="submitForm">确 定</el-button>
  235. <el-button @click="cancel">取 消</el-button>
  236. </div>
  237. </template>
  238. </el-dialog>
  239. <!-- 添加或修改业务模型对话框 -->
  240. <el-dialog :title="titleS" v-model="openS" width="1300" append-to-body>
  241. <select-metrics ref="selectMetricsRef" style="height: 600px; overflow-y: auto;"/>
  242. <template #footer>
  243. <div class="dialog-footer">
  244. <el-button type="primary" @click="selectOK">确 定</el-button>
  245. <el-button @click="cancel">取 消</el-button>
  246. </div>
  247. </template>
  248. </el-dialog>
  249. <el-dialog :title="titleH" v-model="openH" width="1300" append-to-body>
  250. <history v-if="openH" ref="historyRef" :analy-id="_analyId" style="height: 600px; overflow-y: auto;"/>
  251. <template #footer>
  252. <div class="dialog-footer">
  253. <el-button type="primary" @click="selectOK">确 定</el-button>
  254. <el-button @click="cancel">取 消</el-button>
  255. </div>
  256. </template>
  257. </el-dialog>
  258. </div>
  259. </template>
  260. <script setup name="Analy">
  261. import {addAnaly, analy, batchInsert, delAnaly, getAnaly, listAnaly, updateAnaly} from "@/api/ripa/analy";
  262. import {listAlgo} from "@/api/ripa/algo";
  263. import selectMetrics from "@/views/ripa/analy/component/selectMetrics.vue"
  264. import history from "@/views/ripa/record/index.vue"
  265. const {proxy} = getCurrentInstance();
  266. const {sys_yes_no} = proxy.useDict('sys_yes_no');
  267. // 添加这行确保组件被视为已使用
  268. const _unused = selectMetrics; // 防止IDE认为组件未被使用
  269. const _unused1 = history; // 防止IDE认为组件未被使用
  270. const analyList = ref([]);
  271. const algoList = ref([]);
  272. const algoResultList = ref([]);
  273. const open = ref(false);
  274. const openS = ref(false);
  275. const openH = ref(false);
  276. const loading = ref(true);
  277. const showSearch = ref(true);
  278. const ids = ref([]);
  279. const single = ref(true);
  280. const multiple = ref(true);
  281. const total = ref(0);
  282. const title = ref("");
  283. const titleS = ref("");
  284. const titleH = ref("");
  285. const selectMetricsRef = ref(null);
  286. const historyRef = ref(null);
  287. const _analyId = ref("");
  288. const data = reactive({
  289. form: {},
  290. queryParams: {
  291. pageNum: 1,
  292. pageSize: 10,
  293. autoId: null,
  294. algoId: null,
  295. timeSwitch: null,
  296. scheduleCycle: null,
  297. lastTime: null,
  298. alarmWitch: null,
  299. alarmKey: null,
  300. alarmContent: null,
  301. createBy: null,
  302. createTime: null,
  303. updateBy: null,
  304. updateTime: null,
  305. remark: null
  306. },
  307. rules: {
  308. algoId: [
  309. {required: true, message: "算法不能为空", trigger: "blur"}
  310. ],
  311. alarmKey: [
  312. {
  313. required: true,
  314. message: "告警包含关键字不能为空",
  315. trigger: "blur",
  316. validator: (rule, value, callback) => {
  317. // 只有当 alarmWitch 为 'Y' 时才验证
  318. if (form.value.alarmWitch === 'Y' && (!value || value.trim() === '')) {
  319. callback(new Error('告警包含关键字不能为空'));
  320. } else {
  321. callback();
  322. }
  323. }
  324. }
  325. ],
  326. alarmContent: [
  327. {
  328. required: true,
  329. message: "告警内容不能为空",
  330. trigger: "blur",
  331. validator: (rule, value, callback) => {
  332. // 只有当 alarmWitch 为 'Y' 时才验证
  333. if (form.value.alarmWitch === 'Y' && (!value || value.trim() === '')) {
  334. callback(new Error('告警内容不能为空'));
  335. } else {
  336. callback();
  337. }
  338. }
  339. }
  340. ]
  341. }
  342. });
  343. const {queryParams, form, rules} = toRefs(data);
  344. // 监听算法选择变化
  345. function handleAlgoChange(newVal) {
  346. if (newVal) {
  347. // 找到选中的算法
  348. const selectedAlgo = algoList.value.find(algo => algo.algoId === newVal);
  349. const defaultTemplate = `使用算法"${selectedAlgo.algoName}"检测,发现指标恶化,请注意!`;
  350. form.value.alarmContent = defaultTemplate;
  351. form.value.algoName = selectedAlgo.algoName;
  352. if (selectedAlgo && selectedAlgo.remark) {
  353. // 将remark按||拆分并转换为选项列表
  354. algoResultList.value = selectedAlgo.remark.split('||').map(item => ({
  355. value: item,
  356. label: item
  357. }));
  358. // 只有当 alarmContent 为空时才设置默认值
  359. // 检查是否使用默认模板或为空,如果是则更新
  360. } else {
  361. algoResultList.value = [];
  362. }
  363. } else {
  364. algoResultList.value = [];
  365. }
  366. }
  367. /** 选择指标确定按钮 */
  368. function selectOK() {
  369. try {
  370. // 调用子组件的方法获取选中的数据
  371. const selectedIds = selectMetricsRef.value.getSelectedData();
  372. if (!selectedIds || selectedIds.length === 0) {
  373. proxy.$modal.msgWarning("请先选择指标");
  374. return;
  375. }
  376. const analyDataList = selectedIds.map(id => ({
  377. autoId: id
  378. }));
  379. // 显示加载状态
  380. proxy.$modal.loading("正在处理...");
  381. batchInsert(analyDataList)
  382. .then(response => {
  383. proxy.$modal.closeLoading();
  384. proxy.$modal.msgSuccess("操作成功");
  385. getList();
  386. openS.value = false;
  387. })
  388. .catch(error => {
  389. proxy.$modal.closeLoading();
  390. console.error('操作失败:', error);
  391. proxy.$modal.msgError("操作失败: " + (error.message || "请检查网络连接或联系管理员"));
  392. });
  393. } catch (error) {
  394. proxy.$modal.closeLoading();
  395. console.error('发生错误:', error);
  396. proxy.$modal.msgError("发生错误: " + error.message);
  397. }
  398. }
  399. function getAlgoList() {
  400. listAlgo({
  401. algoOk: '0',
  402. pageNum: 1,
  403. pageSize: 9999
  404. }).then(response => {
  405. algoList.value = response.rows;
  406. });
  407. }
  408. /** 查询模型指标分析列表 */
  409. function getList() {
  410. loading.value = true;
  411. listAnaly(queryParams.value).then(response => {
  412. analyList.value = response.rows;
  413. total.value = response.total;
  414. loading.value = false;
  415. });
  416. }
  417. // 取消按钮
  418. function cancel() {
  419. open.value = false;
  420. openS.value = false;
  421. openH.value = false;
  422. reset();
  423. }
  424. // 表单重置
  425. function reset() {
  426. form.value = {
  427. analyId: null,
  428. autoId: null,
  429. algoId: null,
  430. timeSwitch: null,
  431. scheduleCycle: 7,
  432. lastTime: null,
  433. alarmWitch: null,
  434. alarmKey: null,
  435. alarmContent: null,
  436. createBy: null,
  437. createTime: null,
  438. updateBy: null,
  439. updateTime: null,
  440. remark: null
  441. };
  442. proxy.resetForm("analyRef");
  443. }
  444. /** 搜索按钮操作 */
  445. function handleQuery() {
  446. queryParams.value.pageNum = 1;
  447. getList();
  448. }
  449. /** 重置按钮操作 */
  450. function resetQuery() {
  451. proxy.resetForm("queryRef");
  452. handleQuery();
  453. }
  454. // 多选框选中数据
  455. function handleSelectionChange(selection) {
  456. ids.value = selection.map(item => item.analyId);
  457. single.value = selection.length != 1;
  458. multiple.value = !selection.length;
  459. }
  460. /** 新增按钮操作 */
  461. function handleAdd() {
  462. reset();
  463. open.value = true;
  464. title.value = "添加模型指标分析";
  465. }
  466. /** 修改按钮操作 */
  467. function handleSelect() {
  468. openS.value = true;
  469. titleS.value = "修改模型指标分析";
  470. // reset();
  471. // const _analyId = row.analyId || ids.value
  472. // getAnaly(_analyId).then(response => {
  473. // form.value = response.data;
  474. // });
  475. }
  476. /** 修改按钮操作 */
  477. function handleUpdate(row) {
  478. reset();
  479. const _analyId = row.analyId || ids.value
  480. getAnaly(_analyId).then(response => {
  481. form.value = response.data;
  482. if (!form.value.scheduleCycle) {
  483. form.value.scheduleCycle = 7;
  484. }
  485. if (!form.value.alarmWitch) {
  486. form.value.alarmWitch = 'Y';
  487. }
  488. if (!form.value.timeSwitch) {
  489. form.value.timeSwitch = 'Y';
  490. }
  491. open.value = true;
  492. title.value = "修改模型指标分析";
  493. });
  494. }
  495. /** 立即分析 */
  496. function handleAnaly(row) {
  497. const _analyId = row.analyId || ids.value
  498. analy(_analyId).then(response => {
  499. if (response.code == 200) {
  500. proxy.$modal.confirm("分析结果:" + response.msg)
  501. // proxy.$modal.msgSuccess("分析结果:" + response.msg);
  502. } else {
  503. proxy.$modal.msgError("分析失败:" + response.msg);
  504. }
  505. getList()
  506. });
  507. }
  508. function handleHistory(row) {
  509. _analyId.value = row.analyId;
  510. openH.value = true;
  511. titleH.value = "模型指标分析历史记录";
  512. }
  513. /** 提交按钮 */
  514. function submitForm() {
  515. proxy.$refs["analyRef"].validate(valid => {
  516. if (valid) {
  517. if (form.value.analyId != null) {
  518. updateAnaly(form.value).then(response => {
  519. proxy.$modal.msgSuccess("修改成功");
  520. open.value = false;
  521. getList();
  522. });
  523. } else {
  524. addAnaly(form.value).then(response => {
  525. proxy.$modal.msgSuccess("新增成功");
  526. open.value = false;
  527. getList();
  528. });
  529. }
  530. }
  531. });
  532. }
  533. /** 删除按钮操作 */
  534. function handleDelete(row) {
  535. const _analyIds = row.analyId || ids.value;
  536. proxy.$modal.confirm('是否确认删除模型指标分析编号为"' + _analyIds + '"的数据项?').then(function () {
  537. return delAnaly(_analyIds);
  538. }).then(() => {
  539. getList();
  540. proxy.$modal.msgSuccess("删除成功");
  541. }).catch(() => {
  542. });
  543. }
  544. /** 导出按钮操作 */
  545. function handleExport() {
  546. proxy.download('biz/analy/export', {
  547. ...queryParams.value
  548. }, `analy_${new Date().getTime()}.xlsx`)
  549. }
  550. getList();
  551. getAlgoList();
  552. </script>