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.

201 lines
7.7 KiB

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 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. <div class="h-full flex flex-col">
  3. <div class="bg-white border-b p-5">
  4. <div v-for="(status,index) in statuses" :key="index" class="inline-block py-1 px-2 rounded border ml-1">
  5. {{ status.name }} : {{ status.value }}
  6. </div>
  7. </div>
  8. <a-row class="h-0 grow">
  9. <a-col class="border-r h-full overflow-y-auto" :span="16">
  10. <div class="p-5 border-t border-b" v-if="0 < params.length">
  11. <a-row>
  12. <a-col :span="8" v-for="group in params" :key="group.name" class="p-1">
  13. <fieldset class="border">
  14. <legend>{{ group.name }}</legend>
  15. <div class="p-1" v-for="item in group.items" :key="item.key">
  16. <service-configuration-param-value-edit
  17. :param="item"
  18. v-model:value="item.value"
  19. @save-request="actionServiceParamSave"
  20. ></service-configuration-param-value-edit>
  21. </div>
  22. </fieldset>
  23. </a-col>
  24. </a-row>
  25. <div class="p-1">
  26. <a-button class="mr-1" @click="actionServiceParamReload">刷新</a-button>
  27. <a-button @click="actionServiceParamSave">保存</a-button>
  28. </div>
  29. </div>
  30. <div class="p-5">
  31. <fieldset v-for="(group,groupIndex) in actions" :key="groupIndex" class="border my-1 p-1">
  32. <legend>{{ group.name }}</legend>
  33. <div v-for="action in group.items" :key="action.key" :class="{'inline-block ml-1':0 === action.params.length}">
  34. <a-button v-if="0 === action.params.length" class="my-1"
  35. :loading="action.isExecuting"
  36. @click="actionServiceExecute(action)"
  37. >{{ action.name }}</a-button>
  38. <div v-else class="border rounded-md my-1 px-3 bg-white">
  39. <span>{{ action.name }}</span>
  40. <div class="inline-block mx-2" v-for="actionParam in action.params" :key="actionParam.key">
  41. {{ actionParam.name }} :
  42. <a-switch v-if="'java.lang.Boolean' === actionParam.type" v-model:checked="actionParam.value" />
  43. <a-input v-else-if="'java.lang.String' === actionParam.type" class="w-24" v-model:value="actionParam.value" />
  44. <a-input-number v-else-if="'java.lang.Integer' === actionParam.type" class="w-24" v-model:value="actionParam.value" />
  45. <a-select v-else-if="'Enum' === actionParam.type" v-model:value="actionParam.value" :dropdownMatchSelectWidth="false">
  46. <a-select-option v-for="(enumItem,enumIndex) in actionParam.options" :key="enumIndex" :value="enumItem.value">{{ enumItem.name }}</a-select-option>
  47. </a-select>
  48. <span v-else>{{ actionParam }}</span>
  49. </div>
  50. <a-button class="m-1" :loading="action.isExecuting" @click="actionServiceExecute(action)">执行</a-button>
  51. </div>
  52. </div>
  53. </fieldset>
  54. </div>
  55. </a-col>
  56. <a-col :span="8" class="p-5 h-full">
  57. <service-configuration-action-log :log="actionLog"/>
  58. </a-col>
  59. </a-row>
  60. </div>
  61. </template>
  62. <script setup>
  63. import { onUnmounted, ref, watch } from 'vue';
  64. import ApiClient from '@/utils/ApiClient';
  65. import ServiceConfigurationParamValueEdit from './ServiceConfigurationParamValueEdit.vue'
  66. import ServiceConfigurationActionLog from './ServiceConfigurationActionLog.vue'
  67. /** @var {Object} */
  68. const props = defineProps({
  69. serviceKey : String,
  70. });
  71. /** @var {Array} */
  72. const params = ref([]);
  73. /** @var {Array} */
  74. const actions = ref([]);
  75. /** @var {Array} */
  76. const statuses = ref([]);
  77. /** @var {Object} */
  78. const actionLog = ref(null);
  79. /** @var {Integer} */
  80. let statusRefreshTimer = null;
  81. // watch service key
  82. watch(() => props.serviceKey, handleServiceKeyChange);
  83. // on unmounted
  84. onUnmounted(() => {
  85. if ( null !== statusRefreshTimer ) {
  86. clearTimeout(statusRefreshTimer);
  87. statusRefreshTimer = false;
  88. }
  89. });
  90. // on mounted
  91. async function handleServiceKeyChange() {
  92. actionLog.value = null;
  93. if ( null !== statusRefreshTimer ) {
  94. clearTimeout(statusRefreshTimer);
  95. statusRefreshTimer = null;
  96. }
  97. if ( null === props.serviceKey ) {
  98. return ;
  99. }
  100. await actionServiceParamReload();
  101. await serviceActionReload();
  102. await refreshServiceStatusList();
  103. }
  104. // refresh service status list
  105. async function refreshServiceStatusList() {
  106. try {
  107. let client = ApiClient.getClient();
  108. statuses.value = await client.call('service-config/service-status-list', {serviceKey:props.serviceKey});
  109. if ( false !== statusRefreshTimer ) {
  110. statusRefreshTimer = setTimeout(refreshServiceStatusList, 500);
  111. }
  112. } catch ( e ) {/** nothing to do here */}
  113. }
  114. // service param reload
  115. async function actionServiceParamReload() {
  116. try {
  117. params.value = [];
  118. let client = ApiClient.getClient();
  119. let list = await client.call('service-config/service-params-list', {serviceKey:props.serviceKey});
  120. for ( var item of list ) {
  121. let groupName = item.group;
  122. let group = params.value.find( i => i.name === groupName);
  123. if ( undefined === group ) {
  124. group = {name:groupName, items:[]};
  125. params.value.push(group);
  126. }
  127. group.items.push(item);
  128. }
  129. params.value.sort((a,b) => b.items.length - a.items.length || b.name.localeCompare(a.name));
  130. } catch ( e ) {/** nothing to do here */}
  131. }
  132. // service param save
  133. async function actionServiceParamSave() {
  134. try {
  135. let values = {};
  136. for ( let group of params.value ) {
  137. for ( let item of group.items ) {
  138. values[item.key] = item.value;
  139. }
  140. }
  141. let client = ApiClient.getClient();
  142. await client.call('service-config/service-params-update', {serviceKey:props.serviceKey,params:values});
  143. await actionServiceParamReload();
  144. } catch ( e ) {/** nothing to do here */}
  145. }
  146. // service actions reload
  147. async function serviceActionReload() {
  148. try {
  149. actions.value = [];
  150. let client = ApiClient.getClient();
  151. let list = await client.call('service-config/service-action-list', {serviceKey:props.serviceKey});
  152. for ( let item of list ) {
  153. let group = actions.value.find(i => i.name === item.group);
  154. if ( undefined === group ) {
  155. group = {name:item.group, items:[]};
  156. actions.value.push(group);
  157. }
  158. group.items.push(item);
  159. group.items.sort((a,b) => a.params.length - b.params.length);
  160. }
  161. actions.value.sort((a,b) => a.name.localeCompare(b.name));
  162. } catch ( e ) {/** nothing to do here */}
  163. }
  164. // service action execute
  165. async function actionServiceExecute(action) {
  166. try {
  167. let client = ApiClient.getClient();
  168. let params = {};
  169. params.serviceKey = props.serviceKey;
  170. params.action = action.key;
  171. params.params = [];
  172. params.paramTypes = [];
  173. for ( let item of action.params ) {
  174. params.params.push(item.value);
  175. let type = item.type;
  176. if ( 'Enum' === type ) {
  177. type = item.typeEnum;
  178. }
  179. params.paramTypes.push(type);
  180. }
  181. actionLog.value = {};
  182. actionLog.value.action = params.action;
  183. actionLog.value.params = params.params;
  184. actionLog.value.response = null;
  185. action.isExecuting = true;
  186. actionLog.value.response = await client.call('service-config/service-action-exec',params);
  187. action.isExecuting = false;
  188. } catch ( e ) {
  189. /** nothing to do here */
  190. } finally {
  191. action.isExecuting = false;
  192. }
  193. }
  194. </script>