|
|
@@ -0,0 +1,314 @@
|
|
|
+<template>
|
|
|
+<a-card>
|
|
|
+ <a-row justify="space-between" >
|
|
|
+ <a-col :span="18" >
|
|
|
+ <form-pro
|
|
|
+ search
|
|
|
+ :formProps="formPropsSearch"
|
|
|
+ layout="inline"
|
|
|
+ itemWidth="170px"
|
|
|
+ @search="search"
|
|
|
+ >
|
|
|
+
|
|
|
+ </form-pro>
|
|
|
+ </a-col>
|
|
|
+ <a-col>
|
|
|
+ <a-button type="primary" @click="state.visible = true" >创建规则</a-button>
|
|
|
+ </a-col>
|
|
|
+ </a-row>
|
|
|
+
|
|
|
+ <a-table
|
|
|
+ style="margin-top: 20px;"
|
|
|
+ :columns="columns"
|
|
|
+ :data-source="state.dataSource"
|
|
|
+ :loading="state.loading"
|
|
|
+ :pagenation="{}"
|
|
|
+ >
|
|
|
+ <template #bodyCell="{column, record}" >
|
|
|
+ <template v-if="column.key === 'subjectResource'" >
|
|
|
+ {{RuleController.SubjectResourceMap.get(record.subjectResource)?.name}}
|
|
|
+ </template>
|
|
|
+ <template v-if="column.key === 'subjectEvent'" >
|
|
|
+ {{RuleController.SubjectEventMap.get(record.subjectEvent)?.name}}
|
|
|
+ </template>
|
|
|
+ <template v-if="column.key === 'status'" >
|
|
|
+ <a-switch
|
|
|
+ v-model:checked="record.status"
|
|
|
+ checked-children="运行中"
|
|
|
+ un-checked-children="已停止"
|
|
|
+ @click="changeStatus(record)"
|
|
|
+ />
|
|
|
+ </template>
|
|
|
+ <template v-if="column.key === 'action'" >
|
|
|
+ <a-space>
|
|
|
+ <a-popconfirm
|
|
|
+ title="确实要删除吗?"
|
|
|
+ ok-text="确定"
|
|
|
+ cancel-text="取消"
|
|
|
+ @confirm="delForwardRule(record.id)"
|
|
|
+ >
|
|
|
+ <a>删除</a>
|
|
|
+ </a-popconfirm>
|
|
|
+ </a-space>
|
|
|
+ </template>
|
|
|
+ </template>
|
|
|
+ </a-table>
|
|
|
+</a-card>
|
|
|
+
|
|
|
+<!-- 创建规则 -->
|
|
|
+<modal-pro
|
|
|
+ width="1000px"
|
|
|
+ label="创建规则"
|
|
|
+ :visible="state.visible"
|
|
|
+ @cancel="state.visible = false"
|
|
|
+ @ok="ok('visible')"
|
|
|
+>
|
|
|
+ <a-steps :current="state.stepCount">
|
|
|
+ <a-step title="设置转发数据" ></a-step>
|
|
|
+ <a-step title="设置转发目标" />
|
|
|
+ <a-step title="启动规则"/>
|
|
|
+ </a-steps>
|
|
|
+ <div style="margin: 20px 0px;" >
|
|
|
+ <div v-if="state.stepCount === 0" >针对部分类型数据提供的快速配置,将引导您完成简单的业务设置。您也可以直接编辑过滤语句,实现更复杂的查询要求</div>
|
|
|
+ <div v-else-if="state.stepCount === 1" >您可以设置将数据转发至华为云其他服务或私有服务器。</div>
|
|
|
+ <div v-else >完成完整的规则定义后,您就可以控制规则的运行,以实现数据转发。</div>
|
|
|
+ </div>
|
|
|
+ <form-pro
|
|
|
+ v-if="state.stepCount == 0"
|
|
|
+ validate
|
|
|
+ :formProps="formProps"
|
|
|
+ ref="formProo"
|
|
|
+ />
|
|
|
+ <div v-if="state.stepCount == 1" >
|
|
|
+ <a-row>
|
|
|
+ <a-col>
|
|
|
+ <a-space>
|
|
|
+ <a-button type="primary" @click="state.targetVisible = true">添加</a-button>
|
|
|
+ </a-space>
|
|
|
+ </a-col>
|
|
|
+ </a-row>
|
|
|
+ </div>
|
|
|
+ <div v-if="state.stepCount == 2" >
|
|
|
+ <a-button>启动规则</a-button>
|
|
|
+ </div>
|
|
|
+</modal-pro>
|
|
|
+
|
|
|
+<modal-pro
|
|
|
+ label="转发目标"
|
|
|
+ :visible="state.targetVisible"
|
|
|
+ @cancel="state.targetVisible = false"
|
|
|
+ @ok="ok('targetVisible')"
|
|
|
+>
|
|
|
+ <a-select
|
|
|
+ style="width: 100%;"
|
|
|
+ >
|
|
|
+ <a-select-option
|
|
|
+ v-for="item in forwardTatget"
|
|
|
+ :key="item.key"
|
|
|
+ :value="item.key"
|
|
|
+ >
|
|
|
+ {{item.name}}
|
|
|
+ </a-select-option>
|
|
|
+ </a-select>
|
|
|
+</modal-pro>
|
|
|
+</template>
|
|
|
+
|
|
|
+<script lang='ts' setup >
|
|
|
+import { onMounted, reactive, ref, toRefs } from 'vue'
|
|
|
+import { RuleController } from '@/controller/index'
|
|
|
+import type { FormItemProps } from '@/components/FormPro/index.vue'
|
|
|
+
|
|
|
+const columns = [
|
|
|
+ {
|
|
|
+ title: '规则名称',
|
|
|
+ dataIndex: 'ruleLabel'
|
|
|
+ },
|
|
|
+ {
|
|
|
+ title: '规则ID',
|
|
|
+ dataIndex: 'id'
|
|
|
+ },
|
|
|
+ {
|
|
|
+ title: '数据来源',
|
|
|
+ dataIndex: 'subjectResource',
|
|
|
+ key: 'subjectResource'
|
|
|
+ },
|
|
|
+ {
|
|
|
+ title: '触发事件',
|
|
|
+ dataIndex: 'subjectEvent',
|
|
|
+ key: 'subjectEvent'
|
|
|
+ },
|
|
|
+ {
|
|
|
+ title: '状态',
|
|
|
+ dataIndex: 'status',
|
|
|
+ key: 'status'
|
|
|
+ },
|
|
|
+ {
|
|
|
+ title: '操作',
|
|
|
+ dataIndex: 'action',
|
|
|
+ key: 'action'
|
|
|
+ }
|
|
|
+]
|
|
|
+
|
|
|
+const formProps: FormItemProps[] = [
|
|
|
+ {
|
|
|
+ label: '规则名称',
|
|
|
+ key: 'ruleLabel',
|
|
|
+ type: 'input',
|
|
|
+ rules: true,
|
|
|
+ value: ''
|
|
|
+ },
|
|
|
+ {
|
|
|
+ label: '数据来源',
|
|
|
+ key: 'subjectResource',
|
|
|
+ type: 'select',
|
|
|
+ rules: true,
|
|
|
+ request: async () => await Array.from(RuleController.SubjectResourceMap, ([key, value]) => ({ ...value, value: value.key }))
|
|
|
+ },
|
|
|
+ {
|
|
|
+ label: '触发事件',
|
|
|
+ key: 'subjectEvent',
|
|
|
+ type: 'select',
|
|
|
+ rules: true,
|
|
|
+ request: async () => await Array.from(RuleController.SubjectEventMap, ([key, value]) => ({ ...value, value: value.key }))
|
|
|
+ },
|
|
|
+ {
|
|
|
+ label: '规则描述',
|
|
|
+ key: 'ruleDescription',
|
|
|
+ type: 'textarea',
|
|
|
+ rules: false,
|
|
|
+ value: ''
|
|
|
+ }
|
|
|
+]
|
|
|
+
|
|
|
+const formPropsSearch: FormItemProps[] = [
|
|
|
+ {
|
|
|
+ label: '规则名称',
|
|
|
+ key: 'ruleLabel',
|
|
|
+ type: 'input',
|
|
|
+ rules: false,
|
|
|
+ value: ''
|
|
|
+ },
|
|
|
+ {
|
|
|
+ label: '规则ID',
|
|
|
+ key: 'ruleId',
|
|
|
+ type: 'input',
|
|
|
+ rules: false,
|
|
|
+ value: ''
|
|
|
+ },
|
|
|
+ {
|
|
|
+ label: '数据来源',
|
|
|
+ key: 'subjectResource',
|
|
|
+ type: 'select',
|
|
|
+ rules: false,
|
|
|
+ request: async () => await Array.from(RuleController.SubjectResourceMap, ([key, value]) => ({ ...value, value: value.key }))
|
|
|
+ },
|
|
|
+ {
|
|
|
+ label: '触发事件',
|
|
|
+ key: 'subjectEvent',
|
|
|
+ type: 'select',
|
|
|
+ rules: false,
|
|
|
+ request: async () => await Array.from(RuleController.SubjectEventMap, ([key, value]) => ({ ...value, value: value.key }))
|
|
|
+ },
|
|
|
+ {
|
|
|
+ label: '状态',
|
|
|
+ key: 'status',
|
|
|
+ type: 'select',
|
|
|
+ rules: false,
|
|
|
+ request: async () => {
|
|
|
+ const getData = () => {
|
|
|
+ return [
|
|
|
+ { name: '所有状态', key: '', value: '' },
|
|
|
+ { name: '运行中', key: 'status', value: true },
|
|
|
+ { name: '未启动', key: 'status', value: false }
|
|
|
+ ]
|
|
|
+ }
|
|
|
+ return await getData()
|
|
|
+ }
|
|
|
+ }
|
|
|
+]
|
|
|
+
|
|
|
+const forwardTatget = [
|
|
|
+ { name: 'RabbitMQ', key: 'RabbitMQ' },
|
|
|
+ { name: 'Kafka', key: 'Kafka' },
|
|
|
+ { name: 'HTTP编码', key: 'HTTP编码' }
|
|
|
+]
|
|
|
+
|
|
|
+const formProo = ref('')
|
|
|
+
|
|
|
+let queryParams = reactive({
|
|
|
+ page: 1,
|
|
|
+ pageSize: 10,
|
|
|
+ total: 0,
|
|
|
+ ruleId: '',
|
|
|
+ ruleLabel: '',
|
|
|
+ status: '',
|
|
|
+ subjectEvent: '',
|
|
|
+ subjectResource: ''
|
|
|
+})
|
|
|
+
|
|
|
+const state = reactive({
|
|
|
+ loading: false,
|
|
|
+ dataSource: [],
|
|
|
+ visible: false,
|
|
|
+ targetVisible: false,
|
|
|
+ stepCount: 1
|
|
|
+})
|
|
|
+
|
|
|
+let forwardState = reactive({})
|
|
|
+
|
|
|
+const search = (record) => {
|
|
|
+ console.log('search', record)
|
|
|
+ queryParams = { ...queryParams, ...record }
|
|
|
+ getForwardList()
|
|
|
+}
|
|
|
+
|
|
|
+const changeStatus = async (record) => {
|
|
|
+ console.log(record.status)
|
|
|
+
|
|
|
+ // return
|
|
|
+ await RuleController.updateForwardStatus({ id: record.id, status: record.status })
|
|
|
+}
|
|
|
+
|
|
|
+/** 提交转发规则 */
|
|
|
+const ok = async (visibleKey: string) => {
|
|
|
+ if (state.stepCount === 0) {
|
|
|
+ const r1 = await formProo.value.onSubmit()
|
|
|
+ if (r1) {
|
|
|
+ state.stepCount++
|
|
|
+ forwardState = toRefs({ ...forwardState, ...r1 })
|
|
|
+ console.log(forwardState)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (state.stepCount === 1) {
|
|
|
+ if (state.targetVisible) {
|
|
|
+ state.targetVisible = false
|
|
|
+ } else {
|
|
|
+ state.stepCount++
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (state.stepCount >= 3) {
|
|
|
+ console.log('出发提交规则')
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+const delForwardRule = async (id: string) => {
|
|
|
+ await RuleController.delForward(id)
|
|
|
+ getForwardList()
|
|
|
+}
|
|
|
+
|
|
|
+const getForwardList = async () => {
|
|
|
+ state.loading = true
|
|
|
+ const { data, sum } = await RuleController.pageForward(queryParams)
|
|
|
+ state.loading = false
|
|
|
+ state.dataSource = data
|
|
|
+ queryParams.total = sum
|
|
|
+}
|
|
|
+
|
|
|
+onMounted(() => {
|
|
|
+ getForwardList()
|
|
|
+})
|
|
|
+</script>
|
|
|
+<style lang='less' scoped >
|
|
|
+</style>
|