index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415
  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="" size="small" @click="getList">查询</el-button>
  9. <el-button type="primary" size="small" @click="handleAdd(0)">新增</el-button>
  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. border
  18. @select="changeData"
  19. header-row-class-name="custom-table-header"
  20. >
  21. <el-table-column type="selection" width="60" align="center"></el-table-column>
  22. <el-table-column prop="name" label="数据权限名称" align="" show-overflow-tooltip></el-table-column>
  23. <el-table-column prop="tenant" label="条件" align="center" show-overflow-tooltip></el-table-column>
  24. <el-table-column prop="remark" label="备注" align="center" show-overflow-tooltip></el-table-column>
  25. <el-table-column label="操作" align="center" width="150">
  26. <template slot-scope="scope">
  27. <el-dropdown split-button type="primary" size="small" @click="handleEdit(scope.row)">
  28. 编辑
  29. <el-dropdown-menu slot="dropdown" class="text-align_center">
  30. <el-dropdown-item class="color-red" @click.native="handleDelete(scope.row)" divided>删除</el-dropdown-item>
  31. </el-dropdown-menu>
  32. </el-dropdown>
  33. </template>
  34. </el-table-column>
  35. </el-table>
  36. <el-dialog :title="title" :visible.sync="visible" width="800px" :before-close="close" :append-to-body="true">
  37. <el-form v-if="visible" :model="ruleForm" :rules="rules" ref="ruleForm" label-width="80px" label-position="left">
  38. <el-form-item label="所属功能" prop="function">
  39. <el-input v-model="ruleForm.function" size="small" :readonly="true" placeholder="请输入所属功能"></el-input>
  40. </el-form-item>
  41. <el-form-item label="数据权限名称" prop="function">
  42. <el-input v-model="ruleForm.name" size="small" placeholder="请输入数据权限名称"></el-input>
  43. </el-form-item>
  44. <el-form-item label="数据权限">
  45. <template>
  46. <div class="add"><el-button type="primary" @click="addList()">添加</el-button> </div>
  47. <div style="border:1px solid #C0C0C0;border-radius:4px;overflow:auto;min-height:200px;padding: 10px 20px">
  48. <el-row :gutter="24" v-for="(item,i) in list" :key="i" class="listItem">
  49. <el-col :span="4" style="padding:0">
  50. <span>
  51. <span v-if="i==0" style="opacity: 0;"> 内容 </span>
  52. <el-select v-else v-model="item.logicOpr">
  53. <el-option
  54. v-for="item in dictionaries.LOGIC_OPERATOR"
  55. :key="item.dictChildValue"
  56. :label="item.dictChildLabel"
  57. :value="item.dictChildValue">
  58. </el-option>
  59. </el-select>
  60. </span>
  61. </el-col>
  62. <el-col :span="7">
  63. <el-select v-model="item.field">
  64. <el-option
  65. v-for="item in dictionaries.dataDict"
  66. :key="item.dataSourceField"
  67. :label="item.dataSourceName"
  68. :value="item.dataSourceField">
  69. </el-option>
  70. </el-select>
  71. </el-col>
  72. <el-col :span="3" style="padding:0">
  73. <el-select v-model="item.opr">
  74. <el-option
  75. v-for="item in dictionaries.OPERATOR"
  76. :key="item.dictChildValue"
  77. :label="item.dictChildLabel"
  78. :value="item.dictChildValue">
  79. </el-option>
  80. </el-select>
  81. </el-col>
  82. <el-col :span="7">
  83. <el-select v-model="item.value"
  84. filterable
  85. allow-create
  86. default-first-option
  87. placeholder="请选择">
  88. <el-option
  89. :value="userinfo.tenantName"
  90. >
  91. <el-tooltip class="item" effect="dark" :content="userinfo.tenantName" placement="top">
  92. <span style="float: left;width:100px;white-space:nowrap;overflow:hidden;text-overflow: ellipsis;">{{userinfo.tenantName}}</span>
  93. </el-tooltip>
  94. <span style="float: right; color: #8492a6; font-size: 13px;margin-left:30px">租户</span>
  95. </el-option>
  96. </el-select>
  97. </el-col>
  98. <el-col :span="3">
  99. <el-button @click="deleteList(i)"><i class="el-icon-delete"></i> </el-button>
  100. </el-col>
  101. </el-row>
  102. </div>
  103. </template>
  104. </el-form-item>
  105. <el-form-item label="备注" prop="remark">
  106. <el-input v-model="ruleForm.remark" placeholder="请输入备注" type="textarea" maxlength="100" show-word-limit></el-input>
  107. </el-form-item>
  108. </el-form>
  109. <div slot="footer" class="dialog-footer">
  110. <el-button @click="close">取 消</el-button>
  111. <el-button type="primary" @click="submit" :loading="btnLoading">确 定</el-button>
  112. </div>
  113. </el-dialog>
  114. </div>
  115. </template>
  116. <script>
  117. import Treeselect from '@riophae/vue-treeselect'
  118. import '@riophae/vue-treeselect/dist/vue-treeselect.css'
  119. import TreeItem from './components/TreeItem'
  120. export default {
  121. components: {
  122. Treeselect,
  123. TreeItem
  124. },
  125. data() {
  126. name: 'DataPermission'
  127. props: {
  128. }
  129. return {
  130. options:[{label:'你好',value:1},{label:'你好1',value:2},{label:'你好2',value:3}],
  131. visible: false,
  132. loading: false,
  133. btnLoading: false,
  134. total: 0,
  135. tableData: [],
  136. title: '',
  137. show:false,
  138. disabled:false,
  139. lastName:'',
  140. functionLis: [],
  141. multipleSelection: [],
  142. queryParams: {
  143. size: 10,
  144. current: 1,
  145. name: ''
  146. },
  147. data:[],
  148. ruleForm: {},
  149. roleList:[],
  150. rules: {
  151. name: [{ required: true, message: '请输入部门名称', trigger: 'blur' },],
  152. parentId: [{ required: true, message: '请选择所属部门', trigger: 'change' },],
  153. },
  154. list:[],
  155. dataList:
  156. {
  157. "nodeType": "logic",
  158. "logicOpr": "or",
  159. "left":{
  160. "nodeType": "logic",
  161. "logicOpr": "and",
  162. "left": {
  163. "nodeType": "exp",
  164. "field": "POSITION_DESCRIPTION",
  165. "opr": "=",
  166. "value": "'总经理1'"
  167. },
  168. "right": {
  169. "nodeType": "exp",
  170. "field": "POSITION_DESCRIPTION",
  171. "opr": "=",
  172. "value": "'总经理2'"
  173. }
  174. },
  175. "right": {
  176. "nodeType": "exp",
  177. "field": "POSITION_DESCRIPTION",
  178. "opr": "=",
  179. "value": "'总经理3'"
  180. }
  181. }
  182. }
  183. },
  184. created(){
  185. },
  186. mounted() {
  187. this.getList()
  188. this.getFunctionList()
  189. // this.ListToTree()
  190. },
  191. computed: {
  192. dictionaries() {
  193. console.log(this.$store.state.admin.dictionaries)
  194. return this.$store.state.admin.dictionaries
  195. },
  196. userinfo() {
  197. return this.$store.state.admin.userinfo
  198. }
  199. },
  200. methods: {
  201. changeData(selection,row){
  202. if (selection.length > 1) {
  203. const del_row = selection.shift()
  204. this.$refs.dataTable.toggleRowSelection(del_row, false)
  205. }
  206. // this.checkList = selection[0]
  207. },
  208. addList() {
  209. this.list.push({})
  210. },
  211. deleteList(i) {
  212. this.list.splice(i, 1)
  213. },
  214. ListToTree(){
  215. console.log(this.dataList)
  216. var a =[]
  217. if(this.list.length==1){
  218. a = this.list[0]
  219. a.nodeType='logic'
  220. }else{
  221. a[0]=this.list[0]
  222. a[0].nodeType='exp'
  223. for(var i =1;i<this.list.length;i++){
  224. this.list[i].nodeType='exp'
  225. a[i]={}
  226. a[i].left=a[i-1]
  227. a[i].nodeType='logic'
  228. a[i].right=this.list[i]
  229. a[i].logicOpr = this.list[i].logicOpr
  230. // delete a[i].right.logicOpr
  231. // delete a[i].left.logicOpr
  232. }
  233. }
  234. console.log(a)
  235. this.ruleForm.rule = JSON.stringify(a[a.length-1])
  236. // this.TreeToList(a[a.length-1])
  237. },
  238. TreeToList(data){
  239. var root = data
  240. var a=[]
  241. const result = [];
  242. function l(root){
  243. const stack = [];
  244. let last = null;
  245. let current = root;
  246. while (current || stack.length > 0) {
  247. while (current) {
  248. stack.push(current);
  249. current = current.left;
  250. }
  251. current = stack[stack.length - 1];
  252. if (!current.right || current.right == last) {
  253. current = stack.pop();
  254. result.push(current);
  255. last = current;
  256. current = null;
  257. } else {
  258. current = current.right;
  259. }
  260. }
  261. // console.log(result)
  262. return result;
  263. }
  264. l(root)
  265. // console.log(result)
  266. var i=0
  267. var c=0
  268. function s(i){
  269. if(i<result.length){
  270. if(i==0){
  271. a.push(result[i])
  272. i+=1
  273. c+=1
  274. }
  275. if(i%2==1){
  276. a.push(result[i])
  277. // console.log(a[c])
  278. a[c]['logicOpr'] = result[i+1].logicOpr
  279. i+=2
  280. c+=1
  281. }
  282. s(i)
  283. }
  284. }
  285. s(i)
  286. console.log(a)
  287. this.list= a
  288. },
  289. getNode(node){
  290. console.log(node)
  291. },
  292. normalizer(node) {
  293. return {
  294. id: node.id,
  295. label: node.name,
  296. }
  297. },
  298. handleAdd(updepartmentId,row) {
  299. // console.log(row)
  300. this.title = '新增数据权限'
  301. this.visible = true
  302. this.ruleForm={}
  303. },
  304. handleEdit(row) {
  305. this.title = '编辑数据权限'
  306. this.visible = true
  307. this.TreeToList(JSON.parse(row.rule))
  308. this.ruleForm = { ...row }
  309. },
  310. close() {
  311. this.visible = false
  312. },
  313. handleCurrentChange(val) {
  314. this.queryParams.current = val;
  315. this.getList();
  316. },
  317. getList() {
  318. this.loading = true
  319. this.$api.getDataList(this.queryParams).then(response => {
  320. this.tableData = response.data
  321. this.total=response.pageColumn.total
  322. this.loading = false
  323. }).catch(error => {
  324. this.loading = false
  325. })
  326. },
  327. getFunctionList() {
  328. this.$api.getFunctionList().then(response => {
  329. this.functionList = response.data
  330. })
  331. },
  332. submit() {
  333. this.$refs.ruleForm.validate((valid) => {
  334. if (valid) {
  335. this.btnLoading = true
  336. this.ListToTree()
  337. if (this.ruleForm.id) {
  338. this.$api.editData(this.ruleForm).then(response => {
  339. this.$message.success('编辑成功')
  340. this.btnLoading = false
  341. this.getList()
  342. this.close()
  343. }).catch(error => {
  344. this.btnLoading = false
  345. })
  346. } else {
  347. this.ruleForm.tenant=this.userinfo.tenantId
  348. console.log(this.ruleForm)
  349. this.$api.addData(this.ruleForm).then(response => {
  350. this.$message.success('新增成功')
  351. this.btnLoading = false
  352. this.getList()
  353. this.close()
  354. }).catch(error => {
  355. this.btnLoading = false
  356. })
  357. }
  358. } else {
  359. console.log('error submit!!');
  360. return false;
  361. }
  362. });
  363. },
  364. handleDelete(row) {
  365. this.$confirm('确认删除本条数据吗?', '提示', {
  366. confirmButtonText: '确定',
  367. cancelButtonText: '取消',
  368. type: 'warning'
  369. }).then(() => {
  370. this.loading = true
  371. this.$api.deleteData({ id: row.id }).then(response => {
  372. this.$message.success('删除成功')
  373. this.loading = false
  374. this.getList()
  375. }).catch(error => {
  376. this.loading = false
  377. })
  378. })
  379. }
  380. }
  381. }
  382. </script>
  383. <style lang="scss" scoped>
  384. .admin-department {
  385. }
  386. .add {
  387. display: flex;
  388. justify-content: right;
  389. margin-bottom: 10px;
  390. }
  391. .listItem {
  392. margin: 10px 0;
  393. }
  394. .normal {
  395. }
  396. .hidden {
  397. opacity: 0;
  398. }
  399. </style>