index.vue 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  1. <template>
  2. <div class="bf-rolelist">
  3. <!-- 角色列表 -->
  4. <div class="cont">
  5. <div v-if="title" class="paren_header">
  6. <p>{{ title }}</p>
  7. </div>
  8. <template v-if="dataList.length">
  9. <div :class="active ? 'bgActive' : 'bgActivecheckbox'" class="paren_content">
  10. <template v-if="!type">
  11. <el-scrollbar class="scrollBar" style="height: 100%">
  12. <el-row v-infinite-scroll="load" :infinite-scroll-distance="20" infinite-scroll-disabled="disabled" class="scCont scrollbar" :gutter="16">
  13. <el-checkbox-group @change="checkChange" v-model="checkList">
  14. <el-col :span="number" v-for="(item, index) in dataList" :key="index">
  15. <div @click="handleBg(item, index)" :class="active && msg === index ? 'bgColor' : ''" class="cide">
  16. <div class="cide_header">
  17. <p :title="item.name">{{ item.name }}</p>
  18. <el-checkbox :label="index"></el-checkbox>
  19. </div>
  20. </div>
  21. </el-col>
  22. </el-checkbox-group>
  23. </el-row>
  24. </el-scrollbar>
  25. </template>
  26. <template v-if="total > 1">
  27. <p class="center" v-if="loading">加载中...</p>
  28. <p class="center" v-if="noMore">没有更多数据了~</p>
  29. </template>
  30. </div>
  31. </template>
  32. <template v-else-if="mainData.length">
  33. <div :class="active ? 'bgActive' : 'bgActivecheckbox'" class="paren_content">
  34. <template v-if="type">
  35. <el-scrollbar class="scrollBar" style="height: 100%">
  36. <el-row :gutter="16">
  37. <el-radio-group style="display: block" @change="radioChange" v-model="radio">
  38. <el-col :span="number" v-for="(item, index) in mainData" :key="index">
  39. <div @click.stop="handleBg(index)" :class="active && msg === index ? 'bgColor' : ''" class="cide">
  40. <div class="cide_header">
  41. <p>{{ item.name }}</p>
  42. <el-radio :label="index"></el-radio>
  43. </div>
  44. </div>
  45. </el-col>
  46. </el-radio-group>
  47. </el-row>
  48. </el-scrollbar>
  49. </template>
  50. </div>
  51. </template>
  52. <template v-else>
  53. <el-empty :imageSize="imageSize" description="暂无数据"></el-empty>
  54. </template>
  55. </div>
  56. </div>
  57. </template>
  58. <script>
  59. import { GetAccountList } from "@/api/Account";
  60. import { GetRoleByGroup } from "@/api/AccountGroup";
  61. import { QueryRole } from '@/api/apiAuthority';
  62. export default {
  63. props: {
  64. title: {
  65. type: String,
  66. default: "",
  67. },
  68. type: {
  69. type: Boolean,
  70. default: false,
  71. },
  72. number: {
  73. type: Number,
  74. default: 3,
  75. },
  76. active: {
  77. type: Boolean,
  78. default: false,
  79. },
  80. checkBoxList: {
  81. type: Array,
  82. default: () => [],
  83. },
  84. mainData: {
  85. type: Array,
  86. default: () => [],
  87. },
  88. radioCheck: {
  89. type: Number,
  90. default: 0,
  91. },
  92. imageSize: {
  93. type: Number,
  94. default: 200,
  95. },
  96. roleType: {
  97. type: String,
  98. default: "",
  99. },
  100. GroupIds: {
  101. type: Array,
  102. default: () => [],
  103. },
  104. },
  105. data () {
  106. return {
  107. radio: null,
  108. checkList: [],
  109. dataList: [],
  110. arrsList: [],
  111. msg: null,
  112. pageSize: 100,
  113. pageNum: 1,
  114. total: "",
  115. loading: false,
  116. asyncData: []
  117. };
  118. },
  119. watch: {
  120. radioCheck: {
  121. handler (num) {
  122. this.radio = num;
  123. },
  124. deep: true,
  125. },
  126. roleType: {
  127. handler (msg) {
  128. if (msg == 'account') {
  129. this.getRoleData('UserId', 'UserName');
  130. }
  131. if (msg == "roleByUpId") {
  132. this.getRoleDataByUpId("roleId");
  133. }
  134. if (msg == "onlyRole") {
  135. this.getRoleData('RoleId', 'RoleName');
  136. }
  137. },
  138. deep: true,
  139. },
  140. dataList: {
  141. handler (arr) {
  142. if (arr && arr.length) {
  143. this.asyncData.push(true);
  144. }
  145. },
  146. deep: true,
  147. },
  148. checkBoxList: {
  149. handler (arr) {
  150. if (arr && arr.length) {
  151. this.asyncData.push(true);
  152. }
  153. // if (this.roleType == "roleByUpId") {
  154. // const datas = [];
  155. // this.dataList.forEach((item, index) => {
  156. // arr.forEach((p) => {
  157. // if (item.RoleId == p.RoleId) {
  158. // datas.push(index);
  159. // }
  160. // });
  161. // });
  162. // this.checkList = datas;
  163. // }
  164. },
  165. deep: true,
  166. },
  167. asyncData: {
  168. handler (arr) {
  169. if (arr && arr.length == 2) {
  170. if (this.roleType == "account") {
  171. this.checkBoxs("UserId");
  172. }
  173. if (this.roleType == "onlyRole" || this.roleType == 'roleByUpId') {
  174. this.checkBoxs("RoleId");
  175. }
  176. }
  177. },
  178. deep: true
  179. },
  180. GroupIds: {
  181. handler () {
  182. this.getRoleDataByUpId();
  183. },
  184. deep: true
  185. }
  186. },
  187. computed: {
  188. noMore () {
  189. return this.pageNum >= this.total;
  190. },
  191. disabled () {
  192. return this.loading || this.noMore;
  193. },
  194. },
  195. methods: {
  196. // 选中
  197. handleBg (item, i) {
  198. this.msg = i;
  199. this.$emit("checkClick", item);
  200. },
  201. //多选框
  202. checkChange (arr) {
  203. const datas = this.formatChecks(arr);
  204. // if (this.roleType == 'account') {
  205. // datas = this.formatChecks(arr, 'UserId');
  206. // }
  207. this.$emit("checkChange", datas);
  208. },
  209. //单选框
  210. radioChange (val) {
  211. this.$emit("radioChange", val);
  212. },
  213. //格式化选中回调
  214. formatChecks (arr, key) {
  215. const datas = [];
  216. // const ids = []
  217. this.dataList.forEach((item, index) => {
  218. arr.forEach((p) => {
  219. if (index == p) {
  220. datas.push(item);
  221. }
  222. });
  223. });
  224. // datas.forEach(item => {
  225. // ids.push(item[key])
  226. // })
  227. return datas;
  228. },
  229. //多选框默认选中
  230. checkBoxs (ids) {
  231. const datas = [];
  232. const type = typeof this.checkBoxList[0];
  233. if (type == 'object') {
  234. this.dataList.forEach((item, index) => {
  235. this.checkBoxList.forEach((p) => {
  236. if (item[ids] == p[ids]) {
  237. datas.push(index);
  238. }
  239. });
  240. });
  241. } else {
  242. this.dataList.forEach((item, index) => {
  243. this.checkBoxList.forEach((p) => {
  244. if (item[ids] == p) {
  245. datas.push(index);
  246. }
  247. });
  248. });
  249. }
  250. this.checkList = datas;
  251. },
  252. checkRole () {
  253. const datas = [];
  254. this.dataList.forEach((item, index) => {
  255. this.checkBoxList.forEach((p) => {
  256. if (item.RoleId == p.RoleId) {
  257. datas.push(index);
  258. }
  259. });
  260. });
  261. this.checkList = datas;
  262. },
  263. //获取列表
  264. async getRoleData (ids, names) {
  265. try {
  266. this.loading = true;
  267. const obj = {
  268. QueryName: "",
  269. PageIndex: this.pageNum,
  270. PageSize: this.pageSize,
  271. };
  272. let result = null;
  273. if (this.roleType == "account") {
  274. result = await GetAccountList(obj);
  275. }
  276. if (this.roleType == "onlyRole") {
  277. result = await QueryRole(obj);
  278. }
  279. if (result.code === 0) {
  280. const datas = result.returnData.records;
  281. const num = result.returnData.pages;
  282. this.arrsList.push(datas);
  283. const arrs = this.arrsList.flat();
  284. const msgs = _.unionBy(arrs, ids);
  285. msgs.forEach(item => {
  286. item.name = item[names]
  287. });
  288. this.dataList = msgs;
  289. this.total = num;
  290. this.$emit('roleListChange', msgs)
  291. this.loading = false;
  292. } else {
  293. this.$message.error(result.message);
  294. this.loading = false;
  295. }
  296. } catch (error) {
  297. console.log("出错了", error);
  298. this.loading = false;
  299. }
  300. },
  301. //获取列表2
  302. async getRoleDataByUpId () {
  303. try {
  304. this.loading = true;
  305. const obj = {
  306. GroupIds: this.GroupIds
  307. };
  308. const result = await GetRoleByGroup(obj);
  309. if (result.code === 0) {
  310. const datas = result.returnData;
  311. const msgs = [];
  312. if (datas.length) {
  313. datas.forEach(item => {
  314. item.name = item.RoleName
  315. if (item.IsSelected) {
  316. msgs.push(item);
  317. }
  318. })
  319. this.dataList = msgs;
  320. } else {
  321. this.dataList = msgs;
  322. }
  323. this.$emit('roleListChange', msgs)
  324. // this.checkBoxs(this.dataList, "RoleId");
  325. this.loading = false;
  326. } else {
  327. this.$message.error(result.message);
  328. this.loading = false;
  329. }
  330. } catch (error) {
  331. console.log("出错了", error);
  332. this.loading = false;
  333. }
  334. },
  335. //滚动加载数据
  336. load () {
  337. this.pageNum += 1;
  338. if (this.roleType == 'account') {
  339. this.getRoleData('UserId', 'UserName');
  340. }
  341. if (this.roleType == 'onlyRole') {
  342. this.getRoleData('RoleId', 'RoleName');
  343. }
  344. },
  345. },
  346. };
  347. </script>
  348. <style lang="scss" scoped>
  349. @import "./rolelist.scss";
  350. .paren_content {
  351. ::v-deep .el-radio__label {
  352. display: none;
  353. }
  354. ::v-deep .el-checkbox__label {
  355. display: none;
  356. }
  357. // .scCont {
  358. // height: 65vh;
  359. // overflow-x: hidden;
  360. // overflow-y: auto;
  361. // }
  362. }
  363. </style>