index.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477
  1. <template>
  2. <div class="app-container" style="position: absolute;height:calc(100% - 40px);width:100%;overflow-y: auto;overflow-x: hidden;">
  3. <!-- 服务配置 -->
  4. <el-row type="flex" :gutter="10" style="line-height: 54px;height:100%">
  5. <el-col style="height:100%;width:50%;padding-right:10px">
  6. <el-row type="flex" class="row-bg" justify="center">
  7. <el-col :span="7">
  8. <div class="demo-input-suffix">
  9. <el-row>
  10. <el-col :span="5">
  11. <span>名称:</span>
  12. </el-col>
  13. <el-col :span="16">
  14. <el-input v-model="serviceName" size="small" placeholder="请输入内容" clearable />
  15. </el-col>
  16. </el-row>
  17. </div>
  18. </el-col>
  19. <el-col :span="7">
  20. <div class="demo-input-suffix">
  21. <el-row>
  22. <el-col :span="5">
  23. <span>编码:</span>
  24. </el-col>
  25. <el-col :span="16">
  26. <el-input v-model="serviceCode" placeholder="请输入内容" size="small" clearable />
  27. </el-col>
  28. </el-row>
  29. </div>
  30. </el-col>
  31. <el-col :span="10">
  32. <el-button type="primary" size="small" @click="handleBtnClick('query', 'service')">查询</el-button>
  33. <el-button type="primary" size="small" @click="handleBtnClick('add', 'service')">新增</el-button>
  34. <el-button type="primary" size="small" :disabled="serviceChoosing.length !== 1" @click="handleBtnClick('edit', 'service')">修改</el-button>
  35. <el-button type="primary" size="small" :disabled="serviceChoosing.length === 0" @click="handleBtnClick('delete', 'service')">删除</el-button>
  36. </el-col>
  37. </el-row>
  38. <div style="margin-top: 20px;height:100%;width:100%">
  39. <table-item :table-data="list" :column="column" :pagination="true" :pagesize="pagination.size" :currentpage="pagination.current" :tableheight="'calc(100% - 75px)'" :border="true" :multiple="true" :total="total" :fixed="false" :isdelete="true" :stripe="true" :is-select="false" @handleCurrentChange="handleCurrentChange" @handleSizeChange="handleSizeChange" @handleSelectionChange="serviceSelection" @rowDblclick="handleServiceDbclick" />
  40. </div>
  41. </el-col>
  42. <el-col style="height:100%;width:50%;padding-left:10px">
  43. <el-row type="flex">
  44. <el-col :span="7">
  45. <div class="demo-input-suffix">
  46. <el-row>
  47. <el-col :span="5">
  48. <span>名称:</span>
  49. </el-col>
  50. <el-col :span="15">
  51. <el-input v-model="sourceName" size="small" placeholder="请输入内容" clearable />
  52. </el-col>
  53. </el-row>
  54. </div>
  55. </el-col>
  56. <el-col :span="7">
  57. <div class="demo-input-suffix">
  58. <el-row>
  59. <el-col :span="8">
  60. <span>资源值:</span>
  61. </el-col>
  62. <el-col :span="15">
  63. <el-input v-model="sourceValue" size="small" placeholder="请输入内容" clearable />
  64. </el-col>
  65. </el-row>
  66. </div>
  67. </el-col>
  68. <el-col :span="10">
  69. <el-button type="primary" size="small" @click="handleBtnClick('query', 'source')">查询</el-button>
  70. <el-button type="primary" size="small" :disabled="serviceChoosing.length !== 1" @click="handleBtnClick('add', 'source')">新增</el-button>
  71. <el-button type="primary" size="small" :disabled="sourceChoosing.length !== 1" @click="handleBtnClick('edit', 'source')">修改</el-button>
  72. <el-button type="primary" size="small" :disabled="sourceChoosing.length === 0" @click="handleBtnClick('delete', 'source')">删除</el-button>
  73. </el-col>
  74. </el-row>
  75. <div style="margin-top: 20px;height:100%;width:100%">
  76. <table-item :table-data="list1" :column="column2" :pagination="false" :tableheight="'calc(100% - 75px)'" :border="true" :multiple="true" :fixed="false" :isdelete="true" :is-select="false" @handleSelectionChange="sourceSelection" @rowDblclick="handleSourceDbclick" />
  77. </div>
  78. </el-col>
  79. </el-row>
  80. <el-dialog v-if="dialogShow" v-dialogDrag :visible.sync="dialogShow" :title="dialogTitle" width="600px" @close="closedialogShow">
  81. <template v-if="currDialog === 'service'">
  82. <el-form ref="serviceInfoForm" :model="serviceInfo" :rules="serviceInfoRule" label-position="right" label-width="140px">
  83. <el-form-item label="服务编码:" prop="code">
  84. <el-input v-model="serviceInfo.code" size="small" placeholder="请输入服务编码" :disabled="currType !== 1" />
  85. </el-form-item>
  86. <el-form-item label="服务名称:" prop="name">
  87. <el-input v-model="serviceInfo.name" size="small" placeholder="请输入服务名称" />
  88. </el-form-item>
  89. <el-form-item label="服务类型:" prop="type">
  90. <el-input v-model="serviceInfo.type" size="small" placeholder="请输入服务类型" />
  91. </el-form-item>
  92. </el-form>
  93. </template>
  94. <template v-else>
  95. <el-form ref="sourceInfoForm" :model="sourceInfo" :rules="sourceInfoRule" label-position="right" label-width="140px">
  96. <el-form-item label="资源编码:" prop="ckey">
  97. <el-input v-model="sourceInfo.ckey" size="small" placeholder="请输入资源编码" :disabled="currType !== 1" />
  98. </el-form-item>
  99. <el-form-item label="资源名称:" prop="name">
  100. <el-input v-model="sourceInfo.name" size="small" placeholder="请输入资源名称" />
  101. </el-form-item>
  102. <el-form-item prop="cval" label="资源值:">
  103. <el-input v-model="sourceInfo.cval" size="small" placeholder="请输入资源值" />
  104. </el-form-item>
  105. <el-form-item prop="visible" label="默认加载:">
  106. <el-select style="width:100%" v-model="sourceInfo.isDisplay" size="small">
  107. <el-option value="0" label="否"></el-option>
  108. <el-option value="1" label="是"></el-option>
  109. </el-select>
  110. </el-form-item>
  111. <el-form-item style="width:100%" prop="thirdSys" label="第三方调用:">
  112. <el-input size="small" v-model="sourceInfo.thirdSys" placeholder="第三方系统调用服务需填写" />
  113. </el-form-item>
  114. <el-form-item prop="thirdSysAutoLoad" label="第三方默认加载:">
  115. <el-select style="width:100%" size="small" v-model="sourceInfo.thirdSysAutoLoad">
  116. <el-option value="0" label="否"></el-option>
  117. <el-option value="1" label="是"></el-option>
  118. </el-select>
  119. </el-form-item>
  120. </el-form>
  121. </template>
  122. <template slot="footer">
  123. <el-button @click="footerBtnClick('cancel')">取消</el-button>
  124. <el-button type="primary" @click="footerBtnClick('confirm')">确定</el-button>
  125. </template>
  126. </el-dialog>
  127. </div>
  128. </template>
  129. <script lang="ts">
  130. import { Vue, Component, Watch } from 'vue-property-decorator'
  131. import TableItem from '@/components/Table/index.vue'
  132. import {
  133. serviceAdd,
  134. serviceDelete,
  135. serviceEdit,
  136. serviceList,
  137. sourceAdd,
  138. sourceDelete,
  139. sourceEdit,
  140. sourceList
  141. } from '@/api/base'
  142. @Component({
  143. name: 'ServiceConfig',
  144. components: { TableItem }
  145. })
  146. export default class ServiceConfig extends Vue {
  147. serviceName = ''
  148. serviceCode = ''
  149. sourceName = ''
  150. sourceValue = ''
  151. pagination = { current: 1, size: 30 } // 分页参数信息
  152. total = 1
  153. list = []
  154. column = [
  155. {
  156. label: '服务编码',
  157. prop: 'code'
  158. },
  159. {
  160. label: '服务名称',
  161. prop: 'name'
  162. },
  163. {
  164. label: '类型',
  165. prop: 'type'
  166. }
  167. ]
  168. list1 = []
  169. column2 = [
  170. {
  171. label: '资源编码',
  172. prop: 'ckey'
  173. },
  174. {
  175. label: '资源名称',
  176. prop: 'name'
  177. },
  178. {
  179. label: '资源值',
  180. prop: 'cval'
  181. }
  182. ]
  183. serviceInfo = {
  184. // 服务信息
  185. code: undefined,
  186. name: undefined,
  187. type: undefined,
  188. id: undefined
  189. }
  190. serviceInfoRule = {
  191. code: [{ required: true, message: '服务编码是必填项!', trigger: 'blur' }],
  192. name: [{ required: true, message: '服务名称是必填项!', trigger: 'blur' }],
  193. type: [{ required: true, message: '服务类型是必填项!', trigger: 'blur' }]
  194. }
  195. sourceInfoRule = {
  196. ckey: [{ required: true, message: '资源编码是必填项!', trigger: 'blur' }],
  197. name: [{ required: true, message: '资源名称是必填项!', trigger: 'blur' }],
  198. cval: [{ required: true, message: '资源值是必填项!', trigger: 'blur' }]
  199. }
  200. dialogShow = false // 弹窗
  201. currType = 1
  202. sourceInfo = {
  203. // 资源信息
  204. ckey: undefined,
  205. name: undefined,
  206. cval: undefined,
  207. pid: undefined,
  208. id: undefined,
  209. isDisplay: '0',
  210. thirdSys: '',
  211. thirdSysAutoLoad: '0'
  212. }
  213. currDialog = 'service' // 弹窗当前为左侧服务
  214. serviceChoosing = []
  215. sourceChoosing = []
  216. get dialogTitle() {
  217. const title = this.currDialog === 'service' ? '服务' : '资源'
  218. return (this.currType === 1 ? '新增' : '修改') + title
  219. }
  220. @Watch('serviceChoosing')
  221. serviceChoosingChange() {
  222. if (this.serviceChoosing.length === 1) {
  223. this.getSourceList()
  224. } else this.list1 = []
  225. }
  226. @Watch('dialogShow')
  227. dialogShowChange(val) {
  228. if (!val) {
  229. this.$nextTick(() => {
  230. Object.keys(this.serviceInfo).forEach((item) => {
  231. this.serviceInfo[item] = undefined
  232. })
  233. this.sourceInfo=this.defaultSourceInfo();
  234. })
  235. }
  236. }
  237. defaultSourceInfo() {
  238. return {
  239. ckey: undefined,
  240. name: undefined,
  241. cval: undefined,
  242. pid: undefined,
  243. id: undefined,
  244. isDisplay: '0',
  245. thirdSys: '',
  246. thirdSysAutoLoad: '0'
  247. }
  248. }
  249. // 获取服务列
  250. getServiceList() {
  251. // if (this.serviceName !== '' || this.serviceCode !== '') {
  252. // this.pagination = { current: 1, size: 10 }
  253. // }
  254. const data = {
  255. // name: this.serviceName || undefined,
  256. // code: this.serviceCode || undefined,
  257. current: this.pagination.current,
  258. size: this.pagination.size
  259. // 'orders[0].asc': false,
  260. // 'orders[0].column': 'ID'
  261. }
  262. serviceList(data).then((res) => {
  263. this.total = res.result.total
  264. // console.log(res.result.total, this.total)
  265. this.list = res.result.records || []
  266. })
  267. }
  268. // 新增服务
  269. addService() {
  270. // 新增需要的form数据
  271. serviceAdd(this.serviceInfo).then(() => {
  272. // 新增成功 刷新列表数据
  273. this.closedialogShow()
  274. })
  275. }
  276. // 编辑服务
  277. editService() {
  278. this.serviceInfo.id = this.serviceChoosing[0].id
  279. serviceEdit(this.serviceInfo).then(() => {
  280. // 编辑完成 关闭弹窗并获取新数据
  281. this.closedialogShow()
  282. })
  283. }
  284. // 新增编辑弹窗关闭公用方法
  285. closedialogShow() {
  286. this.dialogShow = false
  287. this.currDialog === 'service' ? this.getServiceList() : this.getSourceList()
  288. if (this.$refs.serviceInfoForm) {
  289. this.$refs.serviceInfoForm['resetFields']()
  290. }
  291. if (this.$refs.sourceInfoForm) {
  292. this.$refs.sourceInfoForm['resetFields']()
  293. }
  294. }
  295. // 删除服务项
  296. deleteService() {
  297. const data = { ids: this.serviceChoosing.map((item) => item.id).join(',') }
  298. serviceDelete(data).then((res) => {
  299. if (res.code !== -1) {
  300. this.$message.success('删除成功')
  301. this.getServiceList()
  302. }
  303. })
  304. }
  305. // 获取资源列
  306. getSourceList() {
  307. if (this.serviceChoosing.length === 0) {
  308. this.$message({
  309. message: '请先选择一项服务',
  310. type: 'error'
  311. })
  312. return
  313. }
  314. const data = {
  315. id: this.serviceChoosing[0].id,
  316. name: this.sourceName || undefined,
  317. cval: this.sourceValue || undefined,
  318. 'orders[0].asc': false,
  319. 'orders[0].column': 'ID'
  320. }
  321. sourceList(data).then((res) => {
  322. this.list1 = res.result.result || []
  323. })
  324. }
  325. // 新增资源
  326. addSource() {
  327. // 新增需要的form数据
  328. this.sourceInfo.pid = this.serviceChoosing[0].id
  329. sourceAdd(this.sourceInfo).then(() => {
  330. // 新增成功 刷新列表数据
  331. this.closedialogShow()
  332. })
  333. }
  334. // 编辑资源
  335. editSource() {
  336. sourceEdit(this.sourceInfo).then(() => {
  337. // 编辑完成 关闭弹窗并获取新数据
  338. this.closedialogShow()
  339. })
  340. }
  341. // 删除资源项
  342. deleteSource() {
  343. const data = { ids: this.sourceChoosing.map((item) => item.id).join(',') }
  344. sourceDelete(data).then((res) => {
  345. if (res.code !== -1) {
  346. this.$message.success('删除成功')
  347. this.getSourceList()
  348. }
  349. })
  350. }
  351. // 服务侧按钮点击
  352. handleBtnClick(type, dialog) {
  353. this.currDialog = dialog
  354. if (type === 'query') {
  355. dialog === 'service' ? this.getServiceList() : this.getSourceList()
  356. } else if (type === 'add') {
  357. this.currType = 1
  358. this.dialogShow = true
  359. } else if (type === 'edit') {
  360. this.currType = 2
  361. this.dialogShow = true
  362. // 判断是服务还是资源
  363. if (dialog === 'service') {
  364. const { code, name, type } = this.serviceChoosing[0]
  365. this.serviceInfo = { code, name, type, id: undefined }
  366. } else {
  367. const { ckey, name, cval, id, isDisplay, thirdSys, thirdSysAutoLoad } = this.sourceChoosing[0]
  368. this.sourceInfo = { ckey, name, cval, id, pid: undefined, isDisplay, thirdSys, thirdSysAutoLoad }
  369. }
  370. } else if (type === 'delete') {
  371. const deleteList = dialog === 'service' ? this.serviceChoosing : this.sourceChoosing
  372. const title = dialog === 'service' ? '服务信息?' : '资源信息?'
  373. this.$confirm('确定删除选中的' + deleteList.length + '条' + title, '提示', {
  374. confirmButtonText: '确定',
  375. cancelButtonText: '取消',
  376. type: 'warning'
  377. })
  378. .then(() => {
  379. dialog === 'service' ? this.deleteService() : this.deleteSource()
  380. })
  381. .catch(() => {
  382. return false
  383. })
  384. }
  385. }
  386. // 弹窗footer按钮点击
  387. footerBtnClick(type) {
  388. if (type === 'cancel') {
  389. // this.dialogShow = false;
  390. this.closedialogShow()
  391. } else if (type === 'confirm') {
  392. // 点击确定判断是服务还是资源
  393. if (this.currDialog === 'service') {
  394. this.$refs.serviceInfoForm['validate']((valid) => {
  395. if (valid) {
  396. // 再判断是新增还是编辑
  397. if (this.currType === 1) {
  398. this.addService()
  399. } else {
  400. this.editService()
  401. }
  402. // this.dialogShow = false;
  403. } else {
  404. return false
  405. }
  406. })
  407. } else {
  408. this.$refs.sourceInfoForm['validate']((valid) => {
  409. if (valid) {
  410. if (this.currType === 1) {
  411. this.addSource()
  412. } else {
  413. this.editSource()
  414. }
  415. // this.dialogShow = false;
  416. } else {
  417. return false
  418. }
  419. })
  420. }
  421. }
  422. }
  423. // 页码
  424. handleCurrentChange(current) {
  425. this.pagination = {
  426. ...this.pagination,
  427. current
  428. }
  429. this.getServiceList()
  430. }
  431. // 条数
  432. handleSizeChange(size = 1) {
  433. this.pagination = {
  434. ...this.pagination,
  435. size,
  436. current: 1
  437. }
  438. this.getServiceList()
  439. }
  440. // 服务列表选择
  441. serviceSelection(value) {
  442. this.serviceChoosing = value
  443. }
  444. // 资源列表选择
  445. sourceSelection(value) {
  446. this.sourceChoosing = value
  447. }
  448. // 双击查看
  449. handleServiceDbclick(data) {
  450. const that = this
  451. that.serviceChoosing = []
  452. that.serviceChoosing.push(data)
  453. // console.log('双击查看'+JSON.stringify(data))
  454. that.handleBtnClick('edit', 'service')
  455. }
  456. // 双击查看
  457. handleSourceDbclick(data) {
  458. const that = this
  459. that.sourceChoosing = []
  460. that.sourceChoosing.push(data)
  461. // console.log('双击查看'+JSON.stringify(data))
  462. that.handleBtnClick('edit', 'source')
  463. }
  464. mounted() {
  465. this.getServiceList()
  466. }
  467. }
  468. </script>
  469. <style lang="scss" scoped>
  470. /deep/ .el-table {
  471. height: 680px;
  472. }
  473. </style>