index.vue 7.7 KB

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