index.vue 4.7 KB

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