normalBtnTable.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  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. if (!params['description']) params['description'] = '';
  142. Object.assign(params, { dictId: dictId.value });
  143. try {
  144. await props.saveOrUpdate(params, isUpdate.value);
  145. !props.showTab ? closeModal() : '';
  146. await doRequest(props.list, { confirm: false });
  147. } catch (error) {
  148. message.error('保存失败,请联系管理员');
  149. }
  150. // 清除数据
  151. dictId.value = null;
  152. };
  153. /**
  154. * 新增事件
  155. */
  156. function handleAdd() {
  157. dictId.value = null;
  158. for (let key in record) {
  159. delete record[key];
  160. }
  161. isUpdate.value = false;
  162. openModal(true, { addParent: true });
  163. }
  164. /**
  165. * 新增下级
  166. */
  167. function handleAdds(data) {
  168. // debugger;
  169. console.log(data, '添加下级');
  170. dictId.value = data.subDictId;
  171. for (let key in record) {
  172. delete record[key];
  173. }
  174. isUpdate.value = false;
  175. openModal(true, { addParent: false });
  176. }
  177. /**
  178. * 编辑事件
  179. */
  180. function handleEdit(data) {
  181. isUpdate.value = true;
  182. dictId.value = data.dictId;
  183. Object.assign(record, toRaw(data));
  184. openModal(true, {
  185. record,
  186. });
  187. }
  188. /**
  189. * 删除事件
  190. */
  191. async function handleDelete(record) {
  192. await props.deleteById({ id: record.id }, reload);
  193. }
  194. /**
  195. * 批量删除事件
  196. */
  197. async function batchHandleDelete() {
  198. doRequest(() => props.batchDelete({ ids: selectedRowKeys.value }));
  199. }
  200. /**
  201. * 查看
  202. */
  203. // function handleDetail(record) {
  204. // iframeUrl.value = `${glob.uploadUrl}/sys/annountCement/show/${record.id}?token=${getToken()}`;
  205. // openDetail(true);
  206. // }
  207. /**
  208. * 操作列定义
  209. * @param record
  210. */
  211. function getActions(record) {
  212. return [
  213. {
  214. label: '编辑',
  215. onClick: handleEdit.bind(null, record),
  216. },
  217. {
  218. label: '新增下级',
  219. onClick: handleAdds.bind(null, record),
  220. },
  221. {
  222. label: '删除',
  223. popConfirm: {
  224. title: '是否确认删除',
  225. confirm: handleDelete.bind(null, record.id),
  226. },
  227. },
  228. // {
  229. // label: '查看',
  230. // onClick: handleDetail.bind(null, record),
  231. // },
  232. ];
  233. }
  234. /**
  235. * 下拉操作栏
  236. */
  237. function getDropDownAction(record) {
  238. return [
  239. // {
  240. // label: '删除',
  241. // popConfirm: {
  242. // title: '是否确认删除',
  243. // confirm: handleDelete.bind(null, record),
  244. // },
  245. // },
  246. // {
  247. // label: '查看',
  248. // onClick: handleDetail.bind(null, record),
  249. // },
  250. ];
  251. }
  252. defineExpose({
  253. doRequest,
  254. });
  255. </script>
  256. <style scoped lang="less">
  257. @ventSpace: zxm;
  258. @vent-table-no-hover: #00bfff10;
  259. :deep(.@{ventSpace}-table-cell-row-hover) {
  260. background: #264d8833 !important;
  261. }
  262. :deep(.@{ventSpace}-table-row-selected) {
  263. background: #268bc522 !important;
  264. }
  265. :deep(.@{ventSpace}-table-tbody > tr > td) {
  266. background-color: #0dc3ff05;
  267. }
  268. :deep(.jeecg-basic-table-row__striped) {
  269. td {
  270. background-color: @vent-table-no-hover !important;
  271. }
  272. }
  273. </style>