70524215bad0a5fe0f383913528c5b8b7d8e7810.svn-base 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600
  1. <template>
  2. <el-row :gutter="5" style="margin-top:5px;margin-left:5px;">
  3. <el-col :span="5">
  4. <el-card class="box-card">
  5. <div slot="header" class="clearfix" style="text-align: right; ">
  6. <el-row :gutter="2" style="margin-top:5px; margin-left:5px;">
  7. <el-col :span="12" style="text-align: left; vertical-align:middle; font-size: 20px"> <span>菜单 </span></el-col>
  8. <el-col :span="6"> <el-col :span="6"> <el-button type="warning" icon="el-icon-edit" size="mini" @click="jump" /></el-col>
  9. </el-col>
  10. <el-col :span="6"> <el-button type="primary" icon="el-icon-refresh" size="mini" @click="getList()" /></el-col>
  11. </el-row>
  12. </div>
  13. <div class="component-item">
  14. <el-tree
  15. ref="tree"
  16. class="filter-tree"
  17. :data="parent"
  18. :props="defaultProps"
  19. @node-click="handleNodeClick"
  20. />
  21. </div>
  22. </el-card>
  23. </el-col>
  24. <el-col :span="19">
  25. <div class="app-container">
  26. <div class="filter-container">
  27. <el-button class="filter-item" style="margin-left: 10px;" type="primary" icon="el-icon-edit" @click="handleCreate">
  28. 新增
  29. </el-button>
  30. <el-input
  31. v-model="interfaceName"
  32. placeholder="接口名称"
  33. style="width: 250px;"
  34. class="filter-item"
  35. clearable
  36. />
  37. <el-button class="filter-item" style="margin-left: 10px;" type="primary" icon="el-icon-edit" @click="handleFind()">
  38. 查找
  39. </el-button>
  40. </div>
  41. <el-table
  42. v-loading="listLoading"
  43. element-loading-text="给我一点时间"
  44. :data="list"
  45. border
  46. fit
  47. highlight-current-row
  48. style="width: 100%;"
  49. :row-style="rowStyle"
  50. :cell-style="cellStyle"
  51. class="elTable"
  52. row-key="id"
  53. default-expand-all
  54. :tree-props="{children: 'children', hasChildren: 'hasChildren'}"
  55. >
  56. <el-table-column label="菜单名称" min-width="100px" header-align="center" align="center">
  57. <template slot-scope="scope">
  58. <span>{{ scope.row.menuname }}</span>
  59. </template>
  60. </el-table-column>
  61. <el-table-column label="名称" min-width="100px" header-align="center" align="center">
  62. <template slot-scope="scope">
  63. <span>{{ scope.row.name }}</span>
  64. </template>
  65. </el-table-column>
  66. <el-table-column label="调用方法" header-align="center" width="100px">
  67. <template slot-scope="scope">
  68. <span>{{ scope.row.method }}</span>
  69. </template>
  70. </el-table-column>
  71. <el-table-column label="接口名称" header-align="center" width="100px">
  72. <template slot-scope="scope">
  73. <span>{{ scope.row.sqlname }}</span>
  74. </template>
  75. </el-table-column>
  76. <el-table-column label="备注" min-width="150px" header-align="center" align="center">
  77. <template slot-scope="scope">
  78. <span>{{ scope.row.remark }}</span>
  79. </template>
  80. </el-table-column>
  81. <el-table-column label="顺序" min-width="80px" header-align="center" align="center">
  82. <template slot-scope="scope">
  83. <span>{{ scope.row.sort }}</span>
  84. </template>
  85. </el-table-column>
  86. <el-table-column label="启用" min-width="80px" header-align="center" align="center">
  87. <template slot-scope="scope">
  88. <el-switch
  89. v-model="scope.row.enable"
  90. active-color="#13ce66"
  91. inactive-color="#ff4949"
  92. :active-value="1"
  93. :inactive-value="0"
  94. @change="handleEnableChange(scope.$index, scope.row)"
  95. />
  96. </template>
  97. </el-table-column>
  98. <el-table-column label="操作" header-align="center" align="center" width="160" class-name="small-padding fixed-width" fixed="right">
  99. <template slot-scope="{row}">
  100. <el-button type="primary" size="mini" @click="handleUpdate(row)">
  101. 编辑
  102. </el-button>
  103. <el-button v-if="row.status!='已删'" size="mini" type="danger" @click="handleDelete(row)">
  104. 删除
  105. </el-button>
  106. </template>
  107. </el-table-column>
  108. </el-table>
  109. <pagination v-show="total>=0" :total="total" :page.sync="getdataListParm.offset" :limit.sync="getdataListParm.pagecount" @pagination="getList" />
  110. <el-dialog :title="textMap[dialogStatus]" :visible.sync="dialogFormVisible" :close-on-click-modal="false">
  111. <el-form ref="dataForm" :rules="rules" :model="deptform" label-position="left" label-width="100px" style="width: 90%; margin-left:50px;">
  112. <el-form-item label="菜单名称22" prop="selectmenutree">
  113. <tree-select
  114. :disabled="disabled"
  115. :height="280"
  116. :width="400"
  117. size="small"
  118. :data="parent"
  119. expand-all
  120. :default-props="defaultProps"
  121. collapse-tags
  122. onlyleaf
  123. node-key="id"
  124. :checked-keys="defaultMenuCheckedKeys"
  125. @popoverHide="menu_popoverHide"
  126. />
  127. </el-form-item>
  128. <el-form-item label="名称" prop="name">
  129. <el-input
  130. ref="name"
  131. v-model="deptform.name"
  132. />
  133. </el-form-item>
  134. <el-form-item label="接口名称" prop="sqlname">
  135. <el-input
  136. ref="sqlname"
  137. v-model="deptform.sqlname"
  138. />
  139. </el-form-item>
  140. <el-form-item label="调用方法" prop="method">
  141. <el-input
  142. ref="method"
  143. v-model="deptform.method"
  144. />
  145. </el-form-item>
  146. <el-form-item label="SQL" prop="sqlstr">
  147. <el-input
  148. ref="sqlstr"
  149. v-model="deptform.sqlstr"
  150. :autosize="{ minRows: 2, maxRows: 100}"
  151. type="textarea"
  152. placeholder="请输入"
  153. />
  154. </el-form-item>
  155. <el-form-item label="参数" prop="params">
  156. <el-input
  157. ref="params"
  158. v-model="deptform.params"
  159. />
  160. </el-form-item>
  161. <el-form-item label="调用示例" prop="request_body">
  162. <el-input
  163. ref="request_body"
  164. v-model="deptform.request_body"
  165. :autosize="{ minRows: 2, maxRows: 100}"
  166. type="textarea"
  167. placeholder="请输入"
  168. />
  169. </el-form-item>
  170. <el-form-item label="备注" prop="remark">
  171. <el-input
  172. ref="remark"
  173. v-model="deptform.remark"
  174. />
  175. </el-form-item>
  176. <el-form-item label="顺序" prop="sort">
  177. <el-input
  178. ref="sort"
  179. v-model="deptform.sort"
  180. />
  181. </el-form-item>
  182. <el-form-item label="启用" prop="enable">
  183. <el-switch
  184. ref="enable"
  185. v-model="deptform.enable"
  186. active-color="#13ce66"
  187. inactive-color="#ff4949"
  188. :active-value="1"
  189. :inactive-value="0"
  190. />
  191. </el-form-item></el-form>
  192. <div slot="footer" class="dialog-footer">
  193. <el-button
  194. v-if="dialogStatus==='create'"
  195. ref="createb"
  196. type="success"
  197. @click="createData_again()"
  198. >
  199. 确认新增
  200. </el-button>
  201. <el-button type="primary" @click="dialogStatus==='create'?createData():updateData()">
  202. 确认
  203. </el-button>
  204. <el-button @click="dialogFormVisible = false">
  205. 关闭
  206. </el-button>
  207. <el-button type="primary" @click="requesttest()">
  208. 调用测试
  209. </el-button>
  210. </div>
  211. </el-dialog>
  212. </div>
  213. </el-col>
  214. </el-row>
  215. </template>
  216. <script>
  217. import TreeSelect from '@/components/TreeSelect'
  218. import waves from '@/directive/waves' // waves directive
  219. import { PostDataByName, GetDataByName, transData, requestbyname } from '@/api/common'
  220. import Pagination from '@/components/Pagination' // secondary package based on el-pagination
  221. import { MessageBox } from 'element-ui'
  222. export default {
  223. name: 'Apisql',
  224. components: { Pagination, TreeSelect },
  225. directives: { waves },
  226. data() {
  227. return {
  228. disabled: false,
  229. defaultProps: {
  230. children: 'children',
  231. label: 'title'
  232. },
  233. menuid: 0,
  234. interfaceName: '',
  235. list: [{ 'sqlname': '', 'id': 0, 'sqlstr': '' }],
  236. total: 0,
  237. listLoading: true,
  238. requestParam: {
  239. name: 'createapisql',
  240. params: []
  241. },
  242. deptform: {
  243. menuid: '',
  244. apisqlid: '',
  245. method: '',
  246. sqlname: '',
  247. sqlstr: '',
  248. request_body: '',
  249. remark: '',
  250. params: '',
  251. sort: '',
  252. enable: '',
  253. return_body: '',
  254. name: ''
  255. },
  256. getdataListParm: { name: 'getapisqlall',
  257. offset: 1,
  258. pagecount: 10,
  259. params: ['', '', '', ''] },
  260. getRecuListParm: { name: 'getMenuRecu' },
  261. rules: {
  262. sqlname: [{ type: 'string', required: true, message: 'sql名称必填', trigger: 'change' }],
  263. sqlstr: [{ type: 'string', required: true, message: 'sql内容必填', trigger: 'change' }],
  264. name: [{ type: 'string', required: true, message: '名称必填', trigger: 'change' }]
  265. },
  266. dialogFormVisible: false,
  267. parentDeptVisible: true,
  268. dialogStatus: '',
  269. textMap: {
  270. update: '编辑',
  271. create: '新增'
  272. },
  273. parent: [],
  274. defaultMenuCheckedKeys: [],
  275. selectedMenu: [],
  276. rowStyle: { maxHeight: 50 + 'px', height: 45 + 'px' },
  277. cellStyle: { padding: 0 + 'px' }
  278. }
  279. },
  280. created() {
  281. this.getList()
  282. },
  283. methods: {
  284. menu_popoverHide(checkedIds, checkedData) {
  285. console.log(checkedIds)
  286. this.deptform.menuid = checkedIds
  287. },
  288. jump() {
  289. this.$router.push('/console/menu')
  290. // 传递的参数用{{ $route.query.goodsId }}获取
  291. // this.$router.push({ path: '/cart?goodsId=12' })
  292. // this.$router.go(-2)
  293. // 后退两步
  294. },
  295. // check-change
  296. // 节点选中状态发生变化时的回调
  297. // 共三个参数,依次为:传递给 data 属性的数组中该节点所对应的对象、节点本身是否被选中、节点的子树中是否有被选中的节点
  298. menuCheckChange(data, checked, indeterminate) {
  299. console.log(data, '数据')
  300. console.log(checked, '选中状态')
  301. console.log(indeterminate, '子树中选中状态')
  302. // 获取当前选择的id在数组中的索引
  303. const indexs = this.selectMenu.menuid.indexOf(data.id)
  304. // 如果不存在数组中,并且数组中已经有一个id并且checked为true的时候,代表不能再次选择。
  305. if (indexs < 0 && this.selectMenu.menuid.length === 1 && checked) {
  306. console.log('only one')
  307. this.$message({
  308. message: '只能选择一个菜单!',
  309. type: 'error',
  310. showClose: true
  311. })
  312. // 设置已选择的节点为false 很重要
  313. this.$refs.selectmenutree.setChecked(data, false)
  314. } else if (this.selectMenu.menuid.length === 0 && checked) {
  315. // 发现数组为空 并且是已选择
  316. // 防止数组有值,首先清空,再push
  317. this.selectMenu.menuid = []
  318. this.deptform.menuid = data.id
  319. this.selectMenu.menuid.push(data.id)
  320. } else if (
  321. indexs >= 0 &&
  322. this.selectMenu.menuid.length === 1 &&
  323. !checked
  324. ) {
  325. // 再次直接进行赋值为空操作
  326. this.selectMenu.menuid = []
  327. }
  328. },
  329. handleFind() {
  330. this.listLoading = true
  331. this.getdataListParm.params = [this.menuid, this.menuid, this.interfaceName, this.interfaceName]
  332. GetDataByName(this.getdataListParm).then(response => {
  333. console.log(response)
  334. this.list = response.data.list
  335. this.total = response.data.total
  336. setTimeout(() => {
  337. this.listLoading = false
  338. }, 100)
  339. })
  340. },
  341. handleNodeClick(data) {
  342. console.log(data)
  343. if (data.children === undefined || (data.children !== undefined && data.children.length === 0)) {
  344. this.listLoading = true
  345. this.menuid = data.id
  346. this.getdataListParm.params = [data.id, data.id, '', '']
  347. GetDataByName(this.getdataListParm).then(response => {
  348. if (response.data.total > 0) {
  349. this.list = response.data.list
  350. this.total = response.data.total
  351. } else {
  352. this.list = []
  353. this.total = 0
  354. }
  355. // Just to simulate the time of the request
  356. setTimeout(() => {
  357. this.listLoading = false
  358. }, 100)
  359. })
  360. }
  361. },
  362. getDownList() {
  363. GetDataByName(this.getRecuListParm).then(response => {
  364. console.log(response)
  365. this.parent = response.data
  366. if (response.data.list !== null) {
  367. this.parent = transData(response.data.list, 'id', 'parentid', 'children')
  368. }
  369. })
  370. },
  371. deptenter() {
  372. this.$nextTick(() => {
  373. this.$refs['remark'].focus()
  374. })
  375. },
  376. getList() {
  377. this.menuid = 0
  378. this.listLoading = true
  379. this.getDownList()
  380. GetDataByName(this.getdataListParm).then(response => {
  381. console.log(response)
  382. this.list = response.data.list
  383. this.total = response.data.total
  384. // Just to simulate the time of the request
  385. setTimeout(() => {
  386. this.listLoading = false
  387. }, 100)
  388. })
  389. },
  390. requesttest() {
  391. this.listLoading = true
  392. console.log(JSON.parse(this.deptform.request_body))
  393. requestbyname(JSON.parse(this.deptform.request_body), this.deptform.method).then(response => {
  394. console.log(response.data)
  395. this.deptform.return_body = JSON.stringify(response.data)
  396. // Just to simulate the time of the request
  397. setTimeout(() => {
  398. this.listLoading = false
  399. }, 100)
  400. })
  401. },
  402. resetRequestParam() {
  403. this.deptform.sqlid = ''
  404. this.deptform.menuid = ''
  405. this.deptform.method = ''
  406. this.deptform.sqlname = ''
  407. this.deptform.sqlstr = ''
  408. this.deptform.params = ''
  409. this.deptform.remark = ''
  410. this.deptform.request_body = ''
  411. this.deptform.sort = '0'
  412. this.deptform.enable = '1'
  413. this.deptform.return_body = ''
  414. this.deptform.name = ''
  415. },
  416. handleCreate() {
  417. this.resetRequestParam()
  418. this.deptform.menuid = this.menuid
  419. this.dialogStatus = 'create'
  420. this.dialogFormVisible = true
  421. this.$nextTick(() => {
  422. this.$refs['dataForm'].clearValidate()
  423. this.$refs.sqlname.focus()
  424. })
  425. },
  426. createData() {
  427. this.$refs['dataForm'].validate((valid) => {
  428. if (valid) {
  429. this.requestParam.name = 'createapisql'
  430. // this.requestParam.parammaps = {}
  431. // this.requestParam.parammaps = this.deptform
  432. this.requestParam.params = []
  433. this.requestParam.params[0] = this.deptform.sqlstr
  434. this.requestParam.params[1] = this.deptform.sqlname
  435. this.requestParam.params[2] = this.deptform.params
  436. this.requestParam.params[3] = this.deptform.menuid
  437. this.requestParam.params[4] = 'tmrgo' // remark
  438. this.requestParam.params[5] = this.deptform.sort
  439. this.requestParam.params[6] = this.deptform.enable
  440. this.requestParam.params[7] = this.deptform.method
  441. this.requestParam.params[8] = this.deptform.name
  442. this.requestParam.params[9] = this.deptform.request_body
  443. this.requestParam.params[10] = this.deptform.return_body
  444. PostDataByName(this.requestParam).then(() => {
  445. this.getList()
  446. this.dialogFormVisible = false
  447. this.$notify({
  448. title: '成功',
  449. message: '新增成功',
  450. type: 'success',
  451. duration: 2000
  452. })
  453. })
  454. }
  455. })
  456. },
  457. createData_again() {
  458. this.$refs['dataForm'].validate((valid) => {
  459. if (valid) {
  460. this.requestParam.name = 'createapisql'
  461. // this.requestParam.parammaps = {}
  462. // this.requestParam.parammaps = this.deptform
  463. this.requestParam.params = []
  464. this.requestParam.params[0] = this.deptform.sqlstr
  465. this.requestParam.params[1] = this.deptform.sqlname
  466. this.requestParam.params[2] = this.deptform.params
  467. this.requestParam.params[3] = this.menuid
  468. this.requestParam.params[4] = 'tmrgo'// remark
  469. this.requestParam.params[5] = this.deptform.sort
  470. this.requestParam.params[6] = this.deptform.enable
  471. this.requestParam.params[7] = this.deptform.method
  472. this.requestParam.params[8] = this.deptform.name
  473. this.requestParam.params[9] = this.deptform.request_body
  474. this.requestParam.params[10] = this.deptform.return_body
  475. PostDataByName(this.requestParam).then(() => {
  476. this.$nextTick(() => {
  477. this.$refs['sqlname'].focus()
  478. })
  479. this.getList()
  480. this.resetRequestParam()
  481. this.$notify({
  482. title: '成功',
  483. message: '新增成功',
  484. type: 'success',
  485. duration: 2000
  486. })
  487. })
  488. }
  489. })
  490. },
  491. handleUpdate(row) {
  492. this.deptform.sqlid = row.id
  493. if (row.menuid === null) { this.deptform.menuid = 0 } else { this.deptform.menuid = row.menuid }
  494. this.deptform.method = row.method
  495. this.deptform.sqlname = row.sqlname
  496. this.deptform.sqlstr = row.sqlstr
  497. this.deptform.params = row.params
  498. this.deptform.request_body = row.request_body
  499. this.deptform.return_body = row.return_body
  500. this.deptform.name = row.name
  501. this.deptform.remark = row.remark
  502. this.deptform.sort = row.sort
  503. this.deptform.enable = row.enable
  504. if (this.deptform.menuid !== 0) { this.defaultMenuCheckedKeys = [this.deptform.menuid] } else { this.defaultMenuCheckedKeys = [] }
  505. this.dialogStatus = 'update'
  506. this.dialogFormVisible = true
  507. this.$nextTick(() => {
  508. this.$refs['dataForm'].clearValidate()
  509. this.$refs['sqlname'].focus()
  510. })
  511. },
  512. updateData() {
  513. this.$refs['dataForm'].validate((valid) => {
  514. if (valid) {
  515. this.requestParam.name = 'updateapisql'
  516. // this.requestParam.parammaps = {}
  517. // this.requestParam.parammaps = this.deptform
  518. this.requestParam.params = []
  519. this.requestParam.params[0] = this.deptform.sqlstr
  520. this.requestParam.params[1] = this.deptform.sqlname
  521. this.requestParam.params[2] = this.deptform.params
  522. this.requestParam.params[3] = this.deptform.menuid
  523. this.requestParam.params[4] = 'tmrgo'// remark
  524. this.requestParam.params[5] = this.deptform.sort
  525. this.requestParam.params[6] = this.deptform.enable
  526. this.requestParam.params[7] = this.deptform.method
  527. this.requestParam.params[8] = this.deptform.name
  528. this.requestParam.params[9] = this.deptform.request_body
  529. this.requestParam.params[10] = this.deptform.return_body
  530. this.requestParam.params[11] = this.deptform.sqlid
  531. PostDataByName(this.requestParam).then(() => {
  532. this.getList()
  533. this.resetRequestParam()
  534. this.dialogFormVisible = false
  535. this.$notify({
  536. title: '成功',
  537. message: '修改成功',
  538. type: 'success',
  539. duration: 2000
  540. })
  541. })
  542. }
  543. })
  544. },
  545. handleEnableChange(index, row) {
  546. this.requestParam.name = 'updateapisql'
  547. this.requestParam.params = []
  548. this.requestParam.params[0] = row.sqlstr
  549. this.requestParam.params[1] = row.sqlname
  550. this.requestParam.params[2] = row.params
  551. this.requestParam.params[3] = row.menuid
  552. this.requestParam.params[4] = row.remark
  553. this.requestParam.params[5] = row.sort
  554. this.requestParam.params[6] = row.enable
  555. this.requestParam.params[7] = row.method
  556. this.requestParam.params[8] = row.name
  557. this.requestParam.params[9] = row.request_body
  558. this.requestParam.params[10] = row.return_body
  559. this.requestParam.params[11] = row.id
  560. PostDataByName(this.requestParam).then(() => {
  561. this.$notify({
  562. title: '成功',
  563. message: '修改成功',
  564. type: 'success',
  565. duration: 2000
  566. })
  567. })
  568. },
  569. handleDelete(row) {
  570. MessageBox.confirm('sql名称:' + row.sqlname, '确认删除?', {
  571. confirmButtonText: '确认',
  572. cancelButtonText: '取消',
  573. type: 'warning'
  574. }).then(() => {
  575. this.requestParam.name = 'deleteapisql'
  576. this.requestParam.params = []
  577. this.requestParam.params[0] = row.id
  578. PostDataByName(this.requestParam).then(() => {
  579. this.getList()
  580. this.resetRequestParam()
  581. this.dialogFormVisible = false
  582. this.$notify({
  583. title: '成功',
  584. message: '删除成功',
  585. type: 'success',
  586. duration: 2000
  587. })
  588. })
  589. })
  590. }
  591. }
  592. }
  593. </script>