normalBtnTable.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  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. <a class="table-action-link" @click="handleEdit(record)">编辑</a>
  25. <a class="table-action-link" @click="handleAdds(record)">新增下级</a>
  26. <a-popconfirm title="确定删除?" @confirm="handleDelete(record)">
  27. <a class="table-action-link">删除</a>
  28. </a-popconfirm>
  29. <slot name="action" v-bind="{ record }"></slot>
  30. <!-- <TableAction :actions="getActions(record)" :dropDownActions="getDropDownAction(record)" /> -->
  31. </template>
  32. <template #bodyCell="{ column, record }">
  33. <slot name="filterCell" v-bind="{ column, record }"></slot>
  34. </template>
  35. </BasicTable>
  36. <DeviceModal @register="registerModal" @saveOrUpdate="saveOrUpdateHandler" />
  37. </div>
  38. </template>
  39. <script lang="ts" name="system-user" setup>
  40. //ts语法
  41. import { ref, provide, reactive, toRaw, defineExpose } from 'vue';
  42. import { BasicTable, TableAction } from '/@/components/Table';
  43. import { useModal } from '/@/components/Modal';
  44. import DeviceModal from './DeviceModal.vue';
  45. import { getTableHeaderColumns } from '/@/hooks/web/useWebColumns';
  46. import { useListPage } from '/@/hooks/system/useListPage';
  47. const props = defineProps({
  48. columnsType: {
  49. type: String,
  50. // required: true,
  51. },
  52. columns: {
  53. type: Array,
  54. // required: true,
  55. default: () => [],
  56. },
  57. formSchema: {
  58. type: Array,
  59. required: true,
  60. },
  61. list: {
  62. type: Function,
  63. required: true,
  64. },
  65. deleteById: {
  66. type: Function,
  67. required: true,
  68. },
  69. saveOrUpdate: {
  70. type: Function,
  71. required: true,
  72. },
  73. showTab: {
  74. type: Boolean,
  75. default: false,
  76. },
  77. designScope: {
  78. type: String,
  79. },
  80. title: {
  81. type: String,
  82. },
  83. deviceType: {
  84. type: String,
  85. },
  86. });
  87. const emit = defineEmits(['submitSuccess']);
  88. const isUpdate = ref(false);
  89. //lxh
  90. let dictId = ref(null);
  91. const record = reactive({});
  92. // const glob = useGlobSetting();
  93. const [registerModal, { openModal, closeModal }] = useModal();
  94. const columnList = getTableHeaderColumns(props.columnsType);
  95. // 列表页面公共参数、方法
  96. const { prefixCls, tableContext, onExportXls, onImportXls, doRequest } = useListPage({
  97. designScope: props.designScope,
  98. tableProps: {
  99. title: props.title, //table标题
  100. api: props.list, //api请求
  101. columns: props.columns.length > 0 ? (props.columns as any[]) : columnList, //列信息
  102. showTableSetting: false,
  103. // size: 'small',
  104. // bordered: false,
  105. formConfig: {
  106. //表单配置
  107. // labelWidth: 100,
  108. labelAlign: 'left',
  109. labelCol: {
  110. xs: 24,
  111. sm: 24,
  112. md: 24,
  113. lg: 9,
  114. xl: 7,
  115. xxl: 5,
  116. },
  117. schemas: props.searchFormSchema as any[],
  118. showActionButtonGroup: false,
  119. },
  120. striped: true, //斑马纹
  121. showIndexColumn: false, //是否显示序号列
  122. actionColumn: {
  123. //操作列配置
  124. width: 180,
  125. },
  126. beforeFetch: (params) => {
  127. return Object.assign({ column: 'createTime', order: 'desc' }, params);
  128. },
  129. },
  130. exportConfig: {
  131. name: props.title,
  132. url: props.getExportUrl,
  133. },
  134. importConfig: {
  135. url: props.getImportUrl,
  136. },
  137. });
  138. //注册table数据
  139. const [registerTable, { reload }] = tableContext;
  140. const saveOrUpdateHandler = async (params) => {
  141. Object.assign(params, { dictId: dictId.value });
  142. try {
  143. await props.saveOrUpdate(params, isUpdate.value);
  144. !props.showTab ? closeModal() : '';
  145. await doRequest(props.list, { confirm: false });
  146. } catch (error) {
  147. message.error('保存失败,请联系管理员');
  148. }
  149. };
  150. /**
  151. * 新增事件
  152. */
  153. function handleAdd() {
  154. dictId.value = null;
  155. for (let key in record) {
  156. delete record[key];
  157. }
  158. isUpdate.value = false;
  159. openModal(true, { addParent: true });
  160. }
  161. /**
  162. * 新增下级
  163. */
  164. function handleAdds(data) {
  165. debugger;
  166. console.log(data, '添加下级');
  167. dictId.value = data.subDictId || data.dictId;
  168. for (let key in record) {
  169. delete record[key];
  170. }
  171. isUpdate.value = false;
  172. openModal(true, { addParent: false });
  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.id }, 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. onClick: handleAdds.bind(null, record),
  216. },
  217. {
  218. label: '删除',
  219. popConfirm: {
  220. title: '是否确认删除',
  221. confirm: handleDelete.bind(null, record.id),
  222. },
  223. },
  224. // {
  225. // label: '查看',
  226. // onClick: handleDetail.bind(null, record),
  227. // },
  228. ];
  229. }
  230. /**
  231. * 下拉操作栏
  232. */
  233. function getDropDownAction(record) {
  234. return [
  235. // {
  236. // label: '删除',
  237. // popConfirm: {
  238. // title: '是否确认删除',
  239. // confirm: handleDelete.bind(null, record),
  240. // },
  241. // },
  242. // {
  243. // label: '查看',
  244. // onClick: handleDetail.bind(null, record),
  245. // },
  246. ];
  247. }
  248. defineExpose({
  249. doRequest,
  250. });
  251. </script>
  252. <style scoped lang="less">
  253. @ventSpace: zxm;
  254. @vent-table-no-hover: #00bfff10;
  255. :deep(.@{ventSpace}-table-cell-row-hover) {
  256. background: #264d8833 !important;
  257. }
  258. :deep(.@{ventSpace}-table-row-selected) {
  259. background: #268bc522 !important;
  260. }
  261. :deep(.@{ventSpace}-table-tbody > tr > td) {
  262. background-color: #0dc3ff05;
  263. }
  264. :deep(.jeecg-basic-table-row__striped) {
  265. td {
  266. background-color: @vent-table-no-hover !important;
  267. }
  268. }
  269. </style>