classification.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. <template>
  2. <div class="app-container">
  3. <HeadSearch :searchTerms="searchTerms" :ruleForm="searchRuleForm" @handleSearch="handleSearch"></HeadSearch>
  4. <tables :tableData="tableData" :operatingList="operatingList" :tableColumns="tableColumns"
  5. @operationBtn="operationBtn" @handleUpdate="handleUpdate"></tables>
  6. <!-- 新增/修改 -->
  7. <el-dialog v-model="dialogVisible" :title="formData.id === undefined ? '新增分类' : '修改分类'" @closed="resetForm"
  8. width="500px">
  9. <forms ref="childRules" :formNewList="classifyForm" :ruleForm="formData"></forms>
  10. <template #footer>
  11. <el-button @click="dialogVisible = false">取消</el-button>
  12. <el-button type="primary" @click="handleCreateOrUpdate" :loading="loading">确认</el-button>
  13. </template>
  14. </el-dialog>
  15. </div>
  16. </template>
  17. <script setup lang="ts">
  18. import { reactive, ref, watch } from "vue"
  19. import { createComponentclassApi, deleteComponentclassApi, updateComponentclassApi, getComponentclassApi } from "@/api/classify/index"
  20. import HeadSearch from "@/components/HeadSearch/index.vue"
  21. import tables from "@/components/tables/index.vue"
  22. import forms from "@/components/forms/index.vue"
  23. import { type CreateOrUpdateTableRequestData, type TableData } from "@/api/classify/types/index"
  24. import { type FormInstance, type FormRules, ElMessage, ElMessageBox } from "element-plus"
  25. import { Search, Refresh, CirclePlus, Delete, Download, RefreshRight } from "@element-plus/icons-vue"
  26. import { cloneDeep } from "lodash-es"
  27. const searchTerms = [{
  28. type: 'input',
  29. label: '名称',
  30. field: 'name',
  31. placeholder: '请输入组件名称',
  32. }]
  33. const searchRuleForm = {
  34. name: '',
  35. }
  36. const operatingList = [{
  37. id: 'add',
  38. typeStyle: 'primary',
  39. title: '新增分类',
  40. icon: CirclePlus,
  41. }, {
  42. id: 'del',
  43. typeStyle: 'danger',
  44. title: '删除分类',
  45. icon: Delete,
  46. }]
  47. const tableColumns = reactive([
  48. { prop: "selection", width: '50' },
  49. { prop: 'name', label: '分类名称' },
  50. {
  51. prop: 'action',
  52. label: '操作',
  53. labelButton: [{
  54. type: 'add',
  55. label: '新增分类',
  56. style: 'success',
  57. }, {
  58. type: 'edit',
  59. label: '编辑',
  60. style: 'primary',
  61. }, {
  62. type: 'del',
  63. label: '删除',
  64. style: 'danger',
  65. }]
  66. }
  67. ])
  68. const classifyForm = ref([{
  69. field: 'name',
  70. label: '分类名称',
  71. placeholder: '请输入分类名称',
  72. type: 'input',
  73. rules: [{
  74. required: true,
  75. message: '请输入分类名称',
  76. trigger: 'blur'
  77. }]
  78. }])
  79. const childRules = ref(null)
  80. const classifyList: any = ref({
  81. name: '',
  82. })
  83. //#region 增
  84. const DEFAULT_FORM_DATA: CreateOrUpdateTableRequestData = {
  85. id: undefined,
  86. name: "",
  87. parentId: 0
  88. }
  89. const formData = ref<CreateOrUpdateTableRequestData>(cloneDeep(DEFAULT_FORM_DATA))
  90. const dialogVisible = ref<boolean>(false)
  91. const operationBtn = (event) => {
  92. if (event.id == 'add') {
  93. dialogVisible.value = true
  94. }
  95. }
  96. const handleUpdate = (event, type) => {
  97. console.log(event, type, 77);
  98. if (type.type == 'add') {
  99. dialogVisible.value = true
  100. formData.value.parentId = event.ID
  101. } else if (type.type == 'edit') {
  102. dialogVisible.value = true
  103. formData.value.id = event.ID
  104. formData.value.name = event.name
  105. // formData.value.parentId = event.ID
  106. } else if (type.type == 'del') {
  107. handleDelete(event)
  108. }
  109. }
  110. const loading = ref<boolean>(false)
  111. const paginationData: any = ref({})
  112. const tableData = ref([])
  113. // 搜索
  114. const handleSearch = () => {
  115. getTableData()
  116. }
  117. // 列表查询
  118. const getTableData = () => {
  119. loading.value = true
  120. getComponentclassApi({
  121. currentPage: paginationData.currentPage,
  122. size: paginationData.pageSize,
  123. name: searchRuleForm.name,
  124. }).then((res: any) => {
  125. // console.log(res, 25);
  126. if (res.code == 200) {
  127. // paginationData.total = data.total
  128. tableData.value = res.data
  129. }
  130. }).catch(() => {
  131. tableData.value = []
  132. }).finally(() => {
  133. loading.value = false
  134. })
  135. }
  136. // 确定添加
  137. const handleCreateOrUpdate = async () => {
  138. let params = await childRules.value.validateForm()
  139. if (params) {
  140. loading.value = true
  141. console.log(formData.value, 24);
  142. const api = formData.value.id === undefined ? createComponentclassApi : updateComponentclassApi
  143. api(formData.value).then((res: any) => {
  144. if (res.code == 200) {
  145. ElMessage.success("操作成功")
  146. dialogVisible.value = false
  147. getTableData()
  148. }
  149. }).finally(() => {
  150. loading.value = false
  151. })
  152. }
  153. }
  154. //#region 删
  155. const handleDelete = (row: TableData) => {
  156. ElMessageBox.confirm(`正在删除组件分类:${row.name},确认删除?`, "提示", {
  157. confirmButtonText: "确定",
  158. cancelButtonText: "取消",
  159. type: "warning"
  160. }).then(() => {
  161. console.log(row, 776);
  162. deleteComponentclassApi({ id: row.ID }).then(() => {
  163. ElMessage.success("删除成功")
  164. getTableData()
  165. })
  166. })
  167. }
  168. const resetForm = () => {
  169. childRules.value?.cleardate()
  170. formData.value = cloneDeep(DEFAULT_FORM_DATA)
  171. }
  172. watch([() => paginationData.currentPage, () => paginationData.pageSize], getTableData, { immediate: true })
  173. </script>
  174. <style lang="scss" scoped></style>