AuthorityUser.vue 15 KB

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