index.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. <!-- eslint-disable vue/multi-word-component-names -->
  2. <template>
  3. <BasicTable @register="registerTable">
  4. <template #tableTitle>
  5. <a-button preIcon="ant-design:plus-outlined" type="primary" @click="handleAdd">新增</a-button>
  6. </template>
  7. <template #action="{ record }">
  8. <a class="table-action-link" @click="handleConfig(record)">配置</a>
  9. <a class="table-action-link" @click="handleEdit(record)">编辑</a>
  10. <a-popconfirm title="确定删除?" @confirm="handleDelete(record)">
  11. <a class="table-action-link">删除</a>
  12. </a-popconfirm>
  13. </template>
  14. <!-- <template #bodyCell="{ column, record }">
  15. <slot name="filterCell" v-bind="{ column, record }"></slot>
  16. </template> -->
  17. </BasicTable>
  18. <DeviceModal @register="registerModal" @save-or-update="saveOrUpdateHandler" :showTab="false" :deviceType="deviceType" />
  19. <BasicModal @register="registerConfigModal" @ok="handleUpdate" title="配置文件编辑" defaultFullscreen>
  20. <CodeEditor v-model:value="configJSON" />
  21. </BasicModal>
  22. </template>
  23. <script lang="ts" setup>
  24. //ts语法
  25. import { ref, provide, reactive, toRaw } from 'vue';
  26. import { BasicTable } from '/@/components/Table';
  27. import { useModal } from '/@/components/Modal';
  28. import DeviceModal from '../comment/DeviceModal.vue';
  29. // import { getToken } from '/@/utils/auth';
  30. // import { useGlobSetting } from '/@/hooks/setting';
  31. import { useListPage } from '/@/hooks/system/useListPage';
  32. import { list, deleteById, saveOrUpdate } from './configuration.api';
  33. import { searchFormSchema, columns, formSchema } from './configuration.data';
  34. import { message } from 'ant-design-vue';
  35. import { BasicModal } from '/@/components/Modal';
  36. import CodeEditor from '/@/components/CodeEditor/src/CodeEditor.vue';
  37. import { ModulePresetMap } from './options';
  38. const formData = reactive({});
  39. const isUpdate = ref(false);
  40. const deviceType = ref('');
  41. const formSchemaData = ref(formSchema);
  42. // const pageType = ref('');
  43. const configJSON = ref('');
  44. provide('formSchema', formSchemaData);
  45. provide('isUpdate', isUpdate);
  46. provide('formData', formData);
  47. provide('deviceType', deviceType);
  48. // const glob = useGlobSetting();
  49. const [registerModal, { openModal, closeModal }] = useModal();
  50. const [registerConfigModal, configModalCtx] = useModal();
  51. // 列表页面公共参数、方法
  52. const { tableContext } = useListPage({
  53. tableProps: {
  54. title: '配置列表',
  55. api: list,
  56. columns,
  57. showTableSetting: false,
  58. // size: 'small',
  59. // bordered: false,
  60. formConfig: {
  61. showAdvancedButton: true,
  62. // labelWidth: 100,
  63. labelAlign: 'left',
  64. labelCol: {
  65. xs: 24,
  66. sm: 24,
  67. md: 24,
  68. lg: 9,
  69. xl: 7,
  70. xxl: 5,
  71. },
  72. schemas: searchFormSchema,
  73. },
  74. useSearchForm: true,
  75. striped: true,
  76. actionColumn: {
  77. width: 180,
  78. },
  79. },
  80. });
  81. //注册table数据
  82. const [registerTable, { reload }] = tableContext;
  83. const saveOrUpdateHandler = async (params) => {
  84. // 如果是新增或者选择了覆盖配置选项的则初始化配置
  85. if (!isUpdate.value || params.allowCover) {
  86. params = {
  87. ...ModulePresetMap[params.desc],
  88. ...params,
  89. };
  90. }
  91. try {
  92. await saveOrUpdate(params, isUpdate.value);
  93. closeModal();
  94. reload();
  95. message.success('保存成功');
  96. } catch (error) {
  97. message.error('保存失败,请联系管理员');
  98. }
  99. };
  100. /**
  101. * 新增事件
  102. */
  103. function handleAdd() {
  104. for (let key in formData) {
  105. delete formData[key];
  106. }
  107. isUpdate.value = false;
  108. openModal(true);
  109. }
  110. /**
  111. * 编辑事件
  112. */
  113. function handleEdit(record) {
  114. isUpdate.value = true;
  115. Object.assign(formData, toRaw(record));
  116. openModal(true, { formData }, false);
  117. }
  118. /**
  119. * 删除事件
  120. */
  121. async function handleDelete(record) {
  122. await deleteById({ id: record.id }, reload);
  123. }
  124. function handleConfig(record) {
  125. Object.assign(formData, toRaw(record));
  126. configJSON.value = record.moduleData || '';
  127. configModalCtx.openModal();
  128. }
  129. /** 更新配置详情 */
  130. async function handleUpdate() {
  131. isUpdate.value = true;
  132. saveOrUpdateHandler({
  133. ...formData,
  134. moduleData: JSON.parse(configJSON.value),
  135. })
  136. .then(() => {
  137. message.success('保存成功');
  138. })
  139. .catch(() => {
  140. message.error('保存失败,请联系管理员');
  141. })
  142. .finally(() => {
  143. configModalCtx.closeModal();
  144. });
  145. }
  146. </script>
  147. <style scoped lang="less">
  148. @ventSpace: zxm;
  149. @vent-table-no-hover: #00bfff10;
  150. :deep(.@{ventSpace}-table-cell-row-hover) {
  151. background: #264d8833 !important;
  152. }
  153. :deep(.@{ventSpace}-table-row-selected) {
  154. background: #268bc522 !important;
  155. }
  156. :deep(.@{ventSpace}-table-tbody > tr > td) {
  157. background-color: #0dc3ff05;
  158. }
  159. :deep(.jeecg-basic-table-row__striped) {
  160. td {
  161. background-color: @vent-table-no-hover !important;
  162. }
  163. }
  164. :deep(.@{ventSpace}-select-dropdown) {
  165. .@{ventSpace}-select-item-option-selected,
  166. .@{ventSpace}-select-item-option-active {
  167. background-color: #ffffff33 !important;
  168. }
  169. .@{ventSpace}-select-item:hover {
  170. background-color: #ffffff33 !important;
  171. }
  172. }
  173. </style>