editModel.vue 73 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765
  1. <template>
  2. <div style="width: 100%;;display: flex;">
  3. <div style="width: 15%;;background-color: #F2F6FC;max-height: 85vh;overflow: auto;">
  4. <div style="display: flex;padding-top: 1%;padding-top: 5%;">
  5. <el-input
  6. v-model="inputNode"
  7. style="width:75%;margin-left: 5%;background-color: #ebeef5;"
  8. class="w-50 m-2"
  9. :prefix-icon="Search"
  10. />
  11. <!-- <el-button style="margin-left: 2%;width: 10%;background-color: #F7F7F7" :icon="Filter"/> -->
  12. <el-button type="primary" @click="showAdd" style="margin-left: 5%;width: 10%;" :icon="Plus"/>
  13. </div>
  14. <!-- <Plus style="width: 1em; height: 1em; margin-left:90%;cursor: pointer;color: #337ecc;" @click="showAddTree"/> -->
  15. <el-tree :expand-on-click-node="false" ref="treeRef" :filter-node-method="filterNode" :current-node-key="currentNodeKey" class="treeLeft" :data="data" @node-click="handleNodeClick" node-key="id" style="margin-left: 5%;margin-top: 5%;width: 90%;background-color: transparent;" default-expand-all :key="valueKet">
  16. <template #default="{ node, data }">
  17. <span style="justify-content: space-between;display: flex;width: 100%;align-items: center;" >
  18. <div class="custom-tree-node">
  19. <!-- <el-tag v-if="data.nodeType=='MODEL'" class="ml-2" type="warning">模型</el-tag> -->
  20. <svg-icon icon-class="model2" style="color: #eebe77;" v-if="data.nodeType=='MODEL'"/>
  21. <!-- <el-tag class="ml-2">
  22. 服务
  23. </el-tag> -->
  24. <svg-icon icon-class="model" dstyle="color: #13E03B;" v-if="data.nodeType=='SERVICE'"/>
  25. <svg-icon svg-icon icon-class="cate" style="color: red;" v-if="data.nodeType=='TREE'"/>
  26. <span>{{ node.label }}</span>
  27. </div>
  28. <div style="margin-right: 1%;position: absolute;margin-left: 75%;">
  29. <el-dropdown trigger="hover" @click.stop v-if="currentNodeKey === data.id&&data.nodeType!=='SERVICE'">
  30. <el-icon class="el-icon--right" style="color: black;">
  31. <plus />
  32. </el-icon>
  33. <template #dropdown>
  34. <el-dropdown-menu>
  35. <el-dropdown-item style="display: flex;" @click="add1Level">
  36. <el-icon class="el-icon--right" style="color: black;">
  37. <CirclePlus />
  38. </el-icon>
  39. <div>
  40. 添加同级
  41. </div>
  42. </el-dropdown-item>
  43. <el-dropdown-item style="display: flex;" @click="addNextLevel">
  44. <el-icon class="el-icon--right" style="color: black;">
  45. <Connection />
  46. </el-icon>
  47. <div>
  48. 新建下级
  49. </div>
  50. </el-dropdown-item>
  51. <divider/>
  52. <el-dropdown-item style="display: flex;" @click="delAll" divided>
  53. <el-icon class="el-icon--right" style="color: black;">
  54. <CircleClose />
  55. </el-icon>
  56. <div>
  57. 删除节点
  58. </div>
  59. </el-dropdown-item>
  60. </el-dropdown-menu>
  61. </template>
  62. </el-dropdown>
  63. </div>
  64. </span>
  65. </template>
  66. </el-tree>
  67. </div>
  68. <div style="width: 84%;margin-left: 1%;padding-top: 1%;" class="tab-container">
  69. <div style="overflow: auto;height: 80vh;">
  70. <div style="display: flex;margin-top: 1%;">
  71. <el-button type="primary" @click="saveEditService" style="margin-left: 80%;z-index: 1000;" :disabled="isEdit">提交</el-button>
  72. <el-button type="danger" @click="delSer" style="margin-left: 1%;z-index: 1000;" :disabled="isEdit">删除</el-button>
  73. </div>
  74. <el-form size="mini" :key="tableKey" style="margin-top: -2%;width: 98%;" :model="formJi" label-position="right" ref="formRefJi" label-width="120px" :rules="rulesJi">
  75. <el-row :gutter="48">
  76. <el-col :span="10">
  77. <el-form-item label="服务名称:" prop="name" style="">
  78. <div style="display: flex;width: 100%;justify-content: space-between;">
  79. <el-input :disabled="isEdit" v-model="formJi.name" style="width: 100%;"/>
  80. </div>
  81. </el-form-item>
  82. </el-col>
  83. <el-col :span="6">
  84. <el-form-item label="接口类型:" prop="" style="">
  85. <div style="display: flex;width: 100%;justify-content: space-between;">
  86. <el-select
  87. v-model="formJi.type"
  88. :disabled="isEdit"
  89. style="width: 100%;margin-left: 0%;"
  90. >
  91. <el-option
  92. v-for="item in optionsType"
  93. :key="item.value"
  94. :label="item.label"
  95. :value="item.value"
  96. />
  97. </el-select>
  98. <div style="display: flex;">
  99. </div>
  100. </div>
  101. </el-form-item>
  102. </el-col>
  103. </el-row>
  104. <el-row :gutter="48">
  105. <el-col :span="10">
  106. <el-form-item label="接口地址:" prop="url" style="">
  107. <el-input
  108. v-model="formJi.url"
  109. :disabled="isEdit"
  110. style="width: 100%;"
  111. placeholder=""
  112. class="input-with-select"
  113. >
  114. </el-input>
  115. </el-form-item>
  116. </el-col>
  117. <el-col :span="6">
  118. <el-form-item label="请求方式:" prop="" style="">
  119. <el-select
  120. v-model="formJi.rqtype"
  121. :disabled="isEdit"
  122. style="width: 100%;margin-left: 0%;"
  123. >
  124. <el-option
  125. v-for="item in optionsRqtype"
  126. :key="item.value"
  127. :label="item.label"
  128. :value="item.value"
  129. />
  130. </el-select>
  131. </el-form-item>
  132. </el-col>
  133. </el-row>
  134. <el-row :gutter="48">
  135. <el-col :span="10">
  136. <el-form-item label="响应类型:" prop="" style="display: flex; align-items: center;">
  137. <el-radio-group :disabled="isEdit" v-model="formJi.rptype" class="ml-4" style="display: inline-flex; align-items: center;">
  138. <el-radio label="1" size="large" style="display: inline-flex; align-items: center;">
  139. <span style="position: relative; top: -1px">JSON</span>
  140. </el-radio>
  141. <el-radio label="2" size="large" style="display: inline-flex; align-items: center;">
  142. <span style="position: relative; top: -1px">XML</span>
  143. </el-radio>
  144. <el-radio label="3" size="large" style="display: inline-flex; align-items: center;">
  145. <span style="position: relative; top: -1px">HTML</span>
  146. </el-radio>
  147. </el-radio-group>
  148. </el-form-item>
  149. </el-col>
  150. <el-col :span="6">
  151. <el-form-item label="服务分类:" prop="cateCode" style="">
  152. <el-cascader :disabled="isEdit" v-model="formJi.cateCode" :options="cascaderOptions" clearable style="width: 100%;"></el-cascader>
  153. </el-form-item>
  154. </el-col>
  155. <!-- <el-col :span="8">
  156. <el-form-item label="请求方式:" prop="name" style="">
  157. <el-select
  158. v-model="formJi.type"
  159. :disabled="isEdit"
  160. style="width: 100%;margin-left: 0%;"
  161. >
  162. <el-option
  163. v-for="item in optionsType"
  164. :key="item.value"
  165. :label="item.label"
  166. :value="item.value"
  167. />
  168. </el-select>
  169. </el-form-item>
  170. </el-col> -->
  171. </el-row>
  172. <el-row :gutter="48">
  173. <el-col :span="13">
  174. <el-form-item label="服务说明:">
  175. <el-input :disabled="isEdit" v-model="formJi.intro" style="width: 100%;" :rows="3" resize="none" type="textarea"/>
  176. </el-form-item>
  177. </el-col>
  178. </el-row>
  179. </el-form>
  180. <div style="margin-top: 2%;">
  181. <div style="display: flex;justify-content: space-between;align-items: center;">
  182. <div>
  183. 请求参数
  184. </div>
  185. <div style="display: flex;justify-content: flex-end;margin-right: 2%;">
  186. <el-button @click="addPa" style="margin-top: 1%;" type="success" size="mini" :disabled="isEdit" plain>新增参数</el-button>
  187. </div>
  188. </div>
  189. <div>
  190. <el-table
  191. style="margin-top: 1%;width: 98%;"
  192. :data="tableDataCan"
  193. :cell-style="{ textAlign: 'center',padding:'2px 0' }"
  194. :header-cell-style="{ textAlign: 'center'}"
  195. :row-style="{ height: heightAll*0.01+'px',fontSize: '16px',textAlign:'center' }"
  196. border >
  197. <el-table-column prop="itemName" label="参数字段(必填)">
  198. <template #default="scope">
  199. <div style="width: 100%;display: flex;">
  200. <el-input :disabled="isEdit" placeholder="请填写参数编码" type="primary" class="noBor" v-model="scope.row.paramCode" size="mini" text style="margin-left: 0%;border: transparent;"></el-input>
  201. </div>
  202. </template>
  203. </el-table-column>
  204. <el-table-column prop="itemName" label="参数名称(必填)">
  205. <template #default="scope">
  206. <div style="width: 100%;">
  207. <el-input :disabled="isEdit" placeholder="请填写参数名称" type="primary" class="noBor" v-model="scope.row.paramName" size="mini" text style="margin-left: 0%;"></el-input>
  208. </div>
  209. </template>
  210. </el-table-column>
  211. <el-table-column prop="itemName" label="参数类型(必填)" width="200">
  212. <template #default="scope">
  213. <div style="width: 100%;">
  214. <el-select
  215. v-model="scope.row.paramType"
  216. class="noBorSel"
  217. :disabled="isEdit"
  218. placeholder=""
  219. style="width: 100%;margin-left: 0%;"
  220. >
  221. <el-option
  222. v-for="item in optionsCan"
  223. :key="item.value"
  224. :label="item.label"
  225. :value="item.value"
  226. />
  227. </el-select>
  228. </div>
  229. </template>
  230. </el-table-column>
  231. <el-table-column prop="itemName" label="参数说明" >
  232. <template #default="scope">
  233. <div style="width: 100%;">
  234. <el-input type="primary" :disabled="isEdit" class="noBor" v-model="scope.row.paramNote" size="mini" text style="margin-left: 0%;"></el-input>
  235. </div>
  236. </template>
  237. </el-table-column>
  238. <el-table-column prop="address" label="操作" width="100">
  239. <template #default="scope">
  240. <div style="width: 100%;">
  241. <el-button type="danger" @click="delCan(scope.$index)" size="mini" text style="margin-left: 0%;">删除</el-button>
  242. </div>
  243. </template>
  244. </el-table-column>
  245. </el-table>
  246. </div>
  247. </div>
  248. <div style="margin-top: 2%;">
  249. <div style="display: flex;justify-content: space-between;align-items: center;">
  250. <div>
  251. 返回参数
  252. </div>
  253. <div style="display: flex;justify-content: flex-end;margin-right: 2%;">
  254. </div>
  255. </div>
  256. <div style="width: 98%;margin-left: 0%;height: 25vh;margin-top: 1%;overflow: auto;border: 1px solid #eee;">
  257. <el-tree :expand-on-click-node="false" ref="treeRefReturun" :filter-node-method="filterNode" :current-node-key="currentNodeKey" class="treeLeft"
  258. :data="dataTreeReturn" @node-click="" node-key="id" style="margin-left: 1%;margin-top: 0%;width: 50%;background-color: transparent;"
  259. default-expand-all :key="valueKet" :props="defaultProps">
  260. <template #default="{ node, data }">
  261. <span style="justify-content: space-between;display: flex;width: 30%;align-items: center;margin-left: 1%;" @mouseenter="setId(data)">
  262. <div class="custom-tree-node" style="align-items: center;line-height: 1.5;font-size: 10px;">
  263. <span style="font-size: 1rem;">{{ node.label }}</span>
  264. </div>
  265. <div style="position: absolute;left:40%;">
  266. <div style="color: #67C23A;" v-if="data.paramType=='string'">
  267. string
  268. </div>
  269. <div style="color: #E6A23C;" v-else-if="data.paramType=='array'">
  270. array
  271. </div>
  272. <div style="color: #F56C6C;" v-else-if="data.paramType=='number'">
  273. number
  274. </div>
  275. <div style="color: #909399;" v-else>
  276. {{ data.paramType }}
  277. </div>
  278. </div>
  279. <div style="margin-right: 1%;position: absolute;left:60%;">
  280. <el-dropdown trigger="hover">
  281. <svg-icon icon-class="zhankai"/>
  282. <template #dropdown>
  283. <el-dropdown-menu>
  284. <el-dropdown-item style="display: flex;" @click="add1LevelTree">
  285. <el-icon class="el-icon--right" style="color: black;">
  286. <CirclePlus />
  287. </el-icon>
  288. <div>
  289. 添加同级
  290. </div>
  291. </el-dropdown-item>
  292. <el-dropdown-item style="display: flex;" @click="addNextLevelTree">
  293. <el-icon class="el-icon--right" style="color: black;">
  294. <Connection />
  295. </el-icon>
  296. <div>
  297. 新建下级
  298. </div>
  299. </el-dropdown-item>
  300. <divider/>
  301. <el-dropdown-item style="display: flex;" @click="delAllTree" divided>
  302. <el-icon class="el-icon--right" style="color: black;">
  303. <CircleClose />
  304. </el-icon>
  305. <div>
  306. 删除
  307. </div>
  308. </el-dropdown-item>
  309. </el-dropdown-menu>
  310. </template>
  311. </el-dropdown>
  312. </div>
  313. <div style="margin-right: 1%;position: absolute;left:70%;">
  314. <div style="">
  315. <span style="font-size: 1rem;">{{ data.paramName }}</span>
  316. </div>
  317. </div>
  318. </span>
  319. </template>
  320. </el-tree>
  321. </div>
  322. </div>
  323. <div style="margin-top: 2%;">
  324. <!-- <div>返回响应</div> -->
  325. <div style="color: #909399;margin-left: 7%;margin-top:1%;">此处填写本服务接口响应信息描述</div>
  326. <el-tabs type="card" style="margin-top: -1.5%;width: 98%;">
  327. <el-tab-pane label="响应内容">
  328. <div style="display: flex; flex-direction: column;">
  329. <!-- <el-tree :data="data" :props="defaultProps" @node-click="handleNodeClick" style="margin-top: 1%;margin-left: 2%;background-color: #F7F7F7;background-color: transparent;width: 15%;" default-expand-all>
  330. <template #default="{ node, data }">
  331. <span style="display: flex;justify-content: space-between;width: 100%;align-items: center;">
  332. <span><el-input v-model="node.label" size="mini"/></span>
  333. <span style="display: flex;align-items: center;">
  334. <el-tooltip
  335. class="box-item"
  336. effect="light"
  337. content="是否必填"
  338. placement="top-start"
  339. >
  340. <el-checkbox v-model="checked1" label="" size="large" />
  341. </el-tooltip>
  342. <el-select
  343. v-model="formJi.type"
  344. :disabled="isEdit"
  345. style="width: 100%;margin-left: -1%;"
  346. >
  347. <el-option
  348. v-for="item in optionsType"
  349. :key="item.value"
  350. :label="item.label"
  351. :value="item.value"
  352. />
  353. </el-select>
  354. <el-tooltip
  355. class="box-item"
  356. effect="light"
  357. content="是否允许null"
  358. placement="top-start"
  359. >
  360. <el-checkbox v-model="checked1" label="" size="large" />
  361. </el-tooltip>
  362. </span>
  363. </span>
  364. </template>
  365. </el-tree> -->
  366. </div>
  367. </el-tab-pane>
  368. </el-tabs>
  369. <div style="overflow: auto;height: 20vh;margin-top: -1%;">
  370. <el-input @change="byWay" :disabled="isEdit" placeholder="请输入示例" :rows="8" type="textarea" v-model="dataJsonXiang" size="mini" text style="margin-top: 0%;width: 98%;" ></el-input>
  371. </div>
  372. </div>
  373. <div style="margin-top: 2.5%;margin-left: 0%;padding-bottom: 1%;">
  374. <el-tabs type="card" style="margin-top: -1.5%;width: 98%;">
  375. <el-tab-pane label="使用说明">
  376. </el-tab-pane>
  377. </el-tabs>
  378. <el-input :disabled="isEdit" placeholder="请输入示例" :rows="8" type="textarea" v-model="example" size="mini" text style="margin-top: -1%;width: 98%;" ></el-input>
  379. </div>
  380. </div>
  381. <el-dialog @close="clearAdd" v-model="dialogVisible" title="新增节点" width="70%" destroy-on-close :key="tableKey">
  382. <div style="overflow: auto;height: 80vh;">
  383. <el-form size="mini" :key="tableKey" style="margin-top: 1%;width: 98%;" :model="formAdd" label-position="right" ref="formRefAdd" label-width="120px" :rules="rulesAdd">
  384. <el-row :gutter="48">
  385. <el-col :span="10">
  386. <el-form-item label="服务名称:" prop="name" style="">
  387. <div style="display: flex;width: 100%;justify-content: space-between;">
  388. <el-input v-model="formAdd.name" style="width: 100%;"/>
  389. </div>
  390. </el-form-item>
  391. </el-col>
  392. <el-col :span="6">
  393. <el-form-item label="接口类型:" prop="" style="">
  394. <div style="display: flex;width: 100%;justify-content: space-between;">
  395. <el-select
  396. v-model="formAdd.type"
  397. :disabled="isEdit"
  398. style="width: 100%;margin-left: 0%;"
  399. >
  400. <el-option
  401. v-for="item in optionsType"
  402. :key="item.value"
  403. :label="item.label"
  404. :value="item.value"
  405. />
  406. </el-select>
  407. <div style="display: flex;">
  408. </div>
  409. </div>
  410. </el-form-item>
  411. </el-col>
  412. </el-row>
  413. <el-row :gutter="48">
  414. <el-col :span="10">
  415. <el-form-item label="接口地址:" prop="url" style="">
  416. <el-input
  417. v-model="formAdd.url"
  418. style="width: 100%;"
  419. placeholder=""
  420. class="input-with-select"
  421. >
  422. </el-input>
  423. </el-form-item>
  424. </el-col>
  425. <el-col :span="6">
  426. <el-form-item label="请求方式:" prop="" style="">
  427. <el-select
  428. v-model="formAdd.rqtype"
  429. :disabled="isEdit"
  430. style="width: 100%;margin-left: 0%;"
  431. >
  432. <el-option
  433. v-for="item in optionsRqtype"
  434. :key="item.value"
  435. :label="item.label"
  436. :value="item.value"
  437. />
  438. </el-select>
  439. </el-form-item>
  440. </el-col>
  441. </el-row>
  442. <el-row :gutter="48">
  443. <el-col :span="10">
  444. <el-form-item label="所属模型:" prop="mdid" style="">
  445. <el-tree-select
  446. v-model="formAdd.mdid"
  447. :data="optionsMdid"
  448. check-strictly
  449. :render-after-expand="false"
  450. style="width: 100%"
  451. />
  452. <!-- <el-select
  453. v-model="formAdd.mdid"
  454. style="width: 100%;margin-left: 0%;"
  455. >
  456. <el-option
  457. v-for="item in optionsMdid"
  458. :key="item.value"
  459. :label="item.label"
  460. :value="item.id"
  461. />
  462. </el-select> -->
  463. </el-form-item>
  464. </el-col>
  465. </el-row>
  466. <el-form-item label="排序:" prop="dcSort">
  467. <el-input-number v-model="formAdd.sort" :min="1" style="width: 15%;"/>
  468. </el-form-item>
  469. <el-row :gutter="48">
  470. <el-col :span="10">
  471. <el-form-item label="响应类型:" prop="" style="display: flex; align-items: center;">
  472. <el-radio-group v-model="formAdd.rptype" class="ml-4" style="display: inline-flex; align-items: center;">
  473. <el-radio label="1" size="large" style="display: inline-flex; align-items: center;">
  474. <span style="position: relative; top: -1px">JSON</span> <!-- 微调文字位置 -->
  475. </el-radio>
  476. <el-radio label="2" size="large" style="display: inline-flex; align-items: center;">
  477. <span style="position: relative; top: -1px">XML</span>
  478. </el-radio>
  479. <el-radio label="3" size="large" style="display: inline-flex; align-items: center;">
  480. <span style="position: relative; top: -1px">HTML</span>
  481. </el-radio>
  482. </el-radio-group>
  483. </el-form-item>
  484. </el-col>
  485. <el-col :span="6">
  486. <el-form-item label="服务分类:" prop="cateCode" style="">
  487. <el-cascader v-model="formAdd.cateCode" :options="cascaderOptions" :props="props1" clearable style="width: 100%;"></el-cascader>
  488. </el-form-item>
  489. </el-col>
  490. <!-- <el-col :span="8">
  491. <el-form-item label="请求方式:" prop="name" style="">
  492. <el-select
  493. v-model="formJi.type"
  494. :disabled="isEdit"
  495. style="width: 100%;margin-left: 0%;"
  496. >
  497. <el-option
  498. v-for="item in optionsType"
  499. :key="item.value"
  500. :label="item.label"
  501. :value="item.value"
  502. />
  503. </el-select>
  504. </el-form-item>
  505. </el-col> -->
  506. </el-row>
  507. <el-row :gutter="48">
  508. <el-col :span="13">
  509. <el-form-item label="服务说明:">
  510. <el-input v-model="formAdd.intro" style="width: 100%;" :rows="3" resize="none" type="textarea"/>
  511. </el-form-item>
  512. </el-col>
  513. </el-row>
  514. </el-form>
  515. <div style="margin-top: 2%;">
  516. <div style="display: flex;justify-content: space-between;align-items: center;">
  517. <div>
  518. 请求参数
  519. </div>
  520. <div style="display: flex;justify-content: flex-end;margin-right: 2%;">
  521. <el-button @click="addCanAdd" style="margin-top: 1%;" type="success" size="mini" plain>新增参数</el-button>
  522. </div>
  523. </div>
  524. <div>
  525. <el-table
  526. style="margin-top: 1%;width: 98%;"
  527. :data="tableDataCanAdd"
  528. :cell-style="{ textAlign: 'center',padding:'2px 0' }"
  529. :header-cell-style="{ textAlign: 'center'}"
  530. :row-style="{ height: heightAll*0.01+'px',fontSize: '16px',textAlign:'center' }"
  531. border >
  532. <el-table-column prop="itemName" label="参数字段">
  533. <template #default="scope">
  534. <div style="width: 100%;">
  535. <el-input placeholder="请填写参数编码" type="primary" class="noBor" v-model="scope.row.parCode" size="mini" text style="margin-left: 0%;border: transparent;"></el-input>
  536. </div>
  537. </template>
  538. </el-table-column>
  539. <el-table-column prop="itemName" label="参数名称">
  540. <template #default="scope">
  541. <div style="width: 100%;">
  542. <el-input placeholder="请填写参数名称" type="primary" class="noBor" v-model="scope.row.parName" size="mini" text style="margin-left: 0%;"></el-input>
  543. </div>
  544. </template>
  545. </el-table-column>
  546. <el-table-column prop="itemName" label="参数类型" width="200">
  547. <template #default="scope">
  548. <div style="width: 100%;">
  549. <el-select
  550. v-model="scope.row.parType"
  551. class="noBorSel"
  552. placeholder=""
  553. style="width: 100%;margin-left: 0%;"
  554. >
  555. <el-option
  556. v-for="item in optionsCan"
  557. :key="item.value"
  558. :label="item.label"
  559. :value="item.value"
  560. />
  561. </el-select>
  562. </div>
  563. </template>
  564. </el-table-column>
  565. <el-table-column prop="itemName" label="参数示例">
  566. <template #default="scope">
  567. <div style="width: 100%;">
  568. <el-input placeholder="请填写参数示例" type="primary" class="noBor" v-model="scope.row.paramValue" size="mini" text style="margin-left: 0%;"></el-input>
  569. </div>
  570. </template>
  571. </el-table-column>
  572. <el-table-column prop="itemName" label="参数说明" >
  573. <template #default="scope">
  574. <div style="width: 100%;">
  575. <el-input type="primary" class="noBor" v-model="scope.row.parNote" size="mini" text style="margin-left: 0%;"></el-input>
  576. </div>
  577. </template>
  578. </el-table-column>
  579. <el-table-column prop="address" label="操作" width="100">
  580. <template #default="scope">
  581. <div style="width: 100%;">
  582. <el-button type="danger" @click="delCanAdd(scope.$index)" size="mini" text style="margin-left: 0%;">删除</el-button>
  583. </div>
  584. </template>
  585. </el-table-column>
  586. </el-table>
  587. </div>
  588. </div>
  589. <div style="margin-top: 2%;">
  590. <!-- <div>返回响应</div> -->
  591. <div style="color: #909399;margin-left: 8%;margin-top:1%;">此处填写本服务接口响应信息描述</div>
  592. <el-tabs type="card" style="margin-top: -2%;width: 98%;">
  593. <el-tab-pane label="响应内容">
  594. <div style="display: flex; flex-direction: column;">
  595. </div>
  596. </el-tab-pane>
  597. </el-tabs>
  598. <div style="overflow: auto;height: 20vh;margin-top: -1%;">
  599. <el-input placeholder="请输入示例" :rows="8" type="textarea" v-model="JsonAdd" size="mini" text style="margin-top: 0%;width: 98%;" ></el-input>
  600. </div>
  601. </div>
  602. <div style="margin-top: 2.5%;margin-left: 0%;padding-bottom: 1%;">
  603. <el-tabs type="card" style="margin-top: -1.5%;width: 98%;">
  604. <el-tab-pane label="使用说明">
  605. </el-tab-pane>
  606. </el-tabs>
  607. <el-input placeholder="请输入示例" :rows="8" type="textarea" v-model="exampleAdd" size="mini" text style="margin-top: -1%;width: 98%;" ></el-input>
  608. </div>
  609. </div>
  610. <template #footer>
  611. <span class="dialog-footer">
  612. <el-button size="mini" @click="dialogVisible = false">取消</el-button>
  613. <el-button type="primary" @click="addSer" size="mini">
  614. 提交
  615. </el-button>
  616. </span>
  617. </template>
  618. </el-dialog>
  619. <el-dialog @close="clearFromLev" title="添加目录" v-model="dialogVisibleLevel" width="30%" destroy-on-close :key="tableKey">
  620. <el-form size="mini" :key="tableKey" style="margin-top: 1%;width: 90%;" :model="formLev" label-position="right" ref="formRefLev" label-width="120px" :rules="rulesLev">
  621. <el-form-item label="名称:" prop="itemName" style="">
  622. <el-input v-model="formLev.itemName" style="width: 100%;"/>
  623. </el-form-item>
  624. <el-form-item label="说明:" prop="itemNotes" style="">
  625. <el-input v-model="formLev.itemNotes" style="width: 100%;"/>
  626. </el-form-item>
  627. <el-form-item label="排序:" prop="itemNo" style="">
  628. <el-input-number v-model="formLev.itemNo" style="width: 100%;" :min="1" :max="10000" @change="handleChange" />
  629. </el-form-item>
  630. </el-form>
  631. <template #footer>
  632. <span class="dialog-footer">
  633. <el-button size="mini" @click="dialogVisibleLevel = false">取消</el-button>
  634. <el-button type="primary" @click="saveAdd1Level" size="mini" v-if="show1Lev">
  635. 提交
  636. </el-button>
  637. <el-button type="primary" @click="saveAddNextLevel" size="mini" v-if="!show1Lev">
  638. 提交
  639. </el-button>
  640. </span>
  641. </template>
  642. </el-dialog>
  643. <el-dialog @close="clearFromLev" title="添加目录" v-model="dialogVisibleTree" width="55%" destroy-on-close :key="tableKey">
  644. <el-button @click="addTreePar" style="margin-top: 1%;" type="success" size="mini" :disabled="isEdit" plain>新增参数</el-button>
  645. <el-table
  646. style="margin-top: 1%;width: 98%;"
  647. :data="tableDataCanAddTree"
  648. :cell-style="{ textAlign: 'center',padding:'2px 0' }"
  649. :header-cell-style="{ textAlign: 'center'}"
  650. :row-style="{ height: heightAll*0.01+'px',fontSize: '16px',textAlign:'center' }"
  651. border >
  652. <el-table-column prop="itemName" label="参数字段">
  653. <template #default="scope">
  654. <div style="width: 100%;">
  655. <el-input placeholder="请填写参数编码" type="primary" class="noBor" v-model="scope.row.paramCode" size="mini" text style="margin-left: 0%;border: transparent;"></el-input>
  656. </div>
  657. </template>
  658. </el-table-column>
  659. <el-table-column prop="itemName" label="参数名称">
  660. <template #default="scope">
  661. <div style="width: 100%;">
  662. <el-input placeholder="请填写参数名称" type="primary" class="noBor" v-model="scope.row.paramName" size="mini" text style="margin-left: 0%;"></el-input>
  663. </div>
  664. </template>
  665. </el-table-column>
  666. <el-table-column prop="itemName" label="参数类型" width="200">
  667. <template #default="scope">
  668. <div style="width: 100%;">
  669. <el-select
  670. v-model="scope.row.paramType"
  671. class="noBorSel"
  672. placeholder=""
  673. style="width: 100%;margin-left: 0%;"
  674. >
  675. <el-option
  676. v-for="item in optionsCan"
  677. :key="item.value"
  678. :label="item.label"
  679. :value="item.value"
  680. />
  681. </el-select>
  682. </div>
  683. </template>
  684. </el-table-column>
  685. <el-table-column prop="itemName" label="参数示例">
  686. <template #default="scope">
  687. <div style="width: 100%;">
  688. <el-input placeholder="请填写参数示例" type="primary" class="noBor" v-model="scope.row.paramValue" size="mini" text style="margin-left: 0%;"></el-input>
  689. </div>
  690. </template>
  691. </el-table-column>
  692. <el-table-column prop="itemName" label="参数说明" >
  693. <template #default="scope">
  694. <div style="width: 100%;">
  695. <el-input type="primary" class="noBor" v-model="scope.row.paramNote" size="mini" text style="margin-left: 0%;"></el-input>
  696. </div>
  697. </template>
  698. </el-table-column>
  699. <el-table-column prop="address" label="操作" width="100">
  700. <template #default="scope">
  701. <div style="width: 100%;">
  702. <el-button type="danger" @click="delTreeAdd(scope.$index)" size="mini" text style="margin-left: 0%;">删除</el-button>
  703. </div>
  704. </template>
  705. </el-table-column>
  706. </el-table>
  707. <template #footer>
  708. <span class="dialog-footer">
  709. <el-button size="mini" @click="dialogVisibleTree = false">取消</el-button>
  710. <el-button type="primary" @click="addToTree" size="mini">
  711. 确定
  712. </el-button>
  713. </span>
  714. </template>
  715. </el-dialog>
  716. </div>
  717. </div>
  718. </template>
  719. <script setup>
  720. import {getCatalog} from "@/api/service/catalog";
  721. import { Plus,Search,Filter,Promotion,Check } from '@element-plus/icons-vue'
  722. import { reactive } from 'vue'
  723. import { modelTreeSelect,getSerDe,addService,addParam,editService,editParam,addServiceParam,delService,getTreeDe,addTree,deTree,getServiceReturn,postReturnlist } from "@/api/service/info";
  724. import { ref, onMounted, onUnmounted, nextTick,onBeforeMount } from 'vue';
  725. import JsonViewer from 'vue-json-viewer'
  726. import 'vue-json-viewer/style.css'
  727. import JsonEditorVue from 'json-editor-vue3'
  728. import { cloneDeep } from 'lodash'
  729. import { useClipboard } from "@vueuse/core";
  730. const { proxy } = getCurrentInstance();
  731. const JsonAdd= ref(JSON.stringify({ data: "初始值1" }))
  732. const exampleAdd = ref('')
  733. const dialogVisibleLevel = ref(false)
  734. const dialogVisieTree = ref(false)
  735. const detail = ref({
  736. name:'',
  737. rqtype:'',
  738. rptype:''
  739. })
  740. const tableDataCanAddTree = ref([
  741. ])
  742. const dataTreeReturn = ref([
  743. ])
  744. const show1Lev = ref(true)
  745. const inputNode =ref('')
  746. const isEdit = ref(true)
  747. const dataReturn = ref({})
  748. const optionsCan = ref([
  749. {
  750. label:"string",
  751. value:'string'
  752. },
  753. {
  754. label:"int",
  755. value:'int'
  756. },
  757. {
  758. label:"boolean",
  759. value:'boolean'
  760. },
  761. {
  762. label:"array",
  763. value:'array'
  764. },
  765. {
  766. label:"object",
  767. value:'object'
  768. },
  769. {
  770. label:"number",
  771. value:'number'
  772. },
  773. {
  774. label:"null",
  775. value:'null'
  776. },
  777. {
  778. label:"any",
  779. value:'any'
  780. },
  781. ])
  782. const parTreeId = ref('')
  783. const parTreeParentId = ref('')
  784. const currentNodeKey = ref('')
  785. const options = ref([
  786. {label:'开发中',
  787. value:'1'
  788. },
  789. {label:'运行中',
  790. value:'2'
  791. },
  792. ])
  793. const dataJsonXiang = ref()
  794. const parTree = ref({})
  795. const valueKet = ref(0)
  796. const tableDataCan = ref([
  797. {
  798. paramName:'',
  799. paramCode:'',
  800. paramType:'',
  801. paramNote:''
  802. }
  803. ])
  804. const optionsMdid = ref([])
  805. const optionsRqtype = ref([
  806. {label:'GET',
  807. value:'GET'
  808. },
  809. {label:'POST',
  810. value:'POST'
  811. },
  812. ])
  813. const defaultProps = ref({
  814. children: 'children',
  815. label: 'paramCode'
  816. })
  817. const optionsType= ref([
  818. {label:'RESTful',
  819. value:'RESTful'
  820. },
  821. {label:'WebService',
  822. value:'WebService'
  823. },
  824. {label:'HTTP',
  825. value:'HTTP'
  826. },
  827. {label:'WebSocket',
  828. value:'WebSocket'
  829. },
  830. ])
  831. const data = ref([])
  832. const select = ref('1')
  833. const activeName = ref('first')
  834. const title = ref('')
  835. const titleTree = ref('')
  836. const currentPage = ref(1)
  837. const total = ref(1)
  838. const tableData = ref([])
  839. const tableheight = window.innerHeight*0.7
  840. const heightAll = window.innerHeight
  841. const dialogVisible = ref(false)
  842. const dialogVisibleTree = ref(false)
  843. const isAdd = ref(false)
  844. const isAddTa = ref(false)
  845. const treeId = ref('');
  846. const valueSta = ref('1');
  847. const example = ref('');
  848. const tableDataCanAdd = ref([
  849. {
  850. itemName:'',
  851. itemCode:'',
  852. paramType:'',
  853. paramNote:''
  854. }
  855. ])
  856. const formZu = ref({
  857. itemName:'',
  858. itemTp:'',
  859. itemEn:'',
  860. itemTp:'',
  861. itemDataTp:'',
  862. itemDefaultVal:'',
  863. itemUnit:'',
  864. itemNotes:'',
  865. });
  866. const parId= ref('')
  867. const formJi = ref({
  868. name:'',
  869. cateCode:'',
  870. type:'',
  871. url:'',
  872. rqtype:'',
  873. rptype:'',
  874. intro:'',
  875. });
  876. const rulesJi = reactive({
  877. name: [{ required: true, message: '必填', trigger: 'blur' }],
  878. url: [{ required: true, message: '必填', trigger: 'blur' }],
  879. cateCode: [{ required: true, message: '必填', trigger: 'blur' }],
  880. });
  881. const byWhich = ref('input');
  882. const formRefJi = ref();
  883. const formAdd = ref({
  884. name:'',
  885. cateCode:'',
  886. type:'',
  887. url:'',
  888. rqtype:'',
  889. rptype:'',
  890. intro:'',
  891. mdid:''
  892. });
  893. const rulesAdd = reactive({
  894. mdid: [{ required: true, message: '必填', trigger: 'blur' }],
  895. name: [{ required: true, message: '必填', trigger: 'blur' }],
  896. url: [{ required: true, message: '必填', trigger: 'blur' }],
  897. cateCode: [{ required: true, message: '必填', trigger: 'blur' }],
  898. });
  899. const formRefAdd = ref();
  900. const treeRef = ref(null);
  901. const formTree = ref({
  902. itemName:'',
  903. catePid:'',
  904. itemNo:'',
  905. itemNotes:''
  906. });
  907. const rulesTree = reactive({
  908. itemNo: [{ required: true, message: '必填', trigger: 'blur' }],
  909. catePid: [{ required: true, message: '必填', trigger: 'blur' }],
  910. itemName: [{ required: true, message: '必填', trigger: 'blur' }],
  911. });
  912. const formRefTree = ref();
  913. const formLev = ref({
  914. itemName:'',
  915. itemNo:'',
  916. itemNotes:'',
  917. });
  918. const rulesLev = reactive({
  919. itemNotes: [{ required: true, message: '必填', trigger: 'blur' }],
  920. itemNo: [{ required: true, message: '必填', trigger: 'blur' }],
  921. itemName: [{ required: true, message: '必填', trigger: 'blur' }],
  922. });
  923. const formRefLev = ref();
  924. const cascaderOptions = ref([])
  925. const props1 = ref({
  926. checkStrictly: true,
  927. })
  928. const detailJson = ref([])
  929. const parLev = ref(1)
  930. watch(inputNode, (val) => {
  931. treeRef.value?.filter(val); // 调用树的过滤方法
  932. });
  933. const filterNode = (value, data) => {
  934. if (!value) return true; // 空搜索时显示所有节点
  935. return data.label.includes(value); // 检查节点标签是否包含关键字
  936. };
  937. const copied = ref(false);
  938. function byWay() {
  939. byWhich.value = 'input'
  940. }
  941. function addToTree() {
  942. byWhich.value = 'tree'
  943. if(parLev.value === 1){
  944. parTreeParentId.value
  945. if(tableDataCanAddTree.value){
  946. tableDataCanAddTree.value.forEach(item=>{
  947. item.parentId = parTreeId.value
  948. item.srvId = parId.value
  949. addSiblingNode(dataTreeReturn.value,parTreeId.value,item)
  950. })
  951. dialogVisibleTree.value = false
  952. }
  953. }
  954. if(parLev.value === 2){
  955. tableDataCanAddTree.value.forEach(item=>{
  956. item.parentId = parTreeId.value
  957. item.srvId = parId.value
  958. addChildNode(dataTreeReturn.value,parTreeId.value,item)
  959. })
  960. dialogVisibleTree.value = false
  961. }
  962. console.log(findNode(dataTreeReturn.value,parTreeParentId.value))
  963. }
  964. function findNode(nodes, targetId, mode = 'id') {
  965. if (!Array.isArray(nodes)) return null;
  966. for (const node of nodes) {
  967. // 检查当前节点是否匹配目标
  968. if ((mode === 'id' && node.id === targetId) || (mode === 'parentId' && node.parentId === targetId)) {
  969. return node;
  970. }
  971. // 如果该节点有子节点,则递归搜索其子树
  972. if (node.children && node.children.length > 0) {
  973. const found = findNode(node.children, targetId, mode);
  974. if (found) return found;
  975. }
  976. }
  977. return null; // 未找到
  978. }
  979. function addChildNode(treeData, parentId, newNode) {
  980. const parentNode = findNode(treeData, parentId, 'id');
  981. if (!parentNode) {
  982. console.warn(`未找到ID为 ${parentId} 的父节点`);
  983. return false;
  984. }
  985. // 初始化父节点的children数组(如果不存在)
  986. if (!Array.isArray(parentNode.children)) {
  987. parentNode.children = [];
  988. }
  989. // 将新节点添加到父节点的children数组中
  990. parentNode.children.push(newNode);
  991. return true;
  992. }
  993. function addSiblingNode(treeData, siblingId, newNode) {
  994. // 1. 首先找到目标兄弟节点
  995. const siblingNode = findNode(treeData, siblingId, 'id');
  996. if (!siblingNode) {
  997. console.warn(`未找到ID为 ${siblingId} 的兄弟节点`);
  998. return false;
  999. }
  1000. // 2. 找到兄弟节点的父节点(通过parentId查找)
  1001. const parentNode = findNode(treeData, siblingNode.parentId, 'id');
  1002. if (!parentNode) {
  1003. console.warn(`未找到ID为 ${siblingNode.parentId} 的父节点(兄弟节点的父节点)`);
  1004. return false;
  1005. }
  1006. // 3. 将新节点添加到父节点的children数组中
  1007. if (!Array.isArray(parentNode.children)) {
  1008. parentNode.children = [];
  1009. }
  1010. parentNode.children.push(newNode);
  1011. return true;
  1012. }
  1013. function setId(data){
  1014. parTreeId.value = data.id
  1015. parTreeParentId.value = data.parentId
  1016. }
  1017. function addTreePar(){
  1018. tableDataCanAddTree.value.push({
  1019. id:Math.random()
  1020. })
  1021. }
  1022. function delTreeAdd(index){
  1023. tableDataCanAddTree.value.splice(index, 1)
  1024. }
  1025. async function copyUrl(){
  1026. try {
  1027. await navigator.clipboard.writeText(detail.value.url);
  1028. copied.value = true;
  1029. console.log(detail.url.value,copied.value)
  1030. setTimeout(() => (copied.value = false), 2000); // 2秒后提示消失
  1031. } catch (err) {
  1032. console.error("复制失败", err);
  1033. }
  1034. };
  1035. function filterModelNodes(nodes) {
  1036. if (!Array.isArray(nodes)) return [];
  1037. const result = [];
  1038. for (const node of nodes) {
  1039. // 递归处理子节点(如果有)
  1040. const filteredChildren = node.children ? filterModelNodes(node.children) : [];
  1041. if (node.nodeType === 'MODEL') {
  1042. // 保留当前节点,并更新其子节点
  1043. node.value = node.id
  1044. result.push({
  1045. ...node,
  1046. children: filteredChildren
  1047. });
  1048. } else {
  1049. // 删除当前节点,将其子节点提升到当前层级
  1050. result.push(...filteredChildren);
  1051. }
  1052. }
  1053. return result;
  1054. }
  1055. function add1LevelTree(){
  1056. dialogVisibleTree.value = true
  1057. parLev.value = 1
  1058. }
  1059. function addNextLevelTree(){
  1060. dialogVisibleTree.value = true
  1061. parLev.value = 2
  1062. }
  1063. function clearAdd(){
  1064. dialogVisible.value = false
  1065. formAdd.value = {
  1066. name:'',
  1067. cateCode:'',
  1068. type:'',
  1069. url:'',
  1070. rqtype:'',
  1071. rptype:'',
  1072. intro:'',
  1073. mdid:''
  1074. }
  1075. tableDataCanAdd.value = []
  1076. JsonAdd.value = ''
  1077. exampleAdd.value = ''
  1078. }
  1079. function delAll(){
  1080. proxy.$modal.confirm('是否确认删除?').then(function () {
  1081. return deTree(parTree.value.id);
  1082. }).then(() => {
  1083. getTreeLeft();
  1084. proxy.$modal.msgSuccess("删除成功");
  1085. dialogVisibleLevel.value = false
  1086. }).catch(() => {});
  1087. }
  1088. function clearFromLev(){
  1089. formLev.value = {
  1090. itemName:'',
  1091. itemNo:'',
  1092. itemNotes:'',
  1093. }
  1094. tableDataCanAddTree.value = []
  1095. }
  1096. function addNextLevel(){
  1097. dialogVisibleLevel.value = true
  1098. show1Lev.value = false
  1099. }
  1100. function saveAddNextLevel(){
  1101. formRefLev.value.validate((valid) => {
  1102. if(valid){
  1103. var par = formLev.value
  1104. par.treeType = parTree.value.nodeType
  1105. par.treePid = parTree.value.id
  1106. addTree(par).then(res=>{
  1107. if(res.code===200){
  1108. proxy.$modal.msgSuccess("新增成功");
  1109. getTreeLeft()
  1110. dialogVisibleLevel.value = false
  1111. }
  1112. })
  1113. }
  1114. });
  1115. }
  1116. function add1Level(){
  1117. dialogVisibleLevel.value = true
  1118. show1Lev.value = true
  1119. }
  1120. function saveAdd1Level(){
  1121. formRefLev.value.validate((valid) => {
  1122. if(valid){
  1123. var par = formLev.value
  1124. par.treeType = parTree.value.nodeType
  1125. par.treePid = parTree.value.pid
  1126. addTree(par).then(res=>{
  1127. if(res.code===200){
  1128. proxy.$modal.msgSuccess("新增成功");
  1129. getTreeLeft()
  1130. dialogVisibleLevel.value = false
  1131. }
  1132. })
  1133. }
  1134. });
  1135. }
  1136. async function delSer(){
  1137. proxy.$modal.confirm('是否确认删除?').then(function () {
  1138. return delService(parId.value);
  1139. }).then(() => {
  1140. getTreeLeft();
  1141. proxy.$modal.msgSuccess("删除成功");
  1142. }).catch(() => {});
  1143. }
  1144. // 辅助函数:根据值获取参数类型
  1145. function getParamType(value) {
  1146. if (Array.isArray(value)) {
  1147. return 'Array';
  1148. } else if (value === null) {
  1149. return 'Null';
  1150. } else {
  1151. return typeof value === 'object' ? 'Object' : capitalizeFirstLetter(typeof value);
  1152. }
  1153. }
  1154. // 辅助函数:首字母大写
  1155. function capitalizeFirstLetter(string) {
  1156. return string.charAt(0).toUpperCase() + string.slice(1);
  1157. }
  1158. // 辅助函数:根据参数代码获取参数名称(可根据需要扩展映射关系)
  1159. function getParamName(paramCode) {
  1160. const nameMap = {
  1161. 'typhoonId': '台风编码',
  1162. 'typhoonName': '台风名称',
  1163. 'data': '数据体'
  1164. // 可以添加更多映射
  1165. };
  1166. return nameMap[paramCode] || '';
  1167. }
  1168. async function saveEditService(){
  1169. console.log(JsonAdd.value)
  1170. var valid
  1171. await formRefJi.value.validate((valid1) => {
  1172. valid = valid1
  1173. });
  1174. console.log(valid)
  1175. if(valid){
  1176. console.log()
  1177. var par = formJi.value
  1178. par.example = example.value
  1179. par.rpcontent = dataJsonXiang.value
  1180. par.cateCode = par.cateCode[0]
  1181. var validTable = true
  1182. for (const item of tableDataCan.value) {
  1183. if (item.paramCode.length === 0 || item.paramName.length === 0 || item.paramType.length === 0) {
  1184. proxy.$modal.msgError("请填写必填项!");
  1185. validTable = false
  1186. break;
  1187. }
  1188. }
  1189. if(validTable){
  1190. await editService(par).then(res=>{
  1191. if(res.code===200){
  1192. var parCan = tableDataCan.value
  1193. parCan.forEach(item => {
  1194. item.srvId = parId.value
  1195. });
  1196. addServiceParam(parCan).then(res1=>{
  1197. if(res1.code===200){
  1198. proxy.$modal.msgSuccess("修改成功");
  1199. getTreeLeft()
  1200. }
  1201. })
  1202. }
  1203. })
  1204. // 处理返回值
  1205. if(byWhich.value==='input'){
  1206. var par = JSON.parse(dataJsonXiang.value)
  1207. var par1 = transformDynamicDataToTree(par)
  1208. // par1.length = par1.length - 1
  1209. console.log(par1)
  1210. postReturnlist(par1).then(res=>{
  1211. if(res.code===200){
  1212. proxy.$modal.msgSuccess("新增成功");
  1213. getTreeLeft()
  1214. }
  1215. })
  1216. }
  1217. if(byWhich.value==='tree'){
  1218. var par = JSON.parse(JSON.stringify(dataTreeReturn.value))
  1219. par.forEach((item,index) => {
  1220. if(item.children && item.children.length > 0){
  1221. item = setArry(item)
  1222. }
  1223. });
  1224. par.forEach((item,index) => {
  1225. if(item.children && item.children.length > 0){
  1226. item = setArrayId(item)
  1227. }
  1228. });
  1229. postReturnlist(par).then(res=>{
  1230. if(res.code===200){
  1231. proxy.$modal.msgSuccess("新增成功");
  1232. getTreeLeft()
  1233. }
  1234. })
  1235. }
  1236. }
  1237. }
  1238. }
  1239. async function addSer(){
  1240. console.log(JsonAdd.value)
  1241. var valid
  1242. await formRefAdd.value.validate((valid1) => {
  1243. valid = valid1
  1244. });
  1245. console.log(valid)
  1246. if(valid){
  1247. var par = formAdd.value
  1248. par.example = exampleAdd.value
  1249. par.rpcontent = JsonAdd.value
  1250. par.cateCode = par.cateCode[0]
  1251. console.log(par)
  1252. await addService(par).then(res=>{
  1253. if(res.code===200){
  1254. var parCan = tableDataCanAdd.value
  1255. if(parCan.length !== 0){
  1256. parCan.forEach((item,index) => {
  1257. item.srvId = res.data.srvId
  1258. if(item.paramName===''){
  1259. parCan.splice(index, 1)
  1260. }
  1261. });
  1262. addServiceParam(parCan).then(res1=>{
  1263. if(res1.code===200){
  1264. proxy.$modal.msgSuccess("新增成功");
  1265. getTreeLeft()
  1266. }
  1267. })
  1268. }
  1269. }
  1270. })
  1271. }
  1272. }
  1273. function showAdd(){
  1274. dialogVisible.value = true
  1275. }
  1276. async function handleNodeClick(node,data,event){
  1277. parTree.value = data.data
  1278. currentNodeKey.value = data.data.id
  1279. isEdit.value = false
  1280. parId.value = data.data.id
  1281. await getSerDe(data.data.id).then(res=>{
  1282. detail.value = res.data.ptService
  1283. tableDataCan.value = res.data.list
  1284. dataJsonXiang.value = res.data.ptService.rpcontent
  1285. formJi.value = res.data.ptService
  1286. example.value = res.data.ptService.example
  1287. })
  1288. detail.value.nodeType = data.data.nodeType
  1289. var par = {
  1290. srvId:data.data.id
  1291. }
  1292. console.log(JSON.parse(dataJsonXiang.value))
  1293. getServiceReturn(par).then(res=>{
  1294. const fullTree = buildTree1(res.data)
  1295. fullTree.forEach((item,index) => {
  1296. if(item.children && item.children.length > 0){
  1297. item = dfsRecursive(item)
  1298. }
  1299. });
  1300. dataTreeReturn.value = fullTree
  1301. console.log(dataTreeReturn.value)
  1302. // var par = JSON.parse(JSON.stringify(fullTree))
  1303. // var par1 = transformDynamicDataToTree(par)
  1304. // par1.length = par1.length - 1
  1305. // par.forEach((item,index) => {
  1306. // if(item.children && item.children.length > 0){
  1307. // item = setArry(item)
  1308. // }
  1309. // });
  1310. // par.forEach((item,index) => {
  1311. // if(item.children && item.children.length > 0){
  1312. // item = setArrayId(item)
  1313. // }
  1314. // });
  1315. })
  1316. }
  1317. function setArry(node, parent = null, grandParent = null) {
  1318. if (!node) return;
  1319. var par = {
  1320. "id": Math.random(),
  1321. "parentId": Math.random(),
  1322. "srvId": parId.value,
  1323. "paramCode": "[0]",
  1324. "paramName": null,
  1325. "paramType": "object",
  1326. "paramValue": "",
  1327. "paramFormat": null,
  1328. "paramNote": null,
  1329. "isArray": null,
  1330. "children": []
  1331. }
  1332. if(parent && parent.paramType === 'array' && parent.children.length > 0){
  1333. parent.children.push(par)
  1334. parent.children = modifyArray(parent.children)
  1335. parent.children.length = 1
  1336. }
  1337. if(node.children){
  1338. node.children.forEach(child => {
  1339. setArry(child, node, parent);
  1340. });
  1341. }
  1342. return node;
  1343. }
  1344. function setArrayId(node, parent = null, grandParent = null) {
  1345. if (!node) return;
  1346. console.log(node,parent)
  1347. node.parentId = parent ? parent.id : Math.random();
  1348. if(node.children){
  1349. node.children.forEach(child => {
  1350. setArrayId(child, node, parent);
  1351. });
  1352. }
  1353. return node;
  1354. }
  1355. function modifyArray(originalArray) {
  1356. // 1. 找到所有 paramCode 为 '[0]' 的对象
  1357. const targetObjects = originalArray.filter(item => item.paramCode === '[0]');
  1358. // 检查是否存在符合条件的对象
  1359. if (targetObjects.length === 0) {
  1360. console.log("没有找到 paramCode 为 '[0]' 的对象");
  1361. return originalArray; // 或者根据需求进行其他处理
  1362. }
  1363. // 获取最后一个 paramCode 为 '[0]' 的对象
  1364. const lastTargetObject = targetObjects[targetObjects.length - 1]; // [7](@ref)
  1365. // 2. 找到所有 paramCode 不为 '[0]' 的对象
  1366. const objectsToAdd = originalArray.filter(item => item.paramCode !== '[0]');
  1367. // 3. 确保目标对象的 children 属性存在且为数组
  1368. if (!lastTargetObject.children) {
  1369. lastTargetObject.children = []; // 如果不存在则初始化
  1370. }
  1371. objectsToAdd.forEach(obj => {
  1372. lastTargetObject.children.push(obj);
  1373. });
  1374. const newArray = originalArray.filter(item => item.paramCode === '[0]');
  1375. // 返回修改后的新数组
  1376. return newArray;
  1377. }
  1378. function transformDynamicDataToTree(sourceData) {
  1379. let idCounter = 1; // ID计数器,确保每个节点有唯一ID
  1380. const result = []; // 最终返回的结果数组
  1381. // 辅助函数:为对象中的每个属性推断类型
  1382. function inferType(value) {
  1383. if (value === null) return 'null';
  1384. if (Array.isArray(value)) return 'array';
  1385. if (typeof value === 'object') return 'object';
  1386. if (typeof value === 'number') {
  1387. // 简单区分整数和浮点数(可根据需要调整)
  1388. return Number.isInteger(value) ? 'int' : 'float';
  1389. }
  1390. if (typeof value === 'boolean') return 'boolean';
  1391. return 'string'; // 默认字符串类型
  1392. }
  1393. // 辅助函数:生成带层级的节点
  1394. function createNode(parentId, paramCode, paramValue, paramType, paramName = null, arrayIndex = null, isArray = null) {
  1395. const node = {
  1396. createBy: null,
  1397. createTime: null,
  1398. updateBy: null,
  1399. updateTime: null,
  1400. remark: null,
  1401. id: idCounter++,
  1402. parentId: parentId,
  1403. srvId: parId.value, // 使用传入的服务ID或示例值
  1404. paramCode: paramCode,
  1405. paramName: paramName, // 可选的友好名称
  1406. paramType: paramType,
  1407. paramValue: paramValue !== null && paramValue !== undefined ? String(paramValue) : '', // 确保值为字符串或空
  1408. paramFormat: null,
  1409. paramNote: null,
  1410. isArray: isArray,
  1411. arrayIndex: arrayIndex,
  1412. sort: idCounter // 简单地用ID作为排序,可根据需要调整
  1413. };
  1414. // 移除可能为null的字段,保持整洁(可选)
  1415. Object.keys(node).forEach(key => {
  1416. if (node[key] === null) {
  1417. delete node[key];
  1418. }
  1419. });
  1420. return node;
  1421. }
  1422. // 1. 处理根级的"data"属性(如果存在且是数组)
  1423. if (sourceData.data && Array.isArray(sourceData.data)) {
  1424. // 创建根节点 (data array)
  1425. const dataRootNode = createNode(0, "data", "", "array", "数据体", null, "1");
  1426. result.push(dataRootNode);
  1427. const dataRootId = dataRootNode.id; // 记录根节点ID
  1428. // 遍历data数组中的每一项
  1429. sourceData.data.forEach((dataItem, dataIndex) => {
  1430. if (typeof dataItem === 'object' && dataItem !== null) {
  1431. // 为数组中的每一项(如台风对象)创建一个节点,其父节点是dataRootId
  1432. const arrayItemNode = createNode(dataRootId, `[${dataIndex}]`, "", "object", null, dataIndex, null);
  1433. result.push(arrayItemNode);
  1434. const arrayItemId = arrayItemNode.id; // 记录当前数组项节点ID
  1435. // 遍历该项的所有属性(如typhoonId, typhoonName)
  1436. for (const [key, value] of Object.entries(dataItem)) {
  1437. const propNode = createNode(arrayItemId, key, value, inferType(value), null, null, null);
  1438. result.push(propNode);
  1439. }
  1440. } else {
  1441. // 处理data数组中是非对象的情况(如基本类型)
  1442. const arrayItemNode = createNode(dataRootId, `[${dataIndex}]`, sourceData.data[dataIndex], inferType(sourceData.data[dataIndex]), null, dataIndex, null);
  1443. result.push(arrayItemNode);
  1444. }
  1445. });
  1446. }
  1447. // 2. 处理源数据中的其他根级属性(排除已经处理的data)
  1448. for (const [key, value] of Object.entries(sourceData)) {
  1449. // 跳过已经处理过的data属性、null和undefined,以及非自有属性
  1450. if (key === 'data' || value === null || value === undefined || !sourceData.hasOwnProperty(key)) continue;
  1451. const rootPropNode = createNode(0, key, value, inferType(value), null, null, null);
  1452. result.push(rootPropNode);
  1453. }
  1454. // 3. 特别处理源数据中值为null或undefined的根级属性(如果需要保留这些信息)
  1455. for (const key in sourceData) {
  1456. if (sourceData[key] === null && sourceData.hasOwnProperty(key) && key !== 'data') {
  1457. const nullNode = createNode(0, key, "", "null", null, null, null);
  1458. result.push(nullNode);
  1459. }
  1460. }
  1461. return result;
  1462. }
  1463. function buildTree1(list, rootParentId = 0) {
  1464. // 1. 创建一个映射(字典)以便通过id快速查找节点,并为每个节点初始化children数组
  1465. const nodeMap = {};
  1466. const tree = [];
  1467. // 初始化映射,每个节点初始时都有空的孩子数组
  1468. list.forEach(item => {
  1469. nodeMap[item.id] = { ...item, children: [] };
  1470. });
  1471. // 2. 遍历数组,根据parentId将节点放入父节点的children中
  1472. list.forEach(item => {
  1473. const node = nodeMap[item.id];
  1474. const parentId = item.parentId;
  1475. if (parentId === rootParentId) {
  1476. // 如果parentId是根父ID(默认为0),则作为根节点直接添加到树中
  1477. tree.push(node);
  1478. } else {
  1479. // 否则,尝试找到父节点并将当前节点加入其children数组
  1480. const parentNode = nodeMap[parentId];
  1481. if (parentNode) {
  1482. parentNode.children.push(node);
  1483. } else {
  1484. // 可选:处理parentId不存在于列表中的情况(孤儿节点)
  1485. // 这里选择将其提升为根节点,你也可以选择其他处理方式,如console.warn报警
  1486. tree.push(node);
  1487. }
  1488. }
  1489. });
  1490. // 3. 返回构建好的树
  1491. return tree;
  1492. }
  1493. function dfsRecursive(node, parent = null, grandParent = null) {
  1494. if (!node) return;
  1495. const reg = /\[\d+\]/;
  1496. if (parent && reg.test(parent.paramCode)) {
  1497. grandParent.children = []
  1498. grandParent.children.push(parent);
  1499. parent.children.forEach(child => {
  1500. child.parentId = grandParent.id
  1501. grandParent.children.push(child);
  1502. });
  1503. grandParent.children.splice(0,1)
  1504. }
  1505. if(node.children){
  1506. node.children.forEach(child => {
  1507. dfsRecursive(child, node, parent);
  1508. });
  1509. }
  1510. return node;
  1511. }
  1512. async function getTreeLeft(){
  1513. var par
  1514. await modelTreeSelect().then(res=>{
  1515. par = res.data
  1516. data.value = res.data
  1517. })
  1518. optionsMdid.value = filterModelNodes(par)
  1519. console.log(optionsMdid.value)
  1520. }
  1521. function renameTreeProperties(tree) {
  1522. // 深拷贝避免修改原始数据(可选,根据需求)
  1523. const newTree = cloneDeep(tree); // 使用 lodash
  1524. // 或:const newTree = JSON.parse(JSON.stringify(tree)); // 原生方法(不兼容函数等)
  1525. // 递归处理函数
  1526. const processNode = (node) => {
  1527. // 重命名属性
  1528. if ('cateName' in node) {
  1529. node.label = node.cateName;
  1530. delete node.cateName;
  1531. }
  1532. if ('cateCode' in node) {
  1533. node.value = node.cateCode;
  1534. delete node.cateCode;
  1535. }
  1536. // 递归处理子节点
  1537. if (node.children && node.children.length > 0) {
  1538. node.children.forEach(child => processNode(child));
  1539. }
  1540. };
  1541. // 遍历根节点
  1542. newTree.forEach(rootNode => processNode(rootNode));
  1543. return newTree;
  1544. }
  1545. function fetchData() {
  1546. getCatalog().then((r) => {
  1547. cascaderOptions.value = renameTreeProperties(buildTree(r.data))
  1548. console.log(cascaderOptions.value)
  1549. });
  1550. }
  1551. function buildTree(flatData, rootValue = '0') {
  1552. const nodeMap = new Map();
  1553. const tree = [];
  1554. flatData.forEach(item => {
  1555. nodeMap.set(item.cateCode, { ...item, children: [] });
  1556. });
  1557. for (const [code, node] of nodeMap) {
  1558. const parentCode = node.catePcode;
  1559. if (parentCode === rootValue || !parentCode) {
  1560. tree.push(node);
  1561. continue;
  1562. }
  1563. const parent = nodeMap.get(parentCode);
  1564. if (parent) {
  1565. parent.children.push(node);
  1566. } else {
  1567. console.warn(`Orphan node detected: ${code}. Parent ${parentCode} not found`);
  1568. }
  1569. }
  1570. return tree;
  1571. }
  1572. function addPa(){
  1573. var par = {
  1574. paramName:'',
  1575. paramNote:'',
  1576. paramType:'',
  1577. paramCode:''
  1578. }
  1579. tableDataCan.value.push(par)
  1580. }
  1581. function delCan(index){
  1582. tableDataCan.value.splice(index, 1)
  1583. }
  1584. function addCanAdd(){
  1585. var par = {
  1586. parName:''
  1587. }
  1588. tableDataCanAdd.value.push(par)
  1589. }
  1590. function delCanAdd(index){
  1591. tableDataCanAdd.value.splice(index, 1)
  1592. }
  1593. onMounted(() => {
  1594. fetchData()
  1595. getTreeLeft()
  1596. });
  1597. </script>
  1598. <style scoped>
  1599. .noBorSel :deep(.el-select__wrapper){
  1600. box-shadow: none !important; /* 去除阴影边框 */
  1601. border: 1px solid transparent !important; /* 设置透明边框 */
  1602. background-color: transparent !important; /* 可选:透明背景 */
  1603. }
  1604. .noBor :deep(.el-input__wrapper) {
  1605. box-shadow: none !important; /* 去除阴影边框 */
  1606. border: 1px solid transparent !important; /* 设置透明边框 */
  1607. background-color: transparent !important; /* 可选:透明背景 */
  1608. }
  1609. /* 节点垂直间距 */
  1610. :deep(.el-tree-node) {
  1611. margin-bottom:5px !important; /* 增大节点间距 */
  1612. }
  1613. .el-popover.custom-popover {
  1614. min-width: 50px;
  1615. padding: 8px; /* 可选:调整内边距 */
  1616. }
  1617. </style>
  1618. <style>
  1619. .dot {
  1620. width: 20px; /* 控制圆点直径 */
  1621. height: 20px;
  1622. background-color: #333; /* 实心颜色 */
  1623. border-radius: 50%; /* 关键属性 */
  1624. display: inline-block; /* 确保与其他元素并排 */
  1625. }
  1626. /* 全局透明样式(不使用 scoped) */
  1627. .transparent-select .el-select__wrapper {
  1628. background-color: transparent !important;
  1629. border-color: transparent !important;
  1630. box-shadow: none !important;
  1631. }
  1632. .transparent-select .el-select__selection {
  1633. background-color: transparent;
  1634. }
  1635. /* 处理悬停和聚焦状态 */
  1636. .transparent-select .el-select__wrapper:hover,
  1637. .transparent-select .el-select__wrapper.is-focused {
  1638. border-color: transparent !important;
  1639. box-shadow: none !important;
  1640. }
  1641. /* 下拉箭头图标 */
  1642. .transparent-select .el-select__caret {
  1643. color: rgba(0, 0, 0, 0.5); /* 半透明图标 */
  1644. }
  1645. </style>
  1646. <style scoped>
  1647. :deep(.svg-icon) {
  1648. outline: none;
  1649. }
  1650. :deep(.svg-icon svg) {
  1651. stroke: none;
  1652. }
  1653. :deep(.treeLeft) .el-tree-node__content {
  1654. display: flex !important;
  1655. height: 28px; /* 按设计稿调整高度 */
  1656. align-items: center;
  1657. padding-top: 0 !important;
  1658. }
  1659. :deep(.treeLeft) .el-tree-node__content:hover {
  1660. background-color: #e9e9eb;
  1661. }
  1662. :deep(.treeLeft) .el-tree-node__content:active {
  1663. background-color: rgka(69,157,255,0.1) !important;
  1664. }
  1665. /* 选中态(Active) */
  1666. :deep(.treeLeft) .el-tree-node.is-current > .el-tree-node__content {
  1667. background-color: #c6e2ff !important;
  1668. }
  1669. .tab-container {
  1670. height: 100vh; /* 关键:父容器明确高度 */
  1671. display: flex;
  1672. flex-direction: column;
  1673. }
  1674. .drag-handle {
  1675. cursor: move;
  1676. }
  1677. .ghost {
  1678. opacity: 0.5;
  1679. background: #c8ebfb;
  1680. }
  1681. /* 防止文字选中 */
  1682. :deep(.el-table__row) {
  1683. user-select: none;
  1684. -webkit-user-select: none;
  1685. }
  1686. </style>
  1687. <style scoped lang="scss">
  1688. .custom-tree-node {
  1689. display: flex; /* 启用 Flex 布局 */
  1690. align-items: center; /* 垂直居中 */
  1691. gap: 8px; /* 图标与文字间距 */
  1692. justify-content: space-between;
  1693. }
  1694. .el-table .el-table__row td {
  1695. height: 60px !important; /* 行高 */
  1696. }
  1697. .custom-tree-node {
  1698. display: flex; /* 启用 Flex 布局 */
  1699. align-items: center; /* 垂直居中 */
  1700. gap: 8px; /* 图标与文字间距 */
  1701. }
  1702. </style>