quanx.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510
  1. <template>
  2. <div>
  3. <!-- 表头 -->
  4. <el-col :span="24" class="toolbar" style="padding-bottom: 0px;">
  5. <el-form :inline="true" style="width: 87%">
  6. <el-form-item :label="$t('roleauthorization')">
  7. </el-form-item>
  8. <el-form-item >
  9. <div>
  10. <el-input style="float:left;" v-model="keyword" class="input-with-select" :placeholder="$t('pleaseenterakeyworforquery')" 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 style="float: right">
  16. <el-link type="primary" :underline="false" @click="handleAdd($t('addingroles'), $t('Immediatelyadd'))">{{ $t('addingroles') }}</el-link>
  17. <el-link type="primary" :underline="false" @click="modify()" style="margin-left: 20px;">{{ $t('modifyingDefaultRole') }}</el-link>
  18. <!-- <el-link type="primary" :underline="false" @click="exportAuthority()" style="margin-left:20px">导出所有权限</el-link> -->
  19. </el-form-item>
  20. </el-form>
  21. </el-col>
  22. <!-- 表格 -->
  23. <el-table :data="tableData" style="width: 100%" height="615">
  24. <el-table-column prop="rolename" :label="$t('jiao-se')" align="center">
  25. <template slot-scope="scope">
  26. {{scope.row.rolename}} <span v-if="scope.row.isDefault == 1" style="color: #909399;"> {{ $t('mo-ren-jiao-se') }}</span>
  27. </template>
  28. </el-table-column>
  29. <el-table-column prop="roleDescribe" :label="$t('other.describe')"></el-table-column>
  30. <el-table-column prop="date" :label="$t('operation')">
  31. <template slot-scope="scope">
  32. <div>
  33. <el-button size="small" @click="handleAdd($t('editingtherole'), $t('Immediatelychange'), scope.row)" :style="scope.row.rolename != $t('role.superAdministrator') ? '' : 'visibility:hidden;'">{{ $t('editingtherole') }}</el-button>
  34. <el-button type="primary" size="small" @click="shisha(scope.row.id), roleName = scope.row.rolename" v-if="scope.row.rolename !=$t('role.superAdministrator') || (scope.row.rolename ==$t('role.superAdministrator') && user.roleName == $t('role.superAdministrator'))">{{ $t('assignpermissions') }}</el-button>
  35. <el-button size="small" @click="exportAuthority(scope.row)" >{{ $t('exportpermission') }}</el-button>
  36. <el-button type="danger" size="small" @click="deteHand(scope.row)" v-if="scope.row.rolename != $t('role.superAdministrator')">{{ $t('btn.delete') }}</el-button>
  37. </div>
  38. </template>
  39. </el-table-column>
  40. </el-table>
  41. <!--工具条-->
  42. <!-- <el-col :span="24" class="toolbar">
  43. <el-pagination
  44. @size-change="handleSizeChange"
  45. @current-change="handleCurrentChange"
  46. :page-sizes="[20 , 50 , 80 , 100]"
  47. :page-size="20"
  48. layout="total, sizes, prev, pager, next"
  49. :total="total"
  50. style="float:right;"
  51. ></el-pagination>
  52. </el-col> -->
  53. <!-- 分配权限弹窗 -->
  54. <el-dialog :title="$t('assignpermissions') +' - '+roleName" :visible.sync="dialogVisible" width="764px" :before-close="handleClose">
  55. <div class="quanxians">
  56. <!-- <el-input placeholder="输入关键字进行过滤" v-model="filterText"></el-input> -->
  57. <!-- <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> -->
  58. <el-form ref="form" :model="form" label-width="0px">
  59. <!-- 分模块展示功能项 -->
  60. <el-form-item>
  61. <ul>
  62. <!-- <li v-for="mainMenu in moduleList" :key="mainMenu.id" style="display: flex;"> -->
  63. <li v-for="mainMenu in moduleList" :key="mainMenu.id">
  64. <!-- <div style="width: 20px; display: inline-block;height: 10px"> -->
  65. <div style="display: inline-block; float: left;width: 20px;height: 10px">
  66. <span v-if="mainMenu.children.length > 0" @click="dianji(mainMenu)" style="cursor:pointer;"><i :class="mainMenu.useState ? 'el-icon-caret-bottom' : 'el-icon-caret-right'"></i></span>
  67. </div>
  68. <span style="display: flex;">
  69. <el-checkbox :label="mainMenu.name" name="type" v-model="mainMenu.checked" style="font-weight:bold;width: 160px" @change="mainChange(mainMenu)"></el-checkbox>
  70. <span v-if="mainMenu.functionList && mainMenu.functionList.length > 0" style="margin-right:10px;margin-left:10px;">
  71. <!-- <div></div>(功能: <el-checkbox v-for="fun in mainMenu.functionList" :key="fun.id" :label="fun.name" name="type" v-model="fun.checked" @change="subChanges(fun, mainMenu.id)"></el-checkbox>) -->
  72. <span class="gongn"><el-checkbox v-for="fun in mainMenu.functionList" :key="fun.id" :label="fun.name" name="type" v-model="fun.checked" style="width: 130px" @change="subChanges(fun, mainMenu.id)"></el-checkbox></span>
  73. </span>
  74. </span>
  75. <ul v-if="mainMenu.children && mainMenu.useState">
  76. <li v-for="subMenu in mainMenu.children" :key="subMenu.id">
  77. <el-checkbox :label="subMenu.name" name="type" v-model="subMenu.checked" style="font-weight:bold;" @change="subChange(subMenu)"></el-checkbox>
  78. <span v-if="subMenu.functionList && subMenu.functionList.length > 0" style="margin-right:10px;margin-left:10px;">({{ $t('gong-neng') }} :
  79. <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>
  80. </li>
  81. </ul>
  82. </li>
  83. </ul>
  84. </el-form-item>
  85. </el-form>
  86. </div>
  87. <span slot="footer" class="dialog-footer">
  88. <el-button type="primary" @click="saveList()">{{ $t('save') }}</el-button>
  89. </span>
  90. </el-dialog>
  91. <!-- 添加角色弹窗 -->
  92. <el-dialog :title="titles" :visible.sync="addDialogVisible" width="600px" :before-close="handleClose">
  93. <div>
  94. <el-form ref="form" :rules="rules" :model="form" label-width="80px">
  95. <el-form-item :label="$t('charactername')" prop="rolename">
  96. <el-input v-model="form.rolename" clearable></el-input>
  97. </el-form-item>
  98. <el-form-item :label="$t('other.describe')">
  99. <el-input type="textarea" v-model="form.roleDescribe" maxlength="25" show-word-limit clearable></el-input>
  100. </el-form-item>
  101. <el-form-item>
  102. <el-button style="float: right" type="primary" @click="onSubmit('form')">{{ $t('btn.determine') }}</el-button>
  103. </el-form-item>
  104. </el-form>
  105. </div>
  106. </el-dialog>
  107. <!-- 修改默认角色弹窗 -->
  108. <el-dialog :title="$t('defaultrole')" :visible.sync="defaultRole" width="400px" :before-close="handleClose">
  109. <div>
  110. <el-form label-width="80px">
  111. <el-form-item :label="$t('defaultrole')">
  112. <el-select v-model="roleId" :placeholder="$t('defaultText.pleaseChoose')">
  113. <el-option v-for="item in auseList" :key="item.id" :label="item.rolename" :value="item.id"></el-option>
  114. </el-select>
  115. </el-form-item>
  116. <div class="daoru"><span type="info" style="color:#999">{{ $t('defaultroleforimportingpeople') }}</span></div>
  117. </el-form>
  118. </div>
  119. <span slot="footer" class="dialog-footer">
  120. <el-button type="primary" @click="determine()">{{ $t('btn.determine') }}</el-button>
  121. </span>
  122. </el-dialog>
  123. </div>
  124. </template>
  125. <script>
  126. export default {
  127. props: {},
  128. components: {},
  129. watch: {
  130. filterText(val) {
  131. this.$refs.tree.filter(val);
  132. }
  133. },
  134. data() {
  135. return {
  136. user: JSON.parse(sessionStorage.getItem("user")),
  137. tableData: [],
  138. total: 0,
  139. dialogVisible: false,
  140. filterText: '',
  141. addDialogVisible: false,
  142. form: {
  143. rolename: '',
  144. roleDescribe: '',
  145. id: ''
  146. },
  147. moduleList: [],
  148. roles: '',
  149. titles: '',
  150. addTil: this.$t('Immediatelyadd'),
  151. keyword: '',
  152. auseList: [],
  153. defaultRole: false,
  154. roleId: '',
  155. roleName: '',
  156. rules: {
  157. rolename: [{
  158. required: true, message: this.$t('peaseenterthe'), trigger: 'blur'
  159. }]
  160. }
  161. };
  162. },
  163. computed: {},
  164. watch: {
  165. filterText(val) {
  166. this.$refs.tree.filter(val);
  167. },
  168. keyword(val) {
  169. if(val == '') {
  170. this.mohu()
  171. }
  172. }
  173. },
  174. created() {},
  175. mounted() {
  176. this.getRole()
  177. // this.shisha()
  178. },
  179. methods: {
  180. // 默认角色点击确定
  181. determine() {
  182. this.http.post('/permission/setDefaultRole', {
  183. companyId: this.user.companyId,
  184. id: this.roleId
  185. },
  186. res => {
  187. if (res.code == "ok") {
  188. this.$message({
  189. message: this.$t('operationissuccessful'),
  190. type: "success"
  191. });
  192. this.defaultRole = false
  193. this.getRole()
  194. } else {
  195. this.$message({
  196. message: res.msg,
  197. type: "error"
  198. });
  199. }
  200. },
  201. error => {
  202. this.$message({
  203. message: error,
  204. type: "error"
  205. });
  206. });
  207. },
  208. // 默认角色
  209. modify() {
  210. for(var i in this.auseList) {
  211. if(this.auseList[i].isDefault == '1') {
  212. this.roleId = this.auseList[i].id
  213. }
  214. }
  215. this.defaultRole = true
  216. },
  217. // 模糊匹配
  218. mohu() {
  219. console.log(this.keyword)
  220. if(this.keyword == '') {
  221. this.tableData = this.auseList
  222. return
  223. }
  224. var len = this.auseList.length;
  225. var arr = []
  226. for(var i = 0; i < len; i++){
  227. if(this.auseList[i].rolename.indexOf(this.keyword)>=0){
  228. arr.push(this.auseList[i]);
  229. }
  230. }
  231. this.tableData = arr
  232. },
  233. // 还不知道是啥
  234. shisha(id) {
  235. this.roles = id
  236. this.http.post('/permission/getAuthority', {
  237. companyId: this.user.companyId,
  238. role: id
  239. },
  240. res => {
  241. if (res.code == "ok") {
  242. console.log(res.data, '数据来源(990)')
  243. this.moduleList = res.data
  244. this.dialogVisible = true
  245. } else {
  246. this.$message({
  247. message: res.msg,
  248. type: "error"
  249. });
  250. }
  251. },
  252. error => {
  253. this.$message({
  254. message: error,
  255. type: "error"
  256. });
  257. });
  258. },
  259. // 获取权限列表
  260. getRole() {
  261. this.http.post('/permission/getRoleList', {
  262. companyId: this.user.companyId
  263. },
  264. res => {
  265. if (res.code == "ok") {
  266. console.log(res.data, '数据来源')
  267. this.tableData = res.data
  268. this.auseList = res.data
  269. } else {
  270. this.$message({
  271. message: res.msg,
  272. type: "error"
  273. });
  274. }
  275. },
  276. error => {
  277. this.$message({
  278. message: error,
  279. type: "error"
  280. });
  281. });
  282. },
  283. handleSizeChange() {},
  284. handleCurrentChange() {},
  285. filterNode(value, data) {
  286. if (!value) return true;
  287. return data.label.indexOf(value) !== -1;
  288. },
  289. handleAdd(tex, tel, id) {
  290. if(id && id.rolename == this.$t('role.superAdministrator')){
  291. this.$message(this.$t('administratorcannotbeedited'));
  292. return
  293. }
  294. this.titles = tex
  295. this.addTil = tel
  296. this.addDialogVisible = true
  297. // var ss = {rolename: '', roleDescribe: '',id: ''}
  298. var ss = {}
  299. id ? ss.id = id.id : ss.id = ''
  300. id ? ss.rolename = id.rolename : ss.rolename = ''
  301. id ? ss.roleDescribe = id.roleDescribe : ss.roleDescribe = ''
  302. this.form = ss
  303. },
  304. // 添加角色
  305. onSubmit(formName) {
  306. // var ss = this.form
  307. this.$refs[formName].validate((valid) => {
  308. if (valid) {
  309. this.http.post('/permission/editRole', {
  310. id: this.form.id,
  311. name: this.form.rolename,
  312. description: this.form.roleDescribe,
  313. companyId: this.user.companyId
  314. },
  315. res => {
  316. if (res.code == "ok") {
  317. console.log(res.data, '数据来源(123)')
  318. this.addDialogVisible = false
  319. this.getRole()
  320. } else {
  321. this.$message({
  322. message: res.msg,
  323. type: "error"
  324. });
  325. }
  326. },
  327. error => {
  328. this.$message({
  329. message: error,
  330. type: "error"
  331. });
  332. });
  333. } else {
  334. console.log('error submit!!');
  335. return false;
  336. }
  337. });
  338. },
  339. deteHand(item) {
  340. this.$confirm(this.$t('operationwilldelete')+'('+item.rolename+')'+this.$t('shifujuxu'), this.$t('other.prompts'), {
  341. confirmButtonText: this.$t('btn.determine'),
  342. cancelButtonText: this.$t('btn.cancel'),
  343. type: 'warning'
  344. }).then(() => {
  345. this.http.post('/permission/deleteRole', {
  346. id: item.id,
  347. },
  348. res => {
  349. if (res.code == "ok") {
  350. this.$message({
  351. message: this.$t('message.successfullyDeleted'),
  352. type: "success"
  353. });
  354. this.getRole()
  355. } else {
  356. this.$message({
  357. message: res.msg,
  358. type: "error"
  359. });
  360. }
  361. },
  362. error => {
  363. this.$message({
  364. message: error,
  365. type: "error"
  366. });
  367. });
  368. }).catch(() => {});
  369. },
  370. mainChange(mainMenu) {
  371. //一级选中,全部选中,一级取消全部取消
  372. console.log(mainMenu);
  373. mainMenu.children.forEach(c=>{
  374. c.checked = mainMenu.checked;
  375. c.functionList.forEach(f=>{
  376. f.checked = mainMenu.checked;
  377. });
  378. });
  379. if(mainMenu.functionList) {
  380. mainMenu.functionList.forEach(c=>{
  381. c.checked = mainMenu.checked;
  382. })
  383. }
  384. },
  385. subChange(subMenu) {
  386. //二级选中,自动勾选对应的一级
  387. console.log(subMenu);
  388. let mainMenuList = this.moduleList;
  389. mainMenuList.forEach(m=>{
  390. //检测子菜单
  391. if (m.id == subMenu.parentId) {
  392. //找到父菜单了
  393. var hasChecked = false;
  394. m.children.forEach(c=>{
  395. if (c.checked) {
  396. hasChecked = true;
  397. }
  398. })
  399. //当前点击的子菜单所有同级菜单是否有点中的,如果没有需要把父级取消勾选
  400. m.checked = hasChecked;
  401. }
  402. });
  403. },
  404. subChanges(subMenu, id) {
  405. let mainMenuList = this.moduleList
  406. mainMenuList.forEach(m=>{
  407. if(m.id == id) {
  408. //找到父菜单了
  409. var hasChecked = false;
  410. m.functionList.forEach(c=>{
  411. if (c.checked) {
  412. hasChecked = true;
  413. }
  414. })
  415. console.log(hasChecked, '事件')
  416. // m.checked = hasChecked;
  417. if(hasChecked) {
  418. console.log('执行')
  419. m.checked = hasChecked;
  420. }
  421. }
  422. });
  423. },
  424. dianji(item) {
  425. console.log(item)
  426. let mainMenuList = this.moduleList
  427. mainMenuList.forEach(m=>{
  428. if(m.id == item.id) {
  429. m.useState = !m.useState
  430. }
  431. });
  432. },
  433. saveList() {
  434. this.dialogVisible = false
  435. console.log(this.moduleList)
  436. this.http.post('/permission/savePermission', {
  437. role: this.roles,
  438. moduleList: JSON.stringify(this.moduleList),
  439. },
  440. res => {
  441. if (res.code == "ok") {
  442. this.$message({
  443. message: this.$t('operationissuccessful'),
  444. type: "success"
  445. });
  446. this.getRole()
  447. } else {
  448. this.$message({
  449. message: res.msg,
  450. type: "error"
  451. });
  452. }
  453. },
  454. error => {
  455. this.$message({
  456. message: error,
  457. type: "error"
  458. });
  459. });
  460. },
  461. exportAuthority(row){ // 导出权限
  462. this.http.post('/permission/exportData',{
  463. role: row.id,
  464. companyId: this.user.companyId
  465. },res => {
  466. if(res.code == 'ok'){
  467. var a = document.createElement('a');
  468. a.download = this.$t('quanxianshuju')+ ".xls";
  469. a.href = res.data;
  470. a.click();
  471. }else{
  472. this.$message({
  473. message: res.msg,
  474. type: 'error'
  475. })
  476. }
  477. },err => {
  478. this.$message({
  479. message: err,
  480. type: 'error'
  481. })
  482. })
  483. }
  484. },
  485. };
  486. </script>
  487. <style scoped>
  488. ul {
  489. padding: 0 0 0 30px;
  490. margin: 0;
  491. }
  492. li {
  493. list-style: none;
  494. }
  495. .quanxians {
  496. height: 400px;
  497. width: 100%;
  498. overflow: auto;
  499. }
  500. .gongn {
  501. display: inline-block;
  502. width: 500px;
  503. }
  504. .daoru {
  505. margin-left: 10px;
  506. }
  507. </style>