index.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  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(["prizeSet"]);
  14. databaseIdQuery();
  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. listId: {
  28. type: Number;
  29. default: 0;
  30. },
  31. }>();
  32. // 表单数据
  33. let UpdateForm = ref({
  34. listId: props.listId, //奖励配置
  35. databaseId: null, //查询数据库
  36. tableEnName: "", //查询表
  37. excuteKind: "", //执行方式
  38. });
  39. // 表单实例
  40. const ruleFormRef = ref()
  41. // 传参选项数据
  42. // 执行方式选项数据
  43. const excuteKindOptionList = [
  44. { id: 'add', label: '添加' },
  45. { id: 'update', label: '修改' },
  46. { id: 'update_or_add', label: '修改否则添加' },
  47. ]
  48. // 选项卡参数(默认值为列表某项的id)
  49. const activeId = ref('1')
  50. // 提交函数
  51. const submit = async (formEl) => {
  52. // 表单校验拦截
  53. if (!formEl) return
  54. await formEl.validate(async (valid, fields) => {
  55. if (valid) {
  56. //表单校验成功回调
  57. console.log('submit!')
  58. // 需动态生成接口
  59. const { status, msg }: any = await http.Request({
  60. method: UrlList.prizeSet.priaddPriPrizeInTable.method,
  61. url: UrlList.prizeSet.priaddPriPrizeInTable.url,
  62. params: UpdateForm.value
  63. });
  64. if (status === 1) {
  65. //业务成功回调
  66. ElMessage({
  67. message: "新增成功",
  68. type: "success"
  69. });
  70. UpdateForm.value = {
  71. listId: props.listId, //奖励配置
  72. databaseId: null, //查询数据库
  73. tableEnName: "", //查询表
  74. excuteKind: "", //执行方式
  75. };
  76. // 关闭新增弹窗;
  77. closeVisible()
  78. } else {
  79. //业务失败回调
  80. ElMessageBox.alert(msg, "提示", {
  81. confirmButtonText: "关闭",
  82. type: "warning"
  83. });
  84. }
  85. } else {
  86. //表单校验失败回调
  87. ElMessage({
  88. message: "请输入完整信息",
  89. type: "error"
  90. });
  91. }
  92. })
  93. };
  94. //获取查询库数据
  95. const databaseIdOptionList = ref([]);
  96. const databaseIdQuery = async () => {
  97. const { status, data }: any = await http.Request({ method: UrlList.prizeSet.prigetPriDatabaseSetDic.method, url: UrlList.prizeSet.prigetPriDatabaseSetDic.url, params: {} });
  98. if (status === 1) {
  99. databaseIdOptionList.value = data.records;
  100. }
  101. };
  102. // 表单校验规则
  103. const rules = reactive({
  104. tableEnName: [
  105. { required: true, message: '请输入查询表', trigger: 'blur' },
  106. ],
  107. })
  108. // 关闭弹窗回调函数
  109. const closeFn: any = inject("closeAddVisible");
  110. const closeVisible = () => {
  111. // 清空表单项;
  112. UpdateForm.value = {
  113. listId: props.listId, //奖励配置
  114. databaseId: null, //查询数据库
  115. tableEnName: "", //查询表
  116. excuteKind: "", //执行方式
  117. };
  118. closeFn();
  119. };
  120. // 弹窗是否全屏
  121. const isFullscreen = ref(false)
  122. </script>
  123. <template lang="pug">
  124. .main
  125. el-dialog(v-model='props.addVisible' width="50%" :fullscreen="isFullscreen" title="新增" draggable @close="closeVisible")
  126. el-form(:model='UpdateForm' label-position="right" ref="ruleFormRef" :rules="rules" label-width="100px")
  127. el-form-item(label='奖励配置' prop="listId")
  128. el-input(v-model='UpdateForm.listId' autocomplete='off'
  129. placeholder="请输入奖励配置")
  130. el-form-item(label="数据库", prop="databaseId")
  131. el-select(
  132. v-model="UpdateForm.databaseId",
  133. placeholder="请选择数据库",
  134. clearable,
  135. )
  136. el-option(:label="item.title", :value="item.id" v-for="(item,index) in databaseIdOptionList")
  137. el-form-item(label='查询表' prop="tableEnName")
  138. el-input(v-model='UpdateForm.tableEnName' autocomplete='off'
  139. placeholder="请输入查询表")
  140. el-form-item(label="执行方式", prop="excuteKind")
  141. el-select(
  142. v-model="UpdateForm.excuteKind",
  143. placeholder="请选择执行方式",
  144. clearable,
  145. )
  146. el-option(:label="item.label", :value="item.id" v-for="(item,index) in excuteKindOptionList")
  147. .flex.justify-end
  148. el-button(
  149. :icon="useRenderIcon(Close)",
  150. @click="closeVisible"
  151. ) 关闭
  152. el-button(
  153. type="primary",
  154. :icon="useRenderIcon(Upload)",
  155. @click="submit(ruleFormRef)"
  156. ) 确认提交
  157. </template>
  158. <style scoped lang="scss">
  159. :deep(.el-dropdown-menu__item i) {
  160. margin: 0;
  161. }
  162. :deep(.el-form-item__label) {
  163. font-weight: 700;
  164. }
  165. :deep(.el-pagination) {
  166. flex-flow: wrap;
  167. }
  168. :deep(.is-draggable) {
  169. max-height: 80vh;
  170. overflow: auto;
  171. }
  172. :deep(.el-dialog__header) {
  173. position: sticky;
  174. top: 0;
  175. z-index: 2;
  176. background: #fff;
  177. }
  178. .collapsedom {
  179. padding: 0 20px;
  180. background-color: #fff;
  181. }
  182. .ovh-x {
  183. height: 40vh;
  184. overflow-y: auto;
  185. }
  186. :deep(.el-descriptions__header) {
  187. margin: 16px 0 !important;
  188. }
  189. .el-select {
  190. width: 100%;
  191. }
  192. </style>