NormalTable.vue 8.0 KB

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