index.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493
  1. <template>
  2. <div class="newService">
  3. <div class="newService-head flex-wrap">
  4. <div class="manageTitle">{{ title }}</div>
  5. </div>
  6. <div class="newService-content flex-wrap">
  7. <div class="newService-content-left">
  8. <div class="newService-content-left-top">
  9. <div class="flex head">
  10. <div class="title">角色列表</div>
  11. <el-button @click="handleAdd" class="serButton" size="small">新增</el-button>
  12. </div>
  13. <div class="search">
  14. <el-input size="small" placeholder="请输入内容" clearable prefix-icon="el-icon-search" v-model="search">
  15. </el-input>
  16. </div>
  17. </div>
  18. <div class="newService-content-left-bottom">
  19. <template v-if="dataList.length">
  20. <el-scrollbar ref="scroll" style="height: 100%">
  21. <div v-loading="loading" element-loading-text="拼命加载中" element-loading-spinner="el-icon-loading" element-loading-background="rgba(0, 0, 0, 0.8)">
  22. <div v-for="(item,index) in dataList" :key="index" @click.stop="handleClick(item,index)" :class="index == activeIndex ? 'active':''" class="contents flex">
  23. <div class="left">
  24. <span class="txt">{{ item.role_name }}</span>
  25. </div>
  26. <div v-show="activeIndex == index" class="right">
  27. <span @click.stop="handleError" class="error">删除</span>
  28. </div>
  29. </div>
  30. </div>
  31. </el-scrollbar>
  32. </template>
  33. <template v-else>
  34. <el-empty description="暂无数据"></el-empty>
  35. </template>
  36. </div>
  37. </div>
  38. <div class="newService-content-right">
  39. <div class="newService-content-right-top">
  40. <div class="flex">
  41. <div class="title">角色信息 {{ dataObj.role_name }}</div>
  42. <el-button type="primary" @click="handleSave" :disabled="flag" class="bcButton" size="small">保存</el-button>
  43. </div>
  44. <div class="demo-form">
  45. <el-form :inline="true" :model="formInline" class="flex-wrap">
  46. <el-form-item label="角色名称">
  47. <el-input style="width:250px" clearable v-model="formInline.role_name" :disabled="activeIndex == null" size="small" placeholder="请输入角色名称"></el-input>
  48. </el-form-item>
  49. <el-form-item class="flex1" label="角色描述">
  50. <el-input style="width:600px;" clearable v-model="formInline.comment" :disabled="activeIndex == null" size="small" placeholder="请输入角色描述"></el-input>
  51. </el-form-item>
  52. </el-form>
  53. </div>
  54. </div>
  55. <div style="height: calc(100% - 180px)" class="flex newService-content-right-new">
  56. <div class="newService-content-right-bottom contents1 flex1">
  57. <div class="newService-content-left-top">
  58. <div class="flex head">
  59. <div class="title">权限列表</div>
  60. </div>
  61. <div class="search">
  62. <el-input size="small" placeholder="请输入内容" clearable prefix-icon="el-icon-search" :filter-node-method="filterNode" v-model="filterText">
  63. </el-input>
  64. </div>
  65. </div>
  66. <div class="newService-content-left-bottom">
  67. <el-scrollbar ref="scroll" style="height: 100%">
  68. <div class="newService-content-left-bottom-tree">
  69. <el-tree ref="tree" show-checkbox :data="treeData" :props="defaultProps" highlight-current :filter-node-method="filterNode" default-expand-all node-key="auth_id" @check="checkChange" @node-click="handleNodeClick" :expand-on-click-node="false">
  70. <span class="custom-tree-node" slot-scope="{ node, data }">
  71. <span class="customTxt">{{ node.label }}</span>
  72. <span v-show="treeCheckId == data.auth_id" class="customBtn">
  73. <span @click="setItem(node,data)" v-if="data.auth_id != 0 && data.auth_type == 4" class="ym">列授权</span>
  74. </span>
  75. </span>
  76. </el-tree>
  77. </div>
  78. </el-scrollbar>
  79. </div>
  80. </div>
  81. <div class="newService-content-right-bottom contents2 flex1">
  82. <div class="newService-content-left-top">
  83. <div class="flex head">
  84. <div class="title">列授权</div>
  85. </div>
  86. </div>
  87. <div class="newService-content-left-bottom">
  88. <template v-if="checkArrs.length">
  89. <el-scrollbar ref="scroll" style="height: 100%">
  90. <el-checkbox-group @change="groupChange" v-model="checkGroup" size="small">
  91. <el-row :gutter="20">
  92. <el-col v-for="(item,index) in checkArrs" :key="index" :span="8">
  93. <el-checkbox :label="item.columnName" border>{{ item.columnLabel }}</el-checkbox>
  94. </el-col>
  95. </el-row>
  96. </el-checkbox-group>
  97. </el-scrollbar>
  98. </template>
  99. <template v-else>
  100. <el-empty description="暂无数据"></el-empty>
  101. </template>
  102. </div>
  103. </div>
  104. </div>
  105. </div>
  106. </div>
  107. </div>
  108. </template>
  109. <script>
  110. import Table from '@/views/newTable/index.vue'
  111. import { Query, newData, modifyData, moveData } from "@/api/webApi"
  112. import { setTree } from '@/utils/validate'
  113. import pb from '@/layout/mixin/getPublicData'
  114. import * as _ from 'lodash'
  115. export default {
  116. name: 'NewService',
  117. components: { Table },
  118. mixins: [pb],
  119. data () {
  120. return {
  121. title: '服务设置',
  122. search: '',
  123. filterText: '',
  124. arrs: [],
  125. flag: true,
  126. formInline: {
  127. role_name: '',
  128. comment: ''
  129. },
  130. activeIndex: null,
  131. pageIndex: 0,
  132. pageSize: 9999,
  133. dataContent: {},
  134. queryId: '',
  135. dataObj: {},
  136. dataType: 'edit',
  137. noMore: false,
  138. loading: false,
  139. treeData: [
  140. {
  141. auth_name: '中小型机场系统',
  142. auth_id: 0,
  143. children: [],
  144. up_auth_id: -1
  145. }
  146. ],
  147. treeCheckId: '',
  148. treeCheckObj: {},
  149. defaultProps: {
  150. children: 'children',
  151. label: 'auth_name'
  152. },
  153. checkGroup: [],
  154. checkArrs: [],
  155. checkDatas: [],
  156. checkGroups: []
  157. }
  158. },
  159. computed: {
  160. dataList () {
  161. return this.arrs.filter(data => !this.search || data.role_name.toLowerCase().includes(this.search.toLowerCase()))
  162. }
  163. },
  164. watch: {
  165. filterText (val) {
  166. this.$refs.tree.filter(val);
  167. }
  168. },
  169. created () {
  170. const { title, qid } = this.$route.meta
  171. this.title = title
  172. this.queryId = qid
  173. this.getQueryList(qid)
  174. this.setTreeData()
  175. },
  176. updated () {
  177. this.scrollDown()
  178. },
  179. methods: {
  180. //获取tree数据
  181. async setTreeData () {
  182. const result = await this.getQuery(SERVICE_ID.sysMenuId)
  183. const treeMenu = setTree(result, 'up_auth_id', 'auth_id')
  184. this.treeData[0].children = treeMenu
  185. },
  186. filterNode (value, data) {
  187. if (!value) return true;
  188. return data.auth_name.indexOf(value) !== -1;
  189. },
  190. async getQueryList (id) {
  191. try {
  192. this.loading = true;
  193. const { code, returnData } = await Query({
  194. serviceId: id,
  195. page: ++this.pageIndex,
  196. pageSize: this.pageSize,
  197. dataContent: this.dataContent,
  198. })
  199. if (code == 0) {
  200. if (returnData.length === 0) {
  201. this.pageIndex--;
  202. this.noMore = true;
  203. }
  204. this.arrs.push(...returnData)
  205. if (this.dataType == 'add') {
  206. const item = this.arrs[this.arrs.length - 1]
  207. if (Object.keys(item).length) {
  208. this.dataObj = item
  209. this.flag = false
  210. }
  211. }
  212. this.loading = false;
  213. } else {
  214. this.pageIndex--;
  215. this.loading = false;
  216. }
  217. } catch (error) {
  218. this.pageIndex--;
  219. this.loading = false;
  220. }
  221. },
  222. load () {
  223. if (!this.noMore) {
  224. this.getQueryList(this.queryId);
  225. }
  226. },
  227. scrollDown () {
  228. if (this.$refs['scroll'] && this.dataType == 'add') {
  229. this.$refs['scroll'].wrap.scrollTop = this.$refs['scroll'].wrap.scrollHeight
  230. }
  231. },
  232. resetTable () {
  233. this.pageIndex = 0;
  234. this.noMore = false;
  235. this.arrs = [];
  236. },
  237. //服务列表-新增
  238. handleAdd () {
  239. this.dataType = 'add'
  240. this.flag = false
  241. this.dataObj.role_name = '新建角色'
  242. this.arrs.push({ role_name: '新建角色' })
  243. this.activeIndex = this.arrs.length - 1
  244. for (const key in this.formInline) {
  245. if (Object.hasOwnProperty.call(this.formInline, key)) {
  246. this.formInline[key] = null
  247. }
  248. }
  249. },
  250. //获取角色已有权限
  251. async getRoleQuth (item) {
  252. const result = await this.getQuery(SERVICE_ID.authTreeId, false, { role_id: item.role_ID })
  253. this.checkDatas.push(result)
  254. if (result && result.length) {
  255. const datas = []
  256. result.forEach(item => {
  257. datas.push(item.auth_id)
  258. })
  259. this.$refs.tree.setCheckedKeys(datas)
  260. const treeDatas = this.$refs.tree.getCheckedNodes().concat(this.$refs.tree.getHalfCheckedNodes())
  261. const res = [...treeDatas, ...result].filter((item) => !(treeDatas.some((p) => item.auth_id == p.auth_id) && result.some((c) => item.auth_id == c.auth_id)))
  262. setTimeout(() => {
  263. res.forEach((item) => {
  264. this.$refs.tree.setChecked(item.auth_id, false, false);
  265. });
  266. }, 50);
  267. }
  268. },
  269. //服务列表-点击
  270. handleClick (item, index) {
  271. this.dataType = 'edit'
  272. this.dataObj = _.cloneDeep(item)
  273. this.formInline = _.cloneDeep(item)
  274. this.activeIndex = index
  275. this.flag = false
  276. this.getRoleQuth(item)
  277. },
  278. //服务列表-保存
  279. handleSave () {
  280. if (this.dataObj.role_ID && this.dataType == 'edit') {
  281. this.generalDataReception(this.queryId, 2, this.formInline)
  282. } else if (this.dataType == 'add' && this.arrs[this.arrs.length - 1].role_ID) {
  283. this.formInline.role_ID = this.arrs[this.arrs.length - 1].role_ID
  284. this.generalDataReception(this.queryId, 2, this.formInline)
  285. } else if (this.dataType == 'add') {
  286. this.generalDataReception(this.queryId, 1, this.formInline)
  287. }
  288. else {
  289. this.$message.error('请先选中服务后再操作')
  290. }
  291. },
  292. //服务列表-删除
  293. handleError () {
  294. if (this.dataObj.role_ID && this.dataType == 'edit') {
  295. this.$confirm('此操作将删除该服务, 是否继续?', '提示', {
  296. confirmButtonText: '确定',
  297. cancelButtonText: '取消',
  298. type: 'warning'
  299. }).then(() => {
  300. this.generalDataReception(this.queryId, 3, this.dataObj)
  301. this.activeIndex = null;
  302. this.dataObj = {};
  303. for (const key in this.formInline) {
  304. if (Object.hasOwnProperty.call(this.formInline, key)) {
  305. this.formInline[key] = null
  306. }
  307. }
  308. this.flag = true
  309. }).catch(() => {
  310. this.$message({
  311. type: 'info',
  312. message: '已取消删除'
  313. });
  314. });
  315. } else if (this.dataType == 'add' && this.arrs[this.arrs.length - 1].role_ID) {
  316. this.$confirm('此操作将删除该服务, 是否继续?', '提示', {
  317. confirmButtonText: '确定',
  318. cancelButtonText: '取消',
  319. type: 'warning'
  320. }).then(() => {
  321. this.generalDataReception(this.queryId, 3, this.arrs[this.arrs.length - 1])
  322. this.activeIndex = null;
  323. this.dataObj = {};
  324. for (const key in this.formInline) {
  325. if (Object.hasOwnProperty.call(this.formInline, key)) {
  326. this.formInline[key] = null
  327. }
  328. }
  329. this.flag = true
  330. this.dataType = 'edit'
  331. }).catch(() => {
  332. this.$message({
  333. type: 'info',
  334. message: '已取消删除'
  335. });
  336. });
  337. }
  338. else {
  339. this.arrs.splice(this.activeIndex, 1)
  340. this.activeIndex = null
  341. this.flag = true
  342. this.dataObj = {}
  343. }
  344. },
  345. //服务列表-增/删/改
  346. async generalDataReception (id = this.queryId, event, data, type) {
  347. try {
  348. const params = {
  349. serviceId: id,
  350. dataContent: data,
  351. event: `${event}`,
  352. };
  353. const { code } =
  354. event == 1
  355. ? await newData(params)
  356. : event == 2
  357. ? await modifyData(params)
  358. : await moveData(params);
  359. if (code == 0) {
  360. this.$message.success("操作成功");
  361. if (type) {
  362. } else {
  363. this.resetTable();
  364. this.getQueryList(this.queryId);
  365. }
  366. } else {
  367. this.$message.error("操作失败");
  368. }
  369. } catch (error) {
  370. this.$message.error("操作失败");
  371. }
  372. },
  373. handleNodeClick (data) {
  374. this.treeCheckId = data.auth_id
  375. this.treeCheckObj = data
  376. },
  377. checkChange () {
  378. if (this.dataObj.role_ID) {
  379. const datas = this.$refs.tree.getCheckedNodes().concat(this.$refs.tree.getHalfCheckedNodes());
  380. const arrs = datas.filter(item => item.auth_id != 0)
  381. this.checkDatas.push(arrs)
  382. const data1 = this.checkDatas[this.checkDatas.length - 1]; //最后一条数据
  383. const data2 = this.checkDatas[this.checkDatas.length - 2]; //倒数第二条数据
  384. if (data1.length > data2.length) {
  385. this.checksBoxTs(data1, data2, "add");
  386. } else {
  387. this.checksBoxTs(data2, data1, "del");
  388. }
  389. } else {
  390. this.$message.error('请选中角色后再操作');
  391. this.$refs.tree.setCheckedKeys([]);
  392. }
  393. },
  394. async checksBoxTs (datas, arr, type) {
  395. const res = [...datas, ...arr].filter((item) => !(datas.some((p) => item.auth_id == p.auth_id) && arr.some((c) => item.auth_id == c.auth_id)));
  396. const msgs = []
  397. res.forEach(item => {
  398. msgs.push({
  399. ID: item.ID
  400. })
  401. item.role_id = this.dataObj.role_ID
  402. item.role_name = this.dataObj.role_name
  403. item.role_status = this.dataObj.role_status
  404. })
  405. if (type == 'add') {
  406. this.generalDataReception(SERVICE_ID.authTreeId, 1, res, true)
  407. this.getRoleQuth(this.dataObj)
  408. } else {
  409. this.generalDataReception(SERVICE_ID.authTreeId, 3, msgs, true)
  410. }
  411. },
  412. async setItem (node, data) {
  413. if (this.dataObj.role_ID) {
  414. const result = await this.getQuery(SERVICE_ID.getTableColumnId, false, { serviceOutPutId: data.auth_id })
  415. if (result && result) {
  416. this.checkArrs = result
  417. const res = await this.getQuery(SERVICE_ID.authTreeId, false, { auth_id: data.auth_id, role_id: this.dataObj.role_ID })
  418. if (res && res.length) {
  419. const datas = []
  420. res.forEach(item => {
  421. if (item.columnname) {
  422. datas.push(item.columnname)
  423. }
  424. })
  425. if (datas.length) {
  426. this.checkGroups.push(datas)
  427. }
  428. this.checkGroup = datas
  429. }
  430. }
  431. } else {
  432. this.$message.error('请选中角色后再操作');
  433. }
  434. },
  435. groupChange (val) {
  436. this.checkGroups.push(val)
  437. if (this.checkGroups.length == 1) {
  438. const res = this.getColName(val)
  439. const result = this.sendCheckData(res)
  440. this.generalDataReception(SERVICE_ID.authTreeId, 1, result, true)
  441. } else if (this.checkGroups.length > 1) {
  442. const data1 = this.checkGroups[this.checkGroups.length - 1]; //最后一条数据
  443. const data2 = this.checkGroups[this.checkGroups.length - 2]; //倒数第二条数据
  444. const msg = [...data1, ...data2].filter((item) => !(data1.some((p) => item == p) && data2.some((c) => item == c)));
  445. const cap = this.getColName(msg)
  446. const result = this.sendCheckData(cap)
  447. if (data1.length > data2.length) {
  448. this.generalDataReception(SERVICE_ID.authTreeId, 1, result, true)
  449. } else {
  450. this.generalDataReception(SERVICE_ID.authTreeId, 3, result, true)
  451. }
  452. }
  453. },
  454. sendCheckData (arr) {
  455. const newData = []
  456. arr.forEach(item => {
  457. const obj = {
  458. "role_id": this.dataObj.role_ID,
  459. "role_name": this.dataObj.role_name,
  460. "role_status": this.dataObj.role_status,
  461. "auth_id": this.treeCheckObj.auth_id,
  462. "auth_type": this.treeCheckObj.auth_type,
  463. "queryTemplateColumnSetID": item.queryTemplateColumnSetID,
  464. "columnLabel": item.columnLabel,
  465. "columnname": item.columnName
  466. }
  467. newData.push(obj)
  468. })
  469. return newData
  470. },
  471. getColName (arr) {
  472. const res = []
  473. this.checkArrs.forEach(item => {
  474. arr.forEach(p => {
  475. if (item.columnName == p) {
  476. res.push(item)
  477. }
  478. })
  479. })
  480. return res
  481. },
  482. handleRemove (node, data) {
  483. }
  484. }
  485. }
  486. </script>
  487. <style lang="scss" scoped>
  488. @import "./css/index.scss";
  489. </style>