NormalTable.vue 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  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. await doRequest(props.list, { confirm: false });
  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(true, {
  206. record,
  207. }, false);
  208. }
  209. /**
  210. * 删除事件
  211. */
  212. async function handleDelete(record) {
  213. await props.deleteById({ id: record.id }, reload);
  214. }
  215. /**
  216. * 批量删除事件
  217. */
  218. async function batchHandleDelete() {
  219. doRequest(() => props.batchDelete({ ids: selectedRowKeys.value }));
  220. }
  221. /**
  222. * 查看
  223. */
  224. // function handleDetail(record) {
  225. // iframeUrl.value = `${glob.uploadUrl}/sys/annountCement/show/${record.id}?token=${getToken()}`;
  226. // openDetail(true);
  227. // }
  228. /**
  229. * 操作列定义
  230. * @param record
  231. */
  232. function getActions(record: EditRecordRow, column: BasicColumn): ActionItem[] {
  233. return [
  234. {
  235. label: '编辑',
  236. onClick: handleEdit.bind(null, record, column),
  237. },
  238. {
  239. label: '删除',
  240. popConfirm: {
  241. title: '是否确认删除',
  242. confirm: handleDelete.bind(null, record, column),
  243. },
  244. },
  245. // {
  246. // label: '查看',
  247. // onClick: handleDetail.bind(null, record),
  248. // },
  249. ];
  250. }
  251. defineExpose({
  252. doRequest, onExportXls, onImportXls, reload, getForm
  253. });
  254. </script>
  255. <style scoped lang="less">
  256. @ventSpace: zxm;
  257. @vent-table-no-hover: #00bfff10;
  258. :deep(.@{ventSpace}-table-cell-row-hover) {
  259. background: #264d8833 !important;
  260. }
  261. :deep(.@{ventSpace}-table-row-selected) {
  262. background: #268bc522 !important;
  263. }
  264. :deep(.@{ventSpace}-table-tbody > tr > td) {
  265. background-color: #0dc3ff05;
  266. }
  267. :deep(.jeecg-basic-table-row__striped) {
  268. td {
  269. background-color: @vent-table-no-hover !important;
  270. }
  271. }
  272. :deep(.@{ventSpace}-select-dropdown) {
  273. .@{ventSpace}-select-item-option-selected,
  274. .@{ventSpace}-select-item-option-active {
  275. background-color: #ffffff33 !important;
  276. }
  277. .@{ventSpace}-select-item:hover {
  278. background-color: #ffffff33 !important;
  279. }
  280. }
  281. </style>