index.vue 22 KB

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