NormalTable.vue 8.1 KB

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