serviceParam.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. <template>
  2. <el-form :model="serviceParamForm" ref="serviceParamForm">
  3. <table id="serviceParamTable">
  4. <colgroup>
  5. <col width="6%" align="center" valign="middle"/>
  6. <col width="20%" align="center" valign="middle"/>
  7. <col width="20%" align="center" valign="middle"/>
  8. <col width="20%" align="center" valign="middle"/>
  9. <col width="20%" align="center" valign="middle"/>
  10. <col width="14%" align="center" valign="middle"/>
  11. </colgroup>
  12. <thead>
  13. <tr>
  14. <th>序号</th>
  15. <th>参数字段</th>
  16. <th>参数名称</th>
  17. <th>参数类型</th>
  18. <th>参数备注</th>
  19. <th>操作</th>
  20. </tr>
  21. </thead>
  22. <tbody>
  23. <tr v-for="(param, index) in serviceParamForm.params" :key="index">
  24. <td>
  25. {{ index + 1 }}
  26. </td>
  27. <td>
  28. <el-form-item
  29. :prop="'params.' + index + '.paramCode'"
  30. :rules="{
  31. required: true,
  32. message: '参数字段不能为空',
  33. trigger: 'blur',
  34. }"
  35. >
  36. <el-input v-model="param.paramCode"></el-input>
  37. </el-form-item>
  38. </td>
  39. <td>
  40. <el-form-item
  41. :prop="'params.' + index + '.paramName'"
  42. :rules="{
  43. required: true,
  44. message: '参数名称不能为空',
  45. trigger: 'blur',
  46. }"
  47. >
  48. <el-input v-model="param.paramName"></el-input>
  49. </el-form-item>
  50. </td>
  51. <td>
  52. <el-form-item
  53. :prop="'params.' + index + '.paramType'"
  54. :rules="{
  55. required: true,
  56. message: '参数类型不能为空',
  57. trigger: 'blur',
  58. }"
  59. >
  60. <el-select v-model="param.paramType" placeholder="请选择">
  61. <el-option
  62. v-for="item in paramTypes"
  63. :key="item"
  64. :label="item"
  65. :value="item"
  66. >
  67. </el-option>
  68. </el-select>
  69. </el-form-item>
  70. </td>
  71. <td>
  72. <el-form-item>
  73. <el-input v-model="param.paramNote"></el-input>
  74. </el-form-item>
  75. </td>
  76. <td>
  77. <el-button @click.prevent="removeParam(param)"> 删除</el-button>
  78. </td>
  79. </tr>
  80. </tbody>
  81. </table>
  82. <el-row type="flex" justify="center">
  83. <el-button
  84. icon="ArrowLeft"
  85. @click="forwardStep"
  86. circle
  87. ></el-button>
  88. <el-button @click="addParam">新增参数</el-button>
  89. <el-button type="primary" @click="submitForm('serviceParamForm')">
  90. 保存
  91. </el-button>
  92. <el-button @click="exit">退出</el-button>
  93. <el-button icon="ArrowRight" @click="nextStep" circle></el-button>
  94. </el-row>
  95. </el-form>
  96. </template>
  97. <script>
  98. import {addServiceParam, delServiceParam, getServiceAllParam,} from "@/api/service/info";
  99. export default {
  100. props: ["srvId"],
  101. data() {
  102. return {
  103. serviceParamForm: {
  104. params: [
  105. {
  106. srvId: this.srvId,
  107. paramCode: "",
  108. paramName: "",
  109. paramType: "string",
  110. paramNote: "",
  111. },
  112. ],
  113. },
  114. paramTypes: ["string", "int", "double", "date"],
  115. };
  116. },
  117. methods: {
  118. // 前进一步
  119. forwardStep() {
  120. this.$emit("forwardStep");
  121. },
  122. // 后退一步
  123. nextStep() {
  124. this.$emit("nextStep");
  125. },
  126. // 保存返回值
  127. submitForm(formName) {
  128. this.$refs[formName].validate((valid) => {
  129. if (valid) {
  130. addServiceParam(this.serviceParamForm.params).then((r) => {
  131. this.$message({
  132. message: "添加参数成功",
  133. type: "success",
  134. });
  135. });
  136. } else {
  137. return false;
  138. }
  139. });
  140. },
  141. // 删除行
  142. removeParam(item) {
  143. if (item.paramCode) {
  144. this.$confirm("此操作将永久删除该参数, 是否继续?", "提示", {
  145. confirmButtonText: "确定",
  146. cancelButtonText: "取消",
  147. type: "warning",
  148. }).then(() => {
  149. delServiceParam({
  150. srvId: item.srvId,
  151. paramCode: item.paramCode,
  152. }).then(() => {
  153. var index = this.serviceParamForm.params.indexOf(item);
  154. if (index !== -1) {
  155. this.serviceParamForm.params.splice(index, 1);
  156. }
  157. this.$message({
  158. type: "success",
  159. message: "删除成功!",
  160. });
  161. });
  162. });
  163. } else {
  164. var index = this.serviceParamForm.params.indexOf(item);
  165. if (index !== -1) {
  166. this.serviceParamForm.params.splice(index, 1);
  167. }
  168. }
  169. },
  170. // 添加参数
  171. addParam() {
  172. this.serviceParamForm.params.push({
  173. srvId: this.srvId,
  174. paramCode: "",
  175. paramName: "",
  176. paramType: "string",
  177. paramNote: "",
  178. });
  179. },
  180. // 获取参数列表
  181. getParamList(id) {
  182. if (id) {
  183. getServiceAllParam(id).then((r) => {
  184. if (r.data && r.data.length > 0) {
  185. this.serviceParamForm.params = r.data;
  186. } else {
  187. this.serviceParamForm.params = [
  188. {
  189. srvId: this.srvId,
  190. paramCode: "",
  191. paramName: "",
  192. paramType: "string",
  193. paramNote: "",
  194. },
  195. ];
  196. }
  197. });
  198. }
  199. },
  200. // 退出
  201. exit() {
  202. this.$emit("close");
  203. },
  204. },
  205. watch: {
  206. srvId: {
  207. handler(val) {
  208. this.getParamList(val);
  209. },
  210. immediate: true,
  211. },
  212. },
  213. };
  214. </script>
  215. <style scoped>
  216. #serviceParamTable {
  217. width: 100%;
  218. margin: 0 auto;
  219. margin-bottom: 20px;
  220. border-radius: 5px;
  221. border: 1px solid #dcdfe6;
  222. border-collapse: collapse;
  223. }
  224. #serviceParamTable th {
  225. text-align: center;
  226. vertical-align: middle;
  227. border-collapse: collapse;
  228. padding: 5px;
  229. background-color: #f6f6f6;
  230. }
  231. #serviceParamTable td {
  232. text-align: center;
  233. vertical-align: middle;
  234. border-top: 1px solid #dcdfe6;
  235. border-bottom: 1px solid #dcdfe6;
  236. border-collapse: collapse;
  237. padding: 5px;
  238. }
  239. #serviceParamTable td :deep(.el-form-item) {
  240. margin: 0;
  241. }
  242. </style>