quanx.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  1. <template>
  2. <div>
  3. <!-- 表头 -->
  4. <el-col :span="24" class="toolbar" style="padding-bottom: 0px;">
  5. <el-form :inline="true">
  6. <el-form-item label="角色权限">
  7. </el-form-item>
  8. <el-form-item >
  9. <div>
  10. <el-input style="float:left;" v-model="keyword" class="input-with-select" placeholder="请输入关键字查询" clearable="true">
  11. <el-button slot="append" @click="mohu" @clear="mohus" icon="el-icon-search"></el-button>
  12. </el-input>
  13. </div>
  14. </el-form-item>
  15. <el-form-item>
  16. <el-link type="primary" :underline="false" @click="handleAdd('添加角色', '立即添加')">添加角色</el-link>
  17. </el-form-item>
  18. </el-form>
  19. </el-col>
  20. <!-- 表格 -->
  21. <el-table :data="tableData" style="width: 100%" height="615">
  22. <el-table-column prop="rolename" label="角色"></el-table-column>
  23. <el-table-column prop="roleDescribe" label="描述"></el-table-column>
  24. <el-table-column prop="date" label="操作">
  25. <template slot-scope="scope">
  26. <div>
  27. <el-button type="primary" size="small" @click="handleAdd('编辑角色', '立即修改', scope.row)">编辑角色</el-button>
  28. <el-button type="primary" size="small" @click="shisha(scope.row.companyId),dialogVisible = true">分配权限</el-button>
  29. <el-button type="danger" size="small" @click="deteHand(scope.row)">删除</el-button>
  30. </div>
  31. </template>
  32. </el-table-column>
  33. </el-table>
  34. <!--工具条-->
  35. <!-- <el-col :span="24" class="toolbar">
  36. <el-pagination
  37. @size-change="handleSizeChange"
  38. @current-change="handleCurrentChange"
  39. :page-sizes="[20 , 50 , 80 , 100]"
  40. :page-size="20"
  41. layout="total, sizes, prev, pager, next"
  42. :total="total"
  43. style="float:right;"
  44. ></el-pagination>
  45. </el-col> -->
  46. <!-- 分配权限弹窗 -->
  47. <el-dialog title="分配权限" :visible.sync="dialogVisible" width="600" :before-close="handleClose">
  48. <div>
  49. <!-- <el-input placeholder="输入关键字进行过滤" v-model="filterText"></el-input> -->
  50. <!-- <el-tree :data="data" show-checkbox node-key="id" :filter-node-method="filterNode" ref="tree" :default-expanded-keys="[2, 3]" :default-checked-keys="[5]" :props="defaultProps"> </el-tree> -->
  51. <el-form ref="form" :model="form" label-width="80px">
  52. <!-- 分模块展示功能项 -->
  53. <el-form-item>
  54. <ul>
  55. <li v-for="mainMenu in moduleList" :key="mainMenu.id">
  56. <el-checkbox :label="mainMenu.name" name="type" v-model="mainMenu.checked" style="font-weight:bold;" @change="mainChange(mainMenu)"></el-checkbox>
  57. <ul v-if="mainMenu.children">
  58. <li v-for="subMenu in mainMenu.children" :key="subMenu.id">
  59. <el-checkbox :label="subMenu.name" name="type" v-model="subMenu.checked" style="font-weight:bold;" @change="subChange(subMenu)"></el-checkbox>
  60. <span v-if="subMenu.functionList && subMenu.functionList.length > 0" style="margin-right:10px;margin-left:10px;">(功能:
  61. <el-checkbox v-for="fun in subMenu.functionList" :key="fun.id" :label="fun.name" name="type" v-model="fun.checked" @change="funChange(fun)"></el-checkbox>)</span>
  62. </li>
  63. </ul>
  64. </li>
  65. </ul>
  66. </el-form-item>
  67. </el-form>
  68. <el-button type="primary" size="small" @click="saveList()">保存</el-button>
  69. </div>
  70. </el-dialog>
  71. <!-- 添加角色弹窗 -->
  72. <el-dialog :title="titles" :visible.sync="addDialogVisible" width="600" :before-close="handleClose">
  73. <div>
  74. <el-form ref="form" :model="form" label-width="80px">
  75. <el-form-item label="角色名称">
  76. <el-input v-model="form.rolename" clearable></el-input>
  77. </el-form-item>
  78. <el-form-item label="描述">
  79. <el-input type="textarea" v-model="form.roleDescribe" clearable></el-input>
  80. </el-form-item>
  81. <el-form-item>
  82. <el-button type="primary" @click="onSubmit()">{{addTil}}</el-button>
  83. </el-form-item>
  84. </el-form>
  85. </div>
  86. </el-dialog>
  87. </div>
  88. </template>
  89. <script>
  90. export default {
  91. props: {},
  92. components: {},
  93. watch: {
  94. filterText(val) {
  95. this.$refs.tree.filter(val);
  96. }
  97. },
  98. data() {
  99. return {
  100. user: JSON.parse(sessionStorage.getItem("user")),
  101. tableData: [],
  102. total: 0,
  103. dialogVisible: false,
  104. filterText: '',
  105. addDialogVisible: false,
  106. form: {
  107. rolename: '',
  108. roleDescribe: '',
  109. id: ''
  110. },
  111. moduleList: [],
  112. roles: '',
  113. titles: '',
  114. addTil: '立即添加',
  115. keyword: '',
  116. auseList: []
  117. };
  118. },
  119. computed: {},
  120. watch: {
  121. filterText(val) {
  122. this.$refs.tree.filter(val);
  123. },
  124. keyword(val) {
  125. if(val == '') {
  126. this.mohu()
  127. }
  128. }
  129. },
  130. created() {},
  131. mounted() {
  132. this.getRole()
  133. // this.shisha()
  134. },
  135. methods: {
  136. // 模糊匹配
  137. mohu() {
  138. console.log(this.keyword)
  139. if(this.keyword == '') {
  140. this.tableData = this.auseList
  141. return
  142. }
  143. var len = this.auseList.length;
  144. var arr = []
  145. for(var i = 0; i < len; i++){
  146. if(this.auseList[i].rolename.indexOf(this.keyword)>=0){
  147. arr.push(this.auseList[i]);
  148. }
  149. }
  150. this.tableData = arr
  151. },
  152. // 还不知道是啥
  153. shisha(id) {
  154. this.roles = id
  155. this.http.post('/permission/getAuthority', {
  156. companyId: this.user.companyId,
  157. role: id
  158. },
  159. res => {
  160. if (res.code == "ok") {
  161. console.log(res.data, '数据来源(990)')
  162. this.moduleList = res.data
  163. } else {
  164. this.$message({
  165. message: res.msg,
  166. type: "error"
  167. });
  168. }
  169. },
  170. error => {
  171. this.$message({
  172. message: error,
  173. type: "error"
  174. });
  175. });
  176. },
  177. // 获取权限列表
  178. getRole() {
  179. this.http.post('/permission/getRoleList', {
  180. companyId: this.user.companyId
  181. },
  182. res => {
  183. if (res.code == "ok") {
  184. console.log(res.data, '数据来源')
  185. this.tableData = res.data
  186. this.auseList = res.data
  187. } else {
  188. this.$message({
  189. message: res.msg,
  190. type: "error"
  191. });
  192. }
  193. },
  194. error => {
  195. this.$message({
  196. message: error,
  197. type: "error"
  198. });
  199. });
  200. },
  201. handleSizeChange() {},
  202. handleCurrentChange() {},
  203. filterNode(value, data) {
  204. if (!value) return true;
  205. return data.label.indexOf(value) !== -1;
  206. },
  207. handleAdd(tex, tel, id) {
  208. this.titles = tex
  209. this.addTil = tel
  210. this.addDialogVisible = true
  211. // var ss = {rolename: '', roleDescribe: '',id: ''}
  212. var ss = {}
  213. id ? ss.id = id.id : ss.id = ''
  214. id ? ss.rolename = id.rolename : ss.rolename = ''
  215. id ? ss.roleDescribe = id.roleDescribe : ss.roleDescribe = ''
  216. this.form = ss
  217. },
  218. // 添加角色
  219. onSubmit() {
  220. // var ss = this.form
  221. this.http.post('/permission/editRole', {
  222. id: this.form.id,
  223. name: this.form.rolename,
  224. description: this.form.roleDescribe,
  225. companyId: this.user.companyId
  226. },
  227. res => {
  228. if (res.code == "ok") {
  229. console.log(res.data, '数据来源(123)')
  230. this.addDialogVisible = false
  231. this.getRole()
  232. } else {
  233. this.$message({
  234. message: res.msg,
  235. type: "error"
  236. });
  237. }
  238. },
  239. error => {
  240. this.$message({
  241. message: error,
  242. type: "error"
  243. });
  244. });
  245. },
  246. deteHand(item) {
  247. this.$confirm('此操作将删除('+item.rolename+')角色, 是否继续?', '提示', {
  248. confirmButtonText: '确定',
  249. cancelButtonText: '取消',
  250. type: 'warning'
  251. }).then(() => {
  252. this.http.post('/permission/deleteRole', {
  253. id: item.id,
  254. },
  255. res => {
  256. if (res.code == "ok") {
  257. this.$message({
  258. message: '删除成功',
  259. type: "success"
  260. });
  261. this.getRole()
  262. } else {
  263. this.$message({
  264. message: res.msg,
  265. type: "error"
  266. });
  267. }
  268. },
  269. error => {
  270. this.$message({
  271. message: error,
  272. type: "error"
  273. });
  274. });
  275. }).catch(() => {});
  276. },
  277. mainChange(mainMenu) {
  278. //一级选中,全部选中,一级取消全部取消
  279. console.log(mainMenu);
  280. mainMenu.children.forEach(c=>{
  281. c.checked = mainMenu.checked;
  282. c.functionList.forEach(f=>{
  283. f.checked = mainMenu.checked;
  284. });
  285. });
  286. },
  287. subChange(subMenu) {
  288. //二级选中,自动勾选对应的一级
  289. console.log(subMenu);
  290. let mainMenuList = this.moduleList;
  291. mainMenuList.forEach(m=>{
  292. //检测子菜单
  293. if (m.id == subMenu.parentId) {
  294. //找到父菜单了
  295. var hasChecked = false;
  296. m.children.forEach(c=>{
  297. if (c.checked) {
  298. hasChecked = true;
  299. }
  300. })
  301. //当前点击的子菜单所有同级菜单是否有点中的,如果没有需要把父级取消勾选
  302. m.checked = hasChecked;
  303. }
  304. });
  305. //子功能全部勾上,取消
  306. subMenu.functionList.forEach(f=>{
  307. f.checked = subMenu.checked;
  308. })
  309. },
  310. saveList() {
  311. this.dialogVisible = false
  312. console.log(this.moduleList)
  313. this.http.post('/permission/savePermission', {
  314. role: this.roles,
  315. moduleList: JSON.stringify(this.moduleList),
  316. },
  317. res => {
  318. if (res.code == "ok") {
  319. this.$message({
  320. message: '操作成功',
  321. type: "success"
  322. });
  323. this.getRole()
  324. } else {
  325. this.$message({
  326. message: res.msg,
  327. type: "error"
  328. });
  329. }
  330. },
  331. error => {
  332. this.$message({
  333. message: error,
  334. type: "error"
  335. });
  336. });
  337. }
  338. },
  339. };
  340. </script>
  341. <style scoped>
  342. li {
  343. list-style: none;
  344. }
  345. </style>