editFun.vue 8.8 KB

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