3467b44693fefa5eaa54d8181d1a89ffe2866e1c.svn-base 23 KB

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