normalBtnTable.vue 7.2 KB

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