index.vue 7.0 KB

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