CustomNormalTable.vue 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  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><span style="color: #f00;">(注:新增时请先选择系统类型 <b style="color: rgb(255, 191, 0); font-size: 20px;">↑</b>)</span>
  6. <a-dropdown v-if="selectedRowKeys.length > 0" :getPopupContainer="getPopupContainer">
  7. <template #overlay>
  8. <a-menu>
  9. <a-menu-item key="1" @click="batchHandleDelete">
  10. <Icon icon="ant-design:delete-outlined" />
  11. 删除
  12. </a-menu-item>
  13. </a-menu>
  14. </template>
  15. <a-button
  16. >批量操作
  17. <Icon style="fontsize: 12px" icon="ant-design:down-outlined" />
  18. </a-button>
  19. </a-dropdown>
  20. </template>
  21. <template #action="{ record }">
  22. <a class="table-action-link" @click="handleEdit(record)">编辑</a>
  23. <a-popconfirm
  24. title="确定删除?"
  25. @confirm="handleDelete(record)"
  26. >
  27. <a class="table-action-link">删除</a>
  28. </a-popconfirm>
  29. <slot name="action" v-bind="{ record }"></slot>
  30. </template>
  31. <template #bodyCell="{ column, record }">
  32. <slot name="filterCell" v-bind="{ column, record }"></slot>
  33. </template>
  34. </BasicTable>
  35. <DeviceModal @register="registerModal" @saveOrUpdate="saveOrUpdateHandler" :showTab="showTab" :deviceType="deviceType" />
  36. <!-- <DeviceModal v-model:visible="modalVisible" @saveOrUpdate="saveOrUpdateHandler" @close-modal="closeModal" :showTab="showTab" /> -->
  37. </div>
  38. </template>
  39. <script lang="ts" setup>
  40. //ts语法
  41. import { ref, provide, reactive, toRaw, defineExpose, watch } from 'vue';
  42. import { BasicTable, ActionItem, EditRecordRow, BasicColumn } from '/@/components/Table';
  43. import { useModal } from '/@/components/Modal';
  44. import DeviceModal from '../comment/DeviceModal.vue';
  45. // import { getToken } from '/@/utils/auth';
  46. // import { useGlobSetting } from '/@/hooks/setting';
  47. import { getTableHeaderColumns } from '/@/hooks/web/useWebColumns';
  48. import { useListPage } from '/@/hooks/system/useListPage';
  49. import { getPopupContainer } from '/@/utils';
  50. import { message } from 'ant-design-vue';
  51. const props = defineProps({
  52. columnsType: {
  53. type: String,
  54. // required: true,
  55. },
  56. columns: {
  57. type: Array,
  58. // required: true,
  59. default: () => [],
  60. },
  61. searchFormSchema: {
  62. type: Array,
  63. default: () => [],
  64. },
  65. formSchema: {
  66. type: Array,
  67. required: true,
  68. },
  69. list: {
  70. type: Function,
  71. required: true,
  72. },
  73. getImportUrl: {
  74. type: String,
  75. },
  76. getExportUrl: {
  77. type: String,
  78. },
  79. deleteById: {
  80. type: Function,
  81. required: true,
  82. },
  83. batchDelete: {
  84. type: Function,
  85. },
  86. saveOrUpdate: {
  87. type: Function,
  88. required: true,
  89. },
  90. pointList: {
  91. type: Function,
  92. },
  93. showTab: {
  94. type: Boolean,
  95. default: false,
  96. },
  97. designScope: {
  98. type: String,
  99. },
  100. title: {
  101. type: String,
  102. },
  103. deviceType: {
  104. type: String,
  105. },
  106. });
  107. const emit = defineEmits(['submitSuccess', 'editHandler']);
  108. const isUpdate = ref(false);
  109. const record = reactive({});
  110. const formSchemaData = ref(props.formSchema)
  111. const deviceTypeId = ref('')
  112. const pageType = ref('')
  113. watch(() => props.formSchema, (val) => {
  114. formSchemaData.value = val
  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. showTableSetting: false,
  128. title: props.title,
  129. api: props.list,
  130. columns: props.columns.length > 0 ? (props.columns as any[]) : columnList,
  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. });
  157. //注册table数据
  158. const [registerTable, { reload, getForm }, { rowSelection, selectedRowKeys }] = tableContext;
  159. const saveOrUpdateHandler = async (params) => {
  160. try {
  161. await props.saveOrUpdate(params, isUpdate.value);
  162. !props.showTab ? closeModal() : '';
  163. await doRequest(props.list, { confirm: false });
  164. emit('submitSuccess', params)
  165. } catch (error) {
  166. message.error('保存失败,请联系管理员');
  167. }
  168. };
  169. // const closeModalFn = () => {
  170. // closeModal()
  171. // }
  172. /**
  173. * 新增事件
  174. */
  175. function handleAdd() {
  176. const searchFormData = getForm().getFieldsValue()
  177. if(searchFormData && searchFormData['strtype']){
  178. emit('editHandler', searchFormData)
  179. for (let key in record) {
  180. if(key == 'strtype'){
  181. record[key] = searchFormData['strtype']
  182. }else{
  183. delete record[key];
  184. }
  185. }
  186. isUpdate.value = false;
  187. openModal(true, {
  188. record: { strtype : searchFormData['strtype'] }
  189. }, false);
  190. }else{
  191. message.info('请先选择系统类型!!')
  192. }
  193. }
  194. /**
  195. * 编辑事件
  196. */
  197. function handleEdit(data) {
  198. emit('editHandler', data)
  199. isUpdate.value = true;
  200. Object.assign(record, toRaw(data));
  201. openModal(true, {
  202. record,
  203. }, false);
  204. }
  205. /**
  206. * 删除事件
  207. */
  208. async function handleDelete(record) {
  209. await props.deleteById({ id: record.id }, reload);
  210. }
  211. /**
  212. * 批量删除事件
  213. */
  214. async function batchHandleDelete() {
  215. doRequest(() => props.batchDelete({ ids: selectedRowKeys.value }));
  216. }
  217. /**
  218. * 查看
  219. */
  220. // function handleDetail(record) {
  221. // iframeUrl.value = `${glob.uploadUrl}/sys/annountCement/show/${record.id}?token=${getToken()}`;
  222. // openDetail(true);
  223. // }
  224. /**
  225. * 操作列定义
  226. * @param record
  227. */
  228. function getActions(record: EditRecordRow, column: BasicColumn): ActionItem[] {
  229. return [
  230. {
  231. label: '编辑',
  232. onClick: handleEdit.bind(null, record, column),
  233. },
  234. {
  235. label: '删除',
  236. popConfirm: {
  237. title: '是否确认删除',
  238. confirm: handleDelete.bind(null, record, column),
  239. },
  240. },
  241. // {
  242. // label: '查看',
  243. // onClick: handleDetail.bind(null, record),
  244. // },
  245. ];
  246. }
  247. defineExpose({
  248. doRequest, onExportXls, onImportXls, reload, getForm
  249. });
  250. </script>
  251. <style scoped lang="less">
  252. @ventSpace: zxm;
  253. @vent-table-no-hover: #00bfff10;
  254. :deep(.@{ventSpace}-table-cell-row-hover) {
  255. background: #264d8833 !important;
  256. }
  257. :deep(.@{ventSpace}-table-row-selected) {
  258. background: #268bc522 !important;
  259. }
  260. :deep(.@{ventSpace}-table-tbody > tr > td) {
  261. background-color: #0dc3ff05;
  262. }
  263. :deep(.jeecg-basic-table-row__striped) {
  264. td {
  265. background-color: @vent-table-no-hover !important;
  266. }
  267. }
  268. :deep(.@{ventSpace}-select-dropdown) {
  269. .@{ventSpace}-select-item-option-selected,
  270. .@{ventSpace}-select-item-option-active {
  271. background-color: #ffffff33 !important;
  272. }
  273. .@{ventSpace}-select-item:hover {
  274. background-color: #ffffff33 !important;
  275. }
  276. }
  277. </style>