editEvent.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. <template>
  2. <div class="system-edit-dic-container">
  3. <el-dialog :title="(ruleForm.id !== 0 ? '修改' : '添加') + '事件定义'" v-model="isShowDialog" width="769px">
  4. <el-form :model="ruleForm" ref="formRef" :rules="rules" label-width="120px">
  5. <el-form-item label="事件定义标识" prop="key">
  6. <el-input v-model="ruleForm.key" placeholder="请输入事件定义标识" :disabled="ruleForm.id !== 0 ? true : false" />
  7. </el-form-item>
  8. <el-form-item label="事件定义名称" prop="name">
  9. <el-input v-model="ruleForm.name" placeholder="请输入事件定义名称" />
  10. </el-form-item>
  11. <el-form-item label="事件类型" prop="level">
  12. <el-radio-group v-model="ruleForm.level">
  13. <el-radio :label="0">信息</el-radio>
  14. <el-radio :label="1">告警</el-radio>
  15. <el-radio :label="2">故障</el-radio>
  16. </el-radio-group>
  17. </el-form-item>
  18. <el-form-item label="输出参数" prop="maxLength">
  19. <div v-for="(item, index) in outputsdata" :key="index" class="jslist">
  20. <div class="jsonlist">
  21. <div>参数标识:{{ item.key }}</div>
  22. <div>参数名称:{{ item.name }}</div>
  23. <div>数据类型:{{ item.valueType.type }}</div>
  24. <div class="jsonoption">
  25. <el-link type="primary" @click="editjson(index, 'fun')">编辑</el-link>
  26. <el-link type="primary" @click="deljson(index, 'fun')">删除</el-link>
  27. </div>
  28. </div>
  29. </div>
  30. <div style="display: block; width: 100%">
  31. <div class="input-options" @click="addJson('fun')">
  32. <el-icon><Plus /></el-icon>
  33. <div>添加参数</div>
  34. </div>
  35. </div>
  36. </el-form-item>
  37. <el-form-item label="事件定义描述 " prop="desc">
  38. <el-input v-model="ruleForm.desc" type="textarea" placeholder="请输入事件定义描述"></el-input>
  39. </el-form-item>
  40. </el-form>
  41. <template #footer>
  42. <span class="dialog-footer">
  43. <el-button @click="onCancel">取 消</el-button>
  44. <el-button type="primary" @click="onSubmit">{{ ruleForm.id !== 0 ? '修 改' : '添 加' }}</el-button>
  45. </span>
  46. </template>
  47. </el-dialog>
  48. <EditOption ref="editOptionRef" @typeList="getOptionData" />
  49. </div>
  50. </template>
  51. <script lang="ts">
  52. import { reactive, toRefs, defineComponent, ref, unref } from 'vue';
  53. import api from '/@/api/device';
  54. import { Plus, Minus, Right } from '@element-plus/icons-vue';
  55. import EditOption from './editOption.vue';
  56. import { validateNoSpace } from '/@/utils/validator';
  57. import { ElMessage, UploadProps } from 'element-plus';
  58. interface RuleFormState {
  59. id: number;
  60. productId: number;
  61. level: number;
  62. name: string;
  63. dictType: string;
  64. inputs: Object;
  65. outputs: Object [];
  66. status: number;
  67. desc: string;
  68. }
  69. interface DicState {
  70. isShowDialog: boolean;
  71. ruleForm: RuleFormState;
  72. typeData: RuleFormState[];
  73. rules: {};
  74. }
  75. export default defineComponent({
  76. name: 'deviceEditPro',
  77. components: { Plus, Minus, Right, EditOption },
  78. setup(prop, { emit }) {
  79. const formRef = ref<HTMLElement | null>(null);
  80. const editOptionRef = ref();
  81. const state = reactive<DicState>({
  82. isShowDialog: false,
  83. typeData: [], //
  84. type: '',
  85. types: '',
  86. productId: 0,
  87. elementType: {
  88. type: '',
  89. maxLength: '',
  90. },
  91. enumdata: [
  92. {
  93. text: '',
  94. value: '',
  95. },
  96. ],
  97. jsondata: [],
  98. outputsdata: [],
  99. ruleForm: {
  100. productId: 0,
  101. name: '',
  102. key: '',
  103. outputs: [],
  104. desc: '',
  105. },
  106. rules: {
  107. name: [ { required: true, message: '事件定义名称不能为空', trigger: 'blur' },
  108. { max: 32, message: '事件定义名称不能超过32个字符', trigger: 'blur' },
  109. { validator: validateNoSpace, message: '事件定义名称不能包含空格', trigger: 'blur' }
  110. ],
  111. key: [{ required: true, message: '事件定义标识不能为空', trigger: 'blur' }],
  112. type: [{ required: true, message: '请选择数据类型', trigger: 'blur' }],
  113. },
  114. });
  115. // 打开弹窗
  116. const openDialog = (row: RuleFormState | null, productId: number | null) => {
  117. resetForm();
  118. api.product.getDataType({ status: -1 }).then((res: any) => {
  119. const datat = Object.values(res.dataType);
  120. datat.forEach((item, index) => {
  121. if (index == 0) {
  122. datat[index]['label'] = '基础类型';
  123. datat[index]['options'] = item;
  124. } else {
  125. datat[index]['label'] = '扩展类型';
  126. datat[index]['options'] = item;
  127. }
  128. });
  129. state.typeData = datat || [];
  130. });
  131. state.ruleForm = row;
  132. if (row.outputs) {
  133. state.ruleForm = row;
  134. state.productId = productId;
  135. state.outputsdata = row.outputs;
  136. }
  137. state.isShowDialog = true;
  138. };
  139. const resetForm = () => {
  140. state.ruleForm = {
  141. name: '',
  142. key: '',
  143. status: 1,
  144. desc: '',
  145. };
  146. state.type = '';
  147. state.types = '';
  148. state.outputsdata = [];
  149. state.elementType = [];
  150. };
  151. const seletChange = (val) => {
  152. state.type = val;
  153. state.ruleForm.type = val;
  154. };
  155. const seletChanges = (val) => {
  156. state.types = val;
  157. };
  158. const addEnum = () => {
  159. state.enumdata.push({
  160. text: '',
  161. value: '',
  162. });
  163. };
  164. const delEnum = (index) => {
  165. state.enumdata.splice(index, 1);
  166. };
  167. const deljson = (index, type) => {
  168. if (type == 'fun') {
  169. state.outputsdata.splice(index, 1);
  170. } else {
  171. state.jsondata.splice(index, 1);
  172. }
  173. };
  174. const editjson=(index,type)=>{
  175. if (type == 'fun') {
  176. editOptionRef.value.openDialog(state.outputsdata[index]);
  177. } else {
  178. editOptionRef.value.openDialog(state.jsondata[index]);
  179. }
  180. }
  181. const addJson = (type) => {
  182. editOptionRef.value.openDialog({ product_id: 0, id: 0, type_data: type });
  183. };
  184. const getOptionData = (data, type_data) => {
  185. if (type_data == 'fun') {
  186. state.outputsdata.push(data);
  187. } else {
  188. state.jsondata.push(data);
  189. }
  190. };
  191. // 关闭弹窗
  192. const closeDialog = () => {
  193. state.isShowDialog = false;
  194. };
  195. // 取消
  196. const onCancel = () => {
  197. closeDialog();
  198. };
  199. // 新增
  200. const onSubmit = () => {
  201. const formWrap = unref(formRef) as any;
  202. if (!formWrap) return;
  203. formWrap.validate((valid: boolean) => {
  204. if (valid) {
  205. state.ruleForm.outputs = state.outputsdata;
  206. const theApi = state.ruleForm.id !== 0 ? api.model.eventedit : api.model.eventadd;
  207. if (state.ruleForm.id !== 0) {
  208. state.ruleForm.productId = state.productId;
  209. }
  210. theApi(state.ruleForm).then(() => {
  211. ElMessage.success('事件定义类型操作成功');
  212. closeDialog(); // 关闭弹窗
  213. emit('typeList');
  214. });
  215. }
  216. });
  217. };
  218. return {
  219. editOptionRef,
  220. getOptionData,
  221. openDialog,
  222. deljson,
  223. editjson,
  224. addEnum,
  225. delEnum,
  226. addJson,
  227. seletChange,
  228. seletChanges,
  229. closeDialog,
  230. onCancel,
  231. onSubmit,
  232. formRef,
  233. ...toRefs(state),
  234. };
  235. },
  236. });
  237. </script>
  238. <style>
  239. .input-box {
  240. display: flex;
  241. flex-direction: row;
  242. justify-content: space-between;
  243. margin-top: 10px;
  244. }
  245. .input-option {
  246. line-height: 30px;
  247. padding-top: 5px;
  248. width: 140px;
  249. }
  250. .input-option i {
  251. margin: 0px 5px;
  252. border: 1px solid #c3c3c3;
  253. font-size: 16px;
  254. }
  255. .input-options {
  256. display: flex;
  257. align-items: center;
  258. color: #409eff;
  259. cursor: pointer;
  260. }
  261. .jslist {
  262. width: 100%;
  263. border: 1px solid #e8e8e8;
  264. padding: 10px;
  265. margin-bottom: 10px;
  266. }
  267. .jsonlist {
  268. display: flex;
  269. flex-direction: row;
  270. justify-content: space-between;
  271. }
  272. .jsonoption {
  273. }
  274. .jsonoption a {
  275. margin: 0px 10px;
  276. }
  277. </style>