NormalTable.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  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 isUpdate = ref(false);
  110. const record = reactive({});
  111. const deviceTypeId = ref('')
  112. const pageType = ref('')
  113. provide('formSchema', props.formSchema);
  114. provide('isUpdate', isUpdate);
  115. provide('formData', record);
  116. provide('deviceType', props.deviceType);
  117. // const glob = useGlobSetting();
  118. const [registerModal, { openModal, closeModal }] = useModal();
  119. const columnList = getTableHeaderColumns(props.columnsType);
  120. // 列表页面公共参数、方法
  121. const { prefixCls, tableContext, onExportXls, onImportXls, doRequest } = useListPage({
  122. designScope: props.designScope,
  123. tableProps: {
  124. title: props.title,
  125. api: props.list,
  126. columns: props.columns.length > 0 ? (props.columns as any[]) : columnList,
  127. // size: 'small',
  128. // bordered: false,
  129. formConfig: {
  130. showAdvancedButton: true,
  131. // labelWidth: 100,
  132. labelAlign: 'left',
  133. labelCol: {
  134. xs: 24,
  135. sm: 24,
  136. md: 24,
  137. lg: 9,
  138. xl: 7,
  139. xxl: 5,
  140. },
  141. schemas: props.searchFormSchema as any[],
  142. },
  143. useSearchForm: props.searchFormSchema.length > 0 ? true : false,
  144. striped: true,
  145. actionColumn: {
  146. width: 180,
  147. },
  148. beforeFetch: (params) => {
  149. return Object.assign(params, { column: 'createTime', devicekind: props.deviceType });
  150. },
  151. },
  152. exportConfig: {
  153. name: props.title,
  154. url: props.getExportUrl,
  155. },
  156. importConfig: {
  157. url: props.getImportUrl,
  158. },
  159. });
  160. //注册table数据
  161. const [registerTable, { reload }, { rowSelection, selectedRowKeys }] = tableContext;
  162. const saveOrUpdateHandler = async (params) => {
  163. try {
  164. await props.saveOrUpdate(params, isUpdate.value);
  165. !props.showTab ? closeModal() : '';
  166. await doRequest(props.list, { confirm: false });
  167. } catch (error) {
  168. message.error('保存失败,请联系管理员');
  169. }
  170. };
  171. /**
  172. * 新增事件
  173. */
  174. function handleAdd() {
  175. for (let key in record) {
  176. delete record[key];
  177. }
  178. isUpdate.value = false;
  179. openModal(true);
  180. }
  181. /**
  182. * 编辑事件
  183. */
  184. function handleEdit(data) {
  185. isUpdate.value = true;
  186. Object.assign(record, toRaw(data));
  187. openModal(true, {
  188. record,
  189. });
  190. }
  191. /**
  192. * 删除事件
  193. */
  194. async function handleDelete(record) {
  195. await props.deleteById({id: record.id}, reload);
  196. }
  197. /**
  198. * 批量删除事件
  199. */
  200. async function batchHandleDelete() {
  201. doRequest(() => props.batchDelete({ ids: selectedRowKeys.value }));
  202. }
  203. /**
  204. * 查看
  205. */
  206. // function handleDetail(record) {
  207. // iframeUrl.value = `${glob.uploadUrl}/sys/annountCement/show/${record.id}?token=${getToken()}`;
  208. // openDetail(true);
  209. // }
  210. /**
  211. * 操作列定义
  212. * @param record
  213. */
  214. function getActions(record: EditRecordRow, column: BasicColumn): ActionItem[] {
  215. return [
  216. {
  217. label: '编辑',
  218. onClick: handleEdit.bind(null, record, column),
  219. },
  220. {
  221. label: '删除',
  222. popConfirm: {
  223. title: '是否确认删除',
  224. confirm: handleDelete.bind(null, record, column),
  225. },
  226. },
  227. // {
  228. // label: '查看',
  229. // onClick: handleDetail.bind(null, record),
  230. // },
  231. ];
  232. }
  233. defineExpose({
  234. doRequest, onExportXls, onImportXls, reload
  235. });
  236. </script>
  237. <style scoped lang="less">
  238. @ventSpace: zxm;
  239. @vent-table-no-hover: #00bfff10;
  240. :deep(.@{ventSpace}-table-cell-row-hover) {
  241. background: #264d8833 !important;
  242. }
  243. :deep(.@{ventSpace}-table-row-selected) {
  244. background: #268bc522 !important;
  245. }
  246. :deep(.@{ventSpace}-table-tbody > tr > td) {
  247. background-color: #0dc3ff05;
  248. }
  249. :deep(.jeecg-basic-table-row__striped) {
  250. td {
  251. background-color: @vent-table-no-hover !important;
  252. }
  253. }
  254. :deep(.@{ventSpace}-select-dropdown) {
  255. .@{ventSpace}-select-item {
  256. color: #fff !important;
  257. }
  258. .@{ventSpace}-select-item-option-selected,
  259. .@{ventSpace}-select-item-option-active {
  260. background-color: #00678b66 !important;
  261. }
  262. .@{ventSpace}-select-item:hover {
  263. background-color: #008fc366 !important;
  264. }
  265. }
  266. </style>