AuthorityUser.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451
  1. <template>
  2. <div v-loading="loading" element-loading-text="拼命加载中" element-loading-spinner="el-icon-loading">
  3. <div class="job-box">
  4. <div class="job-head">
  5. <div class="job-user">
  6. <el-select @change="Inquirechange()" v-model="value" clearable placeholder="权限模块">
  7. <el-option v-for="item in authority" :key="item.value" :label="item.name" :value="item.id">
  8. </el-option>
  9. </el-select>
  10. <el-select v-model="pageValue" filterable placeholder="页面名称搜索" @change="pageChange">
  11. <el-option v-for="item in pageOptions" :key="item.pageid" :label="item.pageName"
  12. :value="item.pageid">
  13. </el-option>
  14. </el-select>
  15. </div>
  16. <div class="job-input">
  17. <el-select @change="companyChange()" v-model="valuecorporation" clearable placeholder="公司">
  18. <el-option v-for="item in corporation" :key="item.value" :label="item.companyName" :value="item.id">
  19. </el-option>
  20. </el-select>
  21. <el-select @change="depaChange()" v-model="valuedepartmental" clearable placeholder="部门">
  22. <el-option v-for="item in departmental" :key="item.id" :label="item.depName" :value="item.id">
  23. </el-option>
  24. </el-select>
  25. <el-select @change="JobChange()" v-model="valueposition" clearable placeholder="职位">
  26. <el-option v-for="item in position" :key="item.id" :label="item.jobName" :value="item.id">
  27. </el-option>
  28. </el-select>
  29. <el-select @change="UserChange()" v-model="Valueuesr" clearable placeholder="员工">
  30. <el-option v-for="item in Users" :key="item.id" :label="item.cnName" :value="item.id">
  31. </el-option>
  32. </el-select>
  33. <el-button type="primary" @click="saveAuth()">保 存</el-button>
  34. </div>
  35. </div>
  36. <div class="job-table">
  37. <el-table :data="authorityLists.slice((currentPage - 1) * pageSize, currentPage * pageSize)" border
  38. @select="handleSelect" @select-all="allchange" style="width: 100%">
  39. <el-table-column type="selection" width="55">
  40. </el-table-column>
  41. <el-table-column prop="name" label="权限页面" width="180">
  42. </el-table-column>
  43. <el-table-column width="55" :label="op.functionName" :key="op.id" v-for="op in opList">
  44. <template slot-scope="scope">
  45. <div>
  46. <el-checkbox @change='checkchange(scope.row.id, op.id)'
  47. v-if="scope.row.opList.indexOf(op.id) != -1"
  48. :value="scope.row.selList.indexOf(op.id) != -1">
  49. </el-checkbox>
  50. <el-checkbox v-else :disabled="true" :value="false">
  51. </el-checkbox>
  52. </div>
  53. </template>
  54. </el-table-column>
  55. <el-table-column prop="address" label="备注">
  56. </el-table-column>
  57. </el-table>
  58. <div class="block">
  59. <el-pagination align='center' @size-change="handleSizeChange" @current-change="handleCurrentChange"
  60. :current-page="currentPage" :page-sizes="[14, 20]" :page-size="pageSize"
  61. layout="total, sizes, prev, pager, next" :total="authorityList.length">
  62. </el-pagination>
  63. </div>
  64. </div>
  65. </div>
  66. </div>
  67. </template>
  68. <script>
  69. export default {
  70. data() {
  71. return {
  72. authority: [],
  73. value: '', //模块下拉框数据
  74. corporation: [],
  75. valuecorporation: '',//公司val
  76. departmental: [], //部门数据
  77. valuedepartmental: '', //部门val
  78. position: [], //职位数据
  79. valueposition: '',//职位val
  80. authorityLists: [],
  81. authorityList: [],
  82. currentPage: 1, // 当前页码
  83. pageSize: 14,// 每页的数据条数
  84. stateArr: [],
  85. selectedAccount: [],
  86. PathUrl: '',
  87. opList: [],//操作方式
  88. loading: true,
  89. Users: [],
  90. Valueuesr: '',//员工val
  91. userId: 0,
  92. token: '',
  93. pageOptions: [],
  94. pageValue: ''
  95. }
  96. },
  97. methods: {
  98. //每页条数改变时触发 选择一页显示多少行
  99. handleSizeChange(val) {
  100. this.currentPage = 1;
  101. this.pageSize = val;
  102. },
  103. //当前页改变时触发 跳转其他页
  104. handleCurrentChange(val) {
  105. this.currentPage = val;
  106. },
  107. //模块下拉框
  108. Inquirechange() {
  109. this.currentPage = 1;
  110. this.pageValue = '';
  111. this.pageload(this.value);
  112. },
  113. //多选框选中方法
  114. handleSelect(selection, row) {
  115. console.log(selection, row)
  116. if (selection.length > 0) {
  117. row.selList = this.opList.map(x => x.id);
  118. } else {
  119. row.selList = [];
  120. }
  121. },
  122. selectRadiocheck(index, row) {
  123. console.log(index)
  124. console.log(row)
  125. },
  126. selectRadioerase(index, row) {
  127. console.log(index, row)
  128. },
  129. selectRadioedit(index, row) {
  130. console.log(index, row)
  131. },
  132. selectRadiodown(index, row) {
  133. console.log(index, row)
  134. },
  135. selectRadioup(index, row) {
  136. console.log(index, row)
  137. },
  138. pageload(moduleId) {
  139. var that = this;
  140. //初始化界面数据
  141. this.$axios.post(this.PathUrl + '/api/System/GetAuth', {
  142. "pageSize": this.pageSize,
  143. "currentPage": this.currentPage,
  144. "moduleId": moduleId,
  145. }, {
  146. headers: {
  147. 'Authorization': that.token,
  148. }
  149. }).then(resp => {
  150. if (resp.data.code == 200) {
  151. that.authority = resp.data.data.setDataResult; //模块数据
  152. that.corporation = resp.data.data.companyDataResult; //公司数据
  153. that.authorityList = resp.data.data.systemMenuPermissionData; //页面数据(默认权限页面)
  154. that.authorityLists = that.authorityList;
  155. that.opList = resp.data.data.pageOperation; //操作方式
  156. that.loading = false;
  157. }
  158. }).then(suc => {
  159. if (this.Valueuesr != '') {
  160. //链式调用加载
  161. this.UserChange();
  162. }
  163. })
  164. },
  165. //公司下拉框
  166. companyChange() {
  167. this.valuedepartmental = ''; //清空数据
  168. this.valueposition = '';
  169. this.position = [];
  170. this.departmental = [];
  171. this.Valueuesr = ''; //清空数据
  172. this.Users = [];
  173. if (this.valuecorporation == '') {
  174. return;
  175. }
  176. var that = this;
  177. //初始化界面数据
  178. this.$axios.post(this.PathUrl + '/api/System/QueryDepartmentList', {
  179. "CompanyId": this.valuecorporation,
  180. "PortType": 1,
  181. }, {
  182. headers: {
  183. 'Authorization': that.token,
  184. }
  185. }).then(resp => {
  186. console.log(resp);
  187. if (resp.data.code == 200) {
  188. that.departmental = resp.data.data;
  189. }
  190. })
  191. },
  192. //部门下拉框
  193. depaChange() {
  194. this.position = []; //职位数据
  195. this.valueposition = '';//职位val
  196. this.Valueuesr = ''; //清空数据
  197. this.Users = [];
  198. if (this.valuecorporation == '' || this.valuedepartmental == '') {
  199. return;
  200. }
  201. var that = this;
  202. //初始化界面数据
  203. this.$axios.post(this.PathUrl + '/api/System/QueryJobPost', {
  204. "CompanyId": this.valuecorporation,
  205. "DepId": this.valuedepartmental,
  206. "PortType": 1,
  207. }, {
  208. headers: {
  209. 'Authorization': that.token,
  210. }
  211. }).then(resp => {
  212. console.log(resp);
  213. if (resp.data.code == 200) {
  214. that.position = resp.data.data;
  215. }
  216. })
  217. },
  218. //保存权限
  219. saveAuth() {
  220. var that = this;
  221. if (this.Valueuesr == '') {
  222. this.$message.error('请选择员工!');
  223. return;
  224. }
  225. var savejob = [];
  226. this.authorityLists.forEach(item => {
  227. savejob.push({
  228. SmId: item.id,
  229. FIds: this.unique(item.selList),
  230. });
  231. })
  232. console.log(savejob);
  233. //保存数据
  234. this.$axios.post(this.PathUrl + '/api/System/SaveUserAuth', {
  235. "uid": this.Valueuesr,
  236. "Savejobs": savejob,
  237. "Modulid": this.value == '' ? '13' : this.value,
  238. }, {
  239. headers: {
  240. 'Authorization': that.token,
  241. }
  242. }).then(resp => {
  243. console.log(resp);
  244. if (resp.data.code == 200) {
  245. this.$message({
  246. message: '保存成功!',
  247. type: 'success'
  248. });
  249. } else {
  250. this.$message.error('保存失败!' + resp.data.msg);
  251. }
  252. })
  253. },
  254. //职位下拉获取权限
  255. JobChange() {
  256. this.Valueuesr = ''; //清空数据
  257. this.Users = [];
  258. if (this.valuecorporation == '' || this.valuedepartmental == '' || this.valueposition == '') {
  259. return;
  260. }
  261. var that = this;
  262. //获取员工信息
  263. this.$axios.post(this.PathUrl + '/api/System/QueryUserList', {
  264. "CompanyId": this.valuecorporation,
  265. "DepId": this.valuedepartmental,
  266. "JobPostId": this.valueposition,
  267. "PortType": 1
  268. }, {
  269. headers: {
  270. 'Authorization': that.token,
  271. }
  272. }).then(resp => {
  273. console.log(resp);
  274. if (resp.data.code == 200) {
  275. that.Users = resp.data.data;
  276. }
  277. })
  278. },
  279. //全选
  280. allchange(selection) {
  281. let that = this;
  282. if (selection.length > 0) {
  283. selection.forEach(item => {
  284. item.selList = that.opList.map(x => x.id);
  285. });
  286. } else {
  287. this.authorityLists.forEach(item => {
  288. item.selList = [];
  289. });
  290. }
  291. },
  292. checkchange(rowid, linid) {
  293. this.authorityLists.forEach(item => {
  294. if (item.id == rowid) {
  295. if (item.selList.indexOf(linid) == -1) {
  296. item.selList.push(linid);
  297. } else {
  298. item.selList.splice(item.selList.indexOf(linid), 1)
  299. }
  300. }
  301. });
  302. console.warn(this.authorityLists);
  303. },
  304. //员工下拉框
  305. UserChange() {
  306. console.log(this.Valueuesr);
  307. var moduleId = this.value == "" ? 13 : this.value;
  308. if (this.Valueuesr == '') {
  309. var arr = this.authorityList;
  310. arr.forEach(item => {
  311. item.selList = [];
  312. })
  313. this.authorityList = arr;
  314. this.authorityLists = this.authorityList;
  315. return;
  316. }
  317. var that = this;
  318. //获取员工信息
  319. this.$axios.post(this.PathUrl + '/api/System/QueryUserAuth', {
  320. "Userid": this.Valueuesr,
  321. "moduleId": moduleId
  322. }, {
  323. headers: {
  324. 'Authorization': that.token,
  325. }
  326. }).then(resp => {
  327. console.log(resp);
  328. if (resp.data.code == 200) {
  329. that.authorityList = resp.data.data; //页面数据(默认权限页面)
  330. that.authorityLists = that.authorityList;
  331. }
  332. })
  333. },
  334. unique(arr) {
  335. return Array.from(new Set(arr));
  336. },
  337. pageChange() {
  338. console.log(this.pageValue);
  339. var that = this;
  340. let ischange = false;
  341. this.pageOptions.forEach(function (item, index) {
  342. if (item.pageid == that.pageValue) {
  343. ischange = true;
  344. that.value = item.modulid;
  345. }
  346. })
  347. if (ischange) {
  348. this.Inquirechange();
  349. } else {
  350. console.log("搜索异常!!");
  351. }
  352. },
  353. loadPages() {
  354. var that = this;
  355. this.$axios.post('/api/System/PageConfigInit', {
  356. }, {
  357. headers: {
  358. 'Authorization': that.token,
  359. }
  360. }).then(resp => {
  361. console.log(resp.data.data);
  362. if (resp.data.code == 200) {
  363. that.pageOptions = resp.data.data.viewList.data;
  364. }
  365. })
  366. }
  367. },
  368. mounted() {
  369. this.token = JSON.parse(localStorage.getItem('userinif')).token;
  370. this.userId = JSON.parse(localStorage.getItem('userinif')).userInfo.userId
  371. this.pageload(13);
  372. this.loadPages();
  373. }
  374. }
  375. </script>
  376. <style>
  377. body {
  378. margin: 0;
  379. padding: 0;
  380. }
  381. .job-head {
  382. display: flex;
  383. justify-content: space-between;
  384. }
  385. .job-box {
  386. background-color: #fff;
  387. padding: 10px;
  388. border-radius: 10px;
  389. }
  390. .job-table {
  391. margin-top: 10px;
  392. }
  393. .job-table .block {
  394. margin-top: 10px;
  395. }
  396. .job-table .el-table--enable-row-transition .el-table__body td.el-table__cell {
  397. text-align: center;
  398. }
  399. .job-table .el-table--border .el-table__cell:first-child .cell {
  400. text-align: center;
  401. }
  402. .job-input {
  403. display: flex;
  404. }
  405. .job-input .el-select {
  406. margin-right: 5px;
  407. }
  408. .job-user .el-select {
  409. width: 250px;
  410. }
  411. </style>