index.vue 5.7 KB

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