index.vue 12 KB

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