NormalTable.vue 8.2 KB

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