index.vue 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. <template>
  2. <div class="p-2">
  3. <transition :enter-active-class="proxy?.animate.searchAnimate.enter" :leave-active-class="proxy?.animate.searchAnimate.leave">
  4. <div v-show="showSearch" class="search">
  5. <el-form ref="queryFormRef" :model="queryParams" :inline="true">
  6. <el-form-item label="分类名称" prop="categoryName">
  7. <el-input v-model="queryParams.categoryName" placeholder="请输入分类名称" clearable @keyup.enter="handleQuery" />
  8. </el-form-item>
  9. <el-form-item label="分类编码" prop="categoryCode">
  10. <el-input v-model="queryParams.categoryCode" placeholder="请输入分类编码" clearable @keyup.enter="handleQuery" />
  11. </el-form-item>
  12. <el-form-item>
  13. <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
  14. <el-button icon="Refresh" @click="resetQuery">重置</el-button>
  15. </el-form-item>
  16. </el-form>
  17. </div>
  18. </transition>
  19. <el-card shadow="never">
  20. <template #header>
  21. <el-row :gutter="10" class="mb8">
  22. <el-col :span="1.5">
  23. <el-button v-hasPermi="['workflow:category:add']" type="primary" plain icon="Plus" @click="handleAdd()">新增</el-button>
  24. </el-col>
  25. <el-col :span="1.5">
  26. <el-button type="info" plain icon="Sort" @click="handleToggleExpandAll">展开/折叠</el-button>
  27. </el-col>
  28. <right-toolbar v-model:show-search="showSearch" @query-table="getList"></right-toolbar>
  29. </el-row>
  30. </template>
  31. <el-table
  32. ref="categoryTableRef"
  33. v-loading="loading"
  34. :data="categoryList"
  35. row-key="id"
  36. :default-expand-all="isExpandAll"
  37. :tree-props="{ children: 'children', hasChildren: 'hasChildren' }"
  38. >
  39. <el-table-column label="分类名称" prop="categoryName" />
  40. <el-table-column label="分类编码" align="center" prop="categoryCode" />
  41. <el-table-column label="排序" align="center" prop="sortNum" />
  42. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  43. <template #default="scope">
  44. <el-tooltip content="修改" placement="top">
  45. <el-button v-hasPermi="['workflow:category:edit']" link type="primary" icon="Edit" @click="handleUpdate(scope.row)" />
  46. </el-tooltip>
  47. <el-tooltip content="新增" placement="top">
  48. <el-button v-hasPermi="['workflow:category:add']" link type="primary" icon="Plus" @click="handleAdd(scope.row)" />
  49. </el-tooltip>
  50. <el-tooltip content="删除" placement="top">
  51. <el-button v-hasPermi="['workflow:category:remove']" link type="primary" icon="Delete" @click="handleDelete(scope.row)" />
  52. </el-tooltip>
  53. </template>
  54. </el-table-column>
  55. </el-table>
  56. </el-card>
  57. <!-- 添加或修改流程分类对话框 -->
  58. <el-dialog v-model="dialog.visible" :title="dialog.title" width="500px" append-to-body>
  59. <el-form ref="categoryFormRef" v-loading="loading" :model="form" :rules="rules" label-width="80px">
  60. <el-form-item label="父级分类" prop="parentId">
  61. <el-tree-select
  62. v-model="form.parentId"
  63. :data="categoryOptions"
  64. :props="{ value: 'id', label: 'categoryName', children: 'children' }"
  65. value-key="id"
  66. placeholder="请选择父级id"
  67. check-strictly
  68. />
  69. </el-form-item>
  70. <el-form-item label="分类名称" prop="categoryName">
  71. <el-input v-model="form.categoryName" placeholder="请输入分类名称" />
  72. </el-form-item>
  73. <el-form-item label="分类编码" prop="categoryCode">
  74. <el-input v-model="form.categoryCode" placeholder="请输入分类编码" />
  75. </el-form-item>
  76. <el-form-item label="排序" prop="sortNum">
  77. <el-input-number v-model="form.sortNum" placeholder="请输入排序" controls-position="right" :min="0" />
  78. </el-form-item>
  79. </el-form>
  80. <template #footer>
  81. <div class="dialog-footer">
  82. <el-button :loading="buttonLoading" type="primary" @click="submitForm">确 定</el-button>
  83. <el-button @click="cancel">取 消</el-button>
  84. </div>
  85. </template>
  86. </el-dialog>
  87. </div>
  88. </template>
  89. <script setup name="Category" lang="ts">
  90. import { listCategory, getCategory, delCategory, addCategory, updateCategory } from '@/api/workflow/category';
  91. import { CategoryVO, CategoryQuery, CategoryForm } from '@/api/workflow/category/types';
  92. type CategoryOption = {
  93. id: number;
  94. categoryName: string;
  95. children?: CategoryOption[];
  96. };
  97. const { proxy } = getCurrentInstance() as ComponentInternalInstance;
  98. const categoryList = ref<CategoryVO[]>([]);
  99. const categoryOptions = ref<CategoryOption[]>([]);
  100. const buttonLoading = ref(false);
  101. const showSearch = ref(true);
  102. const isExpandAll = ref(true);
  103. const loading = ref(false);
  104. const queryFormRef = ref<ElFormInstance>();
  105. const categoryFormRef = ref<ElFormInstance>();
  106. const categoryTableRef = ref<ElTableInstance>();
  107. const dialog = reactive<DialogOption>({
  108. visible: false,
  109. title: ''
  110. });
  111. const initFormData: CategoryForm = {
  112. id: undefined,
  113. categoryName: undefined,
  114. categoryCode: undefined,
  115. parentId: undefined,
  116. sortNum: 0
  117. };
  118. const data = reactive<PageData<CategoryForm, CategoryQuery>>({
  119. form: { ...initFormData },
  120. queryParams: {
  121. pageNum: 1,
  122. pageSize: 10,
  123. categoryName: undefined,
  124. categoryCode: undefined
  125. },
  126. rules: {
  127. id: [{ required: true, message: '主键不能为空', trigger: 'blur' }],
  128. categoryName: [{ required: true, message: '分类名称不能为空', trigger: 'blur' }],
  129. categoryCode: [{ required: true, message: '分类编码不能为空', trigger: 'blur' }],
  130. parentId: [{ required: true, message: '父级id不能为空', trigger: 'blur' }]
  131. }
  132. });
  133. const { queryParams, form, rules } = toRefs(data);
  134. /** 查询流程分类列表 */
  135. const getList = async () => {
  136. loading.value = true;
  137. const res = await listCategory(queryParams.value);
  138. const data = proxy?.handleTree<CategoryVO>(res.data, 'id', 'parentId');
  139. if (data) {
  140. categoryList.value = data;
  141. loading.value = false;
  142. }
  143. };
  144. /** 查询流程分类下拉树结构 */
  145. const getTreeselect = async () => {
  146. const res = await listCategory();
  147. categoryOptions.value = [];
  148. const data: CategoryOption = { id: 0, categoryName: '顶级节点', children: [] };
  149. data.children = proxy?.handleTree<CategoryOption>(res.data, 'id', 'parentId');
  150. categoryOptions.value.push(data);
  151. };
  152. // 取消按钮
  153. const cancel = () => {
  154. reset();
  155. dialog.visible = false;
  156. };
  157. // 表单重置
  158. const reset = () => {
  159. form.value = { ...initFormData };
  160. categoryFormRef.value?.resetFields();
  161. };
  162. /** 搜索按钮操作 */
  163. const handleQuery = () => {
  164. getList();
  165. };
  166. /** 重置按钮操作 */
  167. const resetQuery = () => {
  168. queryFormRef.value?.resetFields();
  169. handleQuery();
  170. };
  171. /** 新增按钮操作 */
  172. const handleAdd = (row?: CategoryVO) => {
  173. dialog.visible = true;
  174. dialog.title = '添加流程分类';
  175. nextTick(() => {
  176. reset();
  177. getTreeselect();
  178. if (row != null && row.id) {
  179. form.value.parentId = row.id;
  180. } else {
  181. form.value.parentId = 0;
  182. }
  183. });
  184. };
  185. /** 展开/折叠操作 */
  186. const handleToggleExpandAll = () => {
  187. isExpandAll.value = !isExpandAll.value;
  188. toggleExpandAll(categoryList.value, isExpandAll.value);
  189. };
  190. /** 展开/折叠操作 */
  191. const toggleExpandAll = (data: CategoryVO[], status: boolean) => {
  192. data.forEach((item) => {
  193. categoryTableRef.value?.toggleRowExpansion(item, status);
  194. if (item.children && item.children.length > 0) toggleExpandAll(item.children, status);
  195. });
  196. };
  197. /** 修改按钮操作 */
  198. const handleUpdate = (row: CategoryVO) => {
  199. loading.value = true;
  200. dialog.visible = true;
  201. dialog.title = '修改流程分类';
  202. nextTick(async () => {
  203. reset();
  204. await getTreeselect();
  205. if (row != null) {
  206. form.value.parentId = row.id;
  207. }
  208. const res = await getCategory(row.id);
  209. loading.value = false;
  210. Object.assign(form.value, res.data);
  211. });
  212. };
  213. /** 提交按钮 */
  214. const submitForm = () => {
  215. categoryFormRef.value.validate(async (valid: boolean) => {
  216. if (valid) {
  217. buttonLoading.value = true;
  218. if (form.value.id) {
  219. await updateCategory(form.value).finally(() => (buttonLoading.value = false));
  220. } else {
  221. await addCategory(form.value).finally(() => (buttonLoading.value = false));
  222. }
  223. proxy?.$modal.msgSuccess('操作成功');
  224. dialog.visible = false;
  225. await getList();
  226. }
  227. });
  228. };
  229. /** 删除按钮操作 */
  230. const handleDelete = async (row: CategoryVO) => {
  231. await proxy?.$modal.confirm('是否确认删除流程分类编号为"' + row.id + '"的数据项?');
  232. loading.value = true;
  233. await delCategory(row.id).finally(() => (loading.value = false));
  234. await getList();
  235. proxy?.$modal.msgSuccess('删除成功');
  236. };
  237. onMounted(() => {
  238. getList();
  239. });
  240. </script>