NormalGasTable.vue 7.9 KB

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