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.

194 lines
7.3 KiB

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