normalBtnTable.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  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" />
  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 { getTableHeaderColumns } from '/@/hooks/web/useWebColumns';
  40. import { useListPage } from '/@/hooks/system/useListPage';
  41. const props = defineProps({
  42. columnsType: {
  43. type: String,
  44. // required: true,
  45. },
  46. columns: {
  47. type: Array,
  48. // required: true,
  49. default: () => [],
  50. },
  51. formSchema: {
  52. type: Array,
  53. required: true,
  54. },
  55. list: {
  56. type: Function,
  57. required: true,
  58. },
  59. deleteById: {
  60. type: Function,
  61. required: true,
  62. },
  63. saveOrUpdate: {
  64. type: Function,
  65. required: true,
  66. },
  67. showTab: {
  68. type: Boolean,
  69. default: false,
  70. },
  71. designScope: {
  72. type: String,
  73. },
  74. title: {
  75. type: String,
  76. },
  77. deviceType: {
  78. type: String,
  79. },
  80. });
  81. const emit = defineEmits(['submitSuccess']);
  82. const isUpdate = ref(false);
  83. //lxh
  84. let dictId = ref(null);
  85. const record = reactive({});
  86. // const glob = useGlobSetting();
  87. const [registerModal, { openModal, closeModal }] = useModal();
  88. const columnList = getTableHeaderColumns(props.columnsType);
  89. // 列表页面公共参数、方法
  90. const { prefixCls, tableContext, onExportXls, onImportXls, doRequest } = useListPage({
  91. designScope: props.designScope,
  92. tableProps: {
  93. title: props.title, //table标题
  94. api: props.list, //api请求
  95. columns: props.columns.length > 0 ? (props.columns as any[]) : columnList, //列信息
  96. // size: 'small',
  97. // bordered: false,
  98. formConfig: {
  99. //表单配置
  100. // labelWidth: 100,
  101. labelAlign: 'left',
  102. labelCol: {
  103. xs: 24,
  104. sm: 24,
  105. md: 24,
  106. lg: 9,
  107. xl: 7,
  108. xxl: 5,
  109. },
  110. schemas: props.searchFormSchema as any[],
  111. showActionButtonGroup: false,
  112. },
  113. striped: true, //斑马纹
  114. showIndexColumn: false, //是否显示序号列
  115. actionColumn: {
  116. //操作列配置
  117. width: 180,
  118. },
  119. beforeFetch: (params) => {
  120. return Object.assign({ column: 'createTime', order: 'desc' }, params);
  121. },
  122. },
  123. exportConfig: {
  124. name: props.title,
  125. url: props.getExportUrl,
  126. },
  127. importConfig: {
  128. url: props.getImportUrl,
  129. },
  130. });
  131. //注册table数据
  132. const [registerTable, { reload }] = tableContext;
  133. const saveOrUpdateHandler = async (params) => {
  134. Object.assign(params, { dictId: dictId.value });
  135. try {
  136. await props.saveOrUpdate(params, isUpdate.value);
  137. !props.showTab ? closeModal() : '';
  138. await doRequest(props.list, { confirm: false });
  139. } catch (error) {
  140. message.error('保存失败,请联系管理员');
  141. }
  142. };
  143. /**
  144. * 新增事件
  145. */
  146. function handleAdd() {
  147. dictId.value = null;
  148. for (let key in record) {
  149. delete record[key];
  150. }
  151. isUpdate.value = false;
  152. openModal(true, {addParent: true});
  153. }
  154. /**
  155. * 新增下级
  156. */
  157. function handleAdds(data) {
  158. console.log(data,'添加下级')
  159. dictId.value = data.subDictId;
  160. for (let key in record) {
  161. delete record[key];
  162. }
  163. isUpdate.value = false;
  164. openModal(true, { addParent: false });
  165. }
  166. /**
  167. * 编辑事件
  168. */
  169. function handleEdit(data) {
  170. isUpdate.value = true;
  171. Object.assign(record, toRaw(data));
  172. openModal(true, {
  173. record,
  174. });
  175. }
  176. /**
  177. * 删除事件
  178. */
  179. async function handleDelete(record) {
  180. await props.deleteById({ id: record }, reload);
  181. }
  182. /**
  183. * 批量删除事件
  184. */
  185. async function batchHandleDelete() {
  186. doRequest(() => props.batchDelete({ ids: selectedRowKeys.value }));
  187. }
  188. /**
  189. * 查看
  190. */
  191. // function handleDetail(record) {
  192. // iframeUrl.value = `${glob.uploadUrl}/sys/annountCement/show/${record.id}?token=${getToken()}`;
  193. // openDetail(true);
  194. // }
  195. /**
  196. * 操作列定义
  197. * @param record
  198. */
  199. function getActions(record) {
  200. return [
  201. {
  202. label: '编辑',
  203. onClick: handleEdit.bind(null, record),
  204. },
  205. {
  206. label: '新增下级',
  207. onClick: handleAdds.bind(null, record),
  208. },
  209. {
  210. label: '删除',
  211. popConfirm: {
  212. title: '是否确认删除',
  213. confirm: handleDelete.bind(null, record.id),
  214. },
  215. },
  216. // {
  217. // label: '查看',
  218. // onClick: handleDetail.bind(null, record),
  219. // },
  220. ];
  221. }
  222. /**
  223. * 下拉操作栏
  224. */
  225. function getDropDownAction(record) {
  226. return [
  227. // {
  228. // label: '删除',
  229. // popConfirm: {
  230. // title: '是否确认删除',
  231. // confirm: handleDelete.bind(null, record),
  232. // },
  233. // },
  234. // {
  235. // label: '查看',
  236. // onClick: handleDetail.bind(null, record),
  237. // },
  238. ];
  239. }
  240. defineExpose({
  241. doRequest,
  242. });
  243. </script>
  244. <style scoped lang="less">
  245. @ventSpace: zxm;
  246. @vent-table-no-hover: #00bfff10;
  247. :deep(.@{ventSpace}-table-cell-row-hover) {
  248. background: #264d8833 !important;
  249. }
  250. :deep(.@{ventSpace}-table-row-selected) {
  251. background: #268bc522 !important;
  252. }
  253. :deep(.@{ventSpace}-table-tbody > tr > td) {
  254. background-color: #0dc3ff05;
  255. }
  256. :deep(.jeecg-basic-table-row__striped) {
  257. td {
  258. background-color: @vent-table-no-hover !important;
  259. }
  260. }
  261. </style>