index.vue 13 KB

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