0cef850318964704f59ad77ace708a7971ffc78d.svn-base 23 KB

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