index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581
  1. <template>
  2. <div class="pageWrap bgc">
  3. <div class="aside-box">
  4. <el-aside width="200px" style="height: 100%">
  5. <el-container style="height: 100%">
  6. <el-header>
  7. <el-input v-model="groupFilterText" placeholder="输入关键字进行过滤" clearable style="margin-top: 10px" />
  8. </el-header>
  9. <el-main style="flex-basis: 100%; padding: 0px">
  10. <el-tree
  11. ref="treeRef"
  12. class="menu-tree"
  13. :data="treeData"
  14. node-key="id"
  15. :current-node-key="''"
  16. :highlight-current="true"
  17. :expand-on-click-node="false"
  18. :props="{ label: 'name', children: 'children' }"
  19. default-expand-all
  20. :filter-node-method="filterNode"
  21. @node-click="leftTreeClick"
  22. >
  23. <template #default="{ node, data }">
  24. <span class="custom-tree-node">
  25. <span class="label">{{ node.label }}</span>
  26. <span v-if="false" class="code">{{ data.code }}</span>
  27. <span class="do">
  28. <el-icon @click.stop="addHandler('table')"><Plus /></el-icon>
  29. <el-icon @click.stop="dicEdit(data)"><Edit /></el-icon>
  30. <el-icon @click.stop="dictDel(node, data)"><Delete /></el-icon>
  31. </span>
  32. </span>
  33. </template>
  34. </el-tree>
  35. </el-main>
  36. <el-footer style="height: 51px">
  37. <el-button type="primary" style="width: 100%" @click="addHandler('tree')">
  38. <el-icon>
  39. <Plus />
  40. </el-icon>
  41. 表单分类
  42. </el-button>
  43. </el-footer>
  44. </el-container>
  45. </el-aside>
  46. </div>
  47. <div class="content-warp flex-column-page-wrap">
  48. <!-- 公用搜索组件 -->
  49. <LeSearchForm ref="searchForm" v-model:searchData="searchData" :forms="forms" :loading="tableOpts.options.loading"></LeSearchForm>
  50. <!-- LeTable 组件使用 -->
  51. <LeTable
  52. ref="tableRef"
  53. v-model:searchParams="tableOpts.searchParams"
  54. v-bind="tableOpts"
  55. v-model:curRow="tableOpts.curRow"
  56. v-model:checked-options="checkedColumns"
  57. :columns="activeColumns"
  58. >
  59. <template #toolLeft>
  60. <el-button type="primary" @click="addHandler('tableTemplate')">
  61. <el-icon class="btn-icon">
  62. <Plus />
  63. </el-icon>
  64. </el-button>
  65. <el-button type="danger" :disabled="curSelectionRows.length === 0" @click="batch_del">
  66. <el-icon class="btn-icon">
  67. <Delete />
  68. </el-icon>
  69. </el-button>
  70. </template>
  71. <template #filterAvatarSlot="scope">
  72. <el-avatar :src="scope.row.avatar" size="small"></el-avatar>
  73. </template>
  74. <template #statusSlot="{ row }">
  75. <status-indicator pulse :type="row.status === 1 ? 'success' : 'danger'"></status-indicator>
  76. </template>
  77. <template #actionSlot="{ row }">
  78. <div style="display: flex; align-items: center; justify-content: flex-end">
  79. <!--设计表单才有-->
  80. <template v-if="row.type === 0">
  81. <el-tooltip content="设计" placement="bottom" effect="light">
  82. <el-icon class="ibt0" @click="designTemplateEv(row)">
  83. <Money />
  84. </el-icon>
  85. </el-tooltip>
  86. <el-divider direction="vertical"></el-divider>
  87. </template>
  88. <el-tooltip content="编辑" placement="bottom" effect="light">
  89. <el-icon class="ibt0" @click="tableTemplateEdit(row)">
  90. <Edit />
  91. </el-icon>
  92. </el-tooltip>
  93. <el-divider direction="vertical"></el-divider>
  94. <el-popconfirm title="确定删除吗?" @confirm="deleteTemplateItem([row.id])">
  95. <template #reference>
  96. <el-icon class="ibt0">
  97. <Delete />
  98. </el-icon>
  99. </template>
  100. </el-popconfirm>
  101. </div>
  102. </template>
  103. </LeTable>
  104. </div>
  105. <LeFormConfigDialog
  106. v-if="visible"
  107. ref="dialogDictRef"
  108. v-model="visible"
  109. :title="`${isCreate ? '新增' : '编辑'}表单分类`"
  110. width="600px"
  111. :form-data="activeData"
  112. :form-options="formOptions"
  113. @submit="submitHandler"
  114. />
  115. <LeFormConfigDialog
  116. v-if="visibleTemplate"
  117. ref="dialogTemplateRef"
  118. v-model="visibleTemplate"
  119. :title="`${isCreate ? '新增' : '编辑'}表单模板`"
  120. width="600px"
  121. :form-data="activeDataTemplate"
  122. :form-options="formTemplateOptions"
  123. @submit="submitTemplateHandler"
  124. />
  125. <!-- 表单设计Dialog -->
  126. <design-form ref="designForm" v-model="visibleDesignForm" :record="recordObject" @success-fn="queryList"></design-form>
  127. </div>
  128. </template>
  129. <script lang="tsx" setup>
  130. import formCategory from '@/api/flow/formcategory'
  131. import formtemplate from '@/api/flow/formtemplate'
  132. import { computed, nextTick, ref, watch } from 'vue'
  133. import { ElMessage, ElTree, ElMessageBox } from 'element-plus'
  134. import { useTablePage } from '@/hooks/useTablePage'
  135. // import { Plus, Delete, Edit } from '@element-plus/icons-vue'
  136. import StatusIndicator from '@/components/StatusIndicator/index.vue'
  137. import DesignForm from './designForm.vue'
  138. import { statusOptions, templateForms, typeOptions, typeOptions_config } from './data.tsx'
  139. const visible = ref(false) // 弹窗显示隐藏
  140. const visibleTemplate = ref(false) // 弹窗显示隐藏
  141. const visibleDesignForm = ref(false) // 弹窗显示隐藏
  142. const isCreate = ref(true)
  143. const activeData = ref({})
  144. const recordObject = ref({})
  145. const activeDataTemplate = ref({})
  146. const current_mode = ref('') // 当前模式 (tree | table)
  147. const formsDialog = [
  148. {
  149. prop: 'pid',
  150. label: '所属分类',
  151. itemType: 'select',
  152. filterable: true,
  153. options: [],
  154. rules: [{ required: true, message: '请选择所属分类', trigger: 'blur' }]
  155. },
  156. {
  157. prop: 'name',
  158. label: '分类名称',
  159. itemType: 'input',
  160. rules: [{ required: true, message: '请输入分类名称', trigger: 'blur' }]
  161. },
  162. {
  163. prop: 'status',
  164. label: '状态',
  165. itemType: 'switch',
  166. activeText: '正常',
  167. inactiveText: '禁用'
  168. },
  169. {
  170. prop: 'sort',
  171. label: '排序',
  172. itemType: 'inputNumber',
  173. rules: [{ required: true, message: '请输入排序', trigger: 'blur' }]
  174. },
  175. {
  176. prop: 'remark',
  177. label: '备注',
  178. itemType: 'input'
  179. }
  180. ]
  181. // 新增的表单 和 编辑的表单
  182. const formOptions = computed(() => {
  183. let tempForm = []
  184. if (current_mode.value === 'tree') {
  185. for (let i in formsDialog) {
  186. let fd = formsDialog[i]
  187. if (fd.prop == 'pid') {
  188. continue
  189. }
  190. tempForm.push(fd)
  191. }
  192. } else {
  193. tempForm = formsDialog
  194. }
  195. return {
  196. forms: tempForm,
  197. labelWidth: 120,
  198. span: 30,
  199. showResetBtn: true,
  200. formConfig: {
  201. showCancelBtn: true,
  202. submitLoading: false
  203. }
  204. }
  205. })
  206. const showGroupLoading = ref(false)
  207. const groupFilterText = ref('')
  208. const treeRef = ref<InstanceType<typeof ElTree>>()
  209. // 新增的表单模板 和 编辑的表单模板
  210. const formTemplateOptions = computed(() => {
  211. return {
  212. forms: templateForms,
  213. labelWidth: 120,
  214. span: 30,
  215. showResetBtn: true,
  216. formConfig: {
  217. showCancelBtn: true,
  218. submitLoading: false
  219. }
  220. }
  221. })
  222. const filterNode = (value: string, data: Tree) => {
  223. if (!value) return true
  224. return data.name.includes(value)
  225. }
  226. const treeData = ref([])
  227. // 将树形结构扁平化
  228. const treeForArr = data => {
  229. const flattened = []
  230. for (const item of data) {
  231. flattened.push(item)
  232. if (item.children && item.children.length > 0) {
  233. flattened.push(...treeForArr(item.children))
  234. }
  235. }
  236. return flattened
  237. }
  238. // 获取左侧菜单数据
  239. const getGroup = async () => {
  240. showGroupLoading.value = true
  241. let data = await formCategory.formCategoryListTreeApi({})
  242. if (data) {
  243. formOptions.value.forms[0].options = treeForArr(data).map(item => {
  244. return { value: item.id, label: item.name }
  245. })
  246. formTemplateOptions.value.forms[0].options = treeForArr(data).map(item => {
  247. return { value: item.id, label: item.name }
  248. })
  249. showGroupLoading.value = false
  250. treeData.value = [{ id: '', name: '所有', children: data }]
  251. // treeData.value = data
  252. }
  253. }
  254. // 左侧菜单点击
  255. const leftTreeClick = data => {
  256. searchData.value = { ...searchData.value, formCategoryId: data.id ? data.id : null }
  257. }
  258. // 表格搜索条件
  259. const forms = ref([
  260. {
  261. prop: 'name',
  262. label: '名称:',
  263. itemType: 'input',
  264. placeholder: '请输入名称'
  265. },
  266. {
  267. prop: 'type',
  268. label: '类型:',
  269. itemType: 'select',
  270. placeholder: '请选择类型',
  271. options: typeOptions
  272. },
  273. {
  274. prop: 'status',
  275. label: '状态:',
  276. itemType: 'select',
  277. placeholder: '请选择状态',
  278. options: statusOptions
  279. }
  280. ])
  281. // table列表数据请求
  282. const queryList = async () => {
  283. const { options, searchParams } = tableOpts
  284. options.loading = true
  285. try {
  286. const { records: list, total } = await formtemplate.formTemplatePageApi(searchParams)
  287. tableOpts.total = total
  288. tableOpts.list = list
  289. } catch {
  290. tableOpts.total = 0
  291. tableOpts.list = []
  292. } finally {
  293. options.loading = false
  294. }
  295. }
  296. // table 参数
  297. const columns = [
  298. {
  299. prop: 'name',
  300. label: '模板名称',
  301. minWidth: 80
  302. },
  303. {
  304. prop: 'code',
  305. label: '编码',
  306. minWidth: 150
  307. },
  308. {
  309. prop: 'type',
  310. label: '类型',
  311. minWidth: 100,
  312. formatter: (row, column, cellValue) => {
  313. return typeOptions_config[cellValue] || '-'
  314. }
  315. },
  316. {
  317. prop: 'status',
  318. label: '状态',
  319. minWidth: 50,
  320. slots: {
  321. default: 'statusSlot'
  322. }
  323. },
  324. {
  325. prop: 'remark',
  326. label: '备注',
  327. minWidth: 100
  328. },
  329. {
  330. prop: 'sort',
  331. label: '排序',
  332. minWidth: 50
  333. },
  334. {
  335. prop: 'action',
  336. label: '操作',
  337. width: 100,
  338. fixed: 'right',
  339. slots: {
  340. default: 'actionSlot'
  341. }
  342. }
  343. ]
  344. const { searchData, tableOpts, checkedColumns, activeColumns, curSelectionRows, updateParams } = useTablePage(
  345. {
  346. options: {
  347. showIndex: false
  348. },
  349. // 需要展示的列
  350. columns,
  351. // 控制列配置
  352. columnsConfig: {
  353. columns
  354. }
  355. },
  356. {
  357. queryList,
  358. fetchImmediate: false
  359. }
  360. )
  361. // 删除
  362. const deleteItem = async ids => {
  363. await formCategory.formCategoryDeleteApi(ids)
  364. if (current_mode.value === 'tree') {
  365. getGroup()
  366. }
  367. updateParams()
  368. ElMessage.success(`删除成功~`)
  369. }
  370. // 单个删除
  371. const table_del = row => {
  372. deleteItem([row.id])
  373. }
  374. //批量删除
  375. const batch_del = () => {
  376. const ids = curSelectionRows.value.map(item => item.id) // 多选数据
  377. ElMessageBox.confirm('是否删除选中数据?', '提示', {
  378. confirmButtonText: '确认',
  379. cancelButtonText: '取消',
  380. type: 'error',
  381. buttonSize: 'default'
  382. }).then(() => {
  383. deleteTemplateItem(ids)
  384. })
  385. }
  386. const table_edit = async row => {
  387. isCreate.value = false
  388. activeData.value = { ...row, status: row.status ? true : false }
  389. visible.value = true
  390. }
  391. const tableTemplateEdit = async row => {
  392. isCreate.value = false
  393. activeDataTemplate.value = { ...row, status: row.status ? true : false }
  394. visibleTemplate.value = true
  395. }
  396. const designTemplateEv = async row => {
  397. recordObject.value = { ...row }
  398. visibleDesignForm.value = true
  399. }
  400. const deleteTemplateItem = async ids => {
  401. await formtemplate.formTemplateDeleteApi(ids)
  402. updateParams()
  403. ElMessage.success(`删除成功~`)
  404. }
  405. // 弹窗事件
  406. const submitHandler = async params => {
  407. try {
  408. formOptions.value.formConfig.submitLoading = true
  409. console.log('------activeData----', activeData.value)
  410. params.status = params.status ? 1 : 0
  411. if (activeData.value.id) {
  412. params.id = activeData.value.id
  413. } else {
  414. params.pid = 0
  415. }
  416. await formCategory.formCategoryAddOrEditSaveApi(params)
  417. ElMessage.success(`${isCreate.value ? '新增' : '修改'}成功~`)
  418. visible.value = false
  419. getGroup()
  420. // updateParams()
  421. } finally {
  422. formOptions.value.formConfig.submitLoading = false
  423. }
  424. }
  425. // 模板弹窗
  426. const submitTemplateHandler = async params => {
  427. try {
  428. formTemplateOptions.value.formConfig.submitLoading = true
  429. params.status = params.status ? 1 : 0
  430. console.log('------activeDataTemplate-----', activeDataTemplate)
  431. params.id = activeDataTemplate.value.id ? activeDataTemplate.value.id : null
  432. await formtemplate.formTemplateAddOrEditSaveApi(params)
  433. ElMessage.success(`${isCreate.value ? '新增' : '修改'}成功~`)
  434. visibleTemplate.value = false
  435. updateParams()
  436. } finally {
  437. formTemplateOptions.value.formConfig.submitLoading = false
  438. }
  439. }
  440. const addHandler = mode => {
  441. isCreate.value = true
  442. if (mode !== 'tableTemplate') {
  443. activeData.value = {
  444. status: true
  445. }
  446. visible.value = true
  447. current_mode.value = mode
  448. } else {
  449. activeDataTemplate.value = {
  450. // 设计表单
  451. type: 0,
  452. status: true
  453. }
  454. visibleTemplate.value = true
  455. }
  456. }
  457. // 删除左侧树
  458. const dictDel = (node, data) => {
  459. current_mode.value = 'tree'
  460. ElMessageBox.confirm(`确定删除 ${data.name} 项吗?`, '提示')
  461. .then(async () => {
  462. // try {
  463. deleteItem([data.id])
  464. // } catch (e) {
  465. // ElMessage.error(`删除失败~`)
  466. // }
  467. })
  468. .catch(() => {})
  469. }
  470. const dicEdit = data => {
  471. current_mode.value = data.pid !== '0' ? 'table' : 'tree'
  472. table_edit(data)
  473. }
  474. nextTick(() => {
  475. getGroup()
  476. queryList()
  477. })
  478. watch(groupFilterText, val => {
  479. treeRef.value!.filter(val)
  480. })
  481. watch(
  482. treeData.value,
  483. val => {
  484. formOptions.value.forms[0].options = treeForArr(val).map(item => {
  485. return { value: item.id, label: item.name }
  486. })
  487. formTemplateOptions.value.forms[0].options = treeForArr(val).map(item => {
  488. return { value: item.id, label: item.name }
  489. })
  490. },
  491. { immediate: true }
  492. )
  493. </script>
  494. <style scoped lang="scss">
  495. // 表单的树结构样式
  496. :deep(.menu-tree) {
  497. .el-tree-node {
  498. //&:first-child {
  499. // .custom-tree-node {
  500. // .do {
  501. // display: none !important;
  502. // }
  503. // }
  504. //}
  505. }
  506. }
  507. .custom-tree-node {
  508. display: flex;
  509. flex: 1;
  510. align-items: center;
  511. justify-content: space-between;
  512. font-size: 14px;
  513. padding-right: 24px;
  514. height: 100%;
  515. }
  516. .custom-tree-node .code {
  517. font-size: 12px;
  518. color: #999;
  519. }
  520. .custom-tree-node {
  521. .do {
  522. display: none;
  523. }
  524. }
  525. .custom-tree-node .do i {
  526. margin-left: 3px;
  527. color: #999;
  528. padding: 3px;
  529. font-size: 20px;
  530. }
  531. .custom-tree-node .do i:hover {
  532. color: #333;
  533. }
  534. .custom-tree-node {
  535. &:hover {
  536. .code {
  537. display: none;
  538. }
  539. }
  540. }
  541. .custom-tree-node:hover .do {
  542. display: inline-block;
  543. }
  544. </style>