index.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. <template>
  2. <div class="pageWrap">
  3. <div class="content-warp flex-column-page-wrap">
  4. <!-- 公用搜索组件 -->
  5. <LeSearchForm ref="searchForm" v-model:searchData="searchData" :forms="forms" :loading="tableOpts.options.loading"> </LeSearchForm>
  6. <!-- LeTable 组件使用 -->
  7. <LeTable
  8. ref="tableRef"
  9. v-model:searchParams="tableOpts.searchParams"
  10. v-bind="tableOpts"
  11. v-model:curRow="tableOpts.curRow"
  12. v-model:checked-options="checkedColumns"
  13. :columns="activeColumns"
  14. >
  15. <template #toolLeft>
  16. <el-button type="primary" @click="addHandler">
  17. <el-icon class="btn-icon">
  18. <Plus />
  19. </el-icon>
  20. </el-button>
  21. </template>
  22. <template #actionSlot="scope">
  23. <el-link type="primary">编辑</el-link>
  24. <el-divider direction="vertical"></el-divider>
  25. <el-link type="primary">预览</el-link>
  26. <el-divider direction="vertical"></el-divider>
  27. <el-link type="primary">设计</el-link>
  28. <el-divider direction="vertical"></el-divider>
  29. <el-link type="primary">字段</el-link>
  30. </template>
  31. </LeTable>
  32. </div>
  33. <LeFormConfigDialog
  34. v-if="visible"
  35. ref="dialogUserRef"
  36. v-model="visible"
  37. :title="`${isCreate ? '新增' : '编辑'}应用`"
  38. width="600px"
  39. :form-data="activeData"
  40. :form-options="formOptions"
  41. @submit="submitHandler"
  42. />
  43. </div>
  44. </template>
  45. <script lang="tsx" setup name="flow_form">
  46. import app from '@/api/system/app'
  47. import { computed, nextTick, ref, watch } from 'vue'
  48. import { ElMessage, ElTree } from 'element-plus'
  49. import { useTablePage } from '@/hooks/useTablePage'
  50. import { Plus, Edit } from '@element-plus/icons-vue'
  51. const visible = ref(false) // 弹窗显示隐藏
  52. const isCreate = ref(true)
  53. const activeData = ref({})
  54. const formsDialog = [
  55. {
  56. prop: 'identification',
  57. label: '表单名称',
  58. itemType: 'input',
  59. rules: [{ required: true, message: '请输入表单名称', trigger: 'blur' }]
  60. },
  61. {
  62. prop: 'name',
  63. label: '表单编码',
  64. itemType: 'input',
  65. rules: [{ required: true, message: '请输入表单编码', trigger: 'blur' }]
  66. },
  67. {
  68. prop: 'pid',
  69. label: '分组',
  70. itemType: 'select',
  71. filterable: true,
  72. options: [],
  73. rules: [{ required: true, message: '请选择分组', trigger: 'blur' }]
  74. },
  75. {
  76. prop: 'pid1',
  77. label: '表单类型',
  78. itemType: 'select',
  79. filterable: true,
  80. options: [],
  81. rules: [{ required: true, message: '请选择表单类型', trigger: 'blur' }]
  82. }
  83. ]
  84. // 新增的表单 和 编辑的表单
  85. const formOptions = computed(() => {
  86. return {
  87. forms: formsDialog,
  88. labelWidth: 120,
  89. span: 30,
  90. showResetBtn: true,
  91. formConfig: {
  92. showCancelBtn: true,
  93. submitLoading: false
  94. }
  95. }
  96. })
  97. const groupFilterText = ref('')
  98. const treeRef = ref<InstanceType<typeof ElTree>>()
  99. // 表格搜索条件
  100. const forms = ref([
  101. {
  102. prop: 'keyword',
  103. label: '表单名称:',
  104. itemType: 'input',
  105. placeholder: '请输入表单名称'
  106. }
  107. ])
  108. // table列表数据请求
  109. const queryList = async () => {
  110. const { options, searchParams } = tableOpts
  111. options.loading = true
  112. try {
  113. const { records: list, total } = await app.appPageApi(searchParams)
  114. tableOpts.total = total
  115. tableOpts.list = list
  116. } catch {
  117. console.log('获取列表数据失败')
  118. tableOpts.total = 0
  119. tableOpts.list = []
  120. options.loading = false // 更改加载中的 loading值
  121. } finally {
  122. options.loading = false
  123. }
  124. }
  125. // table 参数
  126. const columns = [
  127. {
  128. prop: 'identification',
  129. label: '表单名称',
  130. minWidth: 80
  131. },
  132. {
  133. prop: 'name',
  134. label: '表单编码',
  135. minWidth: 100
  136. },
  137. {
  138. prop: 'secretKey',
  139. label: '表单类型',
  140. minWidth: 100
  141. },
  142. {
  143. prop: 'sort',
  144. label: '版本',
  145. minWidth: 80
  146. },
  147. {
  148. prop: 'action',
  149. label: '操作',
  150. width: 190,
  151. fixed: 'right',
  152. slots: {
  153. default: 'actionSlot'
  154. }
  155. }
  156. ]
  157. const { searchData, tableOpts, checkedColumns, activeColumns, curSelectionRows, updateParams } = useTablePage(
  158. {
  159. options: {
  160. showIndex: false
  161. },
  162. // 需要展示的列
  163. columns,
  164. // 控制列配置
  165. columnsConfig: {
  166. columns
  167. }
  168. },
  169. {
  170. queryList,
  171. fetchImmediate: false
  172. }
  173. )
  174. // 删除
  175. const deleteItem = async ids => {
  176. try {
  177. await app.appDeleteApi(ids)
  178. updateParams()
  179. } catch (e) {
  180. console.log('删除失败')
  181. ElMessage.error(`删除失败~`)
  182. }
  183. }
  184. // 单个删除
  185. const table_del = row => {
  186. deleteItem([row.id])
  187. }
  188. //批量删除
  189. const batch_del = () => {
  190. const ids = curSelectionRows.value.map(item => item.id) // 多选数据
  191. deleteItem(ids)
  192. }
  193. const table_edit = async row => {
  194. isCreate.value = false
  195. activeData.value = { ...row, status: row.status ? true : false }
  196. visible.value = true
  197. }
  198. // 弹窗事件
  199. const submitHandler = async params => {
  200. formOptions.value.formConfig.submitLoading = true
  201. try {
  202. params.status = params.status ? 1 : 0
  203. params.expire = params.expire + ' 00:00:00'
  204. params.id = activeData.value.id ? activeData.value.id : null
  205. await app.appAddOrEditSaveApi(params)
  206. ElMessage.success(`${isCreate.value ? '新增' : '修改'}成功~`)
  207. visible.value = false
  208. updateParams()
  209. formOptions.value.formConfig.submitLoading = false
  210. } catch (e) {
  211. console.log(e)
  212. formOptions.value.formConfig.submitLoading = false
  213. }
  214. }
  215. const addHandler = () => {
  216. isCreate.value = true
  217. activeData.value = {}
  218. visible.value = true
  219. }
  220. nextTick(() => {
  221. queryList()
  222. })
  223. watch(groupFilterText, val => {
  224. treeRef.value!.filter(val)
  225. })
  226. </script>
  227. <style scoped lang="scss">
  228. .pageWrap {
  229. flex: 1;
  230. display: flex;
  231. height: 100%;
  232. //background: #fff;
  233. }
  234. .content-warp {
  235. flex: 1;
  236. //width: calc(100% - 250px);
  237. width: calc(100% - 210px);
  238. }
  239. // 单独自己写的
  240. /*:deep(.box-card) {
  241. height: 100%;
  242. .el-card__body {
  243. padding: 0;
  244. }
  245. }*/
  246. // 应用的树结构样式
  247. :deep(.menu-tree) {
  248. .el-tree-node__content {
  249. height: 36px;
  250. }
  251. .el-tree-node__content .el-tree-node__label .icon {
  252. margin-right: 5px;
  253. }
  254. }
  255. .nopadding {
  256. padding: 0px;
  257. }
  258. </style>