NormalTable.vue 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  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
  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. <!-- <DeviceModal v-model:visible="modalVisible" @saveOrUpdate="saveOrUpdateHandler" @close-modal="closeModal" :showTab="showTab" /> -->
  39. </div>
  40. </template>
  41. <script lang="ts" setup>
  42. //ts语法
  43. import { ref, provide, reactive, toRaw, defineExpose, watch } from 'vue';
  44. import { BasicTable, ActionItem, EditRecordRow, BasicColumn } from '/@/components/Table';
  45. import { useModal } from '/@/components/Modal';
  46. import DeviceModal from './DeviceModal.vue';
  47. // import { getToken } from '/@/utils/auth';
  48. // import { useGlobSetting } from '/@/hooks/setting';
  49. import { getTableHeaderColumns } from '/@/hooks/web/useWebColumns';
  50. import { useListPage } from '/@/hooks/system/useListPage';
  51. import { getPopupContainer } from '/@/utils';
  52. const props = defineProps({
  53. columnsType: {
  54. type: String,
  55. // required: true,
  56. },
  57. columns: {
  58. type: Array,
  59. // required: true,
  60. default: () => [],
  61. },
  62. searchFormSchema: {
  63. type: Array,
  64. default: () => [],
  65. },
  66. formSchema: {
  67. type: Array,
  68. required: true,
  69. },
  70. list: {
  71. type: Function,
  72. required: true,
  73. },
  74. getImportUrl: {
  75. type: String,
  76. },
  77. getExportUrl: {
  78. type: String,
  79. },
  80. deleteById: {
  81. type: Function,
  82. required: true,
  83. },
  84. batchDelete: {
  85. type: Function,
  86. },
  87. saveOrUpdate: {
  88. type: Function,
  89. required: true,
  90. },
  91. pointList: {
  92. type: Function,
  93. },
  94. showTab: {
  95. type: Boolean,
  96. default: false,
  97. },
  98. designScope: {
  99. type: String,
  100. },
  101. title: {
  102. type: String,
  103. },
  104. deviceType: {
  105. type: String,
  106. },
  107. });
  108. const emit = defineEmits(['submitSuccess', 'editHandler']);
  109. const isUpdate = ref(false);
  110. const record = reactive({});
  111. const formSchemaData = ref(props.formSchema)
  112. const deviceTypeId = ref('')
  113. const pageType = ref('')
  114. watch(() => props.formSchema, (val) => {
  115. formSchemaData.value = val
  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. debugger
  181. await doRequest(props.list, { confirm: false });
  182. debugger
  183. reload()
  184. emit('submitSuccess', params)
  185. } catch (error) {
  186. message.error('保存失败,请联系管理员');
  187. }
  188. };
  189. // const closeModalFn = () => {
  190. // closeModal()
  191. // }
  192. /**
  193. * 新增事件
  194. */
  195. function handleAdd() {
  196. for (let key in record) {
  197. delete record[key];
  198. }
  199. isUpdate.value = false;
  200. openModal(true);
  201. }
  202. /**
  203. * 编辑事件
  204. */
  205. function handleEdit(data) {
  206. isUpdate.value = true;
  207. Object.assign(record, toRaw(data));
  208. openModal(true, {
  209. record,
  210. }, false);
  211. }
  212. /**
  213. * 删除事件
  214. */
  215. async function handleDelete(record) {
  216. await props.deleteById({ id: record.id }, reload);
  217. }
  218. /**
  219. * 批量删除事件
  220. */
  221. async function batchHandleDelete() {
  222. doRequest(() => props.batchDelete({ ids: selectedRowKeys.value }));
  223. }
  224. /**
  225. * 查看
  226. */
  227. // function handleDetail(record) {
  228. // iframeUrl.value = `${glob.uploadUrl}/sys/annountCement/show/${record.id}?token=${getToken()}`;
  229. // openDetail(true);
  230. // }
  231. /**
  232. * 操作列定义
  233. * @param record
  234. */
  235. function getActions(record: EditRecordRow, column: BasicColumn): ActionItem[] {
  236. return [
  237. {
  238. label: '编辑',
  239. onClick: handleEdit.bind(null, record, column),
  240. },
  241. {
  242. label: '删除',
  243. popConfirm: {
  244. title: '是否确认删除',
  245. confirm: handleDelete.bind(null, record, column),
  246. },
  247. },
  248. // {
  249. // label: '查看',
  250. // onClick: handleDetail.bind(null, record),
  251. // },
  252. ];
  253. }
  254. defineExpose({
  255. doRequest, onExportXls, onImportXls, reload, getForm
  256. });
  257. </script>
  258. <style scoped lang="less">
  259. @ventSpace: zxm;
  260. @vent-table-no-hover: #00bfff10;
  261. :deep(.@{ventSpace}-table-cell-row-hover) {
  262. background: #264d8833 !important;
  263. }
  264. :deep(.@{ventSpace}-table-row-selected) {
  265. background: #268bc522 !important;
  266. }
  267. :deep(.@{ventSpace}-table-tbody > tr > td) {
  268. background-color: #0dc3ff05;
  269. }
  270. :deep(.jeecg-basic-table-row__striped) {
  271. td {
  272. background-color: @vent-table-no-hover !important;
  273. }
  274. }
  275. :deep(.@{ventSpace}-select-dropdown) {
  276. .@{ventSpace}-select-item-option-selected,
  277. .@{ventSpace}-select-item-option-active {
  278. background-color: #ffffff33 !important;
  279. }
  280. .@{ventSpace}-select-item:hover {
  281. background-color: #ffffff33 !important;
  282. }
  283. }
  284. </style>