You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

128 lines
3.7 KiB

1 year ago
1 year ago
1 year ago
8 months ago
1 year ago
1 year ago
8 months ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
  1. <template>
  2. <a-button size="small" type="text" class="w-full" @click="actionEditEable">编辑</a-button>
  3. <a-modal v-model:open="isModalOpen" title="参数编辑" @ok="actionOk">
  4. <a-table bordered size="small"
  5. v-model:expandedRowKeys="tableExpandedKeys"
  6. :columns="tableColumns"
  7. :data-source="tableData"
  8. :pagination="false"
  9. >
  10. <template #bodyCell="{ column, record }">
  11. <template v-if="column.key === 'value'">
  12. <!-- Integer -->
  13. <a-input-number v-if="'java.lang.Integer' === record.type"
  14. size="small" class="w-full !border-none"
  15. v-model:value="record.value"
  16. ></a-input-number>
  17. <!-- Double -->
  18. <a-input-number v-if="'java.lang.Double' === record.type"
  19. size="small" class="w-full !border-none" :step="0.01"
  20. v-model:value="record.value"
  21. ></a-input-number>
  22. </template>
  23. </template>
  24. </a-table>
  25. </a-modal>
  26. </template>
  27. <script setup>
  28. import { nextTick, onMounted, ref } from 'vue';
  29. import ApiClient from '@/utils/ApiClient';
  30. /** @var {Function} */
  31. const emits = defineEmits(['update:value','change', 'save-request']);
  32. /** @var {Object} */
  33. const props = defineProps({
  34. structClassName : String,
  35. value : Object,
  36. });
  37. /** @var {Array} */
  38. const tableColumns = ref([
  39. {key:'title',title:'属性',dataIndex:'title'},
  40. {key:'value',title:'取值'},
  41. ]);
  42. /** @var {Array} */
  43. const tableData = ref([]);
  44. /** @var {String} */
  45. const tableExpandedKeys = ref([]);
  46. /** @var {Boolean} */
  47. const isModalOpen = ref(false);
  48. // on mounted
  49. onMounted(mounted);
  50. // on mounted
  51. async function mounted() {
  52. let structClassName = props.structClassName;
  53. tableData.value = await setupTableData(structClassName);
  54. }
  55. // setup tree data
  56. async function setupTableData(structClassName, path=[]) {
  57. let classPath = `${0===path.length ? '' : path.join('.')+'.'}${structClassName}`;
  58. console.log(`setup for : ${classPath}`);
  59. let baseTypes = ['Integer','Double'];
  60. let client = ApiClient.getClient();
  61. try {
  62. let structInfo = await client.call('service-config/class-struct-info-get', {class:structClassName});
  63. let nodes = [];
  64. for ( let item of structInfo ) {
  65. let itemPath = structuredClone(path);
  66. itemPath.push(item.name);
  67. tableExpandedKeys.value.push(item.name);
  68. let node = {};
  69. node.key = `${classPath}#${item.name}`;
  70. node.attr = item.name;
  71. node.title = item.name;
  72. node.type = item.type;
  73. node.info = item;
  74. if ( !baseTypes.includes(item.type) ) {
  75. node.children = await setupTableData(item.type, itemPath);
  76. }
  77. node.value = getValueFromJson(itemPath);
  78. nodes.push(node);
  79. }
  80. return nodes;
  81. } catch ( e ) { console.error(e); }
  82. }
  83. // get value from json by path
  84. function getValueFromJson( path ) {
  85. let value = props.value;
  86. for ( var item of path ) {
  87. if ( null === value || undefined === value[item] ) {
  88. return undefined;
  89. }
  90. value = value[item];
  91. }
  92. return value;
  93. }
  94. // generate json data
  95. function generateJsonData( nodes ) {
  96. let obj = {};
  97. for ( let node of nodes ) {
  98. if ( undefined !== node.children ) {
  99. obj[node.attr] = generateJsonData(node.children);
  100. } else {
  101. obj[node.attr] = node.value;
  102. }
  103. }
  104. return obj;
  105. }
  106. // enable edit
  107. function actionEditEable() {
  108. isModalOpen.value = true;
  109. }
  110. // ok
  111. async function actionOk() {
  112. let newValue = generateJsonData(tableData.value);
  113. emits('update:value', newValue);
  114. emits('change');
  115. await nextTick();
  116. emits('save-request');
  117. isModalOpen.value = false;
  118. }
  119. </script>