index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481
  1. <router lang="yaml">
  2. meta:
  3. enabled: false
  4. </router>
  5. <script lang="ts" setup name="apiTrans">
  6. import type { FormInstance } from 'element-plus'
  7. import useSettingsStore from '@/store/modules/settings'
  8. import { getApiById } from '@/api/api/apiApi'
  9. import { createX, deleteX, generateParams, getX, patchX, updateX } from '@/api/api/apiGatewayApi'
  10. import { getObjectOAMParamsListByOamId } from '@/api/biz/bizObjectOAMParamsApi'
  11. import { httpMethod, oamType } from '@/utils/tool'
  12. const settingsStore = useSettingsStore()
  13. const route = useRoute()
  14. const router = useRouter()
  15. const tabbar = useTabbar()
  16. const apiId = parseInt(route.params.apiId.toString())
  17. interface ObjectOAMParams {
  18. bizId: number
  19. objectId: number
  20. oamId: number
  21. paramId: number
  22. logicalOperator: string
  23. compareOperator: string
  24. paramName: string
  25. paramValue: string
  26. paramType: number
  27. paramRemark: string
  28. isRuled: number
  29. ruleId: number
  30. sortNo: number
  31. }
  32. const state = reactive({
  33. loading: false,
  34. dialogState: 1,
  35. search: {
  36. apiId,
  37. keywords: '',
  38. },
  39. params: {},
  40. viewData: {
  41. bizId: 0,
  42. bizTitle: '',
  43. apiTitle: '',
  44. apiMethod: 1,
  45. apiCode: '',
  46. apiType: 0,
  47. apiParams: '',
  48. objectId: 0,
  49. objectType: 0,
  50. objectCode: '',
  51. objectTitle: '',
  52. oamId: 0,
  53. oamType: 0,
  54. oamCode: '',
  55. oamTitle: '',
  56. },
  57. paramList: [] as ObjectOAMParams[],
  58. formData: {
  59. params: '',
  60. apiBody: '',
  61. },
  62. reservedParams: {
  63. limit: 1,
  64. page: 2,
  65. },
  66. result: '',
  67. })
  68. const getApiParams = async () => {
  69. state.loading = true
  70. const { bizId, objectId, oamId } = state.viewData
  71. const { data } = await getObjectOAMParamsListByOamId(bizId, objectId, oamId)
  72. data.forEach((item: any) => {
  73. item.paramName = item.paramValue
  74. })
  75. state.paramList = data
  76. if (state.viewData.oamType === 7) {
  77. state.paramList.push(
  78. {
  79. bizId: 0,
  80. objectId: 0,
  81. oamId: 0,
  82. paramId: 0,
  83. logicalOperator: '',
  84. compareOperator: '',
  85. paramName: 'page',
  86. paramValue: '1',
  87. paramType: 1,
  88. paramRemark: '',
  89. isRuled: 0,
  90. ruleId: 0,
  91. sortNo: 0,
  92. },
  93. {
  94. bizId: 0,
  95. objectId: 0,
  96. oamId: 0,
  97. paramId: 0,
  98. logicalOperator: '',
  99. compareOperator: '',
  100. paramName: 'limit',
  101. paramValue: '10',
  102. paramType: 1,
  103. paramRemark: '',
  104. isRuled: 0,
  105. ruleId: 0,
  106. sortNo: 0,
  107. },
  108. )
  109. }
  110. state.loading = false
  111. }
  112. // 查询数据
  113. const getData = async () => {
  114. state.loading = true
  115. const { data } = await getApiById(apiId)
  116. state.viewData.bizId = data.bizId
  117. state.viewData.bizTitle = data.bizTitle
  118. state.viewData.apiTitle = data.apiTitle
  119. state.viewData.apiCode = data.apiCode
  120. state.viewData.apiParams = data.apiParams
  121. state.viewData.apiMethod = data.apiMethod
  122. state.viewData.apiType = data.apiType
  123. state.viewData.objectId = data.objectId
  124. state.viewData.objectTitle = data.objectTitle
  125. state.viewData.objectCode = data.objectCode
  126. state.viewData.objectType = data.objectType
  127. state.viewData.oamId = data.oamId
  128. state.viewData.oamType = data.oamType
  129. state.viewData.oamTitle = data.oamTitle
  130. state.viewData.oamCode = data.oamCode
  131. if (data.oamType > 4) {
  132. await getApiParams()
  133. }
  134. }
  135. const paramsTableRef = ref()
  136. const paramsTableKey = ref(0)
  137. onMounted(() => {
  138. getData()
  139. })
  140. const formRef = ref<FormInstance>()
  141. const onGenerateData = async () => {
  142. const objectCode = state.viewData.objectCode
  143. const oamCode = state.viewData.oamCode
  144. const { data } = await generateParams(objectCode, oamCode)
  145. state.formData.apiBody = JSON.stringify(data)
  146. }
  147. interface param {
  148. [x: string]: any
  149. }
  150. const onExecute = async () => {
  151. const apiMethod = state.viewData.apiMethod
  152. const objectCode = state.viewData.objectCode
  153. const oamCode = state.viewData.oamCode
  154. const queryParams: param = {}
  155. state.paramList.forEach((item: { paramName: string; paramValue: string }) => {
  156. queryParams[item.paramName] = item.paramValue
  157. })
  158. let apiBody = ''
  159. if (state.formData.apiBody !== '') {
  160. apiBody = JSON.parse(state.formData.apiBody)
  161. }
  162. if (apiMethod === 1) {
  163. const { data } = await getX(objectCode, oamCode, queryParams)
  164. state.result = JSON.stringify(data)
  165. }
  166. else if (apiMethod === 2) {
  167. const { data } = await createX(objectCode, oamCode, apiBody)
  168. state.result = JSON.stringify(data)
  169. }
  170. else if (apiMethod === 3) {
  171. const { data } = await updateX(objectCode, oamCode, apiBody)
  172. state.result = JSON.stringify(data)
  173. }
  174. else if (apiMethod === 4) {
  175. const { data } = await patchX(objectCode, oamCode, apiBody)
  176. state.result = JSON.stringify(data)
  177. }
  178. else if (apiMethod === 5) {
  179. const { data } = await deleteX(objectCode, oamCode, apiBody)
  180. state.result = JSON.stringify(data)
  181. }
  182. }
  183. // 返回列表页
  184. function goBack() {
  185. if (settingsStore.settings.tabbar.enable && settingsStore.settings.tabbar.mergeTabsBy !== 'activeMenu') {
  186. tabbar.close({ name: 'api' })
  187. }
  188. else {
  189. router.push({ name: 'api' })
  190. }
  191. }
  192. </script>
  193. <template>
  194. <div class="absolute-container">
  195. <page-header :title="state.viewData.apiTitle" :content="state.apiCode">
  196. <el-button size="default" round @click="goBack">
  197. <template #icon>
  198. <el-icon>
  199. <svg-icon name="i-ep:arrow-left" />
  200. </el-icon>
  201. </template>
  202. 返回
  203. </el-button>
  204. </page-header>
  205. <div class="page-main">
  206. <LayoutContainer left-side-width="350px" hide-left-side-toggle>
  207. <template #leftSide>
  208. <el-descriptions
  209. :title="state.viewData.oamTitle"
  210. direction="horizontal"
  211. :column="1"
  212. size="small"
  213. border
  214. >
  215. <el-descriptions-item
  216. label-align="right"
  217. label="URL:"
  218. width="150px"
  219. >
  220. <span>{{ httpMethod(state.viewData.apiMethod) }}: /{{ state.viewData.objectCode }}/{{ state.viewData.oamCode }} </span>
  221. </el-descriptions-item>
  222. <el-descriptions-item
  223. label-align="right"
  224. label="业务模型"
  225. width="150px"
  226. >
  227. {{ state.viewData.bizTitle }}
  228. </el-descriptions-item>
  229. <el-descriptions-item
  230. label-align="right"
  231. label="业务对象"
  232. width="150px"
  233. >
  234. {{ state.viewData.objectTitle }}
  235. </el-descriptions-item>
  236. <el-descriptions-item
  237. label-align="right"
  238. label="编码"
  239. width="150px"
  240. >
  241. {{ state.viewData.oamCode }}
  242. </el-descriptions-item>
  243. <el-descriptions-item
  244. label="行为类型"
  245. width="150px"
  246. label-align="right"
  247. >
  248. {{ oamType(state.viewData.oamType) }}
  249. </el-descriptions-item>
  250. <el-descriptions-item
  251. label-align="right"
  252. width="150px"
  253. label="说明"
  254. >
  255. {{ state.viewData.oamDesc }}
  256. </el-descriptions-item>
  257. </el-descriptions>
  258. </template>
  259. <div class="form">
  260. <el-form ref="formRef" label-width="100px" label-position="top">
  261. <el-form-item v-if="state.viewData.oamType > 4" label="查询条件">
  262. <el-table
  263. ref="paramsTableRef"
  264. :key="paramsTableKey"
  265. :data="state.paramList"
  266. class="list-table"
  267. size="small"
  268. :show-header="false"
  269. border
  270. stripe
  271. highlight-current-row
  272. >
  273. <el-table-column label="参数" header-align="center" align="center" width="150">
  274. <template #default="scope">
  275. <span>{{ scope.row.paramName }}</span>
  276. </template>
  277. </el-table-column>
  278. <el-table-column label="值" header-align="left" align="left">
  279. <template #default="scope">
  280. <input v-model="scope.row.paramValue">
  281. </template>
  282. </el-table-column>
  283. </el-table>
  284. </el-form-item>
  285. <el-form-item v-if="state.viewData.oamType <= 4" label="数据">
  286. <el-input v-model="state.formData.apiBody" type="textarea" rows="10" placeholder="数据" />
  287. </el-form-item>
  288. <el-form-item v-if="state.result" label="结果">
  289. <el-input v-model="state.result" type="textarea" rows="10" placeholder="结果" readonly />
  290. </el-form-item>
  291. <div class="action-bottom">
  292. <el-button v-if="state.viewData.oamType <= 4" type="primary" @click="onGenerateData">
  293. 生成API数据
  294. </el-button>
  295. <el-button type="primary" @click="onExecute">
  296. 立即执行
  297. </el-button>
  298. </div>
  299. </el-form>
  300. </div>
  301. </LayoutContainer>
  302. </div>
  303. </div>
  304. </template>
  305. <style lang="scss" scoped>
  306. .absolute-container {
  307. position: absolute;
  308. width: 100%;
  309. height: 100%;
  310. display: flex;
  311. flex-direction: column;
  312. .page-header {
  313. margin-bottom: 0;
  314. }
  315. .page-main {
  316. flex: 1;
  317. overflow: auto;
  318. display: flex;
  319. flex-direction: column;
  320. .flex-container {
  321. position: static;
  322. }
  323. }
  324. }
  325. .flex-container {
  326. :deep(.left-side) {
  327. display: flex;
  328. flex-direction: column;
  329. height: 100%;
  330. .btns {
  331. display: inline-flex;
  332. width: 100%;
  333. margin-bottom: var(--container-padding);
  334. .add {
  335. width: 100%;
  336. }
  337. }
  338. .tree {
  339. flex: 1;
  340. overflow-y: auto;
  341. .el-tree {
  342. .el-tree-node__content {
  343. height: 40px;
  344. }
  345. .is-current > .el-tree-node__content {
  346. background-color: var(--el-color-primary-light-9);
  347. }
  348. .custom-tree-node {
  349. flex: 1;
  350. position: relative;
  351. width: 0;
  352. height: 100%;
  353. display: flex;
  354. flex-direction: column;
  355. justify-content: center;
  356. .label {
  357. display: inline-flex;
  358. align-items: center;
  359. width: calc(100% - 10px);
  360. color: var(--el-text-color-primary);
  361. .text {
  362. @include text-overflow;
  363. }
  364. }
  365. &:hover {
  366. .actions {
  367. display: block;
  368. }
  369. }
  370. .actions {
  371. display: none;
  372. position: absolute;
  373. right: 10px;
  374. top: 50%;
  375. transform: translateY(-50%);
  376. .el-button {
  377. padding: 5px 8px;
  378. }
  379. }
  380. }
  381. }
  382. }
  383. }
  384. :deep(.main) {
  385. .main-container {
  386. display: flex;
  387. flex-direction: column;
  388. justify-content: center;
  389. width: 100%;
  390. height: 100%;
  391. }
  392. }
  393. }
  394. .form {
  395. flex: 1;
  396. min-height: 0;
  397. display: flex;
  398. flex-direction: column;
  399. .el-form {
  400. flex: 1;
  401. min-height: 0;
  402. display: flex;
  403. flex-direction: column;
  404. .columns-table {
  405. flex: 1;
  406. height: 0;
  407. display: flex;
  408. flex-direction: column;
  409. :deep(.el-form-item__content) {
  410. min-height: 0;
  411. .el-table {
  412. height: 100%;
  413. }
  414. }
  415. }
  416. }
  417. }
  418. .action-bottom {
  419. padding: var(--container-padding);
  420. border-top: 1px dashed var(--el-disabled-border-color);
  421. background-color: var(--g-app-bg);
  422. transition: background-color 0.3s;
  423. display: flex;
  424. justify-content: right;
  425. }
  426. </style>