NormalTable.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. <template>
  2. <div>
  3. <BasicTable @register="registerTable" :rowSelection="rowSelection">
  4. <template #tableTitle>
  5. <a-button preIcon="ant-design:plus-outlined" type="primary" @click="handleAdd">新增</a-button>
  6. <a-button type="primary" preIcon="ant-design:export-outlined" @click="onExportXls"> 导出</a-button>
  7. <j-upload-button type="primary" preIcon="ant-design:import-outlined" @click="onImportXls">导入</j-upload-button>
  8. <a-dropdown v-if="selectedRowKeys.length > 0">
  9. <template #overlay>
  10. <a-menu>
  11. <a-menu-item key="1" @click="batchHandleDelete">
  12. <Icon icon="ant-design:delete-outlined" />
  13. 删除
  14. </a-menu-item>
  15. </a-menu>
  16. </template>
  17. <a-button
  18. >批量操作
  19. <Icon style="fontsize: 12px" icon="ant-design:down-outlined" />
  20. </a-button>
  21. </a-dropdown>
  22. </template>
  23. <template #action="{ record }">
  24. <TableAction :actions="getActions(record)" :dropDownActions="getDropDownAction(record)" />
  25. </template>
  26. </BasicTable>
  27. <DeviceModal @register="registerModal" @saveOrUpdate="saveOrUpdateHandler" :showTab="showTab" :deviceType="deviceType" />
  28. </div>
  29. </template>
  30. <script lang="ts" name="system-user" setup>
  31. //ts语法
  32. import { ref, provide, reactive, toRaw, defineExpose } from 'vue';
  33. import { BasicTable, TableAction } from '/@/components/Table';
  34. import { useModal } from '/@/components/Modal';
  35. import DeviceModal from './DeviceModal.vue';
  36. import DeviceModalTable from './pointTabel/DeviceModalTabel.vue';
  37. // import { getToken } from '/@/utils/auth';
  38. // import { useGlobSetting } from '/@/hooks/setting';
  39. import { getTableHeaderColumns } from '/@/hooks/web/useWebColumns';
  40. import { useListPage } from '/@/hooks/system/useListPage';
  41. import { useMessage } from '/@/hooks/web/useMessage';
  42. const { notification } = useMessage();
  43. const props = defineProps({
  44. columnsType: {
  45. type: String,
  46. // required: true,
  47. },
  48. columns: {
  49. type: Array,
  50. // required: true,
  51. default: () => [],
  52. },
  53. searchFormSchema: {
  54. type: Array,
  55. required: true,
  56. default: () => [],
  57. },
  58. formSchema: {
  59. type: Array,
  60. required: true,
  61. },
  62. list: {
  63. type: Function,
  64. required: true,
  65. },
  66. getImportUrl: {
  67. type: String,
  68. required: true,
  69. },
  70. getExportUrl: {
  71. type: String,
  72. required: true,
  73. },
  74. deleteById: {
  75. type: Function,
  76. required: true,
  77. },
  78. batchDelete: {
  79. type: Function,
  80. // required: true,
  81. },
  82. saveOrUpdate: {
  83. type: Function,
  84. required: true,
  85. },
  86. pointList: {
  87. type: Function,
  88. // required: true,
  89. },
  90. showTab: {
  91. type: Boolean,
  92. default: false,
  93. },
  94. designScope: {
  95. type: String,
  96. },
  97. title: {
  98. type: String,
  99. },
  100. deviceType: {
  101. type: String,
  102. },
  103. });
  104. const isUpdate = ref(false);
  105. const record = reactive({});
  106. provide('formSchema', props.formSchema);
  107. provide('isUpdate', isUpdate);
  108. provide('formData', record);
  109. provide('deviceType', props.deviceType);
  110. // const glob = useGlobSetting();
  111. const [registerModal, { openModal, closeModal }] = useModal();
  112. const columnList = getTableHeaderColumns(props.columnsType);
  113. console.log('aaa', columnList);
  114. // 列表页面公共参数、方法
  115. const { prefixCls, tableContext, onExportXls, onImportXls, doRequest } = useListPage({
  116. designScope: props.designScope,
  117. tableProps: {
  118. title: props.title,
  119. api: props.list,
  120. columns: props.columns.length > 0 ? (props.columns as any[]) : columnList,
  121. size: 'small',
  122. formConfig: {
  123. // labelWidth: 100,
  124. labelAlign: 'left',
  125. labelCol: {
  126. xs: 24,
  127. sm: 24,
  128. md: 24,
  129. lg: 9,
  130. xl: 7,
  131. xxl: 5,
  132. },
  133. schemas: props.searchFormSchema as any[],
  134. },
  135. actionColumn: {
  136. width: 180,
  137. },
  138. beforeFetch: (params) => {
  139. return Object.assign({ column: 'createTime', order: 'desc' }, params);
  140. },
  141. },
  142. exportConfig: {
  143. name: props.title,
  144. url: props.getExportUrl,
  145. },
  146. importConfig: {
  147. url: props.getImportUrl,
  148. },
  149. });
  150. //注册table数据
  151. const [registerTable, { reload }, { rowSelection, selectedRowKeys }] = tableContext;
  152. const saveOrUpdateHandler = async (params) => {
  153. try {
  154. const res = await props.saveOrUpdate(params, isUpdate.value);
  155. notification.success({ message: res });
  156. !props.showTab ? closeModal() : '';
  157. await doRequest(props.list, { confirm: false });
  158. } catch (error) {
  159. notification.error({ message: '保存失败,请联系管理员' });
  160. }
  161. };
  162. /**
  163. * 新增事件
  164. */
  165. function handleAdd() {
  166. for (let key in record) {
  167. delete record[key];
  168. }
  169. isUpdate.value = false;
  170. openModal(true);
  171. }
  172. /**
  173. * 编辑事件
  174. */
  175. function handleEdit(data) {
  176. isUpdate.value = true;
  177. Object.assign(record, toRaw(data));
  178. openModal(true, {
  179. record,
  180. });
  181. }
  182. /**
  183. * 删除事件
  184. */
  185. async function handleDelete(record) {
  186. await props.deleteById({ id: record }, reload);
  187. }
  188. /**
  189. * 批量删除事件
  190. */
  191. async function batchHandleDelete() {
  192. doRequest(() => props.batchDelete({ ids: selectedRowKeys.value }));
  193. }
  194. /**
  195. * 查看
  196. */
  197. // function handleDetail(record) {
  198. // iframeUrl.value = `${glob.uploadUrl}/sys/annountCement/show/${record.id}?token=${getToken()}`;
  199. // openDetail(true);
  200. // }
  201. /**
  202. * 操作列定义
  203. * @param record
  204. */
  205. function getActions(record) {
  206. return [
  207. {
  208. label: '编辑',
  209. onClick: handleEdit.bind(null, record),
  210. },
  211. {
  212. label: '删除',
  213. popConfirm: {
  214. title: '是否确认删除',
  215. confirm: handleDelete.bind(null, record),
  216. },
  217. },
  218. // {
  219. // label: '查看',
  220. // onClick: handleDetail.bind(null, record),
  221. // },
  222. ];
  223. }
  224. /**
  225. * 下拉操作栏
  226. */
  227. function getDropDownAction(record) {
  228. return [
  229. // {
  230. // label: '删除',
  231. // popConfirm: {
  232. // title: '是否确认删除',
  233. // confirm: handleDelete.bind(null, record),
  234. // },
  235. // },
  236. // {
  237. // label: '查看',
  238. // onClick: handleDetail.bind(null, record),
  239. // },
  240. ];
  241. }
  242. defineExpose({
  243. doRequest,
  244. });
  245. </script>
  246. <style scoped lang="less">
  247. // :deep(.ant-table-header){
  248. // background-color:transparent;
  249. // height: 0;
  250. // }
  251. // :deep(.jeecg-basic-table .ant-table-wrapper){
  252. // background-color: #ffffff00;
  253. // }
  254. // :deep(.ant-table-body) {
  255. // height: auto !important;
  256. // }
  257. // :deep(.ant-table){
  258. // background-color: #ffffff00 !important;
  259. // }
  260. // :deep(.ant-table-thead > tr > th){
  261. // background-color:transparent
  262. // }
  263. // :deep(.ant-table-body > tr > th){
  264. // background-color:transparent
  265. // }
  266. // :deep(.ant-table-body > tr > td){
  267. // border: none;
  268. // }
  269. // :deep(.ant-table-fixed-header > .ant-table-content > .ant-table-scroll > .ant-table-body){
  270. // background-color:transparent
  271. // }
  272. // :deep(.jeecg-basic-table-row__striped td){
  273. // background-color: transparent;
  274. // }
  275. </style>