NormalTable.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. <template>
  2. <div style="height: 100%">
  3. <BasicTable @register="registerTable">
  4. <!-- <template #tableTitle>
  5. <a-button preIcon="ant-design:plus-outlined" type="primary" @click="handleAdd">新增</a-button>
  6. </template> -->
  7. <template #action="{ record }">
  8. <TableAction :actions="getActions(record)" :dropDownActions="getDropDownAction(record)" />
  9. </template>
  10. <template #bodyCell="{ column, record }">
  11. <slot name="filterCell" v-bind="{ column, record }"></slot>
  12. </template>
  13. </BasicTable>
  14. <DeviceModal @register="registerModal" @saveOrUpdate="saveOrUpdateHandler" :deviceType="deviceType" />
  15. </div>
  16. </template>
  17. <script lang="ts" name="system-user" setup>
  18. //ts语法
  19. import { ref, provide, reactive, toRaw, defineExpose } from 'vue';
  20. import { BasicTable, TableAction } from '/@/components/Table';
  21. import { useModal } from '/@/components/Modal';
  22. import DeviceModal from './DeviceModal.vue';
  23. import { getTableHeaderColumns } from '/@/hooks/web/useWebColumns';
  24. import { useListPage } from '/@/hooks/system/useListPage';
  25. const props = defineProps({
  26. columnsType: {
  27. type: String,
  28. // required: true,
  29. },
  30. columns: {
  31. type: Array,
  32. // required: true,
  33. default: () => [],
  34. },
  35. searchFormSchema: {
  36. type: Array,
  37. required: true,
  38. default: () => [],
  39. },
  40. formSchema: {
  41. type: Array,
  42. required: true,
  43. },
  44. list: {
  45. type: Function,
  46. required: true,
  47. },
  48. deleteById: {
  49. type: Function,
  50. required: true,
  51. },
  52. saveOrUpdate: {
  53. type: Function,
  54. required: true,
  55. },
  56. pointList: {
  57. type: Function,
  58. // required: true,
  59. },
  60. designScope: {
  61. type: String,
  62. },
  63. title: {
  64. type: String,
  65. },
  66. deviceType: {
  67. type: String,
  68. },
  69. });
  70. const isUpdate = ref(false);
  71. const record = reactive({});
  72. provide('formSchema', props.formSchema);
  73. provide('isUpdate', isUpdate);
  74. provide('formData', record);
  75. provide('deviceType', props.deviceType);
  76. // const glob = useGlobSetting();
  77. const [registerModal, { openModal, closeModal }] = useModal();
  78. const columnList = getTableHeaderColumns(props.columnsType);
  79. console.log('aaa', columnList);
  80. // 列表页面公共参数、方法
  81. const { tableContext, doRequest } = useListPage({
  82. designScope: props.designScope,
  83. tableProps: {
  84. title: props.title,
  85. api: props.list,
  86. columns: props.columns.length > 0 ? (props.columns as any[]) : columnList,
  87. // size: 'small',
  88. bordered: false,
  89. // formConfig: {
  90. // // labelWidth: 100,
  91. // labelAlign: 'left',
  92. // labelCol: {
  93. // xs: 24,
  94. // sm: 24,
  95. // md: 24,
  96. // lg: 9,
  97. // xl: 7,
  98. // xxl: 5,
  99. // },
  100. // schemas: props.searchFormSchema as any[],
  101. // },
  102. striped: true,
  103. showIndexColumn: true, //是否显示序列号
  104. actionColumn: {
  105. width: 300,
  106. },
  107. useSearchForm: false, //不使用查询条件
  108. pagination: false, //不使用分页组件
  109. beforeFetch: (params) => {
  110. params.parentId = '';
  111. params.selectFlag = true;
  112. params.likeFileName = '';
  113. // return Object.assign({ column: '111', order: 'd11' }, params);
  114. // return Object.assign({ parentId: '', selectFlag: true, likeFileName: '' }, params);
  115. },
  116. },
  117. });
  118. //注册table数据
  119. const [registerTable, { reload }, { selectedRowKeys }] = tableContext;
  120. const saveOrUpdateHandler = async (params) => {
  121. try {
  122. await props.saveOrUpdate(params, isUpdate.value);
  123. closeModal();
  124. await doRequest(props.list, { confirm: false });
  125. } catch (error) {
  126. message.error('保存失败,请联系管理员');
  127. }
  128. };
  129. /**
  130. * 新增事件
  131. */
  132. function handleAdd() {
  133. for (let key in record) {
  134. delete record[key];
  135. }
  136. isUpdate.value = false;
  137. openModal(true);
  138. }
  139. /**
  140. * 编辑事件
  141. */
  142. function handleEdit(data) {
  143. isUpdate.value = true;
  144. Object.assign(record, toRaw(data));
  145. openModal(true, {
  146. record,
  147. });
  148. }
  149. /**
  150. * 删除事件
  151. */
  152. async function handleDelete(record) {
  153. await props.deleteById({ id: record }, reload);
  154. }
  155. /**
  156. * 查看
  157. */
  158. // function handleDetail(record) {
  159. // iframeUrl.value = `${glob.uploadUrl}/sys/annountCement/show/${record.id}?token=${getToken()}`;
  160. // openDetail(true);
  161. // }
  162. /**
  163. * 操作列定义
  164. * @param record
  165. */
  166. function getActions(record) {
  167. return [
  168. {
  169. label: '详情',
  170. onClick: handleEdit.bind(null, record),
  171. },
  172. {
  173. label: '编辑',
  174. onClick: handleEdit.bind(null, record),
  175. },
  176. {
  177. label: '删除',
  178. popConfirm: {
  179. title: '是否确认删除',
  180. confirm: handleDelete.bind(null, record),
  181. },
  182. },
  183. {
  184. label: '下载',
  185. onClick: handleEdit.bind(null, record),
  186. },
  187. {
  188. label: '审批',
  189. onClick: handleEdit.bind(null, record),
  190. },
  191. // {
  192. // label: '查看',
  193. // onClick: handleDetail.bind(null, record),
  194. // },
  195. ];
  196. }
  197. /**
  198. * 下拉操作栏
  199. */
  200. function getDropDownAction(record) {
  201. return [
  202. // {
  203. // label: '删除',
  204. // popConfirm: {
  205. // title: '是否确认删除',
  206. // confirm: handleDelete.bind(null, record),
  207. // },
  208. // },
  209. // {
  210. // label: '查看',
  211. // onClick: handleDetail.bind(null, record),
  212. // },
  213. ];
  214. }
  215. defineExpose({
  216. doRequest,
  217. });
  218. </script>
  219. <style scoped lang="less">
  220. @ventSpace: zxm;
  221. @vent-table-no-hover: rgba(43, 135, 255, 0.1);
  222. @vent-table-hover: rgba(53, 147, 255, 0.2);
  223. :deep(.zxm-table-row) {
  224. td {
  225. background-color: @vent-table-hover !important;
  226. }
  227. }
  228. :deep(.jeecg-basic-table-row__striped) {
  229. td {
  230. background-color: @vent-table-no-hover !important;
  231. }
  232. }
  233. ::v-deep .zxm-table-title {
  234. display: none;
  235. }
  236. ::v-deep .zxm-table-thead > tr > th {
  237. border-top: 0px !important;
  238. border-left: 0px !important;
  239. border-right: 0px !important;
  240. border-bottom: 1px solid #268bc1 !important;
  241. color: #3beff9 !important;
  242. }
  243. ::v-deep .zxm-table-tbody > tr > td {
  244. border: none;
  245. }
  246. ::v-deep .zxm-table-thead {
  247. background: linear-gradient(to bottom, transparent, rgba(53, 147, 255, 0.5)) !important;
  248. }
  249. </style>