editFun.vue 8.2 KB

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