index.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533
  1. <template>
  2. <div class="admin-department">
  3. <el-form :inline="true">
  4. <el-form-item>
  5. <el-input v-model="queryParams.name" size="small" placeholder="请输入"></el-input>
  6. </el-form-item>
  7. <el-form-item>
  8. <el-button type="" :disabled="!$permission('/admin/role/permissionCheck')" size="small" @click="getList">查询</el-button>
  9. <el-butto :disabled="!$permission('/admin/role/permissionAdd')" type="primary" size="small" @click="handleAdd(func.fun.id)">新增</el-butto>
  10. </el-form-item>
  11. </el-form>
  12. <el-table
  13. row-key="id"
  14. ref="dataTable"
  15. v-loading="loading"
  16. :data="tableData"
  17. max-height="370"
  18. border
  19. @expand-change="getNode"
  20. @select="changeData"
  21. header-row-class-name="custom-table-header"
  22. >
  23. <el-table-column type="selection" width="60" align="center" ></el-table-column>
  24. <el-table-column prop="name" label="数据权限名称" align="" show-overflow-tooltip></el-table-column>
  25. <el-table-column prop="tenant" label="条件" align="center" show-overflow-tooltip></el-table-column>
  26. <el-table-column prop="remark" label="备注" align="center" show-overflow-tooltip></el-table-column>
  27. <el-table-column label="操作" align="center" width="150">
  28. <template slot-scope="scope">
  29. <el-dropdown split-button type="primary" size="small">
  30. <p v-if="$permission('/admin/role/permissionModify')" @click="handleEdit(scope.row)">编辑</p>
  31. <p v-else :disabled="true">编辑</p>
  32. <el-dropdown-menu slot="dropdown" class="text-align_center">
  33. <el-dropdown-item :disabled="!$permission('/admin/role/permissionDelete')" class="color-red" @click.native="handleDelete(scope.row)" divided>删除</el-dropdown-item>
  34. </el-dropdown-menu>
  35. </el-dropdown>
  36. </template>
  37. </el-table-column>
  38. </el-table>
  39. <el-dialog :title="title" :visible.sync="visible" width="900px" :before-close="close" :append-to-body="true">
  40. <el-form v-if="visible" :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" label-position="left">
  41. <el-form-item label="所属功能" prop="func">
  42. <el-input v-model="func.fun.name" size="small" :readonly="true" placeholder="请输入所属功能"></el-input>
  43. </el-form-item>
  44. <el-form-item label="数据权限名称" prop="function">
  45. <el-input v-model="ruleForm.name" size="small" placeholder="请输入数据权限名称"></el-input>
  46. </el-form-item>
  47. <el-form-item label="数据权限">
  48. <template>
  49. <div class="add">
  50. <el-button type="primary" @click="addList()">添加</el-button>
  51. </div>
  52. <div style="border:1px solid #C0C0C0;border-radius:4px;overflow:auto;min-height:200px;padding: 10px 20px">
  53. <el-row :gutter="24" v-for="(item,i) in list" :key="i" class="listItem">
  54. <el-col :span="4" style="padding:0">
  55. <span>
  56. <span v-if="i==0" style="opacity: 0;"> 内容 </span>
  57. <el-select v-else v-model="item.logicOpr">
  58. <el-option
  59. v-for="item in dictionaries.LOGIC_OPERATOR"
  60. :key="item.dictChildValue"
  61. :label="item.dictChildLabel"
  62. :value="item.dictChildValue">
  63. </el-option>
  64. </el-select>
  65. </span>
  66. </el-col>
  67. <el-col :span="7">
  68. <el-select v-model="item.field">
  69. <el-option
  70. v-for="item in dictionaries.dataDict"
  71. :key="item.dataSourceField"
  72. :label="item.dataSourceName"
  73. :value="item.dataSourceField">
  74. </el-option>
  75. </el-select>
  76. </el-col>
  77. <el-col :span="3" style="padding:0">
  78. <el-select v-model="item.opr">
  79. <el-option
  80. v-for="item in dictionaries.OPERATOR"
  81. :key="item.dictChildValue"
  82. :label="item.dictChildLabel"
  83. :value="item.dictChildValue">
  84. </el-option>
  85. </el-select>
  86. </el-col>
  87. <el-col :span="7">
  88. <el-select v-model="item.value"
  89. filterable
  90. allow-create
  91. default-first-option
  92. placeholder="请选择">
  93. <el-option
  94. :value="userinfo.tenantName"
  95. >
  96. <el-tooltip class="item" effect="dark" :content="userinfo.tenantName" placement="top">
  97. <span style="float: left;width:100px;white-space:nowrap;overflow:hidden;text-overflow: ellipsis;">{{userinfo.tenantName}}</span>
  98. </el-tooltip>
  99. <span style="float: right; color: #8492a6; font-size: 13px;margin-left:30px">租户</span>
  100. </el-option>
  101. </el-select>
  102. </el-col>
  103. <el-col :span="3">
  104. <el-button @click="deleteList(i)"><i class="el-icon-delete"></i> </el-button>
  105. </el-col>
  106. </el-row>
  107. </div>
  108. </template>
  109. </el-form-item>
  110. <el-form-item label="备注" prop="remark">
  111. <el-input v-model="ruleForm.remark" placeholder="请输入备注" type="textarea" maxlength="100" show-word-limit></el-input>
  112. </el-form-item>
  113. </el-form>
  114. <div slot="footer" class="dialog-footer">
  115. <el-button @click="close">取 消</el-button>
  116. <el-button type="primary" @click="submit" :loading="btnLoading">确 定</el-button>
  117. </div>
  118. </el-dialog>
  119. <!-- <el-table
  120. ref="multipleTable"
  121. :data="option"
  122. tooltip-effect="dark"
  123. style="width: 100%"
  124. @selection-change="handleSelectionChange">
  125. <el-table-column
  126. type="selection"
  127. width="55">
  128. </el-table-column>
  129. <el-table-column
  130. label="日期"
  131. width="120">
  132. <template slot-scope="scope">{{ scope.row.date }}</template>
  133. </el-table-column>
  134. <el-table-column
  135. prop="name"
  136. label="姓名"
  137. width="120">
  138. </el-table-column>
  139. <el-table-column
  140. prop="address"
  141. label="地址"
  142. show-overflow-tooltip>
  143. </el-table-column>
  144. </el-table>
  145. <div style="margin-top: 20px">
  146. <el-button @click="toggleSelection([option[1], option[2]])">切换第二、第三行的选中状态</el-button>
  147. <el-button @click="toggleSelection()">取消选择</el-button>
  148. </div> -->
  149. </div>
  150. </template>
  151. <script>
  152. import Treeselect from '@riophae/vue-treeselect'
  153. import '@riophae/vue-treeselect/dist/vue-treeselect.css'
  154. import TreeItem from './components/TreeItem'
  155. export default {
  156. components: {
  157. Treeselect,
  158. TreeItem
  159. },
  160. props: [
  161. 'fun',
  162. // 'functionName',
  163. // 'functionInfo'
  164. ],
  165. data() {
  166. name: 'DataPermission'
  167. return {
  168. option: [{
  169. date: '2016-05-03',
  170. name: '王小虎',
  171. address: '上海市普陀区金沙江路 1518 弄'
  172. }, {
  173. date: '2016-05-02',
  174. name: '王小虎',
  175. address: '上海市普陀区金沙江路 1518 弄'
  176. }, {
  177. date: '2016-05-04',
  178. name: '王小虎',
  179. address: '上海市普陀区金沙江路 1518 弄'
  180. }, {
  181. date: '2016-05-01',
  182. name: '王小虎',
  183. address: '上海市普陀区金沙江路 1518 弄'
  184. }, {
  185. date: '2016-05-08',
  186. name: '王小虎',
  187. address: '上海市普陀区金沙江路 1518 弄'
  188. }, {
  189. date: '2016-05-06',
  190. name: '王小虎',
  191. address: '上海市普陀区金沙江路 1518 弄'
  192. }, {
  193. date: '2016-05-07',
  194. name: '王小虎',
  195. address: '上海市普陀区金沙江路 1518 弄'
  196. }],
  197. options:[{label:'你好',value:1},{label:'你好1',value:2},{label:'你好2',value:3}],
  198. visible: false,
  199. loading: false,
  200. btnLoading: false,
  201. total: 0,
  202. tableData: [],
  203. title: '',
  204. show:false,
  205. disabled: false,
  206. lastName: '',
  207. func: this.fun,
  208. // funName: this.functionName,
  209. // funInfo: this.functionInfo,
  210. functionLis: [],
  211. multipleSelection: [],
  212. queryParams: {
  213. name: ''
  214. },
  215. data:[],
  216. ruleForm: {},
  217. roleList:[],
  218. rules: {
  219. name: [{ required: true, message: '请输入部门名称', trigger: 'blur' },],
  220. parentId: [{ required: true, message: '请选择所属部门', trigger: 'change' },],
  221. },
  222. list:[],
  223. times:0
  224. }
  225. },
  226. created(){
  227. },
  228. mounted() {
  229. this.getList()
  230. this.getFunctionList()
  231. // console.log(this.fun)
  232. // this.func=this.fun
  233. // this.funId = 6
  234. // this.$emit('getPremissData', this.funId)
  235. },
  236. computed: {
  237. dictionaries() {
  238. // console.log(this.$store.state.admin.dictionaries)
  239. return this.$store.state.admin.dictionaries
  240. },
  241. userinfo() {
  242. return this.$store.state.admin.userinfo
  243. }
  244. },
  245. watch:{
  246. fun(val){
  247. // console.log(val)
  248. // this.$refs.dataTable.clearSelection()
  249. this.func = val
  250. this.getList()
  251. },
  252. // func(val,oldval){
  253. // if(val!=oldval){
  254. // this.getList()
  255. // }
  256. // }
  257. },
  258. methods: {
  259. // toggleSelection(rows) {
  260. // console.log(rows)
  261. // if (rows) {
  262. // this.$nextTick(()=>{
  263. // rows.forEach(row => {
  264. // console.log(row)
  265. // this.$refs.dataTable.toggleRowSelection(row);
  266. // });
  267. // })
  268. // } else {
  269. // this.$refs.multipleTable.clearSelection();
  270. // }
  271. // },
  272. // handleSelectionChange(val) {
  273. // this.multipleSelection = val;
  274. // },
  275. changeData(selection,row){
  276. if (selection.length > 1) {
  277. const del_row = selection.shift()
  278. this.$refs.dataTable.toggleRowSelection(del_row, false)
  279. // console.log(del_row)
  280. }
  281. this.multipleSelection = selection[0]
  282. this.$emit('getPremissData', this.fun.fun.id, this.fun.fun.name,this.multipleSelection)
  283. // console.log(this.multipleSelection)
  284. },
  285. // getDataList(){
  286. // // var functionList = {
  287. // // functions:this.ruleForm.function
  288. // // }
  289. // this.$api.getDataList({functionId:this.fun.id}).then(response => {
  290. // this.tableData = response.data
  291. // })
  292. // },
  293. addList() {
  294. this.list.push({})
  295. },
  296. deleteList(i) {
  297. this.list.splice(i, 1)
  298. },
  299. ListToTree(){
  300. var a =[]
  301. if(this.list.length==1){
  302. // a[0]={}
  303. // a[0].nodeType='logic'
  304. // a[0].logicOpr = 'and'
  305. // a[0].left=this.list[0]
  306. // a[0].right = {
  307. // field: "1",
  308. // nodeType: "exp",
  309. // opr: "=",
  310. // value: "1"
  311. // }
  312. a[0]=this.list[0]
  313. // a.nodeType='logic'
  314. }else{
  315. a[0]=this.list[0]
  316. a[0].nodeType='exp'
  317. for(var i =1;i<this.list.length;i++){
  318. this.list[i].nodeType='exp'
  319. a[i]={}
  320. a[i].left=a[i-1]
  321. a[i].nodeType='logic'
  322. a[i].right=this.list[i]
  323. a[i].logicOpr = this.list[i].logicOpr
  324. }
  325. }
  326. // console.log(a)
  327. this.ruleForm.rule = JSON.stringify(a[a.length-1])
  328. },
  329. TreeToList(data){
  330. var root = data
  331. var a=[]
  332. const result = [];
  333. function l(root){
  334. const stack = [];
  335. let last = null;
  336. let current = root;
  337. while (current || stack.length > 0) {
  338. while (current) {
  339. stack.push(current);
  340. current = current.left;
  341. }
  342. current = stack[stack.length - 1];
  343. if (!current.right || current.right == last) {
  344. current = stack.pop();
  345. result.push(current);
  346. last = current;
  347. current = null;
  348. } else {
  349. current = current.right;
  350. }
  351. }
  352. // console.log(result)
  353. return result;
  354. }
  355. l(root)
  356. // console.log(result)
  357. var i=0
  358. var c=0
  359. function s(i){
  360. if(i<result.length){
  361. if(i==0){
  362. a.push(result[i])
  363. i+=1
  364. c+=1
  365. }
  366. if(i%2==1){
  367. a.push(result[i])
  368. // console.log(a[c])
  369. a[c]['logicOpr'] = result[i+1].logicOpr
  370. i+=2
  371. c+=1
  372. }
  373. s(i)
  374. }
  375. }
  376. s(i)
  377. // console.log(a)
  378. this.list= a
  379. },
  380. getNode(node){
  381. // console.log(node)
  382. },
  383. normalizer(node) {
  384. return {
  385. id: node.id,
  386. label: node.name,
  387. }
  388. },
  389. handleAdd(id) {
  390. // console.log(id)
  391. this.title = '新增数据权限'
  392. this.visible = true
  393. this.ruleForm={}
  394. this.list=[]
  395. },
  396. handleEdit(row) {
  397. this.title = '编辑数据权限'
  398. this.visible = true
  399. if(JSON.parse(row.rule).hasOwnProperty('left')){
  400. this.TreeToList(JSON.parse(row.rule))
  401. }else{
  402. this.list[0]=JSON.parse(row.rule)
  403. }
  404. this.ruleForm = { ...row }
  405. },
  406. close() {
  407. this.visible = false
  408. },
  409. handleCurrentChange(val) {
  410. this.queryParams.current = val;
  411. this.getList();
  412. },
  413. getList() {
  414. this.times+=1
  415. this.loading = true
  416. this.queryParams.functionId = this.func.fun.id
  417. this.$api.getDataList(this.queryParams).then(response => {
  418. this.tableData = response.data
  419. this.$nextTick(()=>{
  420. if(this.func.permission){
  421. this.$refs.dataTable.toggleRowSelection(this.tableData.find(item=>{
  422. return this.func.permission.id == item.id;
  423. }),true)
  424. }
  425. })
  426. // console.log(response.data)
  427. this.loading = false
  428. }).catch(error => {
  429. this.loading = false
  430. })
  431. },
  432. getFunctionList() {
  433. this.$api.getFunctionList().then(response => {
  434. this.functionList = response.data
  435. })
  436. },
  437. submit() {
  438. this.$refs.ruleForm.validate((valid) => {
  439. if (valid) {
  440. this.ruleForm.functionId=this.fun.fun.id
  441. this.btnLoading = true
  442. this.ListToTree()
  443. if (this.ruleForm.id) {
  444. this.$api.editData(this.ruleForm).then(response => {
  445. this.$message.success('编辑成功')
  446. this.btnLoading = false
  447. this.getList()
  448. this.close()
  449. }).catch(error => {
  450. this.btnLoading = false
  451. })
  452. } else {
  453. this.ruleForm.tenant=this.userinfo.tenantId
  454. this.$api.addData(this.ruleForm).then(response => {
  455. this.$message.success('新增成功')
  456. this.btnLoading = false
  457. this.getList()
  458. this.close()
  459. }).catch(error => {
  460. this.btnLoading = false
  461. })
  462. }
  463. } else {
  464. // console.log('error submit!!');
  465. return false;
  466. }
  467. });
  468. },
  469. handleDelete(row) {
  470. this.$confirm('确认删除本条数据吗?', '提示', {
  471. confirmButtonText: '确定',
  472. cancelButtonText: '取消',
  473. type: 'warning'
  474. }).then(() => {
  475. this.loading = true
  476. this.$refs.dataTable.clearSelection();
  477. delete this.func.permission
  478. this.multipleSelection = {}
  479. this.$emit('getPremissData', this.fun.fun.id, this.fun.fun.name,this.multipleSelection)
  480. this.$api.deleteData({ id: row.id }).then(response => {
  481. this.$message.success('删除成功')
  482. this.loading = false
  483. this.getList()
  484. }).catch(error => {
  485. this.loading = false
  486. })
  487. })
  488. }
  489. }
  490. }
  491. </script>
  492. <style lang="scss">
  493. .el-table__header-wrapper .el-checkbox{
  494. display:none
  495. }
  496. </style>
  497. <style lang="scss" scoped>
  498. .admin-department {
  499. }
  500. .add {
  501. display: flex;
  502. justify-content: right;
  503. margin-bottom: 10px;
  504. }
  505. .listItem {
  506. margin: 10px 0;
  507. }
  508. .normal {
  509. }
  510. .hidden {
  511. opacity: 0;
  512. }
  513. </style>