index.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. <script lang="ts">
  2. // 声明额外的选项
  3. export default {
  4. name: "Add"
  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(["telMainServer"]);
  14. groupIdQuery();
  15. })
  16. // 组件传参对象
  17. const props = defineProps<{
  18. submit: Function;
  19. addVisible: {
  20. type: Boolean;
  21. default: false;
  22. };
  23. width: {
  24. type: Number;
  25. default: 50;
  26. };
  27. }>();
  28. // 表单数据
  29. let UpdateForm = ref({
  30. groupId: "", //分组
  31. apiName: "", //接口名称
  32. apiKey: "", //接口关键字
  33. apiHost: "", //接口主机头
  34. apiPort: "", //接口端口号
  35. apiRouter: "", //接口路由
  36. apiMethod: "", //接口请求方式
  37. });
  38. // 表单实例
  39. const ruleFormRef = ref()
  40. // 传参选项数据
  41. // 分组选项数据
  42. const groupIdOptionList = ref([]);
  43. // 选项卡参数(默认值为列表某项的id)
  44. const activeId = ref('1')
  45. // 提交函数
  46. const submit = async (formEl) => {
  47. // 表单校验拦截
  48. if (!formEl) return
  49. await formEl.validate(async (valid, fields) => {
  50. if (valid) {
  51. //表单校验成功回调
  52. console.log('submit!')
  53. // 需动态生成接口
  54. const { status, msg }: any = await http.Request({
  55. method: UrlList.prizeSet.apiInfoadd.method,
  56. url: UrlList.prizeSet.apiInfoadd.url,
  57. params: UpdateForm.value
  58. });
  59. if (status === 1) {
  60. //业务成功回调
  61. ElMessage({
  62. message: "新增成功",
  63. type: "success"
  64. });
  65. UpdateForm.value = {
  66. groupId: "", //分组
  67. apiName: "", //接口名称
  68. apiKey: "", //接口关键字
  69. apiHost: "", //接口主机头
  70. apiPort: "", //接口端口号
  71. apiRouter: "", //接口路由
  72. apiMethod: "", //接口请求方式
  73. };
  74. // 关闭新增弹窗;
  75. closeVisible()
  76. } else {
  77. //业务失败回调
  78. ElMessageBox.alert(msg, "提示", {
  79. confirmButtonText: "关闭",
  80. type: "warning"
  81. });
  82. }
  83. } else {
  84. //表单校验失败回调
  85. ElMessage({
  86. message: "请输入完整信息",
  87. type: "error"
  88. });
  89. }
  90. })
  91. };
  92. //获取分组数据
  93. const groupIdQuery = async () => {
  94. const { status, data }: any = await http.Request({ method: UrlList.prizeSet.apiGroupselectList.method, url: UrlList.prizeSet.apiGroupselectList.url, params: {} });
  95. if (status === 1) {
  96. groupIdOptionList.value = data.records;
  97. }
  98. };
  99. // 表单校验规则
  100. const rules = reactive({
  101. apiName: [
  102. { required: true, message: '请输入接口名称', trigger: 'blur' },
  103. ],
  104. apiKey: [
  105. { required: true, message: '请输入接口关键字', trigger: 'blur' },
  106. ],
  107. apiHost: [
  108. { required: true, message: '请输入接口主机头', trigger: 'blur' },
  109. ],
  110. apiPort: [
  111. { required: true, message: '请输入接口端口号', trigger: 'blur' },
  112. ],
  113. apiRouter: [
  114. { required: true, message: '请输入接口路由', trigger: 'blur' },
  115. ],
  116. })
  117. // 关闭弹窗回调函数
  118. const closeFn: any = inject("closeAddVisible");
  119. const closeVisible = () => {
  120. // 清空表单项;
  121. UpdateForm.value = {
  122. groupId: "", //分组
  123. apiName: "", //接口名称
  124. apiKey: "", //接口关键字
  125. apiHost: "", //接口主机头
  126. apiPort: "", //接口端口号
  127. apiRouter: "", //接口路由
  128. apiMethod: "", //接口请求方式
  129. };
  130. closeFn();
  131. };
  132. // 弹窗是否全屏
  133. const isFullscreen = ref(false)
  134. </script>
  135. <template lang="pug">
  136. .main
  137. el-dialog(v-model='props.addVisible' width="50%" :fullscreen="isFullscreen" title="新增" draggable @close="closeVisible")
  138. el-form(:model='UpdateForm' label-position="right" ref="ruleFormRef" :rules="rules" label-width="100px")
  139. el-form-item(label="分组", prop="groupId")
  140. el-select(
  141. v-model="UpdateForm.groupId",
  142. placeholder="请选择分组",
  143. clearable,
  144. )
  145. el-option(:label="item.groupName", :value="item.id" v-for="(item,index) in groupIdOptionList")
  146. el-form-item(label='接口名称' prop="apiName")
  147. el-input(v-model='UpdateForm.apiName' autocomplete='off'
  148. placeholder="请输入接口名称")
  149. el-form-item(label='接口关键字' prop="apiKey")
  150. el-input(v-model='UpdateForm.apiKey' autocomplete='off'
  151. placeholder="请输入接口关键字")
  152. el-form-item(label='接口主机头' prop="apiHost")
  153. el-input(v-model='UpdateForm.apiHost' autocomplete='off'
  154. placeholder="请输入接口主机头")
  155. el-form-item(label='接口端口号' prop="apiPort")
  156. el-input-number(v-model='UpdateForm.apiPort' :min="1" :max="1000"
  157. placeholder="请输入接口端口号")
  158. el-form-item(label='接口路由' prop="apiRouter")
  159. el-input(v-model='UpdateForm.apiRouter' autocomplete='off'
  160. placeholder="请输入接口路由")
  161. el-form-item(label='接口请求方式' prop="apiMethod")
  162. el-input(v-model='UpdateForm.apiMethod' autocomplete='off'
  163. placeholder="请输入接口请求方式")
  164. .flex.justify-end
  165. el-button(
  166. :icon="useRenderIcon(Close)",
  167. @click="closeVisible"
  168. ) 关闭
  169. el-button(
  170. type="primary",
  171. :icon="useRenderIcon(Upload)",
  172. @click="submit(ruleFormRef)"
  173. ) 确认提交
  174. </template>
  175. <style scoped lang="scss">
  176. :deep(.el-dropdown-menu__item i) {
  177. margin: 0;
  178. }
  179. :deep(.el-form-item__label) {
  180. font-weight: 700;
  181. }
  182. :deep(.el-pagination) {
  183. flex-flow: wrap;
  184. }
  185. :deep(.is-draggable) {
  186. max-height: 80vh;
  187. overflow: auto;
  188. }
  189. :deep(.el-dialog__header) {
  190. position: sticky;
  191. top: 0;
  192. z-index: 2;
  193. background: #fff;
  194. }
  195. .collapsedom {
  196. padding: 0 20px;
  197. background-color: #fff;
  198. }
  199. .ovh-x {
  200. height: 40vh;
  201. overflow-y: auto;
  202. }
  203. :deep(.el-descriptions__header) {
  204. margin: 16px 0 !important;
  205. }
  206. .el-select {
  207. width: 100%;
  208. }
  209. </style>