index.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. <template>
  2. <ContentWrap>
  3. <!-- 搜索工作栏 -->
  4. <el-form
  5. ref="queryFormRef"
  6. :inline="true"
  7. :model="queryParams"
  8. class="-mb-15px"
  9. label-width="68px"
  10. >
  11. <el-form-item label="表单名" prop="name">
  12. <el-input
  13. v-model="queryParams.name"
  14. class="!w-240px"
  15. clearable
  16. placeholder="请输入表单名"
  17. @keyup.enter="handleQuery"
  18. />
  19. </el-form-item>
  20. <el-form-item>
  21. <el-button @click="handleQuery">
  22. <Icon class="mr-5px" icon="ep:search" />
  23. 搜索
  24. </el-button>
  25. <el-button @click="resetQuery">
  26. <Icon class="mr-5px" icon="ep:refresh" />
  27. 重置
  28. </el-button>
  29. <el-button v-hasPermi="['bpm:form:create']" plain type="primary" @click="openForm">
  30. <Icon class="mr-5px" icon="ep:plus" />
  31. 新增
  32. </el-button>
  33. </el-form-item>
  34. </el-form>
  35. </ContentWrap>
  36. <!-- 列表 -->
  37. <ContentWrap>
  38. <el-table v-loading="loading" :data="list">
  39. <el-table-column align="center" label="编号" prop="id" />
  40. <el-table-column align="center" label="表单名" prop="name" />
  41. <el-table-column align="center" label="状态" prop="status">
  42. <template #default="scope">
  43. <dict-tag :type="DICT_TYPE.COMMON_STATUS" :value="scope.row.status" />
  44. </template>
  45. </el-table-column>
  46. <el-table-column align="center" label="备注" prop="remark" />
  47. <el-table-column
  48. :formatter="dateFormatter"
  49. align="center"
  50. label="创建时间"
  51. prop="createTime"
  52. />
  53. <el-table-column align="center" label="操作">
  54. <template #default="scope">
  55. <el-button
  56. v-hasPermi="['bpm:form:update']"
  57. link
  58. type="primary"
  59. @click="openForm(scope.row.id)"
  60. >
  61. 编辑
  62. </el-button>
  63. <el-button v-hasPermi="['bpm:form:query']" link @click="openDetail(scope.row.id)">
  64. 详情
  65. </el-button>
  66. <el-button
  67. v-hasPermi="['bpm:form:delete']"
  68. link
  69. type="danger"
  70. @click="handleDelete(scope.row.id)"
  71. >
  72. 删除
  73. </el-button>
  74. </template>
  75. </el-table-column>
  76. </el-table>
  77. <!-- 分页 -->
  78. <Pagination
  79. v-model:limit="queryParams.pageSize"
  80. v-model:page="queryParams.pageNo"
  81. :total="total"
  82. @pagination="getList"
  83. />
  84. </ContentWrap>
  85. <!-- 表单详情的弹窗 -->
  86. <Dialog v-model="detailVisible" title="表单详情" width="800">
  87. <form-create :option="detailData.option" :rule="detailData.rule" />
  88. </Dialog>
  89. </template>
  90. <script lang="ts" setup>
  91. import { DICT_TYPE } from '@/utils/dict'
  92. import { dateFormatter } from '@/utils/formatTime'
  93. import * as FormApi from '@/api/bpm/form'
  94. import { setConfAndFields2 } from '@/utils/formCreate'
  95. defineOptions({ name: 'BpmForm' })
  96. const message = useMessage() // 消息弹窗
  97. const { t } = useI18n() // 国际化
  98. const { currentRoute, push } = useRouter() // 路由
  99. const loading = ref(true) // 列表的加载中
  100. const total = ref(0) // 列表的总页数
  101. const list = ref([]) // 列表的数据
  102. const queryParams = reactive({
  103. pageNo: 1,
  104. pageSize: 10,
  105. name: null
  106. })
  107. const queryFormRef = ref() // 搜索的表单
  108. /** 查询列表 */
  109. const getList = async () => {
  110. loading.value = true
  111. try {
  112. const data = await FormApi.getFormPage(queryParams)
  113. list.value = data.list
  114. total.value = data.total
  115. } finally {
  116. loading.value = false
  117. }
  118. }
  119. /** 搜索按钮操作 */
  120. const handleQuery = () => {
  121. queryParams.pageNo = 1
  122. getList()
  123. }
  124. /** 重置按钮操作 */
  125. const resetQuery = () => {
  126. queryFormRef.value.resetFields()
  127. handleQuery()
  128. }
  129. /** 添加/修改操作 */
  130. const openForm = (id?: number) => {
  131. const toRouter: { name: string; query?: { id: number } } = {
  132. name: 'BpmFormEditor'
  133. }
  134. // 表单新建的时候id传的是event需要排除
  135. if (typeof id === 'number') {
  136. toRouter.query = {
  137. id
  138. }
  139. }
  140. push(toRouter)
  141. }
  142. /** 删除按钮操作 */
  143. const handleDelete = async (id: number) => {
  144. try {
  145. // 删除的二次确认
  146. await message.delConfirm()
  147. // 发起删除
  148. await FormApi.deleteForm(id)
  149. message.success(t('common.delSuccess'))
  150. // 刷新列表
  151. await getList()
  152. } catch {}
  153. }
  154. /** 详情操作 */
  155. const detailVisible = ref(false)
  156. const detailData = ref({
  157. rule: [],
  158. option: {}
  159. })
  160. const openDetail = async (rowId: number) => {
  161. // 设置表单
  162. const data = await FormApi.getForm(rowId)
  163. setConfAndFields2(detailData, data.conf, data.fields)
  164. // 弹窗打开
  165. detailVisible.value = true
  166. }
  167. /**表单保存返回后重新加载列表 */
  168. watch(
  169. () => currentRoute.value,
  170. () => {
  171. getList()
  172. },
  173. {
  174. immediate: true
  175. }
  176. )
  177. /** 初始化 **/
  178. onMounted(() => {
  179. getList()
  180. })
  181. </script>