normalBtnTable.vue 6.9 KB

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