normalBtnTable.vue 6.9 KB

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