index.vue 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. <template>
  2. <page-layout-list :no-padding="layoutNoPadding" :compact="layoutCompact">
  3. <template #filter v-if="withSearch">
  4. <cip-search-form v-model:model="searchFilter"
  5. v-model:defaultModel="defaultSearchModel"
  6. :field-list="searchFieldList"
  7. @search="search" />
  8. </template>
  9. <template #handle v-if="withHandle">
  10. <slot name="handle-buttons" :create-item="createItem" :get-item-list="getItemList"></slot>
  11. <template v-if="withCreate">
  12. <cip-judge-privilege :privilege="permission.create">
  13. <cip-button button-type="create" @click="createItem(outParams)"></cip-button>
  14. </cip-judge-privilege>
  15. </template>
  16. <template v-if="batchDelete">
  17. <cip-judge-privilege :privilege="permission.batchDelete ?? permission.delete">
  18. <cip-button v-if="batchDelete" button-type="batchDelete" @click="deleteItemList(getSelectRows)"></cip-button>
  19. </cip-judge-privilege>
  20. </template>
  21. </template>
  22. <slot></slot>
  23. <!-- 从handle中去除 原因:withHandle false 将导致table内的 关于弹窗的按钮无法使用-->
  24. <cip-dialog v-model="itemDialog" :width="dialogWidth" :on-confirm="saveItem" :title="dialogTitle" :show-only="showOnly">
  25. <cip-form :label-width="formLabelWidth"
  26. v-model:model="item"
  27. :grid="formGrid"
  28. :label-suffix="formLabelSuffix"
  29. :show-only="showOnly"
  30. :field-list="saveFormFieldList"></cip-form>
  31. <template #footer="{confirm,loading,cancel}" v-if="$slots['dialog-handle']">
  32. <slot name="dialog-handle" v-bind="{confirm,loading,cancel}" :model="item" :get-item-list="getItemList"></slot>
  33. </template>
  34. </cip-dialog>
  35. <cip-table :data="itemList"
  36. :columns="tableColumns"
  37. ref="tableRef"
  38. size="small"
  39. :default-expand-all="defaultExpandAll"
  40. :row-key="tableRowKey"
  41. :tree-props="tableTreeProps"
  42. :offset="withIndex ? offset : undefined"
  43. :select-type="selectType"
  44. :selectable="tableSelectable"
  45. v-bind="tableAttrs"
  46. @sort="sortChange"
  47. v-loading="listLoading"
  48. :handlerWidth="tableHandleWidth"
  49. :withTableHandle="withTableHandle">
  50. <slot name="table-slots"></slot>
  51. <!-- <el-table-column label="操作" :width="tableHandleWidth" v-if="withTableHandle" fixed="right">-->
  52. <!-- <template #default="scope">-->
  53. <template #_handler="scope">
  54. <slot name="table-handle-prepend" v-bind="scope" :get-item-list="getItemList"></slot>
  55. <slot name="table-handle"
  56. v-bind="scope"
  57. :show-item="showItem"
  58. :delete-item="deleteItem"
  59. :edit-item="editItem"
  60. :get-item-list="getItemList">
  61. <cip-judge-privilege :privilege="permission.info">
  62. <cip-table-button @click="showItem(scope.row, fetchInfo)">查看</cip-table-button>
  63. </cip-judge-privilege>
  64. <cip-judge-privilege :privilege="permission.update">
  65. <cip-table-button @click="editItem(scope.row, fetchInfo)">修改</cip-table-button>
  66. </cip-judge-privilege>
  67. <template v-if="withTableDeleteButton &&(!judgeTableDeleteButtonFn || (judgeTableDeleteButtonFn && judgeTableDeleteButtonFn(scope)))" >
  68. <cip-judge-privilege :privilege="permission.delete">
  69. <cip-table-button type="danger" @click="deleteItem(scope.row)">删除</cip-table-button>
  70. </cip-judge-privilege>
  71. </template>
  72. </slot>
  73. <slot name="table-handle-append" v-bind="scope" :get-item-list="getItemList"></slot>
  74. </template>
  75. </cip-table>
  76. <!-- </template>-->
  77. <!-- </el-table-column>-->
  78. <template #pagination v-if="withPagination">
  79. <cip-pagination v-model:offset="offset"
  80. v-model:limit="limit"
  81. :total="total"
  82. :current-page="currentPage"
  83. :pageSizes="pageSizes"
  84. @refresh="getItemList"></cip-pagination>
  85. </template>
  86. </page-layout-list>
  87. </template>
  88. <script>
  89. import { computed, defineComponent, onActivated, ref } from 'vue'
  90. import { ElLoading } from 'element-plus'
  91. import PageLayoutList from '@cip/components/page-layout/list'
  92. import CipSearchForm from '@cip/components/cip-search-form'
  93. import CipForm from '@cip/components/cip-form'
  94. import CipButton from '@cip/components/cip-button'
  95. import CipDialog from '@cip/components/cip-dialog'
  96. import CipTable from '@cip/components/cip-table'
  97. import CipTableButton from '@cip/components/cip-table-button'
  98. import CipPagination from '@cip/components/cip-pagination'
  99. import CipJudgePrivilege from '@cip/components/cip-judge-privilege'
  100. import { useCurd } from '@cip/hooks/use-curd'
  101. import pageCurdProps from './props'
  102. export default defineComponent({
  103. name: 'CipPageCurd',
  104. components: {
  105. PageLayoutList,
  106. CipSearchForm,
  107. CipPagination,
  108. CipTable,
  109. CipForm,
  110. CipButton,
  111. CipDialog,
  112. CipTableButton,
  113. CipJudgePrivilege
  114. },
  115. directives: {
  116. loading: ElLoading.directive
  117. },
  118. props: pageCurdProps,
  119. setup (props) {
  120. const tableRef = ref()
  121. const CURD = useCurd(props.entity, { ...props.curdFn, itemType: props.itemType })
  122. const { searchFilter, getItemList } = CURD
  123. const defaultSearchModel = ref({ ...props.outParams, ...props.defaultSearchFilter })
  124. searchFilter.value = { ...defaultSearchModel.value, ...searchFilter.value }
  125. // if (props.cache) {
  126. onActivated(() => {
  127. getItemList()
  128. })
  129. if (!props.autoSelected) { // 如果搜索中有autoSelect的字段则传true,避免请求两次数据不一致导致页面“跳动”
  130. getItemList()
  131. }
  132. // } else {
  133. // if (!props.autoSelected) { // 如果搜索中有autoSelect的字段则传true,避免请求两次数据不一致导致页面“跳动”
  134. // getItemList()
  135. // }
  136. // }
  137. // 计算列表是否需要select
  138. const selectType = computed(() => {
  139. if (props.batchDelete) return 'checkbox'
  140. return props.tableSelectType
  141. // return undefined
  142. })
  143. const getSelectRows = () => { // 返回值 Ref<T[]>
  144. return tableRef.value.cipTableRef.value.store.states.selection
  145. }
  146. // 外层触发请求
  147. const getTableList = (item = {}) => {
  148. searchFilter.value = item
  149. getItemList()
  150. }
  151. const sortChange = ({ prop, order }) => {
  152. searchFilter.value = { ...searchFilter.value, ...{ orderBy: prop, orderAsc: order === 'ascending' } }
  153. getItemList()
  154. }
  155. const saveFormFieldList = computed(() => {
  156. if (props.updateFormFieldList) { // 如果存在updateFormFieldList则对当前进行判断
  157. return CURD.isUpdate.value ? props.updateFormFieldList : props.formFieldList
  158. } else {
  159. return props.formFieldList
  160. }
  161. })
  162. return {
  163. ...CURD,
  164. ...props.componentData, // 覆盖默认配置
  165. tableRef,
  166. saveFormFieldList,
  167. selectType,
  168. getSelectRows,
  169. getTableList,
  170. sortChange,
  171. defaultSearchModel
  172. }
  173. }
  174. })
  175. </script>