NormalTable.vue 7.4 KB

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