index.vue 14 KB

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