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 _ from 'lodash-es';
  40. import helpContext from './types?raw';
  41. const formData = reactive<any>({});
  42. const isUpdate = ref(false);
  43. const deviceType = ref('');
  44. const formSchemaData = ref(formSchema);
  45. // const pageType = ref('');
  46. const configJSON = ref('');
  47. provide('formSchema', formSchemaData);
  48. provide('isUpdate', isUpdate);
  49. provide('formData', formData);
  50. provide('deviceType', deviceType);
  51. // const glob = useGlobSetting();
  52. const [registerModal, { openModal, closeModal }] = useModal();
  53. const [registerConfigModal, configModalCtx] = useModal();
  54. // 列表页面公共参数、方法
  55. const { tableContext } = useListPage({
  56. tableProps: {
  57. title: '配置列表',
  58. api: list,
  59. columns,
  60. showTableSetting: false,
  61. // size: 'small',
  62. // bordered: false,
  63. formConfig: {
  64. showAdvancedButton: true,
  65. // labelWidth: 100,
  66. labelAlign: 'left',
  67. labelCol: {
  68. xs: 24,
  69. sm: 24,
  70. md: 24,
  71. lg: 9,
  72. xl: 7,
  73. xxl: 5,
  74. },
  75. schemas: searchFormSchema,
  76. },
  77. useSearchForm: true,
  78. striped: true,
  79. actionColumn: {
  80. width: 180,
  81. },
  82. },
  83. });
  84. //注册table数据
  85. const [registerTable, { reload }] = tableContext;
  86. const saveOrUpdateHandler = async (params) => {
  87. // 如果是新增或者选择了覆盖配置选项的则初始化配置
  88. if (!isUpdate.value || params.allowCover) {
  89. params = {
  90. ...ModulePresetMap[params.desc],
  91. ...params,
  92. };
  93. }
  94. try {
  95. await saveOrUpdate(params, isUpdate.value);
  96. closeModal();
  97. reload();
  98. message.success('保存成功');
  99. } catch (error) {
  100. message.error('保存失败,请联系管理员');
  101. }
  102. };
  103. /**
  104. * 新增事件
  105. */
  106. function handleAdd() {
  107. for (let key in formData) {
  108. delete formData[key];
  109. }
  110. isUpdate.value = false;
  111. openModal(true);
  112. }
  113. function handleHelp() {
  114. configJSON.value = helpContext;
  115. configModalCtx.openModal();
  116. }
  117. /**
  118. * 编辑事件
  119. */
  120. function handleEdit(record) {
  121. isUpdate.value = true;
  122. Object.assign(formData, toRaw(record));
  123. openModal(true, { formData }, false);
  124. }
  125. /**
  126. * 删除事件
  127. */
  128. async function handleDelete(record) {
  129. await deleteById({ id: record.id }, reload);
  130. }
  131. function handleConfig(record) {
  132. Object.assign(formData, toRaw(record));
  133. configJSON.value = _.pick(formData, ['deviceType', 'pageType', 'moduleName', 'moduleData', 'showStyle']);
  134. configModalCtx.openModal();
  135. }
  136. /** 更新配置详情 */
  137. async function handleUpdate() {
  138. isUpdate.value = true;
  139. try {
  140. saveOrUpdateHandler({
  141. id: formData.id,
  142. ...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>