Commit 877e7e08c310ddde1d39ef585c840c896b314fac

Authored by loveumiko
1 parent 6a601e83

fix: 添加规则链库

@@ -22,6 +22,8 @@ enum ScreenManagerApi { @@ -22,6 +22,8 @@ enum ScreenManagerApi {
22 GET_ATTRBUTELIST = '/device/attributes/', 22 GET_ATTRBUTELIST = '/device/attributes/',
23 ALARM_PROFILE = '/alarm/profile/', 23 ALARM_PROFILE = '/alarm/profile/',
24 MASTER_GET_DEVICE = '/device/list', 24 MASTER_GET_DEVICE = '/device/list',
  25 + RULE_CHAINS = '/ruleChains',
  26 + RULE_CHAIN = '/ruleChain',
25 } 27 }
26 28
27 /** 29 /**
@@ -130,3 +132,45 @@ export const byOrganizationIdGetMasterDevice = (params: { @@ -130,3 +132,45 @@ export const byOrganizationIdGetMasterDevice = (params: {
130 }); 132 });
131 }; 133 };
132 //TODO-fengtao 134 //TODO-fengtao
  135 +
  136 +/**
  137 + * 分页查询规则链库
  138 + */
  139 +
  140 +export const getRuleChinsList = (params) => {
  141 + return defHttp.get(
  142 + {
  143 + url: `${ScreenManagerApi.RULE_CHAINS}`,
  144 + params,
  145 + },
  146 + { joinPrefix: false }
  147 + );
  148 +};
  149 +
  150 +/**
  151 + * 新增规则链
  152 + */
  153 +
  154 +export const createRuleChine = (params) => {
  155 + return defHttp.post(
  156 + {
  157 + url: `${ScreenManagerApi.RULE_CHAIN}`,
  158 + params,
  159 + },
  160 + { joinPrefix: false }
  161 + );
  162 +};
  163 +
  164 +/**
  165 + * 删除规则链
  166 + */
  167 +
  168 +export const deleteRuleChine = (params) => {
  169 + return defHttp.delete(
  170 + {
  171 + url: `${ScreenManagerApi.RULE_CHAIN}/`,
  172 + params,
  173 + },
  174 + { joinPrefix: false }
  175 + );
  176 +};
  1 +<template>
  2 + <div>
  3 + <BasicModal
  4 + destroyOnClose
  5 + v-bind="$attrs"
  6 + width="30rem"
  7 + @register="register"
  8 + title="添加规则链"
  9 + @ok="handleSuccess"
  10 + @close="handleClose"
  11 + >
  12 + <div>
  13 + <BasicForm @register="registerForm" />
  14 + </div>
  15 + </BasicModal>
  16 + </div>
  17 +</template>
  18 +<script setup lang="ts">
  19 + import { BasicModal, useModalInner } from '/@/components/Modal';
  20 + import { ExecuteReportRecord } from '/@/api/export/model/exportModel';
  21 + import { useForm, BasicForm } from '/@/components/Form';
  22 + import { formSchema } from './config';
  23 + import { createRuleChine } from '/@/api/ruleengine/ruleengineApi';
  24 + import { useMessage } from '/@/hooks/web/useMessage';
  25 +
  26 + const emit = defineEmits(['register', 'success']);
  27 +
  28 + const { createMessage } = useMessage();
  29 +
  30 + const [registerForm, { getFieldsValue, validate }] = useForm({
  31 + labelWidth: 120,
  32 + schemas: formSchema,
  33 + showActionButtonGroup: false,
  34 + });
  35 +
  36 + const [register, { setModalProps, closeModal }] = useModalInner(
  37 + async (data: { record: ExecuteReportRecord }) => {
  38 + setModalProps({ loading: true });
  39 + console.log(data, 'record');
  40 + }
  41 + );
  42 +
  43 + const handleClose = () => {
  44 + closeModal();
  45 + };
  46 +
  47 + const handleSuccess = async () => {
  48 + console.log(1, '1', getFieldsValue());
  49 + await validate();
  50 + const record = getFieldsValue();
  51 + const { description, debugMode, name } = record;
  52 + const form = {
  53 + additionalInfo: {
  54 + description,
  55 + },
  56 + debugMode,
  57 + name,
  58 + type: 'CORE',
  59 + };
  60 +
  61 + await createRuleChine(form);
  62 + createMessage.success('添加成功');
  63 + handleClose();
  64 + emit('success');
  65 + };
  66 +</script>
  67 +<style lang="less" scoped></style>
  1 +import { FormSchema } from '/@/components/Form';
  2 +
  3 +export const formSchema: FormSchema[] = [
  4 + {
  5 + field: 'name',
  6 + label: '名称',
  7 + colProps: { span: 16 },
  8 + component: 'Input',
  9 + required: true,
  10 + componentProps: {
  11 + placeholder: '请输入名称',
  12 + },
  13 + },
  14 + {
  15 + field: 'debugMode',
  16 + label: '调试模式',
  17 + component: 'Checkbox',
  18 + colProps: { span: 8 },
  19 + componentProps: {},
  20 + },
  21 + {
  22 + field: 'description',
  23 + label: '说明',
  24 + component: 'InputTextArea',
  25 + },
  26 +];
  1 +import RuleChainModal from './RuleChainModal.vue';
  2 +
  3 +export { RuleChainModal };
  1 +import { BasicColumn, FormSchema } from '/@/components/Table';
  2 +import { transformTime } from '/@/hooks/web/useDateToLocaleString';
  3 +
  4 +export const columns: BasicColumn[] = [
  5 + {
  6 + title: '创建时间',
  7 + dataIndex: 'createdTime',
  8 + width: 200,
  9 + format: (_text: string, record: Recordable) => {
  10 + return transformTime(record.createdTime);
  11 + },
  12 + },
  13 + {
  14 + title: '名称',
  15 + dataIndex: 'name',
  16 + width: 200,
  17 + },
  18 + {
  19 + title: '是否跟链',
  20 + dataIndex: 'root',
  21 + slots: {
  22 + customRender: 'root',
  23 + },
  24 + width: 200,
  25 + },
  26 +];
  27 +
  28 +export const searchFormSchema: FormSchema[] = [
  29 + {
  30 + field: 'textSearch',
  31 + label: '名称',
  32 + component: 'Input',
  33 +
  34 + colProps: { span: 8 },
  35 + componentProps: {
  36 + placeholder: '请输入名称',
  37 + },
  38 + },
  39 +];
  40 +
  41 +export const encode = (string: string) => {
  42 + return encodeURIComponent(string);
  43 +};
  1 +<template>
  2 + <div>
  3 + <BasicTable @register="registerTable">
  4 + <template #toolbar>
  5 + <Authority>
  6 + <a-button type="primary" @click="handleAdd"> 新增规则链 </a-button>
  7 + </Authority>
  8 + <!-- <Authority>
  9 + <Popconfirm
  10 + title="您确定要批量删除数据"
  11 + ok-text="确定"
  12 + cancel-text="取消"
  13 + @confirm="handleDeleteOrBatchDelete(null)"
  14 + >
  15 + <a-button color="error" :disabled="hasBatchDelete"> 批量删除 </a-button>
  16 + </Popconfirm>
  17 + </Authority> -->
  18 + </template>
  19 + <template #root="{ record }">
  20 + <Tag :color="record.root ? 'green' : 'red'"> {{ record.root ? '是' : '否' }}</Tag>
  21 + </template>
  22 + <template #action="{ record }">
  23 + <TableAction
  24 + :actions="[
  25 + {
  26 + label: '查看',
  27 + icon: 'ant-design:eye-outlined',
  28 + onClick: handleView.bind(null, record),
  29 + },
  30 + {
  31 + label: '删除',
  32 + icon: 'ant-design:delete-outlined',
  33 + color: 'error',
  34 + ifShow: !record.root,
  35 + popConfirm: {
  36 + title: '是否确认删除',
  37 + confirm: handleDeleteOrBatchDelete.bind(null, record),
  38 + },
  39 + },
  40 + ]"
  41 + />
  42 + </template>
  43 + </BasicTable>
  44 + <RuleChainModal @register="registerModal" @success="handleSuccess" />
  45 + </div>
  46 +</template>
  47 +<script lang="ts" setup>
  48 + import { BasicTable, useTable, TableAction } from '/@/components/Table';
  49 + import { columns, encode, searchFormSchema } from './config/config.data';
  50 + import { deleteRuleChine, getRuleChinsList } from '/@/api/ruleengine/ruleengineApi';
  51 + import { useModal } from '/@/components/Modal';
  52 + import { Authority } from '/@/components/Authority';
  53 + import { Tag } from 'ant-design-vue';
  54 + import { RuleChainModal } from './component/index';
  55 + import { useMessage } from '/@/hooks/web/useMessage';
  56 + import { usePermission } from '/@/hooks/web/usePermission';
  57 + import { useRouter } from 'vue-router';
  58 +
  59 + const [registerTable, { reload, setProps }] = useTable({
  60 + title: '规则链库',
  61 + api: getRuleChinsList,
  62 + columns,
  63 + formConfig: {
  64 + labelWidth: 120,
  65 + schemas: searchFormSchema,
  66 + },
  67 + fetchSetting: {
  68 + pageField: 'page',
  69 + listField: 'data',
  70 + },
  71 + pagination: true,
  72 + useSearchForm: true,
  73 + showTableSetting: true,
  74 + bordered: true,
  75 + showIndexColumn: false,
  76 + beforeFetch(params) {
  77 + Reflect.set(params, 'page', params.page - 1);
  78 + Reflect.set(params, 'sortProperty', 'createdTime');
  79 + Reflect.set(params, 'sortOrder', 'DESC');
  80 + return params;
  81 + },
  82 + actionColumn: {
  83 + width: 200,
  84 + title: '操作',
  85 + dataIndex: 'action',
  86 + slots: { customRender: 'action' },
  87 + fixed: 'right',
  88 + },
  89 + });
  90 +
  91 + const [registerModal, { openModal }] = useModal();
  92 +
  93 + const handleSuccess = () => {
  94 + reload();
  95 + };
  96 +
  97 + const handleAdd = () => {
  98 + openModal(true);
  99 + };
  100 +
  101 + const { createMessage } = useMessage();
  102 + const { hasPermission } = usePermission();
  103 + const router = useRouter();
  104 +
  105 + const handleView = (record: Recordable) => {
  106 + const hasDetailPermission = hasPermission('rule:chain:detail');
  107 + if (hasDetailPermission) {
  108 + const boardId = encode(record.id.id);
  109 + router.push(`/rule/chain/${boardId}`);
  110 + } else createMessage.warning('没有权限');
  111 + };
  112 +
  113 + const handleDeleteOrBatchDelete = async (record: Recordable) => {
  114 + setProps({
  115 + loading: true,
  116 + });
  117 + try {
  118 + await deleteRuleChine(record.id.id);
  119 + createMessage.success('删除成功');
  120 + } finally {
  121 + setProps({
  122 + loading: false,
  123 + });
  124 + }
  125 + reload();
  126 + };
  127 +</script>