normalBtnTable.vue 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  1. <template>
  2. <div>
  3. <BasicTable @register="registerTable">
  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 { getToken } from '/@/utils/auth';
  40. // import { useGlobSetting } from '/@/hooks/setting';
  41. import { getTableHeaderColumns } from '/@/hooks/web/useWebColumns';
  42. import { useListPage } from '/@/hooks/system/useListPage';
  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. //lxh
  106. let dictId = ref(null);
  107. const record = reactive({});
  108. provide('formSchema', props.formSchema);
  109. provide('isUpdate', isUpdate);
  110. provide('formData', record);
  111. provide('deviceType', props.deviceType);
  112. // const glob = useGlobSetting();
  113. const [registerModal, { openModal, closeModal }] = useModal();
  114. const columnList = getTableHeaderColumns(props.columnsType);
  115. console.log('aaa', columnList);
  116. // 列表页面公共参数、方法
  117. const { prefixCls, tableContext, onExportXls, onImportXls, doRequest } = useListPage({
  118. designScope: props.designScope,
  119. tableProps: {
  120. title: props.title, //table标题
  121. api: props.list, //api请求
  122. columns: props.columns.length > 0 ? (props.columns as any[]) : columnList, //列信息
  123. // size: 'small',
  124. // bordered: false,
  125. formConfig: {
  126. //表单配置
  127. // labelWidth: 100,
  128. labelAlign: 'left',
  129. labelCol: {
  130. xs: 24,
  131. sm: 24,
  132. md: 24,
  133. lg: 9,
  134. xl: 7,
  135. xxl: 5,
  136. },
  137. schemas: props.searchFormSchema as any[],
  138. showActionButtonGroup: false,
  139. },
  140. striped: true, //斑马纹
  141. showIndexColumn: false, //是否显示序号列
  142. actionColumn: {
  143. //操作列配置
  144. width: 180,
  145. },
  146. beforeFetch: (params) => {
  147. return Object.assign({ column: 'createTime', order: 'desc' }, params);
  148. },
  149. },
  150. exportConfig: {
  151. name: props.title,
  152. url: props.getExportUrl,
  153. },
  154. importConfig: {
  155. url: props.getImportUrl,
  156. },
  157. });
  158. //注册table数据
  159. const [registerTable, { reload }] = tableContext;
  160. const saveOrUpdateHandler = async (params) => {
  161. Object.assign(params, { dictId: dictId.value });
  162. console.log(params, 'params111');
  163. try {
  164. await props.saveOrUpdate(params, isUpdate.value);
  165. !props.showTab ? closeModal() : '';
  166. await doRequest(props.list, { confirm: false });
  167. } catch (error) {
  168. message.error('保存失败,请联系管理员');
  169. }
  170. };
  171. /**
  172. * 新增事件
  173. */
  174. function handleAdd() {
  175. dictId.value = null;
  176. for (let key in record) {
  177. delete record[key];
  178. }
  179. isUpdate.value = false;
  180. openModal(true);
  181. }
  182. /**
  183. * 新增下级
  184. */
  185. function handleAdds(data) {
  186. dictId.value = data.dictId;
  187. for (let key in record) {
  188. delete record[key];
  189. }
  190. isUpdate.value = false;
  191. openModal(true);
  192. }
  193. /**
  194. * 编辑事件
  195. */
  196. function handleEdit(data) {
  197. isUpdate.value = true;
  198. Object.assign(record, toRaw(data));
  199. openModal(true, {
  200. record,
  201. });
  202. }
  203. /**
  204. * 删除事件
  205. */
  206. async function handleDelete(record) {
  207. await props.deleteById({ id: record }, reload);
  208. }
  209. /**
  210. * 批量删除事件
  211. */
  212. async function batchHandleDelete() {
  213. doRequest(() => props.batchDelete({ ids: selectedRowKeys.value }));
  214. }
  215. /**
  216. * 查看
  217. */
  218. // function handleDetail(record) {
  219. // iframeUrl.value = `${glob.uploadUrl}/sys/annountCement/show/${record.id}?token=${getToken()}`;
  220. // openDetail(true);
  221. // }
  222. /**
  223. * 操作列定义
  224. * @param record
  225. */
  226. function getActions(record) {
  227. return [
  228. {
  229. label: '编辑',
  230. onClick: handleEdit.bind(null, record),
  231. },
  232. {
  233. label: '新增下级',
  234. onClick: handleAdds.bind(null, record),
  235. },
  236. {
  237. label: '删除',
  238. popConfirm: {
  239. title: '是否确认删除',
  240. confirm: handleDelete.bind(null, record),
  241. },
  242. },
  243. // {
  244. // label: '查看',
  245. // onClick: handleDetail.bind(null, record),
  246. // },
  247. ];
  248. }
  249. /**
  250. * 下拉操作栏
  251. */
  252. function getDropDownAction(record) {
  253. return [
  254. // {
  255. // label: '删除',
  256. // popConfirm: {
  257. // title: '是否确认删除',
  258. // confirm: handleDelete.bind(null, record),
  259. // },
  260. // },
  261. // {
  262. // label: '查看',
  263. // onClick: handleDetail.bind(null, record),
  264. // },
  265. ];
  266. }
  267. defineExpose({
  268. doRequest,
  269. });
  270. </script>
  271. <style scoped lang="less">
  272. @ventSpace: zxm;
  273. @vent-table-no-hover: #00bfff10;
  274. // :deep(.ant-table-header){
  275. // background-color:transparent;
  276. // height: 0;
  277. // }
  278. // :deep(.jeecg-basic-table .ant-table-wrapper){
  279. // background-color: #ffffff00;
  280. // }
  281. // :deep(.ant-table-body) {
  282. // height: auto !important;
  283. // }
  284. // :deep(.ant-table){
  285. // background-color: #ffffff00 !important;
  286. // }
  287. // :deep(.ant-table-thead > tr > th){
  288. // background-color:transparent
  289. // }
  290. // :deep(.ant-table-body > tr > th){
  291. // background-color:transparent
  292. // }
  293. // :deep(.ant-table-body > tr > td){
  294. // border: none;
  295. // }
  296. // :deep(.ant-table-fixed-header > .ant-table-content > .ant-table-scroll > .ant-table-body){
  297. // background-color:transparent
  298. // }
  299. // :deep(.jeecg-basic-table-row__striped td){
  300. // background-color: transparent;
  301. // }
  302. :deep(.@{ventSpace}-table-cell-row-hover) {
  303. background: #264d8833 !important;
  304. }
  305. :deep(.@{ventSpace}-table-row-selected) {
  306. background: #268bc522 !important;
  307. }
  308. // :deep(.ant-table-tbody) {
  309. // tr.ant-table-row-selected {
  310. // td {
  311. // background: #007cc415 !important;
  312. // }
  313. // }
  314. // }
  315. :deep(.@{ventSpace}-table-tbody > tr > td) {
  316. background-color: #0dc3ff05;
  317. }
  318. :deep(.jeecg-basic-table-row__striped) {
  319. // background: #97efff11 !important;
  320. td {
  321. // background-color: #97efff11 !important;
  322. background-color: @vent-table-no-hover !important;
  323. }
  324. }
  325. // :deep(.ant-table-thead) {
  326. // // background: linear-gradient(#003f77 0%, #004a86aa 10%) !important; //#003f77, #0a134c
  327. // background-color: #3d9dd45d !important;
  328. // & > tr > th,
  329. // .ant-table-column-title {
  330. // // color: #70f9fc !important;
  331. // color: #fff !important;
  332. // border-color: #91e9fe !important;
  333. // border-left: none !important;
  334. // // border-right: none !important;
  335. // &:last-child {
  336. // border-right: none !important;
  337. // }
  338. // }
  339. // }
  340. </style>