index.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. <script lang="ts">
  2. // 声明额外的选项
  3. export default {
  4. name: "Edit"
  5. };
  6. </script>
  7. <script setup lang="ts">
  8. import { inject, onMounted, reactive, ref, Uploadfile, UploadImg, Editor, useRenderIcon, ElMessage, ElMessageBox, Upload, Close, http, getGroupUrl, RegularVerification, verification } from "@/utils/importUsed"
  9. // 接口列表实例
  10. let UrlList = reactive(null)
  11. // 获取当前板块接口列表
  12. onMounted(async () => {
  13. UrlList = await getGroupUrl(["kxsConfigServer"]);
  14. })
  15. const props = defineProps<{
  16. editVisible: {
  17. type: Boolean;
  18. default: false;
  19. };
  20. width: {
  21. type: Number;
  22. default: 50;
  23. };
  24. formData: {
  25. id: any;
  26. type: any;
  27. default: {};
  28. };
  29. }>();
  30. // 表单数据
  31. const UpdateForm: any = ref({
  32. apiHost: "", //接口主机头
  33. apiPort: "", //接口端口号
  34. apiRouter: "", //接口路由
  35. id: "", //ID
  36. });
  37. // 表单实例
  38. const ruleFormRef = ref()
  39. // 选项卡参数(默认值为列表某项的id)
  40. const activeId = ref('1')
  41. // 提交函数
  42. const submit = async (formEl) => {
  43. // 表单校验拦截
  44. if (!formEl) return
  45. await formEl.validate(async (valid, fields) => {
  46. if (valid) {
  47. //表单校验成功回调
  48. console.log('submit!')
  49. // 需动态生成接口
  50. const { status, msg }: any = await http.Request({
  51. method: UrlList.kxsConfigServer.apiInfosetRouter.method,
  52. url: UrlList.kxsConfigServer.apiInfosetRouter.url,
  53. params: UpdateForm.value
  54. });
  55. if (status === 1) {
  56. //业务成功回调
  57. ElMessage({
  58. message: "修改成功",
  59. type: "success"
  60. });
  61. UpdateForm.value = {
  62. apiHost: "", //接口主机头
  63. apiPort: "", //接口端口号
  64. apiRouter: "", //接口路由
  65. id: "", //ID
  66. };
  67. // 关闭修改弹窗;
  68. closeSetRouterVisible();
  69. } else {
  70. //业务失败回调
  71. ElMessageBox.alert(msg, "提示", {
  72. confirmButtonText: "关闭",
  73. type: "warning"
  74. });
  75. }
  76. } else {
  77. //表单校验失败回调
  78. ElMessage({
  79. message: "请输入完整信息",
  80. type: "error"
  81. });
  82. }
  83. })
  84. };
  85. // 表单校验规则
  86. const rules = reactive({
  87. apiHost: [
  88. { required: true, message: '请输入接口主机头', trigger: 'blur' },
  89. ],
  90. apiPort: [
  91. { required: true, message: '请输入接口端口号', trigger: 'blur' },
  92. ],
  93. apiRouter: [
  94. { required: true, message: '请输入接口路由', trigger: 'blur' },
  95. ],
  96. })
  97. // 关闭弹窗回调函数
  98. const closeFn: any = inject('closeEditSetRouterVisible');
  99. const openVisible = async () => {
  100. //通过ID获取表格数据
  101. const { status, data }: any = await http.Request({ method: UrlList.kxsConfigServer.apiInfoquery.method, url: UrlList.kxsConfigServer.apiInfoquery.url, params: { id: props.formData.id }});
  102. if (status === 1) {
  103. UpdateForm.value = data;
  104. }
  105. };
  106. // 关闭弹窗回调函数
  107. const closeSetRouterVisible = () => {
  108. UpdateForm.value = {
  109. apiHost: "", //接口主机头
  110. apiPort: "", //接口端口号
  111. apiRouter: "", //接口路由
  112. id: "", //ID
  113. };
  114. closeFn();
  115. };
  116. </script>
  117. <template lang="pug">
  118. .main
  119. el-dialog(v-model='props.editVisible' width="50%" title="修改" @close="closeSetRouterVisible()" @open="openVisible")
  120. el-form(:model='UpdateForm' label-position="right" ref="ruleFormRef" :rules="rules" label-width="100px")
  121. el-form-item(label='接口主机头' prop="apiHost")
  122. el-input(v-model='UpdateForm.apiHost' autocomplete='off' class="!w-[230px]"
  123. placeholder="请输入接口主机头")
  124. el-form-item(label='接口端口号' prop="apiPort")
  125. el-input-number(v-model='UpdateForm.apiPort' :min="1" :max="1000"
  126. placeholder="请输入接口端口号")
  127. el-form-item(label='接口路由' prop="apiRouter")
  128. el-input(v-model='UpdateForm.apiRouter' autocomplete='off' class="!w-[230px]"
  129. placeholder="请输入接口路由")
  130. el-form-item(label='ID' prop="id")
  131. el-input-number(v-model='UpdateForm.id' :min="1" :max="1000"
  132. placeholder="请输入ID")
  133. el-button(
  134. :icon="useRenderIcon(Close)",
  135. :loading="loading",
  136. @click="closeSetRouterVisible()"
  137. ) 关闭
  138. el-button(
  139. type="primary",
  140. :icon="useRenderIcon(Upload)",
  141. @click="submit(ruleFormRef)"
  142. ) 确认提交
  143. </template>
  144. <style scoped lang="scss">
  145. :deep(.el-dropdown-menu__item i) {
  146. margin: 0;
  147. }
  148. :deep(.el-form-item__label) {
  149. font-weight: 700;
  150. }
  151. :deep(.el-pagination) {
  152. flex-flow: wrap;
  153. }
  154. :deep(.is-draggable) {
  155. max-height: 80vh;
  156. overflow: auto;
  157. }
  158. :deep(.el-dialog__header) {
  159. position: sticky;
  160. top: 0;
  161. z-index: 2;
  162. background: #fff;
  163. }
  164. .collapsedom {
  165. padding: 0 20px;
  166. background-color: #fff;
  167. }
  168. .ovh-x {
  169. height: 40vh;
  170. overflow-y: auto;
  171. }
  172. :deep(.el-descriptions__header) {
  173. margin: 16px 0 !important;
  174. }
  175. </style>